123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- // 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 supplementDws16(old, new *model.Dws16) (bool) {
- isSupple := false
- if old.BrandName == "" && new.BrandName != ""{
- isSupple = true
- old.BrandName = new.BrandName
- }
- if old.VehicleTypeDetail == "" && new.VehicleTypeDetail != ""{
- isSupple = true
- old.VehicleTypeDetail = new.VehicleTypeDetail
- }
- if old.ApprovedLoad == "" && new.ApprovedLoad != ""{
- isSupple = true
- old.ApprovedLoad = new.ApprovedLoad
- }
- if old.GrossMass == "" && new.GrossMass != ""{
- isSupple = true
- old.GrossMass = new.GrossMass
- }
- if old.UnladenMass == "" && new.UnladenMass != ""{
- isSupple = true
- old.UnladenMass = new.UnladenMass
- }
- if old.FuelTypeDetail == "" && new.FuelTypeDetail != ""{
- isSupple = true
- old.FuelTypeDetail = new.FuelTypeDetail
- }
- if old.AxleNumber == "" && new.AxleNumber != ""{
- isSupple = true
- old.AxleNumber = new.AxleNumber
- }
- if old.EmissionStandard == "" && new.EmissionStandard != ""{
- isSupple = true
- old.EmissionStandard = new.EmissionStandard
- }
- if old.Wheelbase == "" && new.Wheelbase != ""{
- isSupple = true
- old.Wheelbase = new.Wheelbase
- }
- if old.AxleWeight == "" && new.AxleWeight != ""{
- isSupple = true
- old.AxleWeight = new.AxleWeight
- }
- if old.NumberOfLeafSprings == "" && new.NumberOfLeafSprings != ""{
- isSupple = true
- old.NumberOfLeafSprings = new.NumberOfLeafSprings
- }
- if old.TyreNumber == "" && new.TyreNumber != ""{
- isSupple = true
- old.TyreNumber = new.TyreNumber
- }
- if old.TyreSize == "" && new.TyreSize != ""{
- isSupple = true
- old.TyreSize = new.TyreSize
- }
- if old.ApproachingDepartureAngle == "" && new.ApproachingDepartureAngle != ""{
- isSupple = true
- old.ApproachingDepartureAngle = new.ApproachingDepartureAngle
- }
- if old.FrontBackSuspention == "" && new.FrontBackSuspention != ""{
- isSupple = true
- old.FrontBackSuspention = new.FrontBackSuspention
- }
- if old.FrontWheelDistance == "" && new.FrontWheelDistance != ""{
- isSupple = true
- old.FrontWheelDistance = new.FrontWheelDistance
- }
- if old.BackWheelDistance == "" && new.BackWheelDistance != ""{
- isSupple = true
- old.BackWheelDistance = new.BackWheelDistance
- }
- if old.VinRules == "" && new.VinRules != ""{
- isSupple = true
- old.VinRules = new.VinRules
- }
- if old.Long == "" && new.Long != ""{
- isSupple = true
- old.Long = new.Long
- }
- if old.Wide == "" && new.Wide != ""{
- isSupple = true
- old.Wide = new.Wide
- }
- if old.High == "" && new.High != ""{
- isSupple = true
- old.High = new.High
- }
- if old.CargoLong == "" && new.CargoLong != ""{
- isSupple = true
- old.CargoLong = new.CargoLong
- }
- if old.CargoWide == "" && new.CargoWide != ""{
- isSupple = true
- old.CargoWide = new.CargoWide
- }
- if old.CargoHigh == "" && new.CargoHigh != ""{
- isSupple = true
- old.CargoHigh = new.CargoHigh
- }
- if old.TopSpeed == "" && new.TopSpeed != ""{
- isSupple = true
- old.TopSpeed = new.TopSpeed
- }
- if old.ApprovedNumber == "" && new.ApprovedNumber != ""{
- isSupple = true
- old.ApprovedNumber = new.ApprovedNumber
- }
- if old.NumberOfPassengers == "" && new.NumberOfPassengers != ""{
- isSupple = true
- old.NumberOfPassengers = new.NumberOfPassengers
- }
- if old.SteeringMode == "" && new.SteeringMode != ""{
- isSupple = true
- old.SteeringMode = new.SteeringMode
- }
- if old.TractionMass == "" && new.TractionMass != ""{
- isSupple = true
- old.TractionMass = new.TractionMass
- }
- if old.LoadMassCoefficient == "" && new.LoadMassCoefficient != ""{
- isSupple = true
- old.LoadMassCoefficient = new.LoadMassCoefficient
- }
- if old.SemitrailerSaddleMaxAllowGrossMass == "" && new.SemitrailerSaddleMaxAllowGrossMass != ""{
- isSupple = true
- old.SemitrailerSaddleMaxAllowGrossMass = new.SemitrailerSaddleMaxAllowGrossMass
- }
- if old.CompanyName == "" && new.CompanyName != ""{
- isSupple = true
- old.CompanyName = new.CompanyName
- }
- if old.CompanyAddress == "" && new.CompanyAddress != ""{
- isSupple = true
- old.CompanyAddress = new.CompanyAddress
- }
- return isSupple
- }
- // 商车网信息
- func Dws16Task(db *gorm.DB,dwsMessage *apis.DwsMessage, outputSourceCode string) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) {
- dws16 := &model.Dws16{}
- err = json.Unmarshal([]byte(dwsMessage.Content), dws16)
- if err != nil {
- return nil, nil, nil
- }
- if dws16.VehicleBatch == ""{
- dws16.VehicleBatch = "0"
- }
- if dws16.ModelNo == "" {
- return nil, nil, nil
- }
- dws16.ModelNo = strings.Replace(dws16.ModelNo,",","",-1)
- if dws16.Long != ""{
- dws16.Long = strings.Replace(dws16.Long,`"`,"",-1)
- }
- if dws16.Wide != ""{
- dws16.Wide = strings.Replace(dws16.Wide,`"`,"",-1)
- }
- if dws16.High != ""{
- dws16.High = strings.Replace(dws16.High,`"`,"",-1)
- }
- if dws16.ApprovedNumber != ""{
- dws16.ApprovedNumber = strings.Replace(dws16.ApprovedNumber,`"`,"",-1)
- }
- if dws16.GrossMass != ""{
- dws16.GrossMass = strings.Replace(dws16.GrossMass,`"`,"",-1)
- }
- if dws16.UnladenMass != ""{
- dws16.UnladenMass = strings.Replace(dws16.UnladenMass,`"`,"",-1)
- }
- oldDws16 := &model.Dws16{}
- // 批次为0 判断model_no 是否存在
- if dws16.VehicleBatch == "0"{
- err = oldDws16.Query(db,map[string]interface{}{"model_no":dws16.ModelNo})
- if err == nil{
- return nil, nil, nil
- }
- }
- err = oldDws16.Query(db,map[string]interface{}{"model_no":dws16.ModelNo,"vehicle_batch":dws16.VehicleBatch})
- if err != nil{
- if err != gorm.ErrRecordNotFound{
- return nil,nil,err
- }
- // 查无直接插入
- err = dws16.Insert(db)
- if err != nil{
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, nil,err
- }else{
- return nil,nil ,nil
- }
- }
- }else{
- // 有数据更新
- isSupple := supplementDws16(oldDws16,dws16)
- if !isSupple{// 无更新
- return nil ,nil ,nil
- }
- err = oldDws16.Update(db)
- if err != nil{
- return nil,nil, err
- }
- dws16 = oldDws16
- }
- adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
- msgByte, _ := json.Marshal(*dws16)
- adsMsg.Content = string(msgByte)
- adsMsgList = append(adsMsgList,adsMsg)
- return adsMsgList, nil, nil
- //return nil, nil, nil
- }
|