123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- // Copyright 208 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 ParasOds8(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()
- plateNo := requestParam.Get("plateNumber").String()
- if plateNo == ""{
- return nil, fmt.Errorf("数据异常")
- }
- dataMap := make(map[string]string)
- dataMap["plate_no"] = plateNo
- code := gjson.Get(responseParams, "code").String()
- if code != "0"{
- return nil , fmt.Errorf("数据异常,code不为0")
- }
- rdata := gjson.Get(responseParams, "data").String()
- dataMap["vehicle_type_detail"] = gjson.Get(rdata, "cllb").String() //"中型车"
- dataMap["vehicle_type"] = ""
- dataMap["engine_type"] = gjson.Get(rdata, "fdjxh").String()
- dataMap["rated_power"] = gjson.Get(rdata, "gl").String()
- dataMap["back_wheel_distance"] = gjson.Get(rdata, "hlj").String()
- dataMap["front_wheel_distance"] = gjson.Get(rdata, "qlj").String()
- dataMap["unladen_mass"] = gjson.Get(rdata, "zbzl").String()
- dataMap["use_property_detail"] = gjson.Get(rdata, "usage").String()
- dataMap["use_property"] = ""
- dataMap["gross_mass"] = gjson.Get(rdata, "zzl").String()
- dataMap["traction_mass"] = gjson.Get(rdata, "edqyzzl").String()
- dataMap["long"] = gjson.Get(rdata, "wkc").String()
- dataMap["wheel_base"] = gjson.Get(rdata, "zj").String()
- dataMap["high"] = gjson.Get(rdata, "wkg").String()
- dataMap["engine_no"] = gjson.Get(rdata, "fdjh").String()
- dataMap["approved_load"] = gjson.Get(rdata, "edzzl").String()
- //dataMap["state"] = gjson.Get(rdata, "clzl").String()
- dataMap["wide"] = gjson.Get(rdata, "wkk").String()
- dataMap["model_no"] = gjson.Get(rdata, "clxh").String()
- dataMap["fuel_type_detail"] = gjson.Get(rdata, "rlzl").String()
- dataMap["fuel_type"] = ""
- dataMap["axle_number"] = gjson.Get(rdata, "zs").String()
- dataMap["vin"] = gjson.Get(rdata, "vin").String()
- dataMap["emission_standard"] = gjson.Get(rdata, "pfbz").String()
- dataMap["displacement_l"] = gjson.Get(rdata, "pl").String()
- dataMap["displacement"] = ""
- dataMap["brand_name"] = gjson.Get(rdata, "brand").String()
- dataMap["initial_registration_date"] = gjson.Get(rdata, "registerDate").String()
- dataMap["approved_number"] = gjson.Get(rdata, "edzk").String()
- dataMap["vehicle_body_color_detail"] = gjson.Get(rdata, "csys").String()
- dataMap["vehicle_body_color"] = ""
- ret = append(ret, dataMap)
- return ret, nil
- }
- // ZR 车牌查车辆信息
- func HandleOnlineOds8(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds8(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods8 := &model.Ods8{}
- ods8.PlateNo = dataMapList[0]["plate_no"]
- //ods8.PlateType = dataMapList[0]["plate_type"]
- //ods8.Owner = dataMapList[0]["owner"]
- ods8.Content = msg.Content
- err = ods8.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- where := map[string]interface{}{"plate_no": ods8.PlateNo}
- oldOds8 := &model.Ods8{}
- err = oldOds8.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds8(oldOds8.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods8.UpdateWhere(clinit.DB(), where)
- }
- }
- return dataMapList, nil
- }
|