123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- // 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"
- )
- func ParasOds19(content string) (ret []map[string]string, err error) {
- data := gjson.Parse(content)
- requestParams := data.Get("request_params").String()
- requestParamsArray := gjson.Parse(requestParams).Array()
- if len(requestParamsArray) < 1 {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- requestParam := requestParamsArray[0]
- responseParams := data.Get("response_params").String()
- code := gjson.Get(responseParams, "code").String()
- if code != "0" {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- result := gjson.Get(responseParams, "result").String()
- vin := requestParam.Get("vin").String()
- if vin == "" {
- return nil, fmt.Errorf("数据异常")
- }
- dataMap := make(map[string]string)
- dataMap["release_date"] = gjson.Get(result,"manufacturerDate").String()
- dataMap["vehicle_manufacturer"] = gjson.Get(result,"manufacturerName").String()
- dataMap["model_no"] = gjson.Get(result,"vehicleCode").String()
- dataMap["brand_name"] = gjson.Get(result,"brandName").String()
- dataMap["engine_no"] = gjson.Get(result,"engineCode").String()
- dataMap["wheel_base"]= gjson.Get(result,"wheelbase").String()
- dataMap["long"] = gjson.Get(result,"vehicleLength").String()
- dataMap["wide"] = gjson.Get(result,"vehicleWidth").String()
- dataMap["high"] = gjson.Get(result,"vehicleHeight").String()
- dataMap["fuel_type_detail"] = gjson.Get(result,"dynamicType").String()
- dataMap["displacement"] =gjson.Get(result,"displacement").String()
- dataMap["rated_power"] = gjson.Get(result,"power").String()
- dataMap["gross_mass"] = gjson.Get(result,"totalWeight").String()
- dataMap["vehicle_type_detail"] = gjson.Get(result,"autoCategory").String()
- dataMap["vehicle_body_color_detail"] = gjson.Get(result,"color").String()
- dataMap["unladen_mass"] = gjson.Get(result,"curbWeight").String()
- dataMap["approved_number"] = gjson.Get(result,"ratedPassengers").String()
- dataMap["engine_type"] = gjson.Get(result,"engineModel").String()
- dataMap["vin"] = vin
- ret = append(ret, dataMap)
- return ret, nil
- }
- // ZCRK vin 查发动机号(141-003)
- func HandleOnlineOds19(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds19(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods19 := &model.Ods19{}
- ods19.Vin = dataMapList[0]["vin"]
- ods19.Content = msg.Content
- err = ods19.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- where := map[string]interface{}{"vin": ods19.Vin}
- oldOds19 := &model.Ods19{}
- err = oldOds19.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds19(oldOds19.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods19.UpdateWhere(clinit.DB(), where)
- }
- }
- return dataMapList, nil
- }
|