task19.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package task
  4. import (
  5. "adm-ads/apis"
  6. "adm-ads/model"
  7. "encoding/json"
  8. "strings"
  9. "adm-ads/common.in/clinit"
  10. "gorm.io/gorm"
  11. )
  12. func supplementAds19(old, new *model.Ads19) 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 Task19(adsMsg *apis.AdsMessage) (err error) {
  150. ads19 := &model.Ads19{}
  151. err = json.Unmarshal([]byte(adsMsg.Content), ads19)
  152. if err != nil {
  153. return nil
  154. }
  155. if ads19.ModelNo == "" || ads19.VehicleBatch == "" {
  156. return nil
  157. }
  158. db := clinit.DB()
  159. oldAds19 := &model.Ads19{}
  160. err = oldAds19.Query(db, map[string]interface{}{"model_no": ads19.ModelNo, "vehicle_batch": ads19.VehicleBatch})
  161. if err != nil {
  162. if err != gorm.ErrRecordNotFound {
  163. return err
  164. }
  165. // 查无直接插入
  166. err = ads19.Insert(db)
  167. if err != nil {
  168. if !strings.Contains(err.Error(), "Duplicate") {
  169. return err
  170. } else {
  171. return nil
  172. }
  173. }
  174. } else {
  175. // 有数据更新
  176. isSupple := supplementAds19(oldAds19, ads19)
  177. if !isSupple { // 无更新
  178. return nil
  179. }
  180. err = oldAds19.Update(db)
  181. if err != nil {
  182. return err
  183. }
  184. }
  185. return nil
  186. }