作者 Your Name

添加 退货单导入

... ... @@ -3,7 +3,6 @@ package allied_creation_cooperation
import (
"encoding/json"
"fmt"
"time"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
... ... @@ -12,14 +11,15 @@ import (
//ReqImportDividendsReturnedOrder 导入退货数据
type (
ImportDividendsReturnedOrderData struct {
DividendsReturnedCustomerName string `json:"dividendsReturnedCustomerName"` //退货客户名称
OriginalOrderNum string `json:"originalOrderNum"` //来源单号,源单号,订单号
OrderGoodName string `json:"orderGoodName"` //订单产品名称
DividendsReturnedDate time.Time `json:"dividendsReturnedDate"` //退货日期
RegionName string `json:"regionName"` //退货区域名称
OrderGoodPrice float64 `json:"orderGoodPrice"` //订单产品单价
OrderGoodQuantity int64 `json:"orderGoodQuantity"` //订单产品数量
CooperationContractNumber string `json:"cooperationContractNumber"` //合约编号
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 {
... ... @@ -28,25 +28,25 @@ type (
}
//响应参数
DataImportDividendsReturnedOrder struct {
SuccessCount int
SuccessCount int `json:"successCount"`
Fail struct {
Header struct {
}
} `json:"header"`
Body []struct {
}
}
} `json:"body"`
} `json:"fail"`
}
)
// ImportDividendsReturnedOrder 导入退货数据
func (gateway HttplibAlliedCreationCooperation) ImportDividendsReturnedOrder(param ReqDividendsEstimateSearchDividend) (*DataDividendsEstimateSearchDividend, error) {
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,
// "param": param,
})
req, err := req.JSONBody(param)
if err != nil {
... ... @@ -65,7 +65,7 @@ func (gateway HttplibAlliedCreationCooperation) ImportDividendsReturnedOrder(par
if err != nil {
return nil, fmt.Errorf("解析导入退货数据:%w", err)
}
var data DataDividendsEstimateSearchDividend
var data DataImportDividendsReturnedOrder
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ...
package web_client
import (
"github.com/beego/beego/v2/server/web/context"
"path/filepath"
"github.com/beego/beego/v2/server/web/context"
"github.com/linmadan/egglib-go/utils/excel"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
)
... ... @@ -52,3 +54,61 @@ func (controller ExcelDataController) ExportCompanyUser() {
}
controller.responseExcelByFile(controller.Ctx, excelTool, "导出公司用户")
}
func (controller ExcelDataController) ImportDividendsReturnedOrder() {
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
}
//退货单数据
returnedOrderData := []allied_creation_cooperation.ImportDividendsReturnedOrderData{}
for _, v := range excelData {
//TODO 按需转化
item := allied_creation_cooperation.ImportDividendsReturnedOrderData{
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.ImportDividendsReturnedOrder(allied_creation_cooperation.ReqImportDividendsReturnedOrder{
DividendsReturnedOrderData: returnedOrderData,
})
if err != nil {
controller.Response(nil, err)
return
}
controller.Response(result, nil)
}
... ...