123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package adm
- import (
- "context"
- "encoding/json"
- "fmt"
- "gd_service/apis"
- "gd_service/errors"
- "gd_service/rpc_apis"
- dutils "gd_service/utils"
- "gd_service/common.in/jsonrpc2"
- "gd_service/common.in/utils"
- "go.uber.org/zap"
- )
- func AdmRequest(a *apis.ThirdpartRequest) (reply string, err error) {
- // 捕获各个task中的异常并返回给调用者
- defer func() {
- if r := recover(); r != nil {
- err = fmt.Errorf("%+v", r)
- e := &jsonrpc2.Error{}
- if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
- l.Error("err",
- zap.String("system_err", err.Error()),
- zap.Stack("stacktrace"))
- }
- err = errors.VendorError
- }
- }()
- req := apis.QueryRequest{}
- req.Code = a.ProviderInfo.ThirdpartApiRouter
- params, _ := json.Marshal(a.Params)
- req.Params = string(params)
- ret, err := rpc_apis.AdmData.Query(context.Background(), &req)
- if err != nil {
- 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()))
- a.LReq.ResponseParams = err.Error()
- dutils.SetAccessLogReqCodeMsgState(a.LReq, 1101, "gd_1101", "三方错误,请求失败", false)
- } else {
- a.LReq.ResponseParams = err.Error()
- if e.Code == 11004 {
- dutils.SetAccessLogReqCodeMsgState(a.LReq, 1100, "gd_1100", "无数据", false)
- return "",errors.NoRecord
- } else {
- l.Error("func",
- zap.String("call", "Query"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- dutils.SetAccessLogReqCodeMsgState(a.LReq, e.Code, "gd_1101", "三方错误,请求失败", false)
- // 数据无法确认
- if e.Code == 11009{
- return "",errors.NoRecordCannotConfirm
- }
- }
- }
- return "", errors.VendorError
- }
- reply = ret.Data
- a.LReq.ResponseParams = ret.Data
- dutils.SetAccessLogReqCodeMsgState(a.LReq, 0, "0", "成功", true)
- return
- }
|