|
@@ -0,0 +1,124 @@
|
|
|
+// 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/errors"
|
|
|
+ "gd_vehicle/thirdparty"
|
|
|
+ dutils "gd_vehicle/utils"
|
|
|
+ "go.uber.org/zap"
|
|
|
+ gutils "gd_vehicle/common.in/utils"
|
|
|
+ "github.com/tidwall/gjson"
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func getZrVinInfoKey(req *apis.ThirdpartRequest) string {
|
|
|
+ key := req.ProviderApiCode + ":" + gutils.GetInterfaceString(req.Params,"vin")
|
|
|
+ return key
|
|
|
+}
|
|
|
+
|
|
|
+func paramZrVinInfoData(rdata string, respMap map[string]interface{}) {
|
|
|
+ arr := gjson.Parse(rdata).Array()
|
|
|
+ list := []apis.VehicleNew{}
|
|
|
+ for _,v := range arr{
|
|
|
+ tmp := apis.VehicleNew{}
|
|
|
+ tmp.RatedPower = v.Get("power").String()
|
|
|
+ tmp.Long = v.Get("length").String()
|
|
|
+ tmp.EngineType = v.Get("enginemodel").String()
|
|
|
+ tmp.BackWheelDistance = v.Get("reartrack").String()
|
|
|
+ tmp.BrandName = v.Get("brand").String()
|
|
|
+ tmp.GrossMass = v.Get("totalweight").String()
|
|
|
+ tmp.EmissionStandard = v.Get("emissionstandard").String()
|
|
|
+ tmp.Displacement = v.Get("displacement").String()
|
|
|
+ tmp.UnladenMass = v.Get("weight").String()
|
|
|
+ tmp.Wide = v.Get("wide").String()
|
|
|
+ tmp.High = v.Get("height").String()
|
|
|
+ tmp.FuelType = v.Get("fueltype").String()
|
|
|
+ list = append(list,tmp)
|
|
|
+ }
|
|
|
+ respMap["list"] = list
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func paramZrVinInfoReturn(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 VinInfoNationalLocal(req *apis.ThirdpartRequest, respMap map[string]interface{}) error {
|
|
|
+ rawData, err := dutils.GetRawDataByRedis(getZrVinInfoKey(req), int64(req.Req.ReuseTime))
|
|
|
+ if err == nil {
|
|
|
+ paramZrVinInfoData(rawData,respMap)
|
|
|
+ }
|
|
|
+
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+func VinInfoNational(req *apis.ThirdpartRequest, respMap map[string]interface{}) error {
|
|
|
+ vin := gutils.GetInterfaceString(req.Params,"vin")
|
|
|
+ if vin == "" {
|
|
|
+ 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 := paramZrVinInfoReturn(string(ret))
|
|
|
+ message := gjson.GetBytes(ret, "msg").String()
|
|
|
+ code := gjson.GetBytes(ret, "code").String()
|
|
|
+ if err == nil {
|
|
|
+ paramZrVinInfoData(replyData,respMap)
|
|
|
+ dutils.StoreDataToRedis(getZrVinInfoKey(req), replyData)
|
|
|
+ dutils.SetAccessLogReqCodeMsgState(req.LReq, 0, code, message, true)
|
|
|
+ } else if err == errors.NoRecord {
|
|
|
+ dutils.StoreDataToRedis(getZrVinInfoKey(req), replyData)
|
|
|
+ dutils.SetAccessLogReqCodeMsgState(req.LReq, 1100, code, message, false)
|
|
|
+ }else if err == errors.UserTokenExpire{
|
|
|
+ if !req.TryAgain {
|
|
|
+ req.TryAgain = true
|
|
|
+ return VinInfoNational(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
|
|
|
+ }
|
|
|
+}
|
|
|
+
|