123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package task
- import (
- "adm-dws/apis"
- "adm-dws/consts"
- "adm-dws/model"
- "encoding/json"
- "gorm.io/gorm"
- "strings"
- )
- // 车牌vin关系表(无号牌种类)
- func Dws4Task(db *gorm.DB,dwsMessage *apis.DwsMessage, outputSourceCode string) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) {
- // 解析数据
- dws4 := &model.Dws4{}
- err = json.Unmarshal([]byte(dwsMessage.Content), dws4)
- if err != nil {
- return nil, nil, nil
- }
- // 参数判断
- if dws4.PlateNo == "" || dws4.Vin == "" {
- return nil, nil, nil
- }
- isIn, err := isInDws2(db,dws4.PlateNo, dws4.PlateType, dws4.Vin)
- if err != nil {
- return nil, nil, err
- }
- if isIn {
- return nil, nil, nil
- }
- where := map[string]interface{}{"plate_no": dws4.PlateNo, "vin": dws4.Vin}
- err = dws4.Query(db, where)
- if err != nil {
- // 没有数据
- if err == gorm.ErrRecordNotFound {
- err = dws4.Insert(db)
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, nil, err
- }
- return nil,nil,nil
- }
- }else{
- // 数据库错误
- return nil, nil, err
- }
- } else {
- // 有数据
- return nil,nil,nil
- }
- adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
- msgByte, _ := json.Marshal(*dws4)
- adsMsg.Content = string(msgByte)
- adsMsgList = append(adsMsgList,adsMsg)
- return adsMsgList, nil, nil
- }
|