ods8.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. dutils "adm-ods/utils"
  9. "fmt"
  10. "github.com/tidwall/gjson"
  11. "strings"
  12. )
  13. // SPY 首保日期查询(128-009)
  14. func ParasOds8(content string) (ret []map[string]string, err error) {
  15. data := gjson.Parse(content)
  16. requestParams := data.Get("request_params").String()
  17. responseParams := data.Get("response_params").String()
  18. cp := gjson.Get(requestParams, "queryByCp").String()
  19. if cp == "" {
  20. return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
  21. }
  22. code := gjson.Get(responseParams, "respCode").String()
  23. if code != "0" {
  24. return nil, fmt.Errorf("数据异常,没有数据")
  25. }
  26. dataMap := make(map[string]string)
  27. dataMap["cp"] = cp
  28. if dutils.IsPlate(cp) {
  29. dataMap["plate_no"] = cp
  30. } else {
  31. dataMap["vin"] = cp
  32. }
  33. respData := gjson.Get(responseParams, "data").String()
  34. dataMap["city"] = gjson.Get(respData, "city").String()
  35. dataMap["district"] = gjson.Get(respData, "district").String()
  36. dataMap["province"] = gjson.Get(respData, "province").String()
  37. dataMap["last_compulsory_insurance_date"] = gjson.Get(respData, "insuranceMonth").String()
  38. dataMap["insurance_first_date"] = gjson.Get(respData, "registerDate").String()
  39. dataMap["use_property_detail"] = gjson.Get(respData, "usage").String()
  40. ret = append(ret, dataMap)
  41. return ret, nil
  42. }
  43. func HandleOnlineOds8(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
  44. dataMapList, err = ParasOds8(msg.Content)
  45. if err != nil {
  46. // 解析不出来数据直接返回
  47. return nil, nil
  48. }
  49. if len(dataMapList) == 0 {
  50. return nil, nil
  51. }
  52. // 入本地库
  53. ods8 := &model.Ods8{}
  54. ods8.Cp = dataMapList[0]["cp"]
  55. ods8.Content = msg.Content
  56. err = ods8.Insert(clinit.DB())
  57. if err != nil {
  58. if !strings.Contains(err.Error(), "Duplicate") {
  59. return nil, err
  60. } else {
  61. where := map[string]interface{}{"cp": ods8.Cp}
  62. oldOds8 := &model.Ods8{}
  63. err = oldOds8.Query(clinit.DB(), where)
  64. if err == nil {
  65. oldDataMapList, _ := ParasOds8(oldOds8.Content)
  66. if checkDataMapListEqual(oldDataMapList, dataMapList) {
  67. return nil, nil
  68. }
  69. }
  70. ods8.UpdateWhere(clinit.DB(), where)
  71. }
  72. }
  73. for _, dataMap := range dataMapList {
  74. delete(dataMap, "cp")
  75. //dwsMsg := dutils.NewDwsMessage(msg)
  76. //dwsMsg.Content = utils.MarshalJsonString(dataMap)
  77. //ret = append(ret, dwsMsg)
  78. }
  79. return dataMapList, nil
  80. }