ods8.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright 208 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. "strings"
  11. )
  12. func ParasOds8(content string) (ret []map[string]string, err error) {
  13. data := gjson.Parse(content)
  14. requestParams := data.Get("request_params").String()
  15. requestParamsArray := gjson.Parse(requestParams).Array()
  16. if len(requestParamsArray) < 1 {
  17. return nil, fmt.Errorf("数据异常,没有数据")
  18. }
  19. requestParam := requestParamsArray[0]
  20. responseParams := data.Get("response_params").String()
  21. plateNo := requestParam.Get("plateNumber").String()
  22. if plateNo == ""{
  23. return nil, fmt.Errorf("数据异常")
  24. }
  25. dataMap := make(map[string]string)
  26. dataMap["plate_no"] = plateNo
  27. code := gjson.Get(responseParams, "code").String()
  28. if code != "0"{
  29. return nil , fmt.Errorf("数据异常,code不为0")
  30. }
  31. rdata := gjson.Get(responseParams, "data").String()
  32. dataMap["vehicle_type_detail"] = gjson.Get(rdata, "cllb").String() //"中型车"
  33. dataMap["vehicle_type"] = ""
  34. dataMap["engine_type"] = gjson.Get(rdata, "fdjxh").String()
  35. dataMap["rated_power"] = gjson.Get(rdata, "gl").String()
  36. dataMap["back_wheel_distance"] = gjson.Get(rdata, "hlj").String()
  37. dataMap["front_wheel_distance"] = gjson.Get(rdata, "qlj").String()
  38. dataMap["unladen_mass"] = gjson.Get(rdata, "zbzl").String()
  39. dataMap["use_property_detail"] = gjson.Get(rdata, "usage").String()
  40. dataMap["use_property"] = ""
  41. dataMap["gross_mass"] = gjson.Get(rdata, "zzl").String()
  42. dataMap["traction_mass"] = gjson.Get(rdata, "edqyzzl").String()
  43. dataMap["long"] = gjson.Get(rdata, "wkc").String()
  44. dataMap["wheel_base"] = gjson.Get(rdata, "zj").String()
  45. dataMap["high"] = gjson.Get(rdata, "wkg").String()
  46. dataMap["engine_no"] = gjson.Get(rdata, "fdjh").String()
  47. dataMap["approved_load"] = gjson.Get(rdata, "edzzl").String()
  48. //dataMap["state"] = gjson.Get(rdata, "clzl").String()
  49. dataMap["wide"] = gjson.Get(rdata, "wkk").String()
  50. dataMap["model_no"] = gjson.Get(rdata, "clxh").String()
  51. dataMap["fuel_type_detail"] = gjson.Get(rdata, "rlzl").String()
  52. dataMap["fuel_type"] = ""
  53. dataMap["axle_number"] = gjson.Get(rdata, "zs").String()
  54. dataMap["vin"] = gjson.Get(rdata, "vin").String()
  55. dataMap["emission_standard"] = gjson.Get(rdata, "pfbz").String()
  56. dataMap["displacement_l"] = gjson.Get(rdata, "pl").String()
  57. dataMap["displacement"] = ""
  58. dataMap["brand_name"] = gjson.Get(rdata, "brand").String()
  59. dataMap["initial_registration_date"] = gjson.Get(rdata, "registerDate").String()
  60. dataMap["approved_number"] = gjson.Get(rdata, "edzk").String()
  61. dataMap["vehicle_body_color_detail"] = gjson.Get(rdata, "csys").String()
  62. dataMap["vehicle_body_color"] = ""
  63. ret = append(ret, dataMap)
  64. return ret, nil
  65. }
  66. // ZR 车牌查车辆信息
  67. func HandleOnlineOds8(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
  68. dataMapList, err = ParasOds8(msg.Content)
  69. if err != nil {
  70. // 解析不出来数据直接返回
  71. return nil, nil
  72. }
  73. if len(dataMapList) == 0 {
  74. return nil, nil
  75. }
  76. // 入本地库
  77. ods8 := &model.Ods8{}
  78. ods8.PlateNo = dataMapList[0]["plate_no"]
  79. //ods8.PlateType = dataMapList[0]["plate_type"]
  80. //ods8.Owner = dataMapList[0]["owner"]
  81. ods8.Content = msg.Content
  82. err = ods8.Insert(clinit.DB())
  83. if err != nil {
  84. if !strings.Contains(err.Error(), "Duplicate") {
  85. return nil, err
  86. } else {
  87. where := map[string]interface{}{"plate_no": ods8.PlateNo}
  88. oldOds8 := &model.Ods8{}
  89. err = oldOds8.Query(clinit.DB(), where)
  90. if err == nil {
  91. oldDataMapList, _ := ParasOds8(oldOds8.Content)
  92. if checkDataMapListEqual(oldDataMapList, dataMapList) {
  93. return nil, nil
  94. }
  95. }
  96. ods8.UpdateWhere(clinit.DB(), where)
  97. }
  98. }
  99. return dataMapList, nil
  100. }