ods10.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. // SPY 二要素验证(新能源)(128-008)
  13. func ParasOds10(content string) (ret []map[string]string, err error) {
  14. data := gjson.Parse(content)
  15. requestParams := data.Get("request_params").String()
  16. responseParams := data.Get("response_params").String()
  17. plateNo := gjson.Get(requestParams, "cp").String()
  18. owner := gjson.Get(requestParams, "name").String()
  19. code := gjson.Get(responseParams, "respCode").String()
  20. if code != "0" {
  21. return nil, fmt.Errorf("数据异常,没有数据")
  22. }
  23. if plateNo == "" || owner == "" {
  24. return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
  25. }
  26. dataMap := make(map[string]string)
  27. dataMap["plate_no"] = plateNo
  28. dataMap["owner"] = owner
  29. respData := gjson.Get(responseParams, "data").String()
  30. isMatch := gjson.Get(respData, "isMatch").Bool()
  31. if isMatch {
  32. ret = append(ret, dataMap)
  33. return ret, nil
  34. } else {
  35. return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
  36. }
  37. /*if isMatch {
  38. dataMap["is_expire"] = consts.NORMALDATA
  39. }else{
  40. dataMap["is_expire"] = consts.EXPIREDATA
  41. }
  42. ret = append(ret, dataMap)
  43. return ret, nil*/
  44. }
  45. func HandleOnlineOds10(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
  46. dataMapList, err = ParasOds10(msg.Content)
  47. if err != nil {
  48. // 解析不出来数据直接返回
  49. return nil, nil
  50. }
  51. if len(dataMapList) == 0 {
  52. return nil, nil
  53. }
  54. // 入本地库
  55. ods10 := &model.Ods10{}
  56. ods10.PlateNo = dataMapList[0]["plate_no"]
  57. ods10.Owner = dataMapList[0]["owner"]
  58. ods10.Content = msg.Content
  59. err = ods10.Insert(clinit.DB())
  60. if err != nil {
  61. if !strings.Contains(err.Error(), "Duplicate") {
  62. return nil, err
  63. } else {
  64. where := map[string]interface{}{"plate_no": ods10.PlateNo, "owner": ods10.Owner}
  65. oldOds10 := &model.Ods10{}
  66. err = oldOds10.Query(clinit.DB(), where)
  67. if err == nil {
  68. oldDataMapList, _ := ParasOds10(oldOds10.Content)
  69. if checkDataMapListEqual(oldDataMapList, dataMapList) {
  70. return nil, nil
  71. }
  72. }
  73. ods10.UpdateWhere(clinit.DB(), where)
  74. }
  75. }
  76. /*for _, dataMap := range dataMapList {
  77. dwsMsg := dutils.NewDwsMessage(msg)
  78. dwsMsg.Content = utils.MarshalJsonString(dataMap)
  79. ret = append(ret, dwsMsg)
  80. }*/
  81. return dataMapList, nil
  82. }