request.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package adm
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "gd_service/apis"
  7. "gd_service/errors"
  8. "gd_service/rpc_apis"
  9. dutils "gd_service/utils"
  10. "gd_service/common.in/jsonrpc2"
  11. "gd_service/common.in/utils"
  12. "go.uber.org/zap"
  13. )
  14. func AdmRequest(a *apis.ThirdpartRequest) (reply string, err error) {
  15. // 捕获各个task中的异常并返回给调用者
  16. defer func() {
  17. if r := recover(); r != nil {
  18. err = fmt.Errorf("%+v", r)
  19. e := &jsonrpc2.Error{}
  20. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  21. l.Error("err",
  22. zap.String("system_err", err.Error()),
  23. zap.Stack("stacktrace"))
  24. }
  25. err = errors.VendorError
  26. }
  27. }()
  28. req := apis.QueryRequest{}
  29. req.Code = a.ProviderInfo.ThirdpartApiRouter
  30. params, _ := json.Marshal(a.Params)
  31. req.Params = string(params)
  32. ret, err := rpc_apis.AdmData.Query(context.Background(), &req)
  33. if err != nil {
  34. var e jsonrpc2.Error
  35. merr := json.Unmarshal([]byte(err.Error()), &e)
  36. if merr != nil {
  37. l.Error("func",
  38. zap.String("call", "Query"),
  39. zap.String("args", utils.MarshalJsonString(req)),
  40. zap.String("error", err.Error()))
  41. a.LReq.ResponseParams = err.Error()
  42. dutils.SetAccessLogReqCodeMsgState(a.LReq, 1101, "gd_1101", "三方错误,请求失败", false)
  43. } else {
  44. a.LReq.ResponseParams = err.Error()
  45. if e.Code == 11004 {
  46. dutils.SetAccessLogReqCodeMsgState(a.LReq, 1100, "gd_1100", "无数据", false)
  47. return "",errors.NoRecord
  48. } else {
  49. l.Error("func",
  50. zap.String("call", "Query"),
  51. zap.String("args", utils.MarshalJsonString(req)),
  52. zap.String("error", err.Error()))
  53. dutils.SetAccessLogReqCodeMsgState(a.LReq, e.Code, "gd_1101", "三方错误,请求失败", false)
  54. // 数据无法确认
  55. if e.Code == 11009{
  56. return "",errors.NoRecordCannotConfirm
  57. }
  58. }
  59. }
  60. return "", errors.VendorError
  61. }
  62. reply = ret.Data
  63. a.LReq.ResponseParams = ret.Data
  64. dutils.SetAccessLogReqCodeMsgState(a.LReq, 0, "0", "成功", true)
  65. return
  66. }