ods9.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 过户车查询(VIN)(128-007)
  13. func ParasOds9(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. vin := gjson.Get(requestParams, "vin").String()
  18. code := gjson.Get(responseParams, "respCode").String()
  19. if code != "0" {
  20. return nil, fmt.Errorf("数据异常,没有数据")
  21. }
  22. if vin == "" {
  23. return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
  24. }
  25. dataMap := make(map[string]string)
  26. dataMap["vin"] = vin
  27. respData := gjson.Get(responseParams, "data").String()
  28. dataMap["engine_no"] = gjson.Get(respData, "fdjh").String()
  29. if vin == "" {
  30. dataMap["vin"] = gjson.Get(respData, "vin").String()
  31. }
  32. //dataMap["insurance_first_date"] = gjson.Get(respData, "registerDate").String()
  33. dataMap["insurance_first_date"] = gjson.Get(respData, "registerDate").String()
  34. ret = append(ret, dataMap)
  35. return ret, nil
  36. }
  37. func HandleOnlineOds9(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
  38. dataMapList, err = ParasOds9(msg.Content)
  39. if err != nil {
  40. // 解析不出来数据直接返回
  41. return nil, nil
  42. }
  43. if len(dataMapList) == 0 {
  44. return nil, nil
  45. }
  46. // 入本地库
  47. ods9 := &model.Ods9{}
  48. ods9.Vin = dataMapList[0]["vin"]
  49. ods9.Content = msg.Content
  50. err = ods9.Insert(clinit.DB())
  51. if err != nil {
  52. if !strings.Contains(err.Error(), "Duplicate") {
  53. return nil, err
  54. } else {
  55. where := map[string]interface{}{"vin": ods9.Vin}
  56. oldOds9 := &model.Ods9{}
  57. err = oldOds9.Query(clinit.DB(), where)
  58. if err == nil {
  59. oldDataMapList, _ := ParasOds9(oldOds9.Content)
  60. if checkDataMapListEqual(oldDataMapList, dataMapList) {
  61. return nil, nil
  62. }
  63. }
  64. ods9.UpdateWhere(clinit.DB(), where)
  65. }
  66. }
  67. /*for _, dataMap := range dataMapList {
  68. dwsMsg := dutils.NewDwsMessage(msg)
  69. dwsMsg.Content = utils.MarshalJsonString(dataMap)
  70. ret = append(ret, dwsMsg)
  71. }*/
  72. return dataMapList, nil
  73. }