module_excel_data.go 2.8 KB
package allied_creation_cooperation

import (
	"encoding/json"
	"fmt"

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

//ReqImportDividendsReturnedOrder 导入退货数据
type (
	ImportDividendsReturnedOrderData struct {
		DividendsReturnedCustomerName string `json:"dividendsReturnedCustomerName"` //退货客户名称
		OriginalOrderNum              string `json:"originalOrderNum"`              //来源单号,源单号,订单号
		OrderGoodName                 string `json:"orderGoodName"`                 //订单产品名称
		DividendsReturnedDate         string `json:"dividendsReturnedDate"`         //退货日期
		RegionName                    string `json:"regionName"`                    //退货区域名称
		OrderGoodPrice                string `json:"orderGoodPrice"`                //订单产品单价
		OrderGoodQuantity             string `json:"orderGoodQuantity"`             //订单产品数量
		CooperationContractNumber     string `json:"cooperationContractNumber"`     //合约编号
		OrderTime                     string `json:"orderTime"`                     //订单日期
	}
	//请求参数
	ReqImportDividendsReturnedOrder struct {
		// 分红退货单数据
		DividendsReturnedOrderData []ImportDividendsReturnedOrderData `json:"dividendsReturnedOrderData"` //分红退货单数据列表
	}
	//响应参数
	DataImportDividendsReturnedOrder struct {
		SuccessCount int `json:"successCount"`
		Fail         struct {
			Header struct {
			} `json:"header"`
			Body []struct {
			} `json:"body"`
		} `json:"fail"`
	}
)

// ImportDividendsReturnedOrder 导入退货数据
func (gateway HttplibAlliedCreationCooperation) ImportDividendsReturnedOrder(param ReqImportDividendsReturnedOrder) (*DataImportDividendsReturnedOrder, error) {

	url := gateway.baseUrL + "/dividends-returned-orders/import"
	method := "POST"
	req := gateway.CreateRequest(url, method)
	// oneDemo
	log.Logger.Debug("向业务模块请求数据:导入退货数据。", map[string]interface{}{
		"api": method + ":" + url,
	})
	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 DataImportDividendsReturnedOrder
	err = gateway.GetResponseData(result, &data)
	return &data, err
}