jaryhe пре 7 месеци
родитељ
комит
a23ed1502e

+ 2 - 0
consts/common.go

@@ -44,4 +44,6 @@ const (
 	ZRTwoElementVerifyPre         = "zr:two-element:"
 	ZRNationalTwoElementVerifyPre = "zr:two-element-national:"
 	ZRNationalVehicleInfoPre = "zr:vehicle-info:"
+	ZRNationalVehicleVinPre = "zr:vehicle-vin:"
+	ZRNationalVehicleFivePre = "zr:vehicle-five:"
 )

+ 3 - 0
impl/thirdparty_impl/center.go

@@ -47,6 +47,9 @@ var ThirdpartyFuncMap = map[string]ThirdpartyFunc{
 	//dutils.ZRTWOELEMENTVERIFY: {zr.TwoElementVerifyGuangdongLocal, zr.TwoElementVerifyGuangdong, true, false,"plateNo"},
 	dutils.ZRTWOELEMENTVERIFYNATIONAL: {zr.TwoElementVerifyNationalLocal, zr.TwoElementVerifyNational, true, false,"plateNum"},
 	dutils.ZRVEHICLEINFO: {zr.VehicleInfoNationalLocal, zr.VehicleInfoNational, true, false,"plateNumber"},
+	dutils.ZRVEHICLEVIN: {zr.VehicleVinNationalLocal, zr.VehicleVinNational, true, false,"vinOrPlateNumber"},
+	dutils.ZRVEHICLEFIVE: {zr.VehicleFiveNationalLocal, zr.VehicleFiveNational, true, false,"vinOrPlateNumber"},
+
 	//dutils.DYXW: {dybd.TwoElementVerifyLocal, dybd.TwoElementVerify, true, false,"xwzsbh"},
 
 }

+ 142 - 0
impl/thirdparty_impl/zr/vehicle_five.go

@@ -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
+	}
+}
+

+ 110 - 0
impl/thirdparty_impl/zr/vehicle_vin.go

@@ -0,0 +1,110 @@
+// 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 getZrVehicleVinKey(req *apis.ThirdpartRequest) string {
+	key := consts.ZRNationalVehicleVinPre + req.Params["vinOrPlateNumber"]
+	return key
+}
+
+func paramZrVehicleVinData(rdata string, respMap map[string]string) {
+	respMap["engine_type"] = gjson.Get(rdata, "fdjxh").String()
+	respMap["engine_no"] = gjson.Get(rdata, "fdjh").String()
+	respMap["model_no"] = gjson.Get(rdata, "clxh").String()
+	respMap["vin"] = gjson.Get(rdata, "vin").String()
+	respMap["initial_registration_date"] = gjson.Get(rdata, "registerDate").String()
+	respMap["brand_name"] = gjson.Get(rdata, "brand").String()
+}
+
+func paramZrVehicleVinReturn(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  VehicleVinNationalLocal(req *apis.ThirdpartRequest, respMap map[string]string)  error {
+	rawData, err := dutils.GetRawDataByRedis(getZrVehicleVinKey(req), int64(req.Req.ReuseTime))
+	if err == nil {
+		paramZrVehicleVinData(rawData,respMap)
+	}
+
+	return  err
+}
+
+func VehicleVinNational(req *apis.ThirdpartRequest, respMap map[string]string)  error {
+	plateNo := req.Params["vinOrPlateNumber"]
+	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 := paramZrVehicleVinReturn(string(ret))
+		message := gjson.GetBytes(ret, "msg").String()
+		code := gjson.GetBytes(ret, "code").String()
+		if err == nil {
+			paramZrVehicleVinData(replyData,respMap)
+			dutils.StoreDataToRedis(getZrVehicleVinKey(req), replyData)
+			dutils.SetAccessLogReqCodeMsgState(req.LReq, 0, code, message, true)
+		} else if err == errors.NoRecord {
+			dutils.StoreDataToRedis(getZrVehicleVinKey(req), replyData)
+			dutils.SetAccessLogReqCodeMsgState(req.LReq, 1100, code, message, false)
+		}else if err == errors.UserTokenExpire{
+			if !req.TryAgain {
+				req.TryAgain = true
+				return VehicleVinNational(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
+	}
+}
+

+ 11 - 1
impl/vehicle/group.go

@@ -208,7 +208,7 @@ func vehicleInfoByPlateGroup(ctx context.Context, req *apis.CommonReq, reply *ap
 				continue
 			}
 			return nil
-
+        // 车牌查车辆信息
 		case utils.ZRVEHICLEINFO:
 			tReq.Params = map[string]string{
 				"plateNumber":   plateNo,
@@ -218,6 +218,16 @@ func vehicleInfoByPlateGroup(ctx context.Context, req *apis.CommonReq, reply *ap
 				continue
 			}
 			return nil
+        // 车牌查vin
+		case utils.ZRVEHICLEVIN:
+			tReq.Params = map[string]string{
+				"vinOrPlateNumber":   plateNo,
+			}
+			err = thirdparty_impl.CallThirdparty(tReq,respData)
+			if err != nil {
+				continue
+			}
+			return nil
 		default:
 			continue
 		}

+ 2 - 0
utils/provider_api_code.go

@@ -20,5 +20,7 @@ const (
 	DYTWOELEMENTVERIFY         = "102-001"
 	ZRVEHICLEINFO         = "103-001"
 	ZRTWOELEMENTVERIFYNATIONAL = "103-002"
+	ZRVEHICLEVIN        = "103-003"
+	ZRVEHICLEFIVE         = "103-004"
 	DYXW                       = "104-001"
 )