module_cooperation_statistics.go 1.8 KB
package allied_creation_cooperation

import (
	"encoding/json"
	"fmt"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"

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

const (
	// 合约分红列表查询
	SearchContractDividends = "SearchContractDividends"
	// 获取分红合约详情
	GetContractDividends = "GetContractDividends"

	// 企业-商品统计
	CooperationGoodsStatistics = "cooperationGoodsStatistics"
	// 企业-共创模式统计
	CooperationModeStatistics = "CooperationModeStatistics"
	// 企业-分红统计
	CompanyDividendsStatistics = "CompanyDividendsStatistics"
)

// CooperationStatistics 共创统计
func (gateway HttplibAlliedCreationCooperation) CooperationStatistics(action string, queryOptions interface{}) (interface{}, error) {
	url := gateway.baseUrL + "/cooperation-statistics"
	method := "post"
	req := gateway.CreateRequest(url, method)
	log.Logger.Debug("向业务模块请求数据:共创统计。", map[string]interface{}{
		"api":   method + ":" + url,
		"param": queryOptions,
	})
	param := map[string]interface{}{
		"action":       action,
		"queryOptions": queryOptions,
	}
	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 interface{}
	err = gateway.GetResponseData(result, &data)
	return &data, err
}