ods5.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. // Copyright 2019 autocareai.com. All rights reserved.
  2. // Use of this source code is governed by autocareai.com.
  3. package analysis
  4. import (
  5. "gadm-ods/apis"
  6. "gadm-ods/common.in/clinit"
  7. "gadm-ods/model"
  8. "fmt"
  9. "github.com/tidwall/gjson"
  10. "go.uber.org/zap"
  11. "strings"
  12. "time"
  13. )
  14. // spy VIN查询车型信息128-001
  15. func ParasOds5(content string) (ret []map[string]string, err error) {
  16. data := gjson.Parse(content)
  17. requestParams := data.Get("request_params").String()
  18. responseParams := data.Get("response_params").String()
  19. vin := gjson.Get(requestParams, "vin").String()
  20. if vin == "" {
  21. return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
  22. }
  23. code := gjson.Get(responseParams, "respCode").String()
  24. if code != "0" {
  25. return nil, fmt.Errorf("数据异常,没有数据")
  26. }
  27. stateCode := gjson.Get(responseParams, "data.stateCode").String()
  28. if stateCode == "0" {
  29. return nil, fmt.Errorf("数据异常,没有数据")
  30. }
  31. respData := gjson.Get(responseParams, "data").String()
  32. if stateCode == "1" {
  33. arr := gjson.Get(respData, "vecStdVOS").Array()
  34. for _, v := range arr {
  35. dataMap := make(map[string]string)
  36. dataMap["vin"] = vin
  37. dataMap["approved_load"] = v.Get("approvedLoad").String()
  38. dataMap["release_date"] = time.Unix(v.Get("vinTime").Int()/1000, 0).Format("2006-01-02")
  39. dataMap["long"] = v.Get("wkc").String()
  40. dataMap["oil_wear"] = v.Get("yh").String()
  41. dataMap["engine_type"] = v.Get("fdjxh").String()
  42. dataMap["high"] = v.Get("wkg").String()
  43. dataMap["wide"] = v.Get("wkk").String()
  44. dataMap["vehicle_body_color_detail"] = v.Get("csys").String()
  45. dataMap["gross_mass"] = v.Get("zzl").String()
  46. dataMap["front_wheel_distance"] = v.Get("qlj").String()
  47. dataMap["axle_weight"] = v.Get("zh").String()
  48. dataMap["wheel_base"] = v.Get("zj").String()
  49. dataMap["model_no"] = v.Get("clxh").String()
  50. dataMap["axle_number"] = v.Get("zs").String()
  51. dataMap["approved_number"] = v.Get("edzk").String()
  52. plL := v.Get("plL").String()
  53. engineMod := v.Get("engineMod").String()
  54. plLMod := ""
  55. tmp := strings.Split(engineMod, " ")
  56. if len(tmp) > 0 {
  57. plLMod = tmp[0]
  58. }
  59. if plL != "" {
  60. tmp := strings.Replace(plL, "L", "", -1)
  61. tmp = strings.Replace(tmp, "T", "", -1)
  62. dataMap["displacement_l"] = tmp
  63. if strings.HasSuffix(plL, "L") {
  64. dataMap["air_intak_form"] = "L"
  65. } else if strings.HasSuffix(plL, "T") {
  66. dataMap["air_intak_form"] = "T"
  67. }
  68. } else if engineMod != "" {
  69. if plLMod != "" {
  70. pl := strings.Replace(plLMod, "L", "", -1)
  71. pl = strings.Replace(pl, "T", "", -1)
  72. dataMap["displacement_l"] = pl
  73. }
  74. }
  75. if dataMap["air_intak_form"] == "" {
  76. if plLMod != "" {
  77. if strings.HasSuffix(plLMod, "L") {
  78. dataMap["air_intak_form"] = "L"
  79. } else if strings.HasSuffix(plLMod, "T") {
  80. dataMap["air_intak_form"] = "T"
  81. }
  82. }
  83. }
  84. dataMap["engine_no"] = v.Get("fdjh").String()
  85. // TODO 拆分为前后轮胎规格
  86. dataMap["tyre_size"] = v.Get("ltgg").String()
  87. //dataMap["front_wheel_specification"] = dataMap["tyre_size"]
  88. //dataMap["back_wheel_specification"] = dataMap["tyre_size"]
  89. dataMap["fuel_type_detail"] = v.Get("oilWay").String()
  90. dataMap["use_property_detail"] = v.Get("syxz").String()
  91. dataMap["unladen_mass"] = v.Get("zbzl").String()
  92. dataMap["rated_power"] = v.Get("gl").String()
  93. dataMap["back_wheel_distance"] = v.Get("hlj").String()
  94. dataMap["vehicle_type_detail"] = v.Get("vecModType").String()
  95. dataMap["tyre_number"] = v.Get("lts").String()
  96. dataMap["traction_mass"] = v.Get("quasiTraction").String()
  97. dataMap["emission_standard"] = v.Get("pfbz").String()
  98. dataMap["brand_name"] = v.Get("automarkerInfo").String()
  99. dataMap["price"] = v.Get("autoPrice").String()
  100. dataMap["vehicle_structure"] = v.Get("bodyStruct").String()
  101. dataMap["model_year"] = v.Get("modelYear").String()
  102. //dataMap["axle_number"] = v.Get("wheelSum").String()
  103. dataMap["drive_type"] = v.Get("driveWay").String()
  104. dataMap["chassis_model"] = v.Get("chassisModel").String()
  105. if v.Get("cxid").String() != ""{
  106. dataMap["third_style_id"] = v.Get("cxid").String()
  107. dataMap["source"] = "1"
  108. }else{
  109. qczjId := v.Get("qczjId").String()
  110. if qczjId != "" {
  111. dataMap["third_style_id"] = qczjId
  112. dataMap["source"] = "2"
  113. }
  114. }
  115. dataMap["series_source"] = "1"
  116. /*if v.Get("catarcCode").Exists() {
  117. dataMap["third_style_id"] = v.Get("catarcCode").String()
  118. } else {
  119. dataMap["third_style_id"] = v.Get("cxid").String()
  120. }*/
  121. dataMap["third_series_id"] = v.Get("ccs5").String()
  122. dataMap["third_series_name"] = v.Get("vecMod").String()
  123. dataMap["third_style_name"] = v.Get("vecName").String()
  124. ret = append(ret, dataMap)
  125. }
  126. } else if stateCode == "2" {
  127. arr := gjson.Get(respData, "vinSycVO").Array()
  128. for _, v := range arr {
  129. dataMap := make(map[string]string)
  130. dataMap["vin"] = vin
  131. dataMap["approved_load"] = v.Get("ratedLoadMass").String()
  132. if v.Get("createTime").Int() != 0 {
  133. dataMap["release_date"] = time.Unix(v.Get("createTime").Int()/1000, 0).Format("2006-01-02")
  134. } else {
  135. dataMap["release_date"] = ""
  136. }
  137. dataMap["long"] = v.Get("length").String()
  138. dataMap["oil_wear"] = v.Get("oilLoss").String()
  139. dataMap["engine_type"] = v.Get("engineType").String()
  140. dataMap["high"] = v.Get("height").String()
  141. dataMap["wide"] = v.Get("wide").String()
  142. dataMap["gross_mass"] = v.Get("totalQuality").String()
  143. dataMap["front_wheel_distance"] = v.Get("frontGauge").String()
  144. dataMap["axle_weight"] = v.Get("axleLoad").String()
  145. dataMap["wheel_base"] = v.Get("wheelBase").String()
  146. dataMap["model_no"] = v.Get("vehicleNumber").String()
  147. dataMap["axle_number"] = v.Get("numberOfShaft").String()
  148. dataMap["approved_number"] = v.Get("ratedPassenger").String()
  149. dataMap["displacement"] = v.Get("displacement").String()
  150. dataMap["engine_no"] = v.Get("fdjh").String()
  151. dataMap["tyre_size"] = v.Get("tireSize").String()
  152. dataMap["fuel_type_detail"] = v.Get("fuelType").String()
  153. dataMap["unladen_mass"] = v.Get("curbWeight").String()
  154. dataMap["rated_power"] = v.Get("power").String()
  155. dataMap["back_wheel_distance"] = v.Get("trackRear").String()
  156. dataMap["vehicle_type_detail"] = v.Get("vehicleCategory").String() + v.Get("vehicleName").String()
  157. dataMap["tyre_number"] = v.Get("numberOfTires").String()
  158. dataMap["emission_standard"] = v.Get("emissionStandard").String()
  159. dataMap["brand_name"] = v.Get("brand").String()
  160. if v.Get("brand").String() == "" {
  161. dataMap["brand_name"] = v.Get("vehicleBrand").String()
  162. }
  163. dataMap["traction_mass"] = v.Get("totalMassOfQuasiTraction").String()
  164. dataMap["cargo_high"] = v.Get("cargoVanHeight").String()
  165. dataMap["cargo_long"] = v.Get("cargoVanLong").String()
  166. dataMap["cargo_wide"] = v.Get("cargoVanWide").String()
  167. dataMap["chassis_model"] = v.Get("chassisModel").String()
  168. //dataMap["drive_type"] = v.Get("drivingForm").String()
  169. //dataMap["vehicle_type_detail"] = v.Get("vehicleType").String()
  170. dataMap["number_of_leaf_springs"] = v.Get("numberOfLeafSprings").String()
  171. dataMap["number_of_passengers"] = v.Get("numberOfPassengers").String()
  172. ret = append(ret, dataMap)
  173. }
  174. } else if stateCode == "3" {
  175. arr := gjson.Get(respData, "vinMotoVO").Array()
  176. for _, v := range arr {
  177. dataMap := make(map[string]string)
  178. dataMap["vin"] = vin
  179. if v.Get("createTime").Int() != 0 {
  180. dataMap["release_date"] = time.Unix(v.Get("createTime").Int()/1000, 0).Format("2006-01-02")
  181. } else {
  182. dataMap["release_date"] = ""
  183. }
  184. dataMap["brand_name"] = v.Get("brand").String()
  185. if v.Get("brand").String() == "" {
  186. dataMap["brand_name"] = v.Get("vehicleBrand").String()
  187. }
  188. dataMap["front_wheel_distance"] = v.Get("frontGauge").String()
  189. dataMap["back_wheel_distance"] = v.Get("trackRear").String()
  190. dataMap["tyre_number"] = v.Get("numberOfTires").String()
  191. dataMap["tyre_size"] = v.Get("tireSize").String()
  192. dataMap["number_of_leaf_springs"] = v.Get("numberOfLeafSprings").String()
  193. dataMap["wheel_base"] = v.Get("wheelBase").String()
  194. dataMap["axle_weight"] = v.Get("axleLoad").String()
  195. dataMap["axle_number"] = v.Get("numberOfShaft").String()
  196. dataMap["long"] = v.Get("length").String()
  197. dataMap["wide"] = v.Get("wide").String()
  198. dataMap["high"] = v.Get("height").String()
  199. dataMap["cargo_long"] = v.Get("cargoVanLong").String()
  200. dataMap["cargo_wide"] = v.Get("cargoVanWide").String()
  201. dataMap["cargo_high"] = v.Get("cargoVanHeight").String()
  202. dataMap["gross_mass"] = v.Get("totalQuality").String()
  203. dataMap["approved_load"] = v.Get("ratedLoadMass").String()
  204. dataMap["unladen_mass"] = v.Get("curbWeight").String()
  205. dataMap["traction_mass"] = v.Get("totalMassOfQuasiTraction").String()
  206. dataMap["number_of_passengers"] = v.Get("numberOfPassengers").String()
  207. dataMap["approved_number"] = v.Get("ratedPassenger").String()
  208. dataMap["top_speed"] = v.Get("topSpeed").String()
  209. dataMap["model_no"] = v.Get("vehicleNumber").String()
  210. //vehicleCategory
  211. dataMap["vehicle_type_detail"] = v.Get("vehicleName").String()
  212. dataMap["emission_standard"] = v.Get("emissionStandard").String()
  213. dataMap["displacement"] = v.Get("displacement").String()
  214. dataMap["rated_power"] = v.Get("power").String()
  215. dataMap["engine_type"] = v.Get("engineType").String()
  216. dataMap["fuel_type_detail"] = v.Get("fuelType").String()
  217. // enterpriseName
  218. dataMap["engine_no"] = v.Get("fdjh").String()
  219. dataMap["vehicle_body_color_detail"] = v.Get("bodyColor").String()
  220. dataMap["steering_mode"] = v.Get("steeringMode").String()
  221. dataMap["is_moto"] = "1"
  222. ret = append(ret, dataMap)
  223. }
  224. }
  225. if len(ret) == 0 {
  226. l.Error("func",
  227. zap.String("call", "ParasOds5"),
  228. zap.String("args", content),
  229. zap.String("error", "数据异常,无法解析"))
  230. return nil, fmt.Errorf("数据异常")
  231. } else {
  232. return ret, nil
  233. }
  234. }
  235. func HandleOnlineOds5(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
  236. dataMapList, err = ParasOds5(msg.Content)
  237. if err != nil {
  238. // 解析不出来数据直接返回
  239. return nil, nil
  240. }
  241. if len(dataMapList) == 0 {
  242. return nil, nil
  243. }
  244. // 入本地库
  245. ods5 := &model.Ods5{}
  246. ods5.Vin = dataMapList[0]["vin"]
  247. ods5.Content = msg.Content
  248. err = ods5.Insert(clinit.DB())
  249. if err != nil {
  250. if !strings.Contains(err.Error(), "Duplicate") {
  251. return nil, err
  252. } else {
  253. where := map[string]interface{}{"vin": ods5.Vin}
  254. oldOds5 := &model.Ods5{}
  255. err = oldOds5.Query(clinit.DB(), where)
  256. if err == nil {
  257. oldDataMapList, _ := ParasOds5(oldOds5.Content)
  258. if checkDataMapListEqual(oldDataMapList, dataMapList) {
  259. return nil, nil
  260. }
  261. }
  262. ods5.UpdateWhere(clinit.DB(), where)
  263. }
  264. }
  265. /*for _, dataMap := range dataMapList {
  266. dwsMsg := dutils.NewDwsMessage(msg)
  267. dwsMsg.Content = utils.MarshalJsonString(dataMap)
  268. ret = append(ret, dwsMsg)
  269. }*/
  270. return dataMapList, nil
  271. }