task4.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 Dws4Task(db *gorm.DB,dwsMessage *apis.DwsMessage, outputSourceCode string) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) {
  14. // 解析数据
  15. dws4 := &model.Dws4{}
  16. err = json.Unmarshal([]byte(dwsMessage.Content), dws4)
  17. if err != nil {
  18. return nil, nil, nil
  19. }
  20. // 参数判断
  21. if dws4.PlateNo == "" || dws4.Vin == "" {
  22. return nil, nil, nil
  23. }
  24. isIn, err := isInDws2(db,dws4.PlateNo, dws4.PlateType, dws4.Vin)
  25. if err != nil {
  26. return nil, nil, err
  27. }
  28. if isIn {
  29. return nil, nil, nil
  30. }
  31. where := map[string]interface{}{"plate_no": dws4.PlateNo, "vin": dws4.Vin}
  32. err = dws4.Query(db, where)
  33. if err != nil {
  34. // 没有数据
  35. if err == gorm.ErrRecordNotFound {
  36. err = dws4.Insert(db)
  37. if err != nil {
  38. if !strings.Contains(err.Error(), "Duplicate") {
  39. return nil, nil, err
  40. }
  41. return nil,nil,nil
  42. }
  43. }else{
  44. // 数据库错误
  45. return nil, nil, err
  46. }
  47. } else {
  48. // 有数据
  49. return nil,nil,nil
  50. }
  51. adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
  52. msgByte, _ := json.Marshal(*dws4)
  53. adsMsg.Content = string(msgByte)
  54. adsMsgList = append(adsMsgList,adsMsg)
  55. return adsMsgList, nil, nil
  56. }