task23.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/consts"
  7. "adm-ads/model"
  8. "encoding/json"
  9. "strings"
  10. "adm-ads/common.in/clinit"
  11. "gorm.io/gorm"
  12. )
  13. // 处理任务23的删除
  14. func handleTask23Delete(ads23 *model.Ads23) error {
  15. err := ads23.Delete(clinit.DB(), map[string]interface{}{"vin": ads23.Vin, "third_style_id": ads23.ThirdStyleId, "source": ads23.Source})
  16. if err == gorm.ErrRecordNotFound {
  17. return nil
  18. }
  19. return err
  20. }
  21. // 处理任务23的插入
  22. func handleTask23InsertOrUpdate(ads23 *model.Ads23) error {
  23. err := ads23.Insert(clinit.DB())
  24. if err != nil && !strings.Contains(err.Error(), "Duplicate") {
  25. return err
  26. }
  27. return nil
  28. }
  29. // vin模糊定型
  30. func Task23(adsMsg *apis.AdsMessage) (err error) {
  31. ads23 := &model.Ads23{}
  32. json.Unmarshal([]byte(adsMsg.Content), &ads23)
  33. if ads23.Vin == "" || ads23.ThirdStyleId == "" {
  34. return nil
  35. }
  36. if adsMsg.Action == consts.ACTIONDELETE {
  37. // 删除
  38. err = handleTask23Delete(ads23)
  39. } else {
  40. // 新增或插入
  41. err = handleTask23InsertOrUpdate(ads23)
  42. }
  43. return err
  44. }