123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- // Copyright 2019 autocareai.com. All rights reserved.
- // Use of this source code is governed by autocareai.com.
- package analysis
- import (
- "gadm-ods/apis"
- "gadm-ods/common.in/clinit"
- "gadm-ods/model"
- "fmt"
- "github.com/tidwall/gjson"
- "strings"
- )
- // spy VIN查询车型信息128-011
- func ParasOds16(content string) (ret []map[string]string, err error) {
- data := gjson.Parse(content)
- requestParams := data.Get("request_params").String()
- responseParams := data.Get("response_params").String()
- vin := gjson.Get(requestParams, "vin").String()
- if vin == "" {
- return nil, fmt.Errorf("数据异常,vin为空")
- }
- code := gjson.Get(responseParams, "respCode").String()
- if code != "0" {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- stateCode := gjson.Get(responseParams, "data.stateCode").String()
- if stateCode == "0" {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- respData := gjson.Get(responseParams, "data").String()
- dataMap := make(map[string]string)
- dataMap["vin"] = vin
- dataMap["model_no"] = gjson.Get(respData, "clxh").String()
- dataMap["approved_number"] = gjson.Get(respData, "edzk").String()
- dataMap["engine_type"] = gjson.Get(respData, "fdjxh").String()
- dataMap["rated_power"] = gjson.Get(respData, "gl").String()
- plL := gjson.Get(respData, "plL").String()
- if plL != "" {
- tmp := strings.Replace(plL, "L", "", -1)
- tmp = strings.Replace(tmp, "T", "", -1)
- dataMap["displacement_l"] = tmp
- if strings.HasSuffix(plL, "L") {
- dataMap["air_intak_form"] = "L"
- } else if strings.HasSuffix(plL, "T") {
- dataMap["air_intak_form"] = "T"
- }
- }
- dataMap["third_style_ids"] = gjson.Get(respData, "qczjIds").String()
- dataMap["fuel_type_detail"] = gjson.Get(respData, "rlzl").String()
- dataMap["long"] = gjson.Get(respData, "wkc").String()
- dataMap["high"] = gjson.Get(respData, "wkg").String()
- dataMap["wide"] = gjson.Get(respData, "wkk").String()
- dataMap["wheel_base"] = gjson.Get(respData, "zj").String()
- //dataMap["brand_name"] = gjson.Get(respData,"zpp").String()
- dataMap["brand_name"] = gjson.Get(respData,"brand").String()
- dataMap["source"] = "2"
- ret = append(ret, dataMap)
- return ret, nil
- }
- func HandleOnlineOds16(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds16(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods16 := &model.Ods16{}
- ods16.Vin = dataMapList[0]["vin"]
- ods16.Content = msg.Content
- err = ods16.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- where := map[string]interface{}{"vin": ods16.Vin}
- oldOds16 := &model.Ods16{}
- err = oldOds16.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds16(oldOds16.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods16.UpdateWhere(clinit.DB(), where)
- }
- }
- /*for _, dataMap := range dataMapList {
- dwsMsg := dutils.NewDwsMessage(msg)
- dwsMsg.Content = utils.MarshalJsonString(dataMap)
- ret = append(ret, dwsMsg)
- }*/
- return dataMapList, nil
- }
|