// 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 Dws17Task(db *gorm.DB, dwsMessage *apis.DwsMessage, outputSourceCode string) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) { dws17 := &model.Dws17{} err = json.Unmarshal([]byte(dwsMessage.Content), dws17) if err != nil { return nil, nil, nil } if dws17.ThirdStyleIds != "" { if !strings.Contains(dws17.ThirdStyleIds, ",") { return nil, nil, nil } } else { if dwsMessage.MsgLen == 1 { return nil, nil, nil } } if dws17.Vin == "" || (dws17.ThirdStyleIds == "" && dws17.ThirdStyleId == "") { return nil, nil, nil } if dws17.ThirdStyleIds == "" && dws17.ThirdStyleId != "" { dws17.ThirdStyleIds = dws17.ThirdStyleId } thirdStyleIdList := strings.Split(dws17.ThirdStyleIds, ",") for _, v := range thirdStyleIdList { dws17.ID = 0 dws17.ThirdStyleId = v err = dws17.Query(db, map[string]interface{}{"vin": dws17.Vin, "third_style_id": dws17.ThirdStyleId, "source": dws17.Source}) if err != nil { if err != gorm.ErrRecordNotFound { return nil, nil, err } } else { continue } err = dws17.Insert(db) if err != nil { if !strings.Contains(err.Error(), "Duplicate") { return nil, nil, err } else { continue } } adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT) msgByte, _ := json.Marshal(*dws17) adsMsg.Content = string(msgByte) adsMsgList = append(adsMsgList, adsMsg) } return adsMsgList, nil, nil }