httplib_allied_creation_basic.go 1.7 KB
package service_gateway

import (
	"time"

	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"

	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)

type HttplibAlliedCreationBasic struct {
	BaseServiceGateway
	BaseUrL string
}

var alliedCreationBasicClient = &HttplibAlliedCreationBasic{
	BaseServiceGateway: BaseServiceGateway{
		connectTimeout:   100 * time.Second,
		readWriteTimeout: 30 * time.Second,
	},
	BaseUrL: "",
}

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"
	method := "post"
	req := gateway.createRequest(url, method)
	//TODO traceID
	log.Logger.Debug("向基础模块请求数据:根据code获取字典数据。", map[string]interface{}{
		"api":   method + ":" + url,
		"param": param,
	})
	req, err := req.JSONBody(param)
	if err != nil {
		return nil, err
	}
	var result GatewayResponse
	err = req.ToJSON(&result)
	if err != nil {
		return nil, err
	}
	var data DataGetDictionarysByCode
	err = gateway.getResponseData(result, &data)
	log.Logger.Debug("获取基础模块响应数据:根据code获取字典数据。", map[string]interface{}{
		"code": result.Code,
		"msg":  result.Msg,
		"data": data,
	})
	return &data, err
}