123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- // 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"
- "go.uber.org/zap"
- "strings"
- "time"
- )
- // spy VIN查询车型信息128-001
- func ParasOds5(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("数据异常,车牌姓名不匹配")
- }
- 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()
- if stateCode == "1" {
- arr := gjson.Get(respData, "vecStdVOS").Array()
- for _, v := range arr {
- dataMap := make(map[string]string)
- dataMap["vin"] = vin
- dataMap["approved_load"] = v.Get("approvedLoad").String()
- dataMap["release_date"] = time.Unix(v.Get("vinTime").Int()/1000, 0).Format("2006-01-02")
- dataMap["long"] = v.Get("wkc").String()
- dataMap["oil_wear"] = v.Get("yh").String()
- dataMap["engine_type"] = v.Get("fdjxh").String()
- dataMap["high"] = v.Get("wkg").String()
- dataMap["wide"] = v.Get("wkk").String()
- dataMap["vehicle_body_color_detail"] = v.Get("csys").String()
- dataMap["gross_mass"] = v.Get("zzl").String()
- dataMap["front_wheel_distance"] = v.Get("qlj").String()
- dataMap["axle_weight"] = v.Get("zh").String()
- dataMap["wheel_base"] = v.Get("zj").String()
- dataMap["model_no"] = v.Get("clxh").String()
- dataMap["axle_number"] = v.Get("zs").String()
- dataMap["approved_number"] = v.Get("edzk").String()
- plL := v.Get("plL").String()
- engineMod := v.Get("engineMod").String()
- plLMod := ""
- tmp := strings.Split(engineMod, " ")
- if len(tmp) > 0 {
- plLMod = tmp[0]
- }
- 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"
- }
- } else if engineMod != "" {
- if plLMod != "" {
- pl := strings.Replace(plLMod, "L", "", -1)
- pl = strings.Replace(pl, "T", "", -1)
- dataMap["displacement_l"] = pl
- }
- }
- if dataMap["air_intak_form"] == "" {
- if plLMod != "" {
- if strings.HasSuffix(plLMod, "L") {
- dataMap["air_intak_form"] = "L"
- } else if strings.HasSuffix(plLMod, "T") {
- dataMap["air_intak_form"] = "T"
- }
- }
- }
- dataMap["engine_no"] = v.Get("fdjh").String()
- // TODO 拆分为前后轮胎规格
- dataMap["tyre_size"] = v.Get("ltgg").String()
- //dataMap["front_wheel_specification"] = dataMap["tyre_size"]
- //dataMap["back_wheel_specification"] = dataMap["tyre_size"]
- dataMap["fuel_type_detail"] = v.Get("oilWay").String()
- dataMap["use_property_detail"] = v.Get("syxz").String()
- dataMap["unladen_mass"] = v.Get("zbzl").String()
- dataMap["rated_power"] = v.Get("gl").String()
- dataMap["back_wheel_distance"] = v.Get("hlj").String()
- dataMap["vehicle_type_detail"] = v.Get("vecModType").String()
- dataMap["tyre_number"] = v.Get("lts").String()
- dataMap["traction_mass"] = v.Get("quasiTraction").String()
- dataMap["emission_standard"] = v.Get("pfbz").String()
- dataMap["brand_name"] = v.Get("automarkerInfo").String()
- dataMap["price"] = v.Get("autoPrice").String()
- dataMap["vehicle_structure"] = v.Get("bodyStruct").String()
- dataMap["model_year"] = v.Get("modelYear").String()
- //dataMap["axle_number"] = v.Get("wheelSum").String()
- dataMap["drive_type"] = v.Get("driveWay").String()
- dataMap["chassis_model"] = v.Get("chassisModel").String()
- if v.Get("cxid").String() != ""{
- dataMap["third_style_id"] = v.Get("cxid").String()
- dataMap["source"] = "1"
- }else{
- qczjId := v.Get("qczjId").String()
- if qczjId != "" {
- dataMap["third_style_id"] = qczjId
- dataMap["source"] = "2"
- }
- }
- dataMap["series_source"] = "1"
- /*if v.Get("catarcCode").Exists() {
- dataMap["third_style_id"] = v.Get("catarcCode").String()
- } else {
- dataMap["third_style_id"] = v.Get("cxid").String()
- }*/
- dataMap["third_series_id"] = v.Get("ccs5").String()
- dataMap["third_series_name"] = v.Get("vecMod").String()
- dataMap["third_style_name"] = v.Get("vecName").String()
- ret = append(ret, dataMap)
- }
- } else if stateCode == "2" {
- arr := gjson.Get(respData, "vinSycVO").Array()
- for _, v := range arr {
- dataMap := make(map[string]string)
- dataMap["vin"] = vin
- dataMap["approved_load"] = v.Get("ratedLoadMass").String()
- if v.Get("createTime").Int() != 0 {
- dataMap["release_date"] = time.Unix(v.Get("createTime").Int()/1000, 0).Format("2006-01-02")
- } else {
- dataMap["release_date"] = ""
- }
- dataMap["long"] = v.Get("length").String()
- dataMap["oil_wear"] = v.Get("oilLoss").String()
- dataMap["engine_type"] = v.Get("engineType").String()
- dataMap["high"] = v.Get("height").String()
- dataMap["wide"] = v.Get("wide").String()
- dataMap["gross_mass"] = v.Get("totalQuality").String()
- dataMap["front_wheel_distance"] = v.Get("frontGauge").String()
- dataMap["axle_weight"] = v.Get("axleLoad").String()
- dataMap["wheel_base"] = v.Get("wheelBase").String()
- dataMap["model_no"] = v.Get("vehicleNumber").String()
- dataMap["axle_number"] = v.Get("numberOfShaft").String()
- dataMap["approved_number"] = v.Get("ratedPassenger").String()
- dataMap["displacement"] = v.Get("displacement").String()
- dataMap["engine_no"] = v.Get("fdjh").String()
- dataMap["tyre_size"] = v.Get("tireSize").String()
- dataMap["fuel_type_detail"] = v.Get("fuelType").String()
- dataMap["unladen_mass"] = v.Get("curbWeight").String()
- dataMap["rated_power"] = v.Get("power").String()
- dataMap["back_wheel_distance"] = v.Get("trackRear").String()
- dataMap["vehicle_type_detail"] = v.Get("vehicleCategory").String() + v.Get("vehicleName").String()
- dataMap["tyre_number"] = v.Get("numberOfTires").String()
- dataMap["emission_standard"] = v.Get("emissionStandard").String()
- dataMap["brand_name"] = v.Get("brand").String()
- if v.Get("brand").String() == "" {
- dataMap["brand_name"] = v.Get("vehicleBrand").String()
- }
- dataMap["traction_mass"] = v.Get("totalMassOfQuasiTraction").String()
- dataMap["cargo_high"] = v.Get("cargoVanHeight").String()
- dataMap["cargo_long"] = v.Get("cargoVanLong").String()
- dataMap["cargo_wide"] = v.Get("cargoVanWide").String()
- dataMap["chassis_model"] = v.Get("chassisModel").String()
- //dataMap["drive_type"] = v.Get("drivingForm").String()
- //dataMap["vehicle_type_detail"] = v.Get("vehicleType").String()
- dataMap["number_of_leaf_springs"] = v.Get("numberOfLeafSprings").String()
- dataMap["number_of_passengers"] = v.Get("numberOfPassengers").String()
- ret = append(ret, dataMap)
- }
- } else if stateCode == "3" {
- arr := gjson.Get(respData, "vinMotoVO").Array()
- for _, v := range arr {
- dataMap := make(map[string]string)
- dataMap["vin"] = vin
- if v.Get("createTime").Int() != 0 {
- dataMap["release_date"] = time.Unix(v.Get("createTime").Int()/1000, 0).Format("2006-01-02")
- } else {
- dataMap["release_date"] = ""
- }
- dataMap["brand_name"] = v.Get("brand").String()
- if v.Get("brand").String() == "" {
- dataMap["brand_name"] = v.Get("vehicleBrand").String()
- }
- dataMap["front_wheel_distance"] = v.Get("frontGauge").String()
- dataMap["back_wheel_distance"] = v.Get("trackRear").String()
- dataMap["tyre_number"] = v.Get("numberOfTires").String()
- dataMap["tyre_size"] = v.Get("tireSize").String()
- dataMap["number_of_leaf_springs"] = v.Get("numberOfLeafSprings").String()
- dataMap["wheel_base"] = v.Get("wheelBase").String()
- dataMap["axle_weight"] = v.Get("axleLoad").String()
- dataMap["axle_number"] = v.Get("numberOfShaft").String()
- dataMap["long"] = v.Get("length").String()
- dataMap["wide"] = v.Get("wide").String()
- dataMap["high"] = v.Get("height").String()
- dataMap["cargo_long"] = v.Get("cargoVanLong").String()
- dataMap["cargo_wide"] = v.Get("cargoVanWide").String()
- dataMap["cargo_high"] = v.Get("cargoVanHeight").String()
- dataMap["gross_mass"] = v.Get("totalQuality").String()
- dataMap["approved_load"] = v.Get("ratedLoadMass").String()
- dataMap["unladen_mass"] = v.Get("curbWeight").String()
- dataMap["traction_mass"] = v.Get("totalMassOfQuasiTraction").String()
- dataMap["number_of_passengers"] = v.Get("numberOfPassengers").String()
- dataMap["approved_number"] = v.Get("ratedPassenger").String()
- dataMap["top_speed"] = v.Get("topSpeed").String()
- dataMap["model_no"] = v.Get("vehicleNumber").String()
- //vehicleCategory
- dataMap["vehicle_type_detail"] = v.Get("vehicleName").String()
- dataMap["emission_standard"] = v.Get("emissionStandard").String()
- dataMap["displacement"] = v.Get("displacement").String()
- dataMap["rated_power"] = v.Get("power").String()
- dataMap["engine_type"] = v.Get("engineType").String()
- dataMap["fuel_type_detail"] = v.Get("fuelType").String()
- // enterpriseName
- dataMap["engine_no"] = v.Get("fdjh").String()
- dataMap["vehicle_body_color_detail"] = v.Get("bodyColor").String()
- dataMap["steering_mode"] = v.Get("steeringMode").String()
- dataMap["is_moto"] = "1"
- ret = append(ret, dataMap)
- }
- }
- if len(ret) == 0 {
- l.Error("func",
- zap.String("call", "ParasOds5"),
- zap.String("args", content),
- zap.String("error", "数据异常,无法解析"))
- return nil, fmt.Errorf("数据异常")
- } else {
- return ret, nil
- }
- }
- func HandleOnlineOds5(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds5(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods5 := &model.Ods5{}
- ods5.Vin = dataMapList[0]["vin"]
- ods5.Content = msg.Content
- err = ods5.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- where := map[string]interface{}{"vin": ods5.Vin}
- oldOds5 := &model.Ods5{}
- err = oldOds5.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds5(oldOds5.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods5.UpdateWhere(clinit.DB(), where)
- }
- }
- /*for _, dataMap := range dataMapList {
- dwsMsg := dutils.NewDwsMessage(msg)
- dwsMsg.Content = utils.MarshalJsonString(dataMap)
- ret = append(ret, dwsMsg)
- }*/
- return dataMapList, nil
- }
|