作者 陈志颖

feat:增加分红订单导入

... ... @@ -8,7 +8,37 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
)
//ReqImportDividendsReturnedOrder 导入退货数据
// ReqImportDividendsOrder 导入订单数据
type (
ImportDividendsOrderData 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"` //订单日期
}
// ReqImportDividendsOrder 请求参数
ReqImportDividendsOrder struct {
// 分红退货单数据
DividendsOrderData []ImportDividendsOrderData `json:"dividendsOrderData"` //分红订单数据列表
}
// DataImportDividendsOrder 响应参数
DataImportDividendsOrder struct {
SuccessCount int `json:"successCount"`
Fail struct {
Header struct {
} `json:"header"`
Body []struct {
} `json:"body"`
} `json:"fail"`
}
)
//ReqImportDividendsReturnedOrder 导入退货单数据
type (
ImportDividendsReturnedOrderData struct {
DividendsReturnedCustomerName string `json:"dividendsReturnedCustomerName"` //退货客户名称
... ... @@ -21,12 +51,12 @@ type (
CooperationContractNumber string `json:"cooperationContractNumber"` //合约编号
OrderTime string `json:"orderTime"` //订单日期
}
//请求参数
// ReqImportDividendsReturnedOrder 请求参数
ReqImportDividendsReturnedOrder struct {
// 分红退货单数据
DividendsReturnedOrderData []ImportDividendsReturnedOrderData `json:"dividendsReturnedOrderData"` //分红退货单数据列表
}
//响应参数
// DataImportDividendsReturnedOrder 响应参数
DataImportDividendsReturnedOrder struct {
SuccessCount int `json:"successCount"`
Fail struct {
... ... @@ -38,14 +68,42 @@ type (
}
)
// ImportDividendsReturnedOrder 导入退货数据
func (gateway HttplibAlliedCreationCooperation) ImportDividendsReturnedOrder(param ReqImportDividendsReturnedOrder) (*DataImportDividendsReturnedOrder, error) {
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{}{
log.Logger.Debug("向业务模块请求数据:导入退货单数据。", map[string]interface{}{
"api": method + ":" + url,
})
req, err := req.JSONBody(param)
... ...
... ... @@ -83,6 +83,66 @@ func (controller ExcelDataController) ExportCooperationUser() {
controller.responseExcelByFile(controller.Ctx, excelTool, "导出共创用户")
}
// ImportDividendsOrder TODO 导入分红订单
func (controller ExcelDataController) ImportDividendsOrder() {
excelFile, fileHeader, err := controller.GetFile("file")
if err != nil {
log.Logger.Error("接收文件失败," + err.Error())
controller.Response(nil, err)
return
}
if filepath.Ext(fileHeader.Filename) == "" {
//TODO 判断文件类型
log.Logger.Error("获取到的文件:" + fileHeader.Filename)
}
excelImport := excel.NewExcelImport()
excelImport.RowBegin = 2 //第二行开始读取
excelImport.DataFields = []excel.DataField{
{EnName: "OriginalOrderNum", CnName: "*来源源单号"},
{EnName: "DividendsReturnedCustomerName", CnName: "*客户名称"},
{EnName: "OrderGoodName", CnName: "*产品名称"},
{EnName: "DividendsReturnedDate", CnName: "*退货日期"},
{EnName: "OrderTime", CnName: "*订单日期"},
{EnName: "RegionName", CnName: "*退货区域"},
{EnName: "OrderGoodQuantity", CnName: "*退货数量"},
{EnName: "OrderGoodPrice", CnName: "*退货价格"},
{EnName: "CooperationContractNumber", CnName: "项目合约编号"},
}
excelData, err := excelImport.OpenExcelFromIoReader(excelFile)
if err != nil {
log.Logger.Error("解析excel文件失败," + err.Error())
controller.Response(nil, err)
return
}
//订单数据
var returnedOrderData []allied_creation_cooperation.ImportDividendsOrderData
for _, v := range excelData {
//TODO 按需转化
item := allied_creation_cooperation.ImportDividendsOrderData{
OriginalOrderNum: v["OriginalOrderNum"],
DividendsReturnedCustomerName: v["DividendsReturnedCustomerName"],
OrderGoodName: v["OrderGoodName"],
DividendsReturnedDate: v["DividendsReturnedDate"],
OrderTime: v["OrderTime"],
RegionName: v["RegionName"],
OrderGoodQuantity: v["OrderGoodQuantity"],
OrderGoodPrice: v["OrderGoodPrice"],
CooperationContractNumber: v["CooperationContractNumber"],
}
returnedOrderData = append(returnedOrderData, item)
}
creationCooperationGate := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(controller.GetOperator())
result, err := creationCooperationGate.ImportDividendsOrder(allied_creation_cooperation.ReqImportDividendsOrder{
DividendsOrderData: returnedOrderData,
})
if err != nil {
controller.Response(nil, err)
return
}
controller.Response(result, nil)
}
// ImportDividendsReturnedOrder 导入分红退货单
func (controller ExcelDataController) ImportDividendsReturnedOrder() {
excelFile, fileHeader, err := controller.GetFile("file")
if err != nil {
... ...
... ... @@ -11,4 +11,7 @@ func init() {
web.Router("/v1/web/excel/import/company-user", &web_client.ExcelDataController{}, "Post:ImportCompanyUser")
web.Router("/v1/web/excel/import/cooperation-user", &web_client.ExcelDataController{}, "Post:ImportCooperationUser")
web.Router("/v1/web/excel/import/dividends-orders", &web_client.ExcelDataController{}, "Post:ImportDividendsOrder")
web.Router("/v1/web/excel/import/dividends-returned-orders", &web_client.ExcelDataController{}, "Post:ImportDividendsReturnedOrder")
}
... ...