123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package service
- import (
- "context"
- "fmt"
- "gd_service/consts"
- "gd_service/errors"
- "gd_service/impl/thirdparty_impl"
- "gd_service/utils"
- "github.com/astaxie/beego/orm"
- "strings"
- dutils "gd_service/utils"
- gutils "gd_service/common.in/utils"
- "gd_service/apis"
- )
- func IsReuse(reuse *bool, LReq *[]apis.ThirdpartLogWrite) {
- if len(*LReq) > 0 {
- for _, v := range *LReq {
- if v.ProviderCode == "" {
- *reuse = false
- return
- }
- }
- *reuse = true
- } else {
- *reuse = true
- }
- }
- var interfaces = map[string]func(ctx context.Context, req *apis.CommonReq, reply *apis.CommonReply) error{
- "1001": X001,
- "1002": X002,
- "1003": X003,
- }
- func getApiCodeMap(reqCode string) string {
- retCode := ""
- err := orm.NewOrm().Raw("select dest from db_gd_management.t_gd_api_code_map where source = ?", reqCode).QueryRow(&retCode)
- if err == nil {
- return retCode
- }
- return retCode
- }
- func Query(ctx context.Context, req *apis.CommonReq, reply *apis.CommonReply) (err error) {
- defer func() {
- //IsReuse(&reply.IsReuse, &reply.LReq)
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else {
- err = fmt.Errorf("%+v", r)
- }
- }
- }()
- merchantProviderLimitInfoList, err := utils.GetProviderInfo(req.MerchantApiInfo.MerchantChildApiId, req.BaseApiId)
- if err != nil {
- return errors.ServiceError
- }
- req.ProviderMap, req.ProviderGroup = utils.GenProviderInfoMapNew(merchantProviderLimitInfoList)
- err = errors.NoRecord
- if v, ok := interfaces[strings.ToUpper(req.Code)]; ok {
- err = v(ctx, req, reply)
- }else {
- // 接口映射
- retCode := getApiCodeMap(req.Code)
- if retCode != ""{
- if v, ok := interfaces[strings.ToUpper(retCode)]; ok {
- err = v(ctx, req, reply)
- }
- }
- }
- if err == nil {
- // 调用F01格式化
- tReq := &apis.ThirdpartRequest{
- Ctx: ctx,
- Params: reply.Data.(map[string]string),
- ProviderApiCode: dutils.ADMF01,
- ProviderMap: req.ProviderMap,
- RangeNo: consts.RANGEONE,
- Req: req,
- Reply: reply,
- }
- ret, err := thirdparty_impl.CallThirdparty(tReq)
- if err == nil {
- respData := make(map[string]string)
- gutils.Convertion(respData, ret)
- reply.Data = respData
- }
- return nil
- }else {
- return err
- }
- return errors.NoRecord
- }
|