task17.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 Dws17Task(db *gorm.DB, dwsMessage *apis.DwsMessage, outputSourceCode string) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) {
  14. dws17 := &model.Dws17{}
  15. err = json.Unmarshal([]byte(dwsMessage.Content), dws17)
  16. if err != nil {
  17. return nil, nil, nil
  18. }
  19. if dws17.ThirdStyleIds != "" {
  20. if !strings.Contains(dws17.ThirdStyleIds, ",") {
  21. return nil, nil, nil
  22. }
  23. } else {
  24. if dwsMessage.MsgLen == 1 {
  25. return nil, nil, nil
  26. }
  27. }
  28. if dws17.Vin == "" || (dws17.ThirdStyleIds == "" && dws17.ThirdStyleId == "") {
  29. return nil, nil, nil
  30. }
  31. if dws17.ThirdStyleIds == "" && dws17.ThirdStyleId != "" {
  32. dws17.ThirdStyleIds = dws17.ThirdStyleId
  33. }
  34. thirdStyleIdList := strings.Split(dws17.ThirdStyleIds, ",")
  35. for _, v := range thirdStyleIdList {
  36. dws17.ID = 0
  37. dws17.ThirdStyleId = v
  38. err = dws17.Query(db, map[string]interface{}{"vin": dws17.Vin, "third_style_id": dws17.ThirdStyleId, "source": dws17.Source})
  39. if err != nil {
  40. if err != gorm.ErrRecordNotFound {
  41. return nil, nil, err
  42. }
  43. } else {
  44. continue
  45. }
  46. err = dws17.Insert(db)
  47. if err != nil {
  48. if !strings.Contains(err.Error(), "Duplicate") {
  49. return nil, nil, err
  50. } else {
  51. continue
  52. }
  53. }
  54. adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
  55. msgByte, _ := json.Marshal(*dws17)
  56. adsMsg.Content = string(msgByte)
  57. adsMsgList = append(adsMsgList, adsMsg)
  58. }
  59. return adsMsgList, nil, nil
  60. }