module_excel_data.go 8.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"
)

// ReqImportDividendsOrder 导入订单数据
type (
	ImportDividendsOrderData struct {
		OriginalOrderNum          string `json:"originalOrderNum"`          //来源单号,源单号,订单号
		DividendsCustomerName     string `json:"dividendsCustomerName"`     //订单客户名称
		OrderGoodName             string `json:"orderGoodName"`             //订单产品名称
		OrderTime                 string `json:"orderTime"`                 //订单日期
		RegionName                string `json:"regionName"`                //订单区域名称
		OrderGoodQuantity         string `json:"orderGoodQuantity"`         //订单产品数量
		OrderGoodPrice            string `json:"orderGoodPrice"`            //订单产品单价
		Expense                   string `json:"expense"`                   //费用
		CooperationContractNumber string `json:"cooperationContractNumber"` //合约编号
	}
	// ReqImportDividendsOrder 请求参数
	ReqImportDividendsOrder struct {
		// 分红订单数据
		DividendsOrderData []ImportDividendsOrderData `json:"dividendsOrderData"` //分红订单数据列表
	}
	// DataImportDividendsOrder 响应参数
	DataImportDividendsOrder struct {
		SuccessCount int `json:"successCount"`
		Fail         struct {
			Header struct { //
				FailReason                string `json:"failReason"`                //'失败原因',
				OriginalOrderNum          string `json:"originalOrderNum"`          //来源单号,源单号,订单号
				DividendsCustomerName     string `json:"dividendsCustomerName"`     //订单客户名称
				OrderGoodName             string `json:"orderGoodName"`             //订单产品名称
				OrderTime                 string `json:"orderTime"`                 //订单日期
				RegionName                string `json:"regionName"`                //订单区域名称
				OrderGoodQuantity         string `json:"orderGoodQuantity"`         //订单产品数量
				OrderGoodPrice            string `json:"orderGoodPrice"`            //订单产品单价
				Expense                   string `json:"expense"`                   //费用
				CooperationContractNumber string `json:"cooperationContractNumber"` //合约编号
			} `json:"header"`
			Body []struct {
				FailReason                string `json:"failReason"`
				OriginalOrderNum          string `json:"originalOrderNum"`          //来源单号,源单号,订单号
				DividendsCustomerName     string `json:"dividendsCustomerName"`     //订单客户名称
				OrderGoodName             string `json:"orderGoodName"`             //订单产品名称
				OrderTime                 string `json:"orderTime"`                 //订单日期
				RegionName                string `json:"regionName"`                //订单区域名称
				OrderGoodQuantity         string `json:"orderGoodQuantity"`         //订单产品数量
				OrderGoodPrice            string `json:"orderGoodPrice"`            //订单产品单价
				Expense                   string `json:"expense"`                   //费用
				CooperationContractNumber string `json:"cooperationContractNumber"` //合约编号
			} `json:"body"`
		} `json:"fail"`
	}
)

//ReqImportDividendsReturnedOrder 导入退货单数据
type (
	ImportDividendsReturnedOrderData struct {
		OriginalOrderNum              string `json:"originalOrderNum"`              //来源单号,源单号,订单号
		DividendsReturnedCustomerName string `json:"dividendsReturnedCustomerName"` //退货客户名称
		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 请求参数
	ReqImportDividendsReturnedOrder struct {
		// 分红退货单数据
		DividendsReturnedOrderData []ImportDividendsReturnedOrderData `json:"dividendsReturnedOrderData"` //分红退货单数据列表
	}
	// DataImportDividendsReturnedOrder 响应参数
	DataImportDividendsReturnedOrder struct {
		SuccessCount int `json:"successCount"`
		Fail         struct {
			Header struct {
				FailReason                    string `json:"failReason"`
				OriginalOrderNum              string `json:"originalOrderNum"`              //来源单号,源单号,订单号
				DividendsReturnedCustomerName string `json:"dividendsReturnedCustomerName"` //退货客户名称
				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"`                     //订单日期
			} `json:"header"`
			Body []struct {
				FailReason                    string `json:"failReason"`
				OriginalOrderNum              string `json:"originalOrderNum"`              //来源单号,源单号,订单号
				DividendsReturnedCustomerName string `json:"dividendsReturnedCustomerName"` //退货客户名称
				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"`                     //订单日期
			} `json:"body"`
		} `json:"fail"`
	}
)

func (gateway HttplibAlliedCreationCooperation) ImportDividendsOrder(param ReqImportDividendsOrder) (*DataImportDividendsOrder, error) {
	url := gateway.baseUrL + "/dividends-orders/import"
	method := "POST"
	req := gateway.CreateRequest(url, method)
	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 DataImportDividendsOrder
	err = gateway.GetResponseData(result, &data)
	return &data, err
}

// 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
}