|
|
package service_gateway
|
|
|
package allied_creation_basic
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"time"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
|
|
|
)
|
|
|
|
|
|
type HttplibAlliedCreationBasic struct {
|
|
|
BaseServiceGateway
|
|
|
BaseUrL string
|
|
|
service_gateway.BaseServiceGateway
|
|
|
baseUrL string
|
|
|
}
|
|
|
|
|
|
var alliedCreationBasicClient = &HttplibAlliedCreationBasic{
|
|
|
BaseServiceGateway: BaseServiceGateway{
|
|
|
connectTimeout: 100 * time.Second,
|
|
|
readWriteTimeout: 30 * time.Second,
|
|
|
BaseServiceGateway: service_gateway.BaseServiceGateway{
|
|
|
ConnectTimeout: 100 * time.Second,
|
|
|
ReadWriteTimeout: 30 * time.Second,
|
|
|
},
|
|
|
BaseUrL: "",
|
|
|
baseUrL: constant.ALLIED_CREATION_BASIC_HOST,
|
|
|
}
|
|
|
|
|
|
func NewHttplibAlliedCreationBasic() *HttplibAlliedCreationBasic {
|
|
|
return alliedCreationBasicClient
|
|
|
}
|
|
|
|
|
|
//ReqGetDictionarysByCode 根据code获取字典数据
|
|
|
type ReqGetDictionarysByCode struct {
|
|
|
DictCode string `json:"dictCode"`
|
|
|
}
|
|
|
|
|
|
//DataGetDictionarysByCode 根据code获取字典数据
|
|
|
type DataGetDictionarysByCode struct {
|
|
|
Dictionarys []domain.Dictionary `json:"dictionarys"`
|
|
|
}
|
|
|
|
|
|
//GetDictionarysByCode 根据code获取字典数据
|
|
|
func (gateway HttplibAlliedCreationBasic) GetDictionarysByCode(param ReqGetDictionarysByCode) (*DataGetDictionarysByCode, error) {
|
|
|
url := gateway.BaseUrL + "/dictionarys/dictionary-code"
|
|
|
func (gateway HttplibAlliedCreationBasic) GetDictionarysByCode(param ReqGetDictionaryByCode) (*DataGetDictionaryByCode, error) {
|
|
|
url := gateway.baseUrL + "/dictionarys/dictionary-code"
|
|
|
method := "post"
|
|
|
req := gateway.createRequest(url, method)
|
|
|
req := gateway.CreateRequest(url, method)
|
|
|
//TODO traceID
|
|
|
log.Logger.Debug("向基础模块请求数据:根据code获取字典数据。", map[string]interface{}{
|
|
|
"api": method + ":" + url,
|
...
|
...
|
@@ -47,19 +40,22 @@ func (gateway HttplibAlliedCreationBasic) GetDictionarysByCode(param ReqGetDicti |
|
|
})
|
|
|
req, err := req.JSONBody(param)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
return nil, fmt.Errorf("请求字典数据失败:%w", err)
|
|
|
}
|
|
|
var result GatewayResponse
|
|
|
err = req.ToJSON(&result)
|
|
|
|
|
|
byteResult, err := req.Bytes()
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
return nil, fmt.Errorf("获取字典数据失败:%w", err)
|
|
|
}
|
|
|
var data DataGetDictionarysByCode
|
|
|
err = gateway.getResponseData(result, &data)
|
|
|
log.Logger.Debug("获取基础模块响应数据:根据code获取字典数据。", map[string]interface{}{
|
|
|
"code": result.Code,
|
|
|
"msg": result.Msg,
|
|
|
"data": data,
|
|
|
"result": string(byteResult),
|
|
|
})
|
|
|
var result service_gateway.GatewayResponse
|
|
|
err = json.Unmarshal(byteResult, &result)
|
|
|
if err != nil {
|
|
|
return nil, fmt.Errorf("解析字典数据失败:%w", err)
|
|
|
}
|
|
|
var data DataGetDictionaryByCode
|
|
|
err = gateway.GetResponseData(result, &data)
|
|
|
return &data, err
|
|
|
} |
...
|
...
|
|