task16.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. // Copyright 2019 autocareai.com. All rights reserved.
  2. // Use of this source code is governed by autocareai.com.
  3. package task
  4. import (
  5. "gadm-dws/apis"
  6. "gadm-dws/consts"
  7. "gadm-dws/model"
  8. "encoding/json"
  9. "gorm.io/gorm"
  10. "strings"
  11. )
  12. func supplementDws16(old, new *model.Dws16) (bool) {
  13. isSupple := false
  14. if old.BrandName == "" && new.BrandName != ""{
  15. isSupple = true
  16. old.BrandName = new.BrandName
  17. }
  18. if old.VehicleTypeDetail == "" && new.VehicleTypeDetail != ""{
  19. isSupple = true
  20. old.VehicleTypeDetail = new.VehicleTypeDetail
  21. }
  22. if old.ApprovedLoad == "" && new.ApprovedLoad != ""{
  23. isSupple = true
  24. old.ApprovedLoad = new.ApprovedLoad
  25. }
  26. if old.GrossMass == "" && new.GrossMass != ""{
  27. isSupple = true
  28. old.GrossMass = new.GrossMass
  29. }
  30. if old.UnladenMass == "" && new.UnladenMass != ""{
  31. isSupple = true
  32. old.UnladenMass = new.UnladenMass
  33. }
  34. if old.FuelTypeDetail == "" && new.FuelTypeDetail != ""{
  35. isSupple = true
  36. old.FuelTypeDetail = new.FuelTypeDetail
  37. }
  38. if old.AxleNumber == "" && new.AxleNumber != ""{
  39. isSupple = true
  40. old.AxleNumber = new.AxleNumber
  41. }
  42. if old.EmissionStandard == "" && new.EmissionStandard != ""{
  43. isSupple = true
  44. old.EmissionStandard = new.EmissionStandard
  45. }
  46. if old.Wheelbase == "" && new.Wheelbase != ""{
  47. isSupple = true
  48. old.Wheelbase = new.Wheelbase
  49. }
  50. if old.AxleWeight == "" && new.AxleWeight != ""{
  51. isSupple = true
  52. old.AxleWeight = new.AxleWeight
  53. }
  54. if old.NumberOfLeafSprings == "" && new.NumberOfLeafSprings != ""{
  55. isSupple = true
  56. old.NumberOfLeafSprings = new.NumberOfLeafSprings
  57. }
  58. if old.TyreNumber == "" && new.TyreNumber != ""{
  59. isSupple = true
  60. old.TyreNumber = new.TyreNumber
  61. }
  62. if old.TyreSize == "" && new.TyreSize != ""{
  63. isSupple = true
  64. old.TyreSize = new.TyreSize
  65. }
  66. if old.ApproachingDepartureAngle == "" && new.ApproachingDepartureAngle != ""{
  67. isSupple = true
  68. old.ApproachingDepartureAngle = new.ApproachingDepartureAngle
  69. }
  70. if old.FrontBackSuspention == "" && new.FrontBackSuspention != ""{
  71. isSupple = true
  72. old.FrontBackSuspention = new.FrontBackSuspention
  73. }
  74. if old.FrontWheelDistance == "" && new.FrontWheelDistance != ""{
  75. isSupple = true
  76. old.FrontWheelDistance = new.FrontWheelDistance
  77. }
  78. if old.BackWheelDistance == "" && new.BackWheelDistance != ""{
  79. isSupple = true
  80. old.BackWheelDistance = new.BackWheelDistance
  81. }
  82. if old.VinRules == "" && new.VinRules != ""{
  83. isSupple = true
  84. old.VinRules = new.VinRules
  85. }
  86. if old.Long == "" && new.Long != ""{
  87. isSupple = true
  88. old.Long = new.Long
  89. }
  90. if old.Wide == "" && new.Wide != ""{
  91. isSupple = true
  92. old.Wide = new.Wide
  93. }
  94. if old.High == "" && new.High != ""{
  95. isSupple = true
  96. old.High = new.High
  97. }
  98. if old.CargoLong == "" && new.CargoLong != ""{
  99. isSupple = true
  100. old.CargoLong = new.CargoLong
  101. }
  102. if old.CargoWide == "" && new.CargoWide != ""{
  103. isSupple = true
  104. old.CargoWide = new.CargoWide
  105. }
  106. if old.CargoHigh == "" && new.CargoHigh != ""{
  107. isSupple = true
  108. old.CargoHigh = new.CargoHigh
  109. }
  110. if old.TopSpeed == "" && new.TopSpeed != ""{
  111. isSupple = true
  112. old.TopSpeed = new.TopSpeed
  113. }
  114. if old.ApprovedNumber == "" && new.ApprovedNumber != ""{
  115. isSupple = true
  116. old.ApprovedNumber = new.ApprovedNumber
  117. }
  118. if old.NumberOfPassengers == "" && new.NumberOfPassengers != ""{
  119. isSupple = true
  120. old.NumberOfPassengers = new.NumberOfPassengers
  121. }
  122. if old.SteeringMode == "" && new.SteeringMode != ""{
  123. isSupple = true
  124. old.SteeringMode = new.SteeringMode
  125. }
  126. if old.TractionMass == "" && new.TractionMass != ""{
  127. isSupple = true
  128. old.TractionMass = new.TractionMass
  129. }
  130. if old.LoadMassCoefficient == "" && new.LoadMassCoefficient != ""{
  131. isSupple = true
  132. old.LoadMassCoefficient = new.LoadMassCoefficient
  133. }
  134. if old.SemitrailerSaddleMaxAllowGrossMass == "" && new.SemitrailerSaddleMaxAllowGrossMass != ""{
  135. isSupple = true
  136. old.SemitrailerSaddleMaxAllowGrossMass = new.SemitrailerSaddleMaxAllowGrossMass
  137. }
  138. if old.CompanyName == "" && new.CompanyName != ""{
  139. isSupple = true
  140. old.CompanyName = new.CompanyName
  141. }
  142. if old.CompanyAddress == "" && new.CompanyAddress != ""{
  143. isSupple = true
  144. old.CompanyAddress = new.CompanyAddress
  145. }
  146. return isSupple
  147. }
  148. // 商车网信息
  149. func Dws16Task(db *gorm.DB,dwsMessage *apis.DwsMessage, outputSourceCode string) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) {
  150. dws16 := &model.Dws16{}
  151. err = json.Unmarshal([]byte(dwsMessage.Content), dws16)
  152. if err != nil {
  153. return nil, nil, nil
  154. }
  155. if dws16.VehicleBatch == ""{
  156. dws16.VehicleBatch = "0"
  157. }
  158. if dws16.ModelNo == "" {
  159. return nil, nil, nil
  160. }
  161. dws16.ModelNo = strings.Replace(dws16.ModelNo,",","",-1)
  162. if dws16.Long != ""{
  163. dws16.Long = strings.Replace(dws16.Long,`"`,"",-1)
  164. }
  165. if dws16.Wide != ""{
  166. dws16.Wide = strings.Replace(dws16.Wide,`"`,"",-1)
  167. }
  168. if dws16.High != ""{
  169. dws16.High = strings.Replace(dws16.High,`"`,"",-1)
  170. }
  171. if dws16.ApprovedNumber != ""{
  172. dws16.ApprovedNumber = strings.Replace(dws16.ApprovedNumber,`"`,"",-1)
  173. }
  174. if dws16.GrossMass != ""{
  175. dws16.GrossMass = strings.Replace(dws16.GrossMass,`"`,"",-1)
  176. }
  177. if dws16.UnladenMass != ""{
  178. dws16.UnladenMass = strings.Replace(dws16.UnladenMass,`"`,"",-1)
  179. }
  180. oldDws16 := &model.Dws16{}
  181. // 批次为0 判断model_no 是否存在
  182. if dws16.VehicleBatch == "0"{
  183. err = oldDws16.Query(db,map[string]interface{}{"model_no":dws16.ModelNo})
  184. if err == nil{
  185. return nil, nil, nil
  186. }
  187. }
  188. err = oldDws16.Query(db,map[string]interface{}{"model_no":dws16.ModelNo,"vehicle_batch":dws16.VehicleBatch})
  189. if err != nil{
  190. if err != gorm.ErrRecordNotFound{
  191. return nil,nil,err
  192. }
  193. // 查无直接插入
  194. err = dws16.Insert(db)
  195. if err != nil{
  196. if !strings.Contains(err.Error(), "Duplicate") {
  197. return nil, nil,err
  198. }else{
  199. return nil,nil ,nil
  200. }
  201. }
  202. }else{
  203. // 有数据更新
  204. isSupple := supplementDws16(oldDws16,dws16)
  205. if !isSupple{// 无更新
  206. return nil ,nil ,nil
  207. }
  208. err = oldDws16.Update(db)
  209. if err != nil{
  210. return nil,nil, err
  211. }
  212. dws16 = oldDws16
  213. }
  214. adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
  215. msgByte, _ := json.Marshal(*dws16)
  216. adsMsg.Content = string(msgByte)
  217. adsMsgList = append(adsMsgList,adsMsg)
  218. return adsMsgList, nil, nil
  219. //return nil, nil, nil
  220. }