123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package task
- import (
- "adm-ads/apis"
- "adm-ads/model"
- "encoding/json"
- "strings"
- "adm-ads/common.in/clinit"
- "gorm.io/gorm"
- )
- func supplementAds19(old, new *model.Ads19) 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 Task19(adsMsg *apis.AdsMessage) (err error) {
- ads19 := &model.Ads19{}
- err = json.Unmarshal([]byte(adsMsg.Content), ads19)
- if err != nil {
- return nil
- }
- if ads19.ModelNo == "" || ads19.VehicleBatch == "" {
- return nil
- }
- db := clinit.DB()
- oldAds19 := &model.Ads19{}
- err = oldAds19.Query(db, map[string]interface{}{"model_no": ads19.ModelNo, "vehicle_batch": ads19.VehicleBatch})
- if err != nil {
- if err != gorm.ErrRecordNotFound {
- return err
- }
- // 查无直接插入
- err = ads19.Insert(db)
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return err
- } else {
- return nil
- }
- }
- } else {
- // 有数据更新
- isSupple := supplementAds19(oldAds19, ads19)
- if !isSupple { // 无更新
- return nil
- }
- err = oldAds19.Update(db)
- if err != nil {
- return err
- }
- }
- return nil
- }
|