|
@@ -0,0 +1,142 @@
|
|
|
+// Copyright 2019 autocareai.com. All rights reserved.
|
|
|
+// Use of this source code is governed by autocareai.com.
|
|
|
+
|
|
|
+package zr
|
|
|
+
|
|
|
+import (
|
|
|
+ "gd_vehicle/apis"
|
|
|
+ "gd_vehicle/common.in/utils"
|
|
|
+ "gd_vehicle/consts"
|
|
|
+ "gd_vehicle/errors"
|
|
|
+ "gd_vehicle/thirdparty"
|
|
|
+ dutils "gd_vehicle/utils"
|
|
|
+ "go.uber.org/zap"
|
|
|
+
|
|
|
+ "github.com/tidwall/gjson"
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
+func getZrVehicleFiveKey(req *apis.ThirdpartRequest) string {
|
|
|
+ key := consts.ZRNationalVehicleFivePre + req.Params["plateNumber"]
|
|
|
+ return key
|
|
|
+}
|
|
|
+
|
|
|
+func paramZrVehicleFiveData(rdata string, respMap map[string]string) {
|
|
|
+ //respMap["vehicle_type_detail"] = gjson.Get(rdata, "clfl").String() // "乘用车"
|
|
|
+ respMap["vehicle_type_detail"] = gjson.Get(rdata, "cllb").String() //"中型车"
|
|
|
+ respMap["vehicle_type"] = ""
|
|
|
+ respMap["engine_type"] = gjson.Get(rdata, "fdjxh").String()
|
|
|
+ respMap["rated_power"] = gjson.Get(rdata, "gl").String()
|
|
|
+ respMap["back_wheel_distance"] = gjson.Get(rdata, "hlj").String()
|
|
|
+ respMap["front_wheel_distance"] = gjson.Get(rdata, "qlj").String()
|
|
|
+ respMap["unladen_mass"] = gjson.Get(rdata, "zbzl").String()
|
|
|
+ respMap["use_property_detail"] = gjson.Get(rdata, "usage").String()
|
|
|
+ respMap["use_property"] = ""
|
|
|
+
|
|
|
+ respMap["gross_mass"] = gjson.Get(rdata, "zzl").String()
|
|
|
+ respMap["traction_mass"] = gjson.Get(rdata, "edqyzzl").String()
|
|
|
+ respMap["long"] = gjson.Get(rdata, "wkc").String()
|
|
|
+ respMap["wheel_base"] = gjson.Get(rdata, "zj").String()
|
|
|
+
|
|
|
+ respMap["high"] = gjson.Get(rdata, "wkg").String()
|
|
|
+ respMap["engine_no"] = gjson.Get(rdata, "fdjh").String()
|
|
|
+
|
|
|
+ respMap["approved_load"] = gjson.Get(rdata, "edzzl").String()
|
|
|
+ //respMap["state"] = gjson.Get(rdata, "clzl").String()
|
|
|
+ respMap["wide"] = gjson.Get(rdata, "wkk").String()
|
|
|
+ respMap["model_no"] = gjson.Get(rdata, "clxh").String()
|
|
|
+ respMap["fuel_type_detail"] = gjson.Get(rdata, "rlzl").String()
|
|
|
+ respMap["fuel_type"] = ""
|
|
|
+ respMap["axle_number"] = gjson.Get(rdata, "zs").String()
|
|
|
+ respMap["vin"] = gjson.Get(rdata, "vin").String()
|
|
|
+
|
|
|
+
|
|
|
+ respMap["emission_standard"] = gjson.Get(rdata, "pfbz").String()
|
|
|
+ respMap["displacement_l"] = gjson.Get(rdata, "pl").String()
|
|
|
+ respMap["displacement"] = ""
|
|
|
+ respMap["brand_name"] = gjson.Get(rdata, "brand").String()
|
|
|
+ respMap["initial_registration_date"] = gjson.Get(rdata, "registerDate").String()
|
|
|
+ respMap["approved_number"] = gjson.Get(rdata, "edzk").String()
|
|
|
+ respMap["vehicle_body_color_detail"] = gjson.Get(rdata, "csys").String()
|
|
|
+ respMap["vehicle_body_color"] = ""
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func paramZrVehicleFiveReturn(ret string) (reply string, err error) {
|
|
|
+ code := gjson.Get(ret, "code").String()
|
|
|
+ if code == "0" {
|
|
|
+ return gjson.Get(ret, "data").String() ,nil
|
|
|
+ } else if code == "10030"{
|
|
|
+ return "", errors.NoRecord
|
|
|
+ }else if code == "10003"{
|
|
|
+ return "",errors.UserTokenExpire
|
|
|
+ }
|
|
|
+ return "", errors.VendorError
|
|
|
+}
|
|
|
+
|
|
|
+func VehicleFiveNationalLocal(req *apis.ThirdpartRequest, respMap map[string]string) error {
|
|
|
+ rawData, err := dutils.GetRawDataByRedis(getZrVehicleFiveKey(req), int64(req.Req.ReuseTime))
|
|
|
+ if err == nil {
|
|
|
+ paramZrVehicleFiveData(rawData,respMap)
|
|
|
+ }
|
|
|
+
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+func VehicleFiveNational(req *apis.ThirdpartRequest, respMap map[string]string) error {
|
|
|
+ plateNo := req.Params["plateNumber"]
|
|
|
+ if plateNo == "" {
|
|
|
+ return errors.ArgsError
|
|
|
+ }
|
|
|
+
|
|
|
+ req.LReq.Search = plateNo
|
|
|
+ token,err := getZrToken(req.ProviderInfo.ThirdpartHost,req.TryAgain,req.ProviderInfo.Timeout)
|
|
|
+ if err != nil{
|
|
|
+ l.Error("thridPart",
|
|
|
+ zap.String("call", "getZrToken"),
|
|
|
+ zap.String("args",utils.MarshalJsonString(req.Params)),
|
|
|
+ zap.String("error", err.Error()))
|
|
|
+ req.LReq.ResponseParams = err.Error()
|
|
|
+ dutils.SetAccessLogReqCodeMsgState(req.LReq, 1101, "gd_1101", err.Error(), false)
|
|
|
+ return errors.VendorError
|
|
|
+ }
|
|
|
+
|
|
|
+ ret, err := thirdparty.ZrHttpClient(req.ProviderInfo.ThirdpartHost+"/"+req.ProviderInfo.ThirdpartApiRouter, token,req.Params,req.ProviderInfo.Timeout)
|
|
|
+ if err != nil {
|
|
|
+ l.Error("func",
|
|
|
+ zap.String("call", "ZrHttpClient"),
|
|
|
+ zap.String("args", utils.MarshalJsonString(req.Params)),
|
|
|
+ zap.String("error", err.Error()))
|
|
|
+ req.LReq.ResponseParams = err.Error()
|
|
|
+ dutils.SetAccessLogReqCodeMsgState(req.LReq, 1101, "gd_1101", "三方错误,请求失败", false)
|
|
|
+ return errors.VendorError
|
|
|
+ } else {
|
|
|
+ req.LReq.ResponseParams = string(ret)
|
|
|
+ replyData ,err := paramZrVehicleFiveReturn(string(ret))
|
|
|
+ message := gjson.GetBytes(ret, "msg").String()
|
|
|
+ code := gjson.GetBytes(ret, "code").String()
|
|
|
+ if err == nil {
|
|
|
+ paramZrVehicleFiveData(replyData,respMap)
|
|
|
+ dutils.StoreDataToRedis(getZrVehicleFiveKey(req), replyData)
|
|
|
+ dutils.SetAccessLogReqCodeMsgState(req.LReq, 0, code, message, true)
|
|
|
+ } else if err == errors.NoRecord {
|
|
|
+ dutils.StoreDataToRedis(getZrVehicleFiveKey(req), replyData)
|
|
|
+ dutils.SetAccessLogReqCodeMsgState(req.LReq, 1100, code, message, false)
|
|
|
+ }else if err == errors.UserTokenExpire{
|
|
|
+ if !req.TryAgain {
|
|
|
+ req.TryAgain = true
|
|
|
+ return VehicleFiveNational(req,respMap)
|
|
|
+ }
|
|
|
+ dutils.SetAccessLogReqCodeMsgState(req.LReq, 1101, code, message, false)
|
|
|
+ } else {
|
|
|
+ l.Error("func",
|
|
|
+ zap.String("call", "ZrHttpClient"),
|
|
|
+ zap.String("args", utils.MarshalJsonString(req.Params)),
|
|
|
+ zap.String("error", err.Error()))
|
|
|
+ //codeInt,_ := strconv.Atoi(code)
|
|
|
+ dutils.SetAccessLogReqCodeMsgState(req.LReq, 1101, code, message, false)
|
|
|
+ }
|
|
|
+ return err
|
|
|
+ }
|
|
|
+}
|
|
|
+
|