task8.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package task
  4. import (
  5. "adm-ads/apis"
  6. "adm-ads/common.in/clinit"
  7. "adm-ads/consts"
  8. "adm-ads/model"
  9. "encoding/json"
  10. "gorm.io/gorm"
  11. "strings"
  12. )
  13. // 处理任务8的删除
  14. func handleTask8Delete(ads8 *model.Ads8) error {
  15. err := ads8.Delete(clinit.DB(),map[string]interface{}{"vin":ads8.Vin,"third_style_id":ads8.ThirdStyleId,"source":ads8.Source})
  16. if err == gorm.ErrRecordNotFound{
  17. return nil
  18. }
  19. return err
  20. }
  21. // 处理任务8的插入
  22. func handleTask8InsertOrUpdate(ads8 *model.Ads8)error{
  23. err := ads8.Insert(clinit.DB())
  24. if err != nil && !strings.Contains(err.Error(), "Duplicate") {
  25. return err
  26. }
  27. return nil
  28. }
  29. // vin定型
  30. func Task8(adsMsg *apis.AdsMessage) (err error) {
  31. ads8 := &model.Ads8{}
  32. json.Unmarshal([]byte(adsMsg.Content),&ads8)
  33. if ads8.Vin == "" || ads8.ThirdStyleId == "" {
  34. return nil
  35. }
  36. if adsMsg.Action == consts.ACTIONDELETE{
  37. // 删除
  38. err = handleTask8Delete(ads8)
  39. }else{
  40. // 新增或插入
  41. err = handleTask8InsertOrUpdate(ads8)
  42. }
  43. return err
  44. }