|
@@ -8,37 +8,13 @@ import (
|
|
"gd_vehicle/errors"
|
|
"gd_vehicle/errors"
|
|
"gd_vehicle/rpc_apis"
|
|
"gd_vehicle/rpc_apis"
|
|
dutils "gd_vehicle/utils"
|
|
dutils "gd_vehicle/utils"
|
|
- "strconv"
|
|
|
|
- "time"
|
|
|
|
|
|
|
|
"gd_vehicle/common.in/jsonrpc2"
|
|
"gd_vehicle/common.in/jsonrpc2"
|
|
"gd_vehicle/common.in/utils"
|
|
"gd_vehicle/common.in/utils"
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap"
|
|
)
|
|
)
|
|
|
|
|
|
-func CheckProviderApiIsAvaliable(code string, providerMap map[string]apis.MerchantProviderLimitInfo, rangeNo int) error {
|
|
|
|
- v, ok := providerMap[code+strconv.Itoa(rangeNo)]
|
|
|
|
- if ok {
|
|
|
|
- ret, _ := dutils.CheckProviderAvailable(v)
|
|
|
|
- if ret == false {
|
|
|
|
- return errors.ProviderUnavailable
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- return errors.ProviderApiNotFound
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- return nil
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-type Adm struct {
|
|
|
|
- Ctx context.Context
|
|
|
|
- Params map[string]string
|
|
|
|
- Code string
|
|
|
|
- LReqs *[]apis.ThirdpartLogWrite
|
|
|
|
- Provider apis.MerchantProviderLimitInfo
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (a *Adm) Request() (reply string, err error) {
|
|
|
|
|
|
+func AdmRequest(a *apis.ThirdpartRequest) (reply string, err error) {
|
|
// 捕获各个task中的异常并返回给调用者
|
|
// 捕获各个task中的异常并返回给调用者
|
|
defer func() {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
if r := recover(); r != nil {
|
|
@@ -53,13 +29,9 @@ func (a *Adm) Request() (reply string, err error) {
|
|
}()
|
|
}()
|
|
|
|
|
|
req := apis.QueryRequest{}
|
|
req := apis.QueryRequest{}
|
|
- req.Code = a.Code
|
|
|
|
|
|
+ req.Code = a.ProviderInfo.ThirdpartApiRouter
|
|
params, _ := json.Marshal(a.Params)
|
|
params, _ := json.Marshal(a.Params)
|
|
req.Params = string(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 = req.Params
|
|
|
|
ret, err := rpc_apis.AdmData.Query(context.Background(), &req)
|
|
ret, err := rpc_apis.AdmData.Query(context.Background(), &req)
|
|
if err != nil {
|
|
if err != nil {
|
|
var e jsonrpc2.Error
|
|
var e jsonrpc2.Error
|
|
@@ -69,26 +41,26 @@ func (a *Adm) Request() (reply string, err error) {
|
|
zap.String("call", "Query"),
|
|
zap.String("call", "Query"),
|
|
zap.String("args", utils.MarshalJsonString(req)),
|
|
zap.String("args", utils.MarshalJsonString(req)),
|
|
zap.String("error", err.Error()))
|
|
zap.String("error", err.Error()))
|
|
- lReq.ResponseParams = err.Error()
|
|
|
|
- dutils.SetAccessLogReqCodeMsgState(lReq, 1101, "gd_1101", "三方错误,请求失败", false)
|
|
|
|
|
|
+ a.LReq.ResponseParams = err.Error()
|
|
|
|
+ dutils.SetAccessLogReqCodeMsgState(a.LReq, 1101, "gd_1101", "三方错误,请求失败", false)
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- lReq.ResponseParams = err.Error()
|
|
|
|
|
|
+ a.LReq.ResponseParams = err.Error()
|
|
if e.Code == 11004 {
|
|
if e.Code == 11004 {
|
|
- dutils.SetAccessLogReqCodeMsgState(lReq, 1100, "gd_1100", "无数据", false)
|
|
|
|
|
|
+ dutils.SetAccessLogReqCodeMsgState(a.LReq, 1100, "gd_1100", "无数据", false)
|
|
} else {
|
|
} else {
|
|
l.Error("func",
|
|
l.Error("func",
|
|
zap.String("call", "Query"),
|
|
zap.String("call", "Query"),
|
|
zap.String("args", utils.MarshalJsonString(req)),
|
|
zap.String("args", utils.MarshalJsonString(req)),
|
|
zap.String("error", err.Error()))
|
|
zap.String("error", err.Error()))
|
|
- dutils.SetAccessLogReqCodeMsgState(lReq, e.Code, "gd_1101", "三方错误,请求失败", false)
|
|
|
|
|
|
+ dutils.SetAccessLogReqCodeMsgState(a.LReq, e.Code, "gd_1101", "三方错误,请求失败", false)
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
return "", errors.VendorError
|
|
return "", errors.VendorError
|
|
}
|
|
}
|
|
reply = ret.Data
|
|
reply = ret.Data
|
|
- lReq.ResponseParams = ret.Data
|
|
|
|
- dutils.SetAccessLogReqCodeMsgState(lReq, 0, "0", "成功", true)
|
|
|
|
|
|
+ a.LReq.ResponseParams = ret.Data
|
|
|
|
+ dutils.SetAccessLogReqCodeMsgState(a.LReq, 0, "0", "成功", true)
|
|
return
|
|
return
|
|
}
|
|
}
|