// Copyright 2019 autocareai.com. All rights reserved. // Use of this source code is governed by autocareai.com. package task import ( "gadm-dws/apis" "gadm-dws/consts" "gadm-dws/model" "encoding/json" "gorm.io/gorm" "strings" ) // vin定型数据 func Dws9Task(db *gorm.DB, dwsMessage *apis.DwsMessage, outputSourceCode string) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) { dws9 := &model.Dws9{} err = json.Unmarshal([]byte(dwsMessage.Content), dws9) if err != nil { return nil, nil, nil } if dws9.ThirdStyleIds != "" { if strings.Contains(dws9.ThirdStyleIds, ",") { return nil, nil, nil } else { dws9.ThirdStyleId = dws9.ThirdStyleIds } } if dws9.Vin == "" || dws9.ThirdStyleId == "" { return nil, nil, nil } err = dws9.Query(db, map[string]interface{}{"vin": dws9.Vin, "third_style_id": dws9.ThirdStyleId, "source": dws9.Source}) if err != nil { if err != gorm.ErrRecordNotFound { return nil, nil, err } } else { return nil, nil, nil } err = dws9.Insert(db) if err != nil { if !strings.Contains(err.Error(), "Duplicate") { return nil, nil, err } else { return nil, nil, nil } } adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT) msgByte, _ := json.Marshal(*dws9) adsMsg.Content = string(msgByte) adsMsgList = append(adsMsgList, adsMsg) return adsMsgList, nil, nil }