center.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package service
  4. import (
  5. "context"
  6. "fmt"
  7. "gd_service/consts"
  8. "gd_service/errors"
  9. "gd_service/impl/thirdparty_impl"
  10. "gd_service/utils"
  11. "github.com/astaxie/beego/orm"
  12. "strings"
  13. dutils "gd_service/utils"
  14. gutils "gd_service/common.in/utils"
  15. "gd_service/apis"
  16. )
  17. func IsReuse(reuse *bool, LReq *[]apis.ThirdpartLogWrite) {
  18. if len(*LReq) > 0 {
  19. for _, v := range *LReq {
  20. if v.ProviderCode == "" {
  21. *reuse = false
  22. return
  23. }
  24. }
  25. *reuse = true
  26. } else {
  27. *reuse = true
  28. }
  29. }
  30. var interfaces = map[string]func(ctx context.Context, req *apis.CommonReq, reply *apis.CommonReply) error{
  31. "1001": X001,
  32. "1002": X002,
  33. "1003": X003,
  34. }
  35. func getApiCodeMap(reqCode string) string {
  36. retCode := ""
  37. err := orm.NewOrm().Raw("select dest from db_gd_management.t_gd_api_code_map where source = ?", reqCode).QueryRow(&retCode)
  38. if err == nil {
  39. return retCode
  40. }
  41. return retCode
  42. }
  43. func Query(ctx context.Context, req *apis.CommonReq, reply *apis.CommonReply) (err error) {
  44. defer func() {
  45. //IsReuse(&reply.IsReuse, &reply.LReq)
  46. if r := recover(); r != nil {
  47. if e, ok := r.(error); ok {
  48. err = e
  49. } else {
  50. err = fmt.Errorf("%+v", r)
  51. }
  52. }
  53. }()
  54. merchantProviderLimitInfoList, err := utils.GetProviderInfo(req.MerchantApiInfo.MerchantChildApiId, req.BaseApiId)
  55. if err != nil {
  56. return errors.ServiceError
  57. }
  58. req.ProviderMap, req.ProviderGroup = utils.GenProviderInfoMapNew(merchantProviderLimitInfoList)
  59. err = errors.NoRecord
  60. if v, ok := interfaces[strings.ToUpper(req.Code)]; ok {
  61. err = v(ctx, req, reply)
  62. }else {
  63. // 接口映射
  64. retCode := getApiCodeMap(req.Code)
  65. if retCode != ""{
  66. if v, ok := interfaces[strings.ToUpper(retCode)]; ok {
  67. err = v(ctx, req, reply)
  68. }
  69. }
  70. }
  71. if err == nil {
  72. // 调用F01格式化
  73. tReq := &apis.ThirdpartRequest{
  74. Ctx: ctx,
  75. Params: reply.Data.(map[string]string),
  76. ProviderApiCode: dutils.ADMF01,
  77. ProviderMap: req.ProviderMap,
  78. RangeNo: consts.RANGEONE,
  79. Req: req,
  80. Reply: reply,
  81. }
  82. ret, err := thirdparty_impl.CallThirdparty(tReq)
  83. if err == nil {
  84. respData := make(map[string]string)
  85. gutils.Convertion(respData, ret)
  86. reply.Data = respData
  87. }
  88. return nil
  89. }else {
  90. return err
  91. }
  92. return errors.NoRecord
  93. }