module_cooperation_mode.go 9.1 KB
package allied_creation_cooperation

import (
	"fmt"
	"github.com/linmadan/egglib-go/utils/json"
	"strconv"

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

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

// ReqCooperationModeAdd 创建共创模式
func (gateway HttplibAlliedCreationCooperation) CooperationModeAdd(param ReqCooperationModeAdd) (*DataCooperationModeAdd, error) {
	url := gateway.baseUrL + "/cooperation-modes"
	method := "post"
	req := gateway.CreateRequest(url, method)
	log.Logger.Debug("向业务模块请求数据:创建共创模式。", map[string]interface{}{
		"api":   method + ":" + url,
		"param": param,
	})
	req, err := req.JSONBody(param)
	if err != nil {
		return nil, fmt.Errorf("请求创建共创模式失败:%w", err)
	}

	byteResult, err := req.Bytes()
	if err != nil {
		return nil, fmt.Errorf("获取创建共创模式失败:%w", err)
	}
	log.Logger.Debug("获取业务模块请求数据:创建共创模式。", map[string]interface{}{
		"result": string(byteResult),
	})
	var result service_gateway.GatewayResponse
	err = json.Unmarshal(byteResult, &result)
	if err != nil {
		return nil, fmt.Errorf("解析创建共创模式:%w", err)
	}
	var data DataCooperationModeAdd
	err = gateway.GetResponseData(result, &data)
	return &data, err
}

// CooperationModeList 返回共创模式列表
func (gateway HttplibAlliedCreationCooperation) CooperationModeList(param ReqCooperationModeList) (*DataCooperationModeList, error) {
	url := gateway.baseUrL + "/cooperation-modes"
	method := "get"
	req := gateway.CreateRequest(url, method)
	log.Logger.Debug("向业务模块请求数据:返回共创模式列表。", map[string]interface{}{
		"api":   method + ":" + url,
		"param": param,
	})
	req, err := req.JSONBody(param)
	if err != nil {
		return nil, fmt.Errorf("请求返回共创模式列表失败:%w", err)
	}

	byteResult, err := req.Bytes()
	if err != nil {
		return nil, fmt.Errorf("获取返回共创模式列表失败:%w", err)
	}
	log.Logger.Debug("获取业务模块请求数据:返回共创模式列表。", map[string]interface{}{
		"result": string(byteResult),
	})
	var result service_gateway.GatewayResponse
	err = json.Unmarshal(byteResult, &result)
	if err != nil {
		return nil, fmt.Errorf("解析返回共创模式列表:%w", err)
	}
	var data DataCooperationModeList
	err = gateway.GetResponseData(result, &data)
	return &data, err
}

// CooperationModeGet 返回共创模式详情
func (gateway HttplibAlliedCreationCooperation) CooperationModeGet(param ReqCooperationModeGet) (*DataCooperationModeGet, error) {
	url := gateway.baseUrL + "/cooperation-modes/" + strconv.Itoa(param.CooperationModeId)
	method := "get"
	req := gateway.CreateRequest(url, method)
	log.Logger.Debug("向业务模块请求数据:返回共创模式详情。", map[string]interface{}{
		"api":   method + ":" + url,
		"param": param,
	})
	req, err := req.JSONBody(param)
	if err != nil {
		return nil, fmt.Errorf("请求返回共创模式详情失败:%w", err)
	}

	byteResult, err := req.Bytes()
	if err != nil {
		return nil, fmt.Errorf("获取返回共创模式详情失败:%w", err)
	}
	log.Logger.Debug("获取业务模块请求数据:返回共创模式详情。", map[string]interface{}{
		"result": string(byteResult),
	})
	var result service_gateway.GatewayResponse
	err = json.Unmarshal(byteResult, &result)
	if err != nil {
		return nil, fmt.Errorf("解析返回共创模式详情:%w", err)
	}
	var data DataCooperationModeGet
	err = gateway.GetResponseData(result, &data)
	return &data, err
}

// CooperationModeUpdate 更新共创模式
func (gateway HttplibAlliedCreationCooperation) CooperationModeUpdate(param ReqCooperationModeUpdate) (*DataCooperationModeUpdate, error) {
	url := gateway.baseUrL + "/cooperation-modes/" + strconv.Itoa(param.CooperationModeId)
	method := "put"
	req := gateway.CreateRequest(url, method)
	log.Logger.Debug("向业务模块请求数据:更新共创模式。", map[string]interface{}{
		"api":   method + ":" + url,
		"param": param,
	})
	req, err := req.JSONBody(param)
	if err != nil {
		return nil, fmt.Errorf("请求更新共创模式失败:%w", err)
	}

	byteResult, err := req.Bytes()
	if err != nil {
		return nil, fmt.Errorf("获取更新共创模式失败:%w", err)
	}
	log.Logger.Debug("获取业务模块请求数据:更新共创模式。", map[string]interface{}{
		"result": string(byteResult),
	})
	var result service_gateway.GatewayResponse
	err = json.Unmarshal(byteResult, &result)
	if err != nil {
		return nil, fmt.Errorf("解析更新共创模式:%w", err)
	}
	var data DataCooperationModeUpdate
	err = gateway.GetResponseData(result, &data)
	return &data, err
}

//CooperationModeRemove 移除共创模式
func (gateway HttplibAlliedCreationCooperation) CooperationModeRemove(param ReqCooperationModeRemove) (*DataCooperationModeRemove, error) {
	url := gateway.baseUrL + "/cooperation-modes/" + strconv.Itoa(param.CooperationModeId)
	method := "delete"
	req := gateway.CreateRequest(url, method)
	log.Logger.Debug("向业务模块请求数据:移除共创模式。", map[string]interface{}{
		"api":   method + ":" + url,
		"param": param,
	})
	req, err := req.JSONBody(param)
	if err != nil {
		return nil, fmt.Errorf("请求移除共创模式失败:%w", err)
	}

	byteResult, err := req.Bytes()
	if err != nil {
		return nil, fmt.Errorf("获取移除共创模式失败:%w", err)
	}
	log.Logger.Debug("获取业务模块请求数据:移除共创模式。", map[string]interface{}{
		"result": string(byteResult),
	})
	var result service_gateway.GatewayResponse
	err = json.Unmarshal(byteResult, &result)
	if err != nil {
		return nil, fmt.Errorf("解析移除共创模式:%w", err)
	}
	var data DataCooperationModeRemove
	err = gateway.GetResponseData(result, &data)
	return &data, err
}

// CooperationModesSearch查询共创模式
func (gateway HttplibAlliedCreationCooperation) CooperationModesSearch(param ReqCooperationModesSearch) (*DataCooperationModesSearch, error) {
	url := gateway.baseUrL + "/cooperation-modes/search"
	method := "post"
	req := gateway.CreateRequest(url, method)
	log.Logger.Debug("向业务模块请求数据:查询共创模式。", map[string]interface{}{
		"api":   method + ":" + url,
		"param": param,
	})
	req, err := req.JSONBody(param)
	if err != nil {
		return nil, fmt.Errorf("请求查询共创模式失败:%w", err)
	}

	byteResult, err := req.Bytes()
	if err != nil {
		return nil, fmt.Errorf("获取查询共创模式失败:%w", err)
	}
	log.Logger.Debug("获取业务模块请求数据:查询共创模式。", map[string]interface{}{
		"result": string(byteResult),
	})
	var result service_gateway.GatewayResponse
	err = json.Unmarshal(byteResult, &result)
	if err != nil {
		return nil, fmt.Errorf("解析查询共创模式:%w", err)
	}
	var data DataCooperationModesSearch
	err = gateway.GetResponseData(result, &data)
	return &data, err
}

//CooperationModeBatchRemove 批量移除共创模式
func (gateway HttplibAlliedCreationCooperation) CooperationModeBatchRemove(param ReqCooperationModeBatchRemove) (*DataCooperationModeBatchRemove, error) {
	url := gateway.baseUrL + "/cooperation-modes/batch-remove"
	method := "post"
	req := gateway.CreateRequest(url, method)
	log.Logger.Debug("向业务模块请求数据:移除共创模式。", map[string]interface{}{
		"api":   method + ":" + url,
		"param": param,
	})
	req, err := req.JSONBody(param)
	if err != nil {
		return nil, fmt.Errorf("请求移除共创模式失败:%w", err)
	}

	byteResult, err := req.Bytes()
	if err != nil {
		return nil, fmt.Errorf("获取移除共创模式失败:%w", err)
	}
	log.Logger.Debug("获取业务模块请求数据:移除共创模式。", map[string]interface{}{
		"result": string(byteResult),
	})
	var result service_gateway.GatewayResponse
	err = json.Unmarshal(byteResult, &result)
	if err != nil {
		return nil, fmt.Errorf("解析移除共创模式:%w", err)
	}
	var data DataCooperationModeBatchRemove
	err = gateway.GetResponseData(result, &data)
	return &data, err
}

// CooperationModeUpdate 更新共创模式
func (gateway HttplibAlliedCreationCooperation) CooperationModeOperate(param ReqOperateCooperationMode) (*DataOperateCooperationMode, error) {
	url := gateway.baseUrL + "/cooperation-modes/operate"
	method := "post"
	req := gateway.CreateRequest(url, method)
	log.Logger.Debug("向业务模块请求数据:启用或禁用共创模式。", map[string]interface{}{
		"api":   method + ":" + url,
		"param": param,
	})
	req, err := req.JSONBody(param)
	if err != nil {
		return nil, fmt.Errorf("请求启用或禁用共创模式失败:%w", err)
	}

	byteResult, err := req.Bytes()
	if err != nil {
		return nil, fmt.Errorf("获取启用或禁用共创模式失败:%w", err)
	}
	log.Logger.Debug("获取业务模块请求数据:启用或禁用共创模式。", map[string]interface{}{
		"result": string(byteResult),
	})
	var result service_gateway.GatewayResponse
	err = json.Unmarshal(byteResult, &result)
	if err != nil {
		return nil, fmt.Errorf("解析启用或禁用共创模式:%w", err)
	}
	var data DataOperateCooperationMode
	err = gateway.GetResponseData(result, &data)
	return &data, err
}