作者 Your Name

添加 退货单导入

@@ -3,7 +3,6 @@ package allied_creation_cooperation @@ -3,7 +3,6 @@ package allied_creation_cooperation
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
5 "fmt" 5 "fmt"
6 - "time"  
7 6
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
@@ -12,14 +11,15 @@ import ( @@ -12,14 +11,15 @@ import (
12 //ReqImportDividendsReturnedOrder 导入退货数据 11 //ReqImportDividendsReturnedOrder 导入退货数据
13 type ( 12 type (
14 ImportDividendsReturnedOrderData struct { 13 ImportDividendsReturnedOrderData struct {
15 - DividendsReturnedCustomerName string `json:"dividendsReturnedCustomerName"` //退货客户名称  
16 - OriginalOrderNum string `json:"originalOrderNum"` //来源单号,源单号,订单号  
17 - OrderGoodName string `json:"orderGoodName"` //订单产品名称  
18 - DividendsReturnedDate time.Time `json:"dividendsReturnedDate"` //退货日期  
19 - RegionName string `json:"regionName"` //退货区域名称  
20 - OrderGoodPrice float64 `json:"orderGoodPrice"` //订单产品单价  
21 - OrderGoodQuantity int64 `json:"orderGoodQuantity"` //订单产品数量  
22 - CooperationContractNumber string `json:"cooperationContractNumber"` //合约编号 14 + DividendsReturnedCustomerName string `json:"dividendsReturnedCustomerName"` //退货客户名称
  15 + OriginalOrderNum string `json:"originalOrderNum"` //来源单号,源单号,订单号
  16 + OrderGoodName string `json:"orderGoodName"` //订单产品名称
  17 + DividendsReturnedDate string `json:"dividendsReturnedDate"` //退货日期
  18 + RegionName string `json:"regionName"` //退货区域名称
  19 + OrderGoodPrice string `json:"orderGoodPrice"` //订单产品单价
  20 + OrderGoodQuantity string `json:"orderGoodQuantity"` //订单产品数量
  21 + CooperationContractNumber string `json:"cooperationContractNumber"` //合约编号
  22 + OrderTime string `json:"orderTime"` //订单日期
23 } 23 }
24 //请求参数 24 //请求参数
25 ReqImportDividendsReturnedOrder struct { 25 ReqImportDividendsReturnedOrder struct {
@@ -28,25 +28,25 @@ type ( @@ -28,25 +28,25 @@ type (
28 } 28 }
29 //响应参数 29 //响应参数
30 DataImportDividendsReturnedOrder struct { 30 DataImportDividendsReturnedOrder struct {
31 - SuccessCount int 31 + SuccessCount int `json:"successCount"`
32 Fail struct { 32 Fail struct {
33 Header struct { 33 Header struct {
34 - } 34 + } `json:"header"`
35 Body []struct { 35 Body []struct {
36 - }  
37 - } 36 + } `json:"body"`
  37 + } `json:"fail"`
38 } 38 }
39 ) 39 )
40 40
41 // ImportDividendsReturnedOrder 导入退货数据 41 // ImportDividendsReturnedOrder 导入退货数据
42 -func (gateway HttplibAlliedCreationCooperation) ImportDividendsReturnedOrder(param ReqDividendsEstimateSearchDividend) (*DataDividendsEstimateSearchDividend, error) { 42 +func (gateway HttplibAlliedCreationCooperation) ImportDividendsReturnedOrder(param ReqImportDividendsReturnedOrder) (*DataImportDividendsReturnedOrder, error) {
  43 +
43 url := gateway.baseUrL + "/dividends-returned-orders/import" 44 url := gateway.baseUrL + "/dividends-returned-orders/import"
44 method := "POST" 45 method := "POST"
45 req := gateway.CreateRequest(url, method) 46 req := gateway.CreateRequest(url, method)
46 // oneDemo 47 // oneDemo
47 log.Logger.Debug("向业务模块请求数据:导入退货数据。", map[string]interface{}{ 48 log.Logger.Debug("向业务模块请求数据:导入退货数据。", map[string]interface{}{
48 "api": method + ":" + url, 49 "api": method + ":" + url,
49 - // "param": param,  
50 }) 50 })
51 req, err := req.JSONBody(param) 51 req, err := req.JSONBody(param)
52 if err != nil { 52 if err != nil {
@@ -65,7 +65,7 @@ func (gateway HttplibAlliedCreationCooperation) ImportDividendsReturnedOrder(par @@ -65,7 +65,7 @@ func (gateway HttplibAlliedCreationCooperation) ImportDividendsReturnedOrder(par
65 if err != nil { 65 if err != nil {
66 return nil, fmt.Errorf("解析导入退货数据:%w", err) 66 return nil, fmt.Errorf("解析导入退货数据:%w", err)
67 } 67 }
68 - var data DataDividendsEstimateSearchDividend 68 + var data DataImportDividendsReturnedOrder
69 err = gateway.GetResponseData(result, &data) 69 err = gateway.GetResponseData(result, &data)
70 return &data, err 70 return &data, err
71 } 71 }
1 package web_client 1 package web_client
2 2
3 import ( 3 import (
4 - "github.com/beego/beego/v2/server/web/context" 4 + "path/filepath"
5 5
  6 + "github.com/beego/beego/v2/server/web/context"
6 "github.com/linmadan/egglib-go/utils/excel" 7 "github.com/linmadan/egglib-go/utils/excel"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/service" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/service"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
10 ) 12 )
11 13
@@ -52,3 +54,61 @@ func (controller ExcelDataController) ExportCompanyUser() { @@ -52,3 +54,61 @@ func (controller ExcelDataController) ExportCompanyUser() {
52 } 54 }
53 controller.responseExcelByFile(controller.Ctx, excelTool, "导出公司用户") 55 controller.responseExcelByFile(controller.Ctx, excelTool, "导出公司用户")
54 } 56 }
  57 +
  58 +func (controller ExcelDataController) ImportDividendsReturnedOrder() {
  59 + excelFile, fileHeader, err := controller.GetFile("file")
  60 + if err != nil {
  61 + log.Logger.Error("接收文件失败," + err.Error())
  62 + controller.Response(nil, err)
  63 + return
  64 + }
  65 + if filepath.Ext(fileHeader.Filename) == "" {
  66 + //TODO 判断文件类型
  67 + log.Logger.Error("获取到的文件:" + fileHeader.Filename)
  68 + }
  69 + excelImport := excel.NewExcelImport()
  70 + excelImport.RowBegin = 2 //第二行开始读取
  71 + excelImport.DataFields = []excel.DataField{
  72 + {EnName: "OriginalOrderNum", CnName: "*来源源单号"},
  73 + {EnName: "DividendsReturnedCustomerName", CnName: "*客户名称"},
  74 + {EnName: "OrderGoodName", CnName: "*产品名称"},
  75 + {EnName: "DividendsReturnedDate", CnName: "*退货日期"},
  76 + {EnName: "OrderTime", CnName: "*订单日期"},
  77 + {EnName: "RegionName", CnName: "*退货区域"},
  78 + {EnName: "OrderGoodQuantity", CnName: "*退货数量"},
  79 + {EnName: "OrderGoodPrice", CnName: "*退货价格"},
  80 + {EnName: "CooperationContractNumber", CnName: "项目合约编号"},
  81 + }
  82 + excelData, err := excelImport.OpenExcelFromIoReader(excelFile)
  83 + if err != nil {
  84 + log.Logger.Error("解析excel文件失败," + err.Error())
  85 + controller.Response(nil, err)
  86 + return
  87 + }
  88 + //退货单数据
  89 + returnedOrderData := []allied_creation_cooperation.ImportDividendsReturnedOrderData{}
  90 + for _, v := range excelData {
  91 + //TODO 按需转化
  92 + item := allied_creation_cooperation.ImportDividendsReturnedOrderData{
  93 + OriginalOrderNum: v["OriginalOrderNum"],
  94 + DividendsReturnedCustomerName: v["DividendsReturnedCustomerName"],
  95 + OrderGoodName: v["OrderGoodName"],
  96 + DividendsReturnedDate: v["DividendsReturnedDate"],
  97 + OrderTime: v["OrderTime"],
  98 + RegionName: v["RegionName"],
  99 + OrderGoodQuantity: v["OrderGoodQuantity"],
  100 + OrderGoodPrice: v["OrderGoodPrice"],
  101 + CooperationContractNumber: v["CooperationContractNumber"],
  102 + }
  103 + returnedOrderData = append(returnedOrderData, item)
  104 + }
  105 + creationCooperationGate := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(controller.GetOperator())
  106 + result, err := creationCooperationGate.ImportDividendsReturnedOrder(allied_creation_cooperation.ReqImportDividendsReturnedOrder{
  107 + DividendsReturnedOrderData: returnedOrderData,
  108 + })
  109 + if err != nil {
  110 + controller.Response(nil, err)
  111 + return
  112 + }
  113 + controller.Response(result, nil)
  114 +}