ods16.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright 2019 autocareai.com. All rights reserved.
  2. // Use of this source code is governed by autocareai.com.
  3. package analysis
  4. import (
  5. "gadm-ods/apis"
  6. "gadm-ods/common.in/clinit"
  7. "gadm-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["brand_name"] = gjson.Get(respData,"brand").String()
  55. dataMap["source"] = "2"
  56. ret = append(ret, dataMap)
  57. return ret, nil
  58. }
  59. func HandleOnlineOds16(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
  60. dataMapList, err = ParasOds16(msg.Content)
  61. if err != nil {
  62. // 解析不出来数据直接返回
  63. return nil, nil
  64. }
  65. if len(dataMapList) == 0 {
  66. return nil, nil
  67. }
  68. // 入本地库
  69. ods16 := &model.Ods16{}
  70. ods16.Vin = dataMapList[0]["vin"]
  71. ods16.Content = msg.Content
  72. err = ods16.Insert(clinit.DB())
  73. if err != nil {
  74. if !strings.Contains(err.Error(), "Duplicate") {
  75. return nil, err
  76. } else {
  77. where := map[string]interface{}{"vin": ods16.Vin}
  78. oldOds16 := &model.Ods16{}
  79. err = oldOds16.Query(clinit.DB(), where)
  80. if err == nil {
  81. oldDataMapList, _ := ParasOds16(oldOds16.Content)
  82. if checkDataMapListEqual(oldDataMapList, dataMapList) {
  83. return nil, nil
  84. }
  85. }
  86. ods16.UpdateWhere(clinit.DB(), where)
  87. }
  88. }
  89. /*for _, dataMap := range dataMapList {
  90. dwsMsg := dutils.NewDwsMessage(msg)
  91. dwsMsg.Content = utils.MarshalJsonString(dataMap)
  92. ret = append(ret, dwsMsg)
  93. }*/
  94. return dataMapList, nil
  95. }