123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- // 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"
- )
- func supplementDws13(old, new *model.Dws13) (bool) {
- isSupple := false
- if old.ThirdBrandId == "" && new.ThirdBrandId != ""{
- isSupple = true
- old.ThirdBrandId = new.ThirdBrandId
- }
- if old.ThirdSeriesId == "" && new.ThirdSeriesId != ""{
- isSupple = true
- old.ThirdSeriesId = new.ThirdSeriesId
- }
- if old.ThirdBrandName == "" && new.ThirdBrandName != ""{
- isSupple = true
- old.ThirdBrandName = new.ThirdBrandName
- }
- if old.ThirdSeriesName == "" && new.ThirdSeriesName != ""{
- isSupple = true
- old.ThirdSeriesName = new.ThirdSeriesName
- }
- if old.ThirdStyleName == "" && new.ThirdStyleName != ""{
- isSupple = true
- old.ThirdStyleName = new.ThirdStyleName
- }
- if old.ThirdMaker == "" && new.ThirdMaker != ""{
- isSupple = true
- old.ThirdMaker = new.ThirdMaker
- }
- if old.ModelYear == "" && new.ModelYear != ""{
- isSupple = true
- old.ModelYear = new.ModelYear
- }
- if old.StyleId == "" && new.StyleId != ""{
- isSupple = true
- old.StyleId = new.StyleId
- }
- return isSupple
- }
- // 车型映射
- func Dws13Task(db *gorm.DB,dwsMessage *apis.DwsMessage, outputSourceCode string) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) {
- dws13 := &model.Dws13{}
- err = json.Unmarshal([]byte(dwsMessage.Content), dws13)
- if err != nil {
- return nil, nil, nil
- }
- if dws13.ThirdStyleId == ""{
- return nil, nil, nil
- }
- oldDws13 := &model.Dws13{}
- err = oldDws13.Query(db,map[string]interface{}{"third_style_id":dws13.ThirdStyleId,"source":dws13.Source})
- if err != nil{
- if err != gorm.ErrRecordNotFound{
- return nil,nil,err
- }
- // 查无直接插入
- err = dws13.Insert(db)
- if err != nil{
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, nil,err
- }else{
- return nil,nil ,nil
- }
- }
- }else{
- // 有数据更新
- isSupple := supplementDws13(oldDws13,dws13)
- if !isSupple{// 无更新
- return nil ,nil ,nil
- }
- err = oldDws13.Update(db)
- if err != nil{
- return nil,nil, err
- }
- dws13 = oldDws13
- }
- adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
- msgByte, _ := json.Marshal(*dws13)
- adsMsg.Content = string(msgByte)
- adsMsgList = append(adsMsgList,adsMsg)
- return adsMsgList, nil, nil
- }
|