ods11.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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/model"
  8. "fmt"
  9. "github.com/tidwall/gjson"
  10. "strings"
  11. )
  12. // DRV 车牌姓名验证(138-002)
  13. func ParasOds11(content string) (ret []map[string]string, err error) {
  14. data := gjson.Parse(content)
  15. requestParams := data.Get("request_params").String()
  16. requestParamsArray := gjson.Parse(requestParams).Array()
  17. if len(requestParamsArray) < 1 {
  18. return nil, fmt.Errorf("数据异常,没有数据")
  19. }
  20. requestParam := requestParamsArray[0]
  21. plateNo := requestParam.Get("plateNumber").String()
  22. plateType := requestParam.Get("plateType").String()
  23. owner := requestParam.Get("name").String()
  24. responseParams := data.Get("response_params").String()
  25. respData := gjson.Get(responseParams, "data").String()
  26. if respData == "0" {
  27. return nil, fmt.Errorf("数据异常,没有数据")
  28. }
  29. verifyData := gjson.Parse(respData).Get("data").String()
  30. msg := gjson.Parse(respData).Get("msg").String()
  31. if verifyData != "1" {
  32. return nil, fmt.Errorf("数据异常,没有数据")
  33. }
  34. // 0为一致
  35. if msg != "0" {
  36. return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
  37. }
  38. if plateNo == "" || plateType == "" || owner == "" {
  39. return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
  40. }
  41. dataMap := make(map[string]string)
  42. dataMap["plate_no"] = plateNo
  43. dataMap["plate_type"] = plateType
  44. dataMap["owner"] = owner
  45. ret = append(ret, dataMap)
  46. return ret, nil
  47. }
  48. func HandleOnlineOds11(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
  49. dataMapList, err = ParasOds11(msg.Content)
  50. if err != nil {
  51. // 解析不出来数据直接返回
  52. return nil, nil
  53. }
  54. if len(dataMapList) == 0 {
  55. return nil, nil
  56. }
  57. // 入本地库
  58. ods11 := &model.Ods11{}
  59. ods11.PlateNo = dataMapList[0]["plate_no"]
  60. ods11.PlateType = dataMapList[0]["plate_type"]
  61. ods11.Owner = dataMapList[0]["owner"]
  62. ods11.Content = msg.Content
  63. err = ods11.Insert(clinit.DB())
  64. if err != nil {
  65. if !strings.Contains(err.Error(), "Duplicate") {
  66. return nil, err
  67. } else {
  68. where := map[string]interface{}{"plate_no": ods11.PlateNo, "plate_type": ods11.PlateType, "owner": ods11.Owner}
  69. oldOds11 := &model.Ods11{}
  70. err = oldOds11.Query(clinit.DB(), where)
  71. if err == nil {
  72. oldDataMapList, _ := ParasOds11(oldOds11.Content)
  73. if checkDataMapListEqual(oldDataMapList, dataMapList) {
  74. return nil, nil
  75. }
  76. }
  77. ods11.UpdateWhere(clinit.DB(), where)
  78. }
  79. }
  80. /*for _, dataMap := range dataMapList {
  81. dwsMsg := dutils.NewDwsMessage(msg)
  82. dwsMsg.Content = utils.MarshalJsonString(dataMap)
  83. ret = append(ret, dwsMsg)
  84. }*/
  85. return dataMapList, nil
  86. }