1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package base_api
- import (
- "context"
- "gd_management/apis"
- "gd_management/errors"
- "encoding/json"
- "github.com/astaxie/beego/orm"
- )
- func getParam(param []apis.ManagementBaseApiParam,respMap map[string]string){
- for _,v := range param{
- if v.Mean != ""{
- respMap[v.Name] = v.Mean
- if v.In != ""{
- respMap[v.In] = v.Mean
- }
- }
- if len(v.Child) > 0 {
- getParam(v.Child,respMap)
- }
- }
- }
- func ManagementGetBaseApiByRouter(ctx context.Context, req *apis.ManagementGetBaseApiByRouterReq, reply *apis.ManagementGetBaseApiByRouterReply) error {
- var requestParam string
- var responseParam string
- apiId :=req.ApiId
- merchantId := req.MerchantId
- if apiId <=0 {
- err := orm.NewOrm().Raw("select id from t_gd_api where router = ? and method = ?", req.Router, req.Method).QueryRow(&apiId)
- if err != nil {
- if err != orm.ErrNoRows {
- return errors.DataBaseError
- } else {
- return errors.ServiceError
- }
- }
- }
- if merchantId <= 0 {
- err := orm.NewOrm().Raw("select id from t_gd_merchants where app_key = ?", req.AppKey).QueryRow(&merchantId)
- if err != nil {
- if err != orm.ErrNoRows {
- return errors.DataBaseError
- } else {
- return errors.ServiceError
- }
- }
- }
- err := orm.NewOrm().Raw("select a.request_param, a.response_param from t_gd_merchant_child_data_api as a inner join t_gd_merchant_data_api as b on a.merchant_data_api_id=b.id where a.api_id=? and b.merchant_id=?",apiId,merchantId).QueryRow(&requestParam,&responseParam)
- if err != nil {
- if err != orm.ErrNoRows {
- return errors.DataBaseError
- } else {
- return errors.ServiceError
- }
- }
- var RequestParam []apis.ManagementBaseApiParam
- var ResponseParam []apis.ManagementBaseApiParam
- json.Unmarshal([]byte(requestParam), &RequestParam)
- json.Unmarshal([]byte(responseParam), &ResponseParam)
- reply.Data = make(map[string]string)
- getParam(RequestParam,reply.Data)
- getParam(ResponseParam,reply.Data)
- reply.Data["origin"]= "原始响应数据"
- reply.Data["code"]= "错误码"
- reply.Data["msg"]= "错误消息"
- return nil
- }
|