ods7.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. "strings"
  12. )
  13. // spy 过户车记录查询128-010
  14. func ParasOds7(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. vin := gjson.Get(requestParams, "vin").String()
  19. if vin == "" {
  20. return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
  21. }
  22. code := gjson.Get(responseParams, "respCode").String()
  23. if code != "0" {
  24. return nil, fmt.Errorf("数据异常,没有数据")
  25. }
  26. lastTransTime := int64(0)
  27. lastPlate := ""
  28. respData := gjson.Get(responseParams, "data").Array()
  29. for _, v := range respData {
  30. dataMap := make(map[string]string)
  31. //record.TransferNumber = v.Get("transTime").Int()
  32. //record.TransferAge = v.Get("carYear").String()
  33. //record.NewPlateNo = v.Get("newCp").String()
  34. transTime := v.Get("transTime").Int()
  35. dataMap["vin"] = vin
  36. dataMap["plate_no"] = v.Get("oldCp").String()
  37. if transTime > lastTransTime {
  38. lastPlate = v.Get("newCp").String()
  39. lastTransTime = transTime
  40. }
  41. insuranceDate := v.Get("changeMonth").String()
  42. if len(insuranceDate) >= 6 {
  43. insuranceDate = insuranceDate[0:4] + "-" + insuranceDate[4:]
  44. }
  45. dataMap["insurance_date"] = insuranceDate
  46. dataMap["is_expire"] = consts.EXPIREDATA
  47. //record.TransferDate = v.Get("changeMonth").String()
  48. //record.TransferAgeMonth = v.Get("carMonth").String()
  49. ret = append(ret, dataMap)
  50. }
  51. if lastPlate != "" {
  52. dataMap := make(map[string]string)
  53. dataMap["vin"] = vin
  54. dataMap["plate_no"] = lastPlate
  55. dataMap["is_expire"] = consts.NORMALDATA
  56. ret = append(ret, dataMap)
  57. }
  58. return ret, nil
  59. }
  60. func HandleOnlineOds7(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
  61. dataMapList, err = ParasOds7(msg.Content)
  62. if err != nil {
  63. // 解析不出来数据直接返回
  64. return nil, nil
  65. }
  66. if len(dataMapList) == 0 {
  67. return nil, nil
  68. }
  69. // 入本地库
  70. ods7 := &model.Ods7{}
  71. ods7.Vin = dataMapList[0]["vin"]
  72. ods7.Content = msg.Content
  73. err = ods7.Insert(clinit.DB())
  74. if err != nil {
  75. if !strings.Contains(err.Error(), "Duplicate") {
  76. return nil, err
  77. } else {
  78. where := map[string]interface{}{"vin": ods7.Vin}
  79. oldOds7 := &model.Ods7{}
  80. err = oldOds7.Query(clinit.DB(), where)
  81. if err == nil {
  82. oldDataMapList, _ := ParasOds7(oldOds7.Content)
  83. if checkDataMapListEqual(oldDataMapList, dataMapList) {
  84. return nil, nil
  85. }
  86. }
  87. ods7.UpdateWhere(clinit.DB(), where)
  88. }
  89. }
  90. /*for _, dataMap := range dataMapList {
  91. dwsMsg := dutils.NewDwsMessage(msg)
  92. dwsMsg.Content = utils.MarshalJsonString(dataMap)
  93. ret = append(ret, dwsMsg)
  94. }*/
  95. return dataMapList, nil
  96. }