jaryhe 1 سال پیش
والد
کامیت
be668970f8
7فایلهای تغییر یافته به همراه130 افزوده شده و 38 حذف شده
  1. 13 0
      apis/adm_data.go
  2. 1 0
      common.in/config/config.go
  3. 16 0
      conf/common.json
  4. 33 37
      impl/thirdparty_impl/adm/request.go
  5. 4 0
      impl/vehicle/a001.go
  6. 53 0
      rpc_apis/gd_adm_data/client.go
  7. 10 1
      rpc_apis/init.go

+ 13 - 0
apis/adm_data.go

@@ -0,0 +1,13 @@
+// Copyright 2019 getensh.com. All rights reserved.
+// Use of this source code is governed by getensh.com.
+
+package apis
+
+type QueryRequest struct {
+	Code   string `json:"code"`
+	Params string `json:"params"`
+}
+
+type QueryResponse struct {
+	Data string `json:"data"`
+}

+ 1 - 0
common.in/config/config.go

@@ -75,6 +75,7 @@ type RPCConfig struct {
 	Vehicle            RPCNode `json:"gd_vehicle"`
 	CarParts           RPCNode `json:"gd_car_parts"`
 	AuthCheck          RPCNode `json:"gd_auth_check"`
+	AdmData            RPCNode `json:"gd_adm_data"`
 	Service            RPCNode `json:"gd_service"`
 	VehicleAccessories RPCNode `json:"gd_vehicle_accessories"`
 }

+ 16 - 0
conf/common.json

@@ -176,6 +176,22 @@
       "service_name": "127.0.0.1",
       "service_port": 40006
     },
+    "gd_adm_data": {
+      "log": {
+        "disable_stacktrace": "true",
+        "max_age": "30",
+        "max_backups": "7",
+        "max_size": "100"
+      },
+      "log_mode": "info",
+      "mysql_db": "db",
+      "name": "gd_adm_data",
+      "redis_db": "5",
+      "scheme": "tcp",
+      "update_interval": "60",
+      "service_name": "127.0.0.1",
+      "service_port": 40020
+    },
     "gd_auth_check": {
       "log": {
         "disable_stacktrace": "true",

+ 33 - 37
impl/thirdparty_impl/adm/request.go

@@ -6,16 +6,13 @@ import (
 	"fmt"
 	"gd_vehicle/apis"
 	"gd_vehicle/errors"
-	"gd_vehicle/thirdparty"
+	"gd_vehicle/rpc_apis"
+	dutils "gd_vehicle/utils"
 	"strconv"
 	"time"
 
 	"gd_vehicle/common.in/jsonrpc2"
-
-	dutils "gd_vehicle/utils"
-
-	jsoniter "github.com/json-iterator/go"
-	"github.com/tidwall/gjson"
+	"gd_vehicle/common.in/utils"
 	"go.uber.org/zap"
 )
 
@@ -55,44 +52,43 @@ func (a *Adm) Request() (reply string, err error) {
 		}
 	}()
 
+	req := apis.QueryRequest{}
+	req.Code = a.Code
+	params, _ := json.Marshal(a.Params)
+	req.Params = string(params)
 	lReq := &apis.ThirdpartLogWrite{ProviderApiId: a.Provider.ProviderApiId, ProviderCode: a.Provider.ProviderApiCode}
 	startTime := uint64(time.Now().UnixNano())
 	defer dutils.AppendLog(a.LReqs, lReq, startTime)
-
-	lReq.RequestParams, _ = jsoniter.MarshalToString(a.Params)
-
-	result, err := thirdparty.Adm(a.Ctx, a.Code, a.Params, a.Provider)
+	lReq.RequestParams = req.Params
+	ret, err := rpc_apis.AdmData.Query(context.Background(), &req)
 	if err != nil {
-		l.Error("thridPart",
-			zap.String("call", a.Provider.ThirdpartHost+"/"+a.Provider.ThirdpartApiRouter),
-			zap.String("args", a.Code),
-			zap.String("error", err.Error()))
-		lReq.ResponseParams = err.Error()
-		dutils.SetAccessLogReqCodeMsgState(lReq, 20002, "gd_20002", "三方错误,请求失败", false)
-		return reply, errors.VendorError
-	}
-
-	lReq.ResponseParams = string(result)
+		var e jsonrpc2.Error
+		merr := json.Unmarshal([]byte(err.Error()), &e)
+		if merr != nil {
+			l.Error("func",
+				zap.String("call", "Query"),
+				zap.String("args", utils.MarshalJsonString(req)),
+				zap.String("error", err.Error()))
+			lReq.ResponseParams = err.Error()
+			dutils.SetAccessLogReqCodeMsgState(lReq, 1101, "gd_1101", "三方错误,请求失败", false)
+		} else {
+
+			lReq.ResponseParams = err.Error()
+			if e.Code == 11004 {
+				dutils.SetAccessLogReqCodeMsgState(lReq, 1100, "gd_1100", "无数据", false)
+			} else {
+				l.Error("func",
+					zap.String("call", "Query"),
+					zap.String("args", utils.MarshalJsonString(req)),
+					zap.String("error", err.Error()))
+				dutils.SetAccessLogReqCodeMsgState(lReq, e.Code, "gd_1101", "三方错误,请求失败", false)
+			}
 
-	code := gjson.Get(string(result), "code").Int()
-	if code != 0 {
-		c := int(code)
-		if code == 11004 {
-			c = 1100
 		}
-
-		dutils.SetAccessLogReqCodeMsgState(
-			lReq,
-			c,
-			strconv.Itoa(int(code)),
-			gjson.Get(string(result), "message").String(),
-			false,
-		)
-		return reply, errors.NoRecord
+		return "", errors.VendorError
 	}
-
+	reply = ret.Data
+	lReq.ResponseParams = ret.Data
 	dutils.SetAccessLogReqCodeMsgState(lReq, 0, "0", "成功", true)
-	reply = gjson.Get(string(result), "data").String()
-
 	return
 }

+ 4 - 0
impl/vehicle/a001.go

@@ -17,6 +17,9 @@ func A001(ctx context.Context, req *apis.CommonReq, reply *apis.CommonReply) err
 	rData := req.Data.(map[string]interface{})
 	plateNo := rData["plate_no"].(string)
 	plateType := rData["plate_type"].(string)
+	if plateNo == "" && plateType == "" {
+		return errors.ArgsError
+	}
 	MerchantProviderLimitInfoList, err := utils.GetProviderInfo(req.MerchantApiInfo.MerchantChildApiId, req.BaseApiId)
 	if err != nil {
 		return errors.ServiceError
@@ -27,6 +30,7 @@ func A001(ctx context.Context, req *apis.CommonReq, reply *apis.CommonReply) err
 	// TODO 定义返回字段
 	err = adm.A04(ctx, plateNo, plateType, "", respData, &reply.LReq, providerMap, consts.RANGEONE)
 	if err == nil {
+		reply.Data = respData
 		return nil
 	} else {
 		return errors.NoRecord

+ 53 - 0
rpc_apis/gd_adm_data/client.go

@@ -0,0 +1,53 @@
+// Copyright 2019 getensh.com. All rights reserved.
+// Use of this source code is governed by getensh.com.
+
+// package call gd_auth_check micro service function
+package gd_adm_data
+
+import (
+	"context"
+	"fmt"
+	"gd_vehicle/apis"
+	"time"
+
+	"github.com/smallnest/rpcx/client"
+	"github.com/smallnest/rpcx/protocol"
+	"github.com/smallnest/rpcx/share"
+)
+
+type GdAdmDataXClient struct {
+	xcli client.XClient
+}
+
+func (a *GdAdmDataXClient) Init(etcdAddrs []string, basePath, servicePath string) {
+	opt := client.Option{
+		Retries:        3,
+		RPCPath:        share.DefaultRPCPath,
+		ConnectTimeout: 10 * time.Second,
+		SerializeType:  protocol.JSON,
+		CompressType:   protocol.None,
+		BackupLatency:  10 * time.Millisecond,
+	}
+
+	d := client.NewEtcdDiscovery(basePath, servicePath, etcdAddrs, nil)
+	a.xcli = client.NewXClient(servicePath, client.Failtry, client.RandomSelect, d, opt)
+}
+
+// k8s模式下,服务发现方式需要改为点对点,使用k8s自身的Service进行服务发现,Service名称格式必须是abc-xyz的方式,不能使用"_"
+func (a *GdAdmDataXClient) InitForK8s(servicePath string, k8sServiceName string, k8sServicePort int) {
+	opt := client.Option{
+		Retries:        1,
+		RPCPath:        share.DefaultRPCPath,
+		ConnectTimeout: 10 * time.Second,
+		SerializeType:  protocol.JSON,
+		CompressType:   protocol.None,
+		BackupLatency:  10 * time.Millisecond,
+	}
+	sd := client.NewPeer2PeerDiscovery(fmt.Sprintf("tcp@%s:%d", k8sServiceName, k8sServicePort), "")
+	a.xcli = client.NewXClient(servicePath, client.Failtry, client.RandomSelect, sd, opt)
+}
+
+func (a *GdAdmDataXClient) Query(ctx context.Context, req *apis.QueryRequest) (reply apis.QueryResponse, err error) {
+	err = a.xcli.Call(ctx, "Query", req, &reply)
+	return
+}

+ 10 - 1
rpc_apis/init.go

@@ -5,18 +5,27 @@
 package rpc_apis
 
 import (
-	"gd_vehicle/common.in/config"
+	"gd_vehicle/rpc_apis/gd_adm_data"
 	"gd_vehicle/rpc_apis/gd_auth_check"
+
+	"gd_vehicle/common.in/config"
 )
 
 var AuthCheck *gd_auth_check.GdAuthCheckXClient
+var AdmData *gd_adm_data.GdAdmDataXClient
 
 func Init(etcdAddrs []string, conf *config.Configure) {
 	AuthCheck = &gd_auth_check.GdAuthCheckXClient{}
 	AuthCheck.Init(etcdAddrs, conf.Rpc.BasePath, conf.Rpc.AuthCheck.Name)
+
+	AdmData = &gd_adm_data.GdAdmDataXClient{}
+	AdmData.Init(etcdAddrs, conf.Rpc.BasePath, conf.Rpc.AdmData.Name)
 }
 
 func InitForK8s(conf *config.Configure) {
 	AuthCheck = &gd_auth_check.GdAuthCheckXClient{}
 	AuthCheck.InitForK8s(conf.Rpc.AuthCheck.Name, conf.Rpc.AuthCheck.ServiceName, conf.Rpc.AuthCheck.ServicePort)
+
+	AdmData = &gd_adm_data.GdAdmDataXClient{}
+	AdmData.InitForK8s(conf.Rpc.AdmData.Name, conf.Rpc.AdmData.ServiceName, conf.Rpc.AdmData.ServicePort)
 }