task9.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. // 处理任务9的删除
  14. func handleTask9Delete(ads9 *model.Ads9) error {
  15. err := ads9.Delete(clinit.DB(), map[string]interface{}{"uniq": ads9.Uniq})
  16. if err == gorm.ErrRecordNotFound {
  17. return nil
  18. }
  19. return err
  20. }
  21. // 处理任务9的插入
  22. func handleTask9InsertOrUpdate(ads9 *model.Ads9) error {
  23. err := ads9.Insert(clinit.DB())
  24. if err != nil && !strings.Contains(err.Error(), "Duplicate") {
  25. return err
  26. }
  27. return nil
  28. }
  29. // vin定型
  30. func Task9(adsMsg *apis.AdsMessage) (err error) {
  31. ads9 := &model.Ads9{}
  32. json.Unmarshal([]byte(adsMsg.Content), &ads9)
  33. if ads9.Uniq == "" || ads9.ModelNo == "" || ads9.SeriesId == "" || ads9.VinRule == "" {
  34. return nil
  35. }
  36. if adsMsg.Action == consts.ACTIONDELETE {
  37. // 删除
  38. err = handleTask9Delete(ads9)
  39. } else {
  40. // 新增或插入
  41. err = handleTask9InsertOrUpdate(ads9)
  42. }
  43. return err
  44. }