task9.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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-dws/apis"
  6. "adm-dws/consts"
  7. "adm-dws/model"
  8. "encoding/json"
  9. "gorm.io/gorm"
  10. "strings"
  11. )
  12. // vin定型数据
  13. func Dws9Task(db *gorm.DB, dwsMessage *apis.DwsMessage, outputSourceCode string) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) {
  14. dws9 := &model.Dws9{}
  15. err = json.Unmarshal([]byte(dwsMessage.Content), dws9)
  16. if err != nil {
  17. return nil, nil, nil
  18. }
  19. if dws9.ThirdStyleIds != "" {
  20. if strings.Contains(dws9.ThirdStyleIds, ",") {
  21. return nil, nil, nil
  22. } else {
  23. dws9.ThirdStyleId = dws9.ThirdStyleIds
  24. }
  25. }
  26. if dws9.Vin == "" || dws9.ThirdStyleId == "" {
  27. return nil, nil, nil
  28. }
  29. err = dws9.Query(db, map[string]interface{}{"vin": dws9.Vin, "third_style_id": dws9.ThirdStyleId, "source": dws9.Source})
  30. if err != nil {
  31. if err != gorm.ErrRecordNotFound {
  32. return nil, nil, err
  33. }
  34. } else {
  35. return nil, nil, nil
  36. }
  37. err = dws9.Insert(db)
  38. if err != nil {
  39. if !strings.Contains(err.Error(), "Duplicate") {
  40. return nil, nil, err
  41. } else {
  42. return nil, nil, nil
  43. }
  44. }
  45. adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
  46. msgByte, _ := json.Marshal(*dws9)
  47. adsMsg.Content = string(msgByte)
  48. adsMsgList = append(adsMsgList, adsMsg)
  49. return adsMsgList, nil, nil
  50. }