task21.go 851 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/model"
  7. "encoding/json"
  8. "strings"
  9. "adm-ads/common.in/clinit"
  10. "gorm.io/gorm"
  11. )
  12. // vin码model_no关系
  13. func Task21(adsMsg *apis.AdsMessage) (err error) {
  14. ads21 := &model.Ads21{}
  15. err = json.Unmarshal([]byte(adsMsg.Content), ads21)
  16. if err != nil {
  17. return nil
  18. }
  19. if ads21.ModelNo == "" || ads21.VinRule == "" || ads21.Uniq == "" {
  20. return nil
  21. }
  22. db := clinit.DB()
  23. err = ads21.Query(db, map[string]interface{}{"uniq": ads21.Uniq})
  24. if err != nil {
  25. if err != gorm.ErrRecordNotFound {
  26. return err
  27. }
  28. } else {
  29. return nil
  30. }
  31. err = ads21.Insert(db)
  32. if err != nil {
  33. if !strings.Contains(err.Error(), "Duplicate") {
  34. return err
  35. } else {
  36. return nil
  37. }
  38. }
  39. return nil
  40. }