1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- // 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 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
- }
|