ods13.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package analysis
  4. import (
  5. "adm-ods/apis"
  6. "adm-ods/common.in/clinit"
  7. "adm-ods/consts"
  8. "adm-ods/model"
  9. "fmt"
  10. "github.com/tidwall/gjson"
  11. "strings"
  12. )
  13. func dumpOds13() {
  14. }
  15. // ZJC 所有人验证(142-001)
  16. func ParasOds13(content string) (ret []map[string]string, err error) {
  17. data := gjson.Parse(content)
  18. requestParams := data.Get("request_params").String()
  19. requestParamsArray := gjson.Parse(requestParams).Array()
  20. if len(requestParamsArray) < 1 {
  21. return nil, fmt.Errorf("数据异常,没有数据")
  22. }
  23. requestParam := requestParamsArray[0]
  24. plateNo := requestParam.Get("carno").String()
  25. plateType := requestParam.Get("plateType").String()
  26. owner := requestParam.Get("name").String()
  27. if plateNo == "" || owner == "" {
  28. return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
  29. }
  30. responseParams := data.Get("response_params").String()
  31. errorCode := gjson.Get(responseParams, "err_code").String()
  32. if errorCode != "200" {
  33. return nil, fmt.Errorf("数据异常,没有数据", errorCode)
  34. }
  35. respData := gjson.Get(responseParams, "data").String()
  36. if respData == "" {
  37. return nil, fmt.Errorf("数据异常,没有数据")
  38. }
  39. detail := gjson.Get(respData, "vehicle_drivers_permit_detailed").String()
  40. detailCode := gjson.Get(detail, "code").String()
  41. if detailCode != "9100" {
  42. return nil, fmt.Errorf("数据异常,没有数据")
  43. }
  44. dataMap := make(map[string]string)
  45. dataMap["plate_no"] = plateNo
  46. dataMap["plate_type"] = plateType
  47. detailData := gjson.Get(detail, "data")
  48. ownerVerifyResult := detailData.Get("owerState").String()
  49. dataMap["owner"] = owner
  50. if ownerVerifyResult == "1" {
  51. dataMap["is_expire"] = consts.NORMALDATA
  52. } else {
  53. dataMap["is_expire"] = consts.EXPIREDATA
  54. }
  55. dataMap["brand_name"] = detailData.Get("brandName").String()
  56. dataMap["use_property"] = detailData.Get("useType").String()
  57. dataMap["vehicle_body_color"] = detailData.Get("bodyColor").String()
  58. dataMap["engine_no"] = detailData.Get("engineNumber").String()
  59. dataMap["vin"] = detailData.Get("frameVIN").String()
  60. dataMap["compulsory_scrap_to"] = detailData.Get("retirementDate").String()
  61. dataMap["engine_type"] = detailData.Get("engineType").String()
  62. dataMap["initial_registration_date"] = detailData.Get("firstIssueDate").String()
  63. dataMap["inspection_result_effective_to"] = detailData.Get("validityDayEnd").String()
  64. dataMap["fuel_type"] = detailData.Get("fuelType").String()
  65. dataMap["state"] = detailData.Get("vehicleStatus").String()
  66. dataMap["vehicle_type"] = detailData.Get("vehicleType").String()
  67. dataMap["approved_number"] = detailData.Get("passengers").String()
  68. dataMap["displacement"] = detailData.Get("displacement").String()
  69. dataMap["release_date"] = detailData.Get("productionDate").String()
  70. dataMap["rated_power"] = detailData.Get("maxJourney").String()
  71. dataMap["axle_number"] = detailData.Get("shaft").String()
  72. dataMap["wheel_base"] = detailData.Get("wheelBase").String()
  73. dataMap["front_wheel_distance"] = detailData.Get("frontTread").String()
  74. dataMap["back_wheel_distance"] = detailData.Get("rearTread").String()
  75. dataMap["gross_mass"] = detailData.Get("crossWeight").String()
  76. dataMap["unladen_mass"] = detailData.Get("curbWeight").String()
  77. dataMap["approved_load"] = detailData.Get("loadWeight").String()
  78. ret = append(ret, dataMap)
  79. return ret, nil
  80. }
  81. func HandleOnlineOds13(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
  82. dataMapList, err = ParasOds13(msg.Content)
  83. if err != nil {
  84. // 解析不出来数据直接返回
  85. return nil, nil
  86. }
  87. if len(dataMapList) == 0 {
  88. return nil, nil
  89. }
  90. // 入本地库
  91. ods13 := &model.Ods13{}
  92. ods13.PlateNo = dataMapList[0]["plate_no"]
  93. ods13.PlateType = dataMapList[0]["plate_type"]
  94. ods13.Owner = dataMapList[0]["owner"]
  95. ods13.Content = msg.Content
  96. err = ods13.Insert(clinit.DB())
  97. if err != nil {
  98. if !strings.Contains(err.Error(), "Duplicate") {
  99. return nil, err
  100. } else {
  101. where := map[string]interface{}{"plate_no": ods13.PlateNo, "plate_type": ods13.PlateType, "owner": ods13.Owner}
  102. oldOds13 := &model.Ods13{}
  103. err = oldOds13.Query(clinit.DB(), where)
  104. if err == nil {
  105. oldDataMapList, _ := ParasOds13(oldOds13.Content)
  106. if checkDataMapListEqual(oldDataMapList, dataMapList) {
  107. return nil, nil
  108. }
  109. }
  110. ods13.UpdateWhere(clinit.DB(), where)
  111. }
  112. }
  113. for _, dataMap := range dataMapList {
  114. if dataMap["is_expire"] == consts.EXPIREDATA {
  115. delete(dataMap, "owner")
  116. }
  117. }
  118. return dataMapList, nil
  119. }