ods1.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. "go.uber.org/zap"
  12. "strings"
  13. )
  14. // CXY 违章查询
  15. func ParasOds1(content string) (ret []map[string]string, err error) {
  16. data := gjson.Parse(content)
  17. rawCode := data.Get("raw_code").String()
  18. dataMap := make(map[string]string)
  19. if rawCode == "0" || rawCode == "-6" {
  20. arrayStr := data.Get("request_params").String()
  21. array := gjson.Parse(arrayStr).Array()
  22. if len(array) < 2 {
  23. return nil, fmt.Errorf("数据异常,没有数据")
  24. }
  25. requestParams := array[1]
  26. dataMap["plate_no"] = requestParams.Get("carnumber").String()
  27. dataMap["plate_type"] = requestParams.Get("cartype").String()
  28. dataMap["vin"] = requestParams.Get("carcode").String()
  29. dataMap["engine_no"] = requestParams.Get("cardrivenumber").String()
  30. if rawCode == "0" {
  31. dataMap["is_expire"] = consts.NORMALDATA
  32. } else {
  33. dataMap["is_expire"] = consts.EXPIREDATA
  34. }
  35. return append(ret, dataMap), nil
  36. }
  37. l.Error("func",
  38. zap.String("call", "ParasOds2"),
  39. zap.String("args", content),
  40. zap.String("error", "数据异常,无法解析"))
  41. return nil, fmt.Errorf("数据异常")
  42. }
  43. func HandleOnlineOds1(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
  44. dataMapList, err = ParasOds1(msg.Content)
  45. if err != nil {
  46. // 解析不出来数据直接返回
  47. return nil, nil
  48. }
  49. if len(dataMapList) == 0 {
  50. return nil, nil
  51. }
  52. // 如本地库
  53. ods1 := &model.Ods1{}
  54. ods1.Vin = dataMapList[0]["vin"]
  55. ods1.PlateType = dataMapList[0]["plate_type"]
  56. ods1.PlateNo = dataMapList[0]["plate_no"]
  57. ods1.EngineNo = dataMapList[0]["engine_no"]
  58. ods1.Content = msg.Content
  59. err = ods1.Insert(clinit.DB())
  60. if err != nil {
  61. if !strings.Contains(err.Error(), "Duplicate") {
  62. return nil, err
  63. } else {
  64. // 如果存在判断是否字段相等
  65. where := map[string]interface{}{"vin": ods1.Vin, "plate_no": ods1.PlateNo, "plate_type": ods1.PlateType, "engine_no": ods1.EngineNo}
  66. oldOds1 := &model.Ods1{}
  67. err = oldOds1.Query(clinit.DB(), where)
  68. if err == nil {
  69. oldDataMapList, _ := ParasOds1(oldOds1.Content)
  70. if checkDataMapListEqual(oldDataMapList, dataMapList) {
  71. return nil, nil
  72. }
  73. }
  74. ods1.UpdateWhere(clinit.DB(), where)
  75. }
  76. }
  77. // 构建消息
  78. /*for _, dataMap := range dataMapList {
  79. dwsMsg := dutils.NewDwsMessage(msg)
  80. dwsMsg.Content = utils.MarshalJsonString(dataMap)
  81. ret = append(ret, dwsMsg)
  82. }*/
  83. return dataMapList, nil
  84. }