ods4.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 204 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 ParasOds4(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("vinOrPlateNumber").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["engine_type"] = gjson.Get(rdata, "fdjxh").String()
  33. dataMap["engine_no"] = gjson.Get(rdata, "fdjh").String()
  34. dataMap["model_no"] = gjson.Get(rdata, "clxh").String()
  35. dataMap["vin"] = gjson.Get(rdata, "vin").String()
  36. dataMap["initial_registration_date"] = gjson.Get(rdata, "registerDate").String()
  37. dataMap["brand_name"] = gjson.Get(rdata, "brand").String()
  38. ret = append(ret, dataMap)
  39. return ret, nil
  40. }
  41. // ZR 车牌查车五项或者vin
  42. func HandleOnlineOds4(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
  43. dataMapList, err = ParasOds4(msg.Content)
  44. if err != nil {
  45. // 解析不出来数据直接返回
  46. return nil, nil
  47. }
  48. if len(dataMapList) == 0 {
  49. return nil, nil
  50. }
  51. // 入本地库
  52. ods4 := &model.Ods4{}
  53. ods4.PlateNo = dataMapList[0]["plate_no"]
  54. //ods4.PlateType = dataMapList[0]["plate_type"]
  55. //ods4.Owner = dataMapList[0]["owner"]
  56. ods4.Content = msg.Content
  57. err = ods4.Insert(clinit.DB())
  58. if err != nil {
  59. if !strings.Contains(err.Error(), "Duplicate") {
  60. return nil, err
  61. } else {
  62. where := map[string]interface{}{"plate_no": ods4.PlateNo}
  63. oldOds4 := &model.Ods4{}
  64. err = oldOds4.Query(clinit.DB(), where)
  65. if err == nil {
  66. oldDataMapList, _ := ParasOds4(oldOds4.Content)
  67. if checkDataMapListEqual(oldDataMapList, dataMapList) {
  68. return nil, nil
  69. }
  70. }
  71. ods4.UpdateWhere(clinit.DB(), where)
  72. }
  73. }
  74. return dataMapList, nil
  75. }