ods16.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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-011
  13. func ParasOds16(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. if vin == "" {
  19. return nil, fmt.Errorf("数据异常,vin为空")
  20. }
  21. code := gjson.Get(responseParams, "respCode").String()
  22. if code != "0" {
  23. return nil, fmt.Errorf("数据异常,没有数据")
  24. }
  25. stateCode := gjson.Get(responseParams, "data.stateCode").String()
  26. if stateCode == "0" {
  27. return nil, fmt.Errorf("数据异常,没有数据")
  28. }
  29. respData := gjson.Get(responseParams, "data").String()
  30. dataMap := make(map[string]string)
  31. dataMap["vin"] = vin
  32. dataMap["model_no"] = gjson.Get(respData, "clxh").String()
  33. dataMap["approved_number"] = gjson.Get(respData, "edzk").String()
  34. dataMap["engine_type"] = gjson.Get(respData, "fdjxh").String()
  35. dataMap["rated_power"] = gjson.Get(respData, "gl").String()
  36. plL := gjson.Get(respData, "plL").String()
  37. if plL != "" {
  38. tmp := strings.Replace(plL, "L", "", -1)
  39. tmp = strings.Replace(tmp, "T", "", -1)
  40. dataMap["displacement_l"] = tmp
  41. if strings.HasSuffix(plL, "L") {
  42. dataMap["air_intak_form"] = "L"
  43. } else if strings.HasSuffix(plL, "T") {
  44. dataMap["air_intak_form"] = "T"
  45. }
  46. }
  47. dataMap["third_style_ids"] = gjson.Get(respData, "qczjIds").String()
  48. dataMap["fuel_type_detail"] = gjson.Get(respData, "rlzl").String()
  49. dataMap["long"] = gjson.Get(respData, "wkc").String()
  50. dataMap["high"] = gjson.Get(respData, "wkg").String()
  51. dataMap["wide"] = gjson.Get(respData, "wkk").String()
  52. dataMap["wheel_base"] = gjson.Get(respData, "zj").String()
  53. dataMap["brand_name"] = gjson.Get(respData,"zpp").String()
  54. dataMap["source"] = "2"
  55. ret = append(ret, dataMap)
  56. return ret, nil
  57. }
  58. func HandleOnlineOds16(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
  59. dataMapList, err = ParasOds16(msg.Content)
  60. if err != nil {
  61. // 解析不出来数据直接返回
  62. return nil, nil
  63. }
  64. if len(dataMapList) == 0 {
  65. return nil, nil
  66. }
  67. // 入本地库
  68. ods16 := &model.Ods16{}
  69. ods16.Vin = dataMapList[0]["vin"]
  70. ods16.Content = msg.Content
  71. err = ods16.Insert(clinit.DB())
  72. if err != nil {
  73. if !strings.Contains(err.Error(), "Duplicate") {
  74. return nil, err
  75. } else {
  76. where := map[string]interface{}{"vin": ods16.Vin}
  77. oldOds16 := &model.Ods16{}
  78. err = oldOds16.Query(clinit.DB(), where)
  79. if err == nil {
  80. oldDataMapList, _ := ParasOds16(oldOds16.Content)
  81. if checkDataMapListEqual(oldDataMapList, dataMapList) {
  82. return nil, nil
  83. }
  84. }
  85. ods16.UpdateWhere(clinit.DB(), where)
  86. }
  87. }
  88. /*for _, dataMap := range dataMapList {
  89. dwsMsg := dutils.NewDwsMessage(msg)
  90. dwsMsg.Content = utils.MarshalJsonString(dataMap)
  91. ret = append(ret, dwsMsg)
  92. }*/
  93. return dataMapList, nil
  94. }