作者 陈志颖

feat:增加分红订单导入

1 -package allied_creation_cooperation  
2 -  
3 -import (  
4 - "encoding/json"  
5 - "fmt"  
6 -  
7 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"  
8 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"  
9 -)  
10 -  
11 -//ReqImportDividendsReturnedOrder 导入退货数据  
12 -type (  
13 - ImportDividendsReturnedOrderData struct {  
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 - }  
24 - //请求参数  
25 - ReqImportDividendsReturnedOrder struct {  
26 - // 分红退货单数据  
27 - DividendsReturnedOrderData []ImportDividendsReturnedOrderData `json:"dividendsReturnedOrderData"` //分红退货单数据列表  
28 - }  
29 - //响应参数  
30 - DataImportDividendsReturnedOrder struct {  
31 - SuccessCount int `json:"successCount"`  
32 - Fail struct {  
33 - Header struct {  
34 - } `json:"header"`  
35 - Body []struct {  
36 - } `json:"body"`  
37 - } `json:"fail"`  
38 - }  
39 -)  
40 -  
41 -// ImportDividendsReturnedOrder 导入退货数据  
42 -func (gateway HttplibAlliedCreationCooperation) ImportDividendsReturnedOrder(param ReqImportDividendsReturnedOrder) (*DataImportDividendsReturnedOrder, error) {  
43 -  
44 - url := gateway.baseUrL + "/dividends-returned-orders/import"  
45 - method := "POST"  
46 - req := gateway.CreateRequest(url, method)  
47 - // oneDemo  
48 - log.Logger.Debug("向业务模块请求数据:导入退货数据。", map[string]interface{}{  
49 - "api": method + ":" + url,  
50 - })  
51 - req, err := req.JSONBody(param)  
52 - if err != nil {  
53 - return nil, fmt.Errorf("请求导入退货数据失败:%w", err)  
54 - }  
55 -  
56 - byteResult, err := req.Bytes()  
57 - if err != nil {  
58 - return nil, fmt.Errorf("获取导入退货数据失败:%w", err)  
59 - }  
60 - log.Logger.Debug("获取业务模块请求数据:导入退货数据。", map[string]interface{}{  
61 - "result": string(byteResult),  
62 - })  
63 - var result service_gateway.GatewayResponse  
64 - err = json.Unmarshal(byteResult, &result)  
65 - if err != nil {  
66 - return nil, fmt.Errorf("解析导入退货数据:%w", err)  
67 - }  
68 - var data DataImportDividendsReturnedOrder  
69 - err = gateway.GetResponseData(result, &data)  
70 - return &data, err  
71 -} 1 +package allied_creation_cooperation
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "fmt"
  6 +
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
  9 +)
  10 +
  11 +// ReqImportDividendsOrder 导入订单数据
  12 +type (
  13 + ImportDividendsOrderData struct {
  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 + }
  24 + // ReqImportDividendsOrder 请求参数
  25 + ReqImportDividendsOrder struct {
  26 + // 分红退货单数据
  27 + DividendsOrderData []ImportDividendsOrderData `json:"dividendsOrderData"` //分红订单数据列表
  28 + }
  29 + // DataImportDividendsOrder 响应参数
  30 + DataImportDividendsOrder struct {
  31 + SuccessCount int `json:"successCount"`
  32 + Fail struct {
  33 + Header struct {
  34 + } `json:"header"`
  35 + Body []struct {
  36 + } `json:"body"`
  37 + } `json:"fail"`
  38 + }
  39 +)
  40 +
  41 +//ReqImportDividendsReturnedOrder 导入退货单数据
  42 +type (
  43 + ImportDividendsReturnedOrderData struct {
  44 + DividendsReturnedCustomerName string `json:"dividendsReturnedCustomerName"` //退货客户名称
  45 + OriginalOrderNum string `json:"originalOrderNum"` //来源单号,源单号,订单号
  46 + OrderGoodName string `json:"orderGoodName"` //订单产品名称
  47 + DividendsReturnedDate string `json:"dividendsReturnedDate"` //退货日期
  48 + RegionName string `json:"regionName"` //退货区域名称
  49 + OrderGoodPrice string `json:"orderGoodPrice"` //订单产品单价
  50 + OrderGoodQuantity string `json:"orderGoodQuantity"` //订单产品数量
  51 + CooperationContractNumber string `json:"cooperationContractNumber"` //合约编号
  52 + OrderTime string `json:"orderTime"` //订单日期
  53 + }
  54 + // ReqImportDividendsReturnedOrder 请求参数
  55 + ReqImportDividendsReturnedOrder struct {
  56 + // 分红退货单数据
  57 + DividendsReturnedOrderData []ImportDividendsReturnedOrderData `json:"dividendsReturnedOrderData"` //分红退货单数据列表
  58 + }
  59 + // DataImportDividendsReturnedOrder 响应参数
  60 + DataImportDividendsReturnedOrder struct {
  61 + SuccessCount int `json:"successCount"`
  62 + Fail struct {
  63 + Header struct {
  64 + } `json:"header"`
  65 + Body []struct {
  66 + } `json:"body"`
  67 + } `json:"fail"`
  68 + }
  69 +)
  70 +
  71 +func (gateway HttplibAlliedCreationCooperation) ImportDividendsOrder(param ReqImportDividendsOrder) (*DataImportDividendsOrder, error) {
  72 + url := gateway.baseUrL + "/dividends-orders/import"
  73 + method := "POST"
  74 + req := gateway.CreateRequest(url, method)
  75 + log.Logger.Debug("向业务模块请求数据:导入订单数据", map[string]interface{}{
  76 + "api": method + ":" + url,
  77 + })
  78 + req, err := req.JSONBody(param)
  79 + if err != nil {
  80 + return nil, fmt.Errorf("请求导入订单数据失败:%w", err)
  81 + }
  82 +
  83 + byteResult, err := req.Bytes()
  84 + if err != nil {
  85 + return nil, fmt.Errorf("获取导入订单数据失败:%w", err)
  86 + }
  87 + log.Logger.Debug("获取业务耐磨块请求数据:导入订单数据", map[string]interface{}{
  88 + "result": string(byteResult),
  89 + })
  90 + var result service_gateway.GatewayResponse
  91 + err = json.Unmarshal(byteResult, &result)
  92 + if err != nil {
  93 + return nil, fmt.Errorf("解析导入订单数据:%w", err)
  94 + }
  95 + var data DataImportDividendsOrder
  96 + err = gateway.GetResponseData(result, &data)
  97 + return &data, err
  98 +}
  99 +
  100 +// ImportDividendsReturnedOrder 导入退货单数据
  101 +func (gateway HttplibAlliedCreationCooperation) ImportDividendsReturnedOrder(param ReqImportDividendsReturnedOrder) (*DataImportDividendsReturnedOrder, error) {
  102 + url := gateway.baseUrL + "/dividends-returned-orders/import"
  103 + method := "POST"
  104 + req := gateway.CreateRequest(url, method)
  105 + // oneDemo
  106 + log.Logger.Debug("向业务模块请求数据:导入退货单数据。", map[string]interface{}{
  107 + "api": method + ":" + url,
  108 + })
  109 + req, err := req.JSONBody(param)
  110 + if err != nil {
  111 + return nil, fmt.Errorf("请求导入退货数据失败:%w", err)
  112 + }
  113 +
  114 + byteResult, err := req.Bytes()
  115 + if err != nil {
  116 + return nil, fmt.Errorf("获取导入退货数据失败:%w", err)
  117 + }
  118 + log.Logger.Debug("获取业务模块请求数据:导入退货数据。", map[string]interface{}{
  119 + "result": string(byteResult),
  120 + })
  121 + var result service_gateway.GatewayResponse
  122 + err = json.Unmarshal(byteResult, &result)
  123 + if err != nil {
  124 + return nil, fmt.Errorf("解析导入退货数据:%w", err)
  125 + }
  126 + var data DataImportDividendsReturnedOrder
  127 + err = gateway.GetResponseData(result, &data)
  128 + return &data, err
  129 +}
@@ -83,6 +83,66 @@ func (controller ExcelDataController) ExportCooperationUser() { @@ -83,6 +83,66 @@ func (controller ExcelDataController) ExportCooperationUser() {
83 controller.responseExcelByFile(controller.Ctx, excelTool, "导出共创用户") 83 controller.responseExcelByFile(controller.Ctx, excelTool, "导出共创用户")
84 } 84 }
85 85
  86 +// ImportDividendsOrder TODO 导入分红订单
  87 +func (controller ExcelDataController) ImportDividendsOrder() {
  88 + excelFile, fileHeader, err := controller.GetFile("file")
  89 + if err != nil {
  90 + log.Logger.Error("接收文件失败," + err.Error())
  91 + controller.Response(nil, err)
  92 + return
  93 + }
  94 + if filepath.Ext(fileHeader.Filename) == "" {
  95 + //TODO 判断文件类型
  96 + log.Logger.Error("获取到的文件:" + fileHeader.Filename)
  97 + }
  98 + excelImport := excel.NewExcelImport()
  99 + excelImport.RowBegin = 2 //第二行开始读取
  100 + excelImport.DataFields = []excel.DataField{
  101 + {EnName: "OriginalOrderNum", CnName: "*来源源单号"},
  102 + {EnName: "DividendsReturnedCustomerName", CnName: "*客户名称"},
  103 + {EnName: "OrderGoodName", CnName: "*产品名称"},
  104 + {EnName: "DividendsReturnedDate", CnName: "*退货日期"},
  105 + {EnName: "OrderTime", CnName: "*订单日期"},
  106 + {EnName: "RegionName", CnName: "*退货区域"},
  107 + {EnName: "OrderGoodQuantity", CnName: "*退货数量"},
  108 + {EnName: "OrderGoodPrice", CnName: "*退货价格"},
  109 + {EnName: "CooperationContractNumber", CnName: "项目合约编号"},
  110 + }
  111 + excelData, err := excelImport.OpenExcelFromIoReader(excelFile)
  112 + if err != nil {
  113 + log.Logger.Error("解析excel文件失败," + err.Error())
  114 + controller.Response(nil, err)
  115 + return
  116 + }
  117 + //订单数据
  118 + var returnedOrderData []allied_creation_cooperation.ImportDividendsOrderData
  119 + for _, v := range excelData {
  120 + //TODO 按需转化
  121 + item := allied_creation_cooperation.ImportDividendsOrderData{
  122 + OriginalOrderNum: v["OriginalOrderNum"],
  123 + DividendsReturnedCustomerName: v["DividendsReturnedCustomerName"],
  124 + OrderGoodName: v["OrderGoodName"],
  125 + DividendsReturnedDate: v["DividendsReturnedDate"],
  126 + OrderTime: v["OrderTime"],
  127 + RegionName: v["RegionName"],
  128 + OrderGoodQuantity: v["OrderGoodQuantity"],
  129 + OrderGoodPrice: v["OrderGoodPrice"],
  130 + CooperationContractNumber: v["CooperationContractNumber"],
  131 + }
  132 + returnedOrderData = append(returnedOrderData, item)
  133 + }
  134 + creationCooperationGate := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(controller.GetOperator())
  135 + result, err := creationCooperationGate.ImportDividendsOrder(allied_creation_cooperation.ReqImportDividendsOrder{
  136 + DividendsOrderData: returnedOrderData,
  137 + })
  138 + if err != nil {
  139 + controller.Response(nil, err)
  140 + return
  141 + }
  142 + controller.Response(result, nil)
  143 +}
  144 +
  145 +// ImportDividendsReturnedOrder 导入分红退货单
86 func (controller ExcelDataController) ImportDividendsReturnedOrder() { 146 func (controller ExcelDataController) ImportDividendsReturnedOrder() {
87 excelFile, fileHeader, err := controller.GetFile("file") 147 excelFile, fileHeader, err := controller.GetFile("file")
88 if err != nil { 148 if err != nil {
@@ -11,4 +11,7 @@ func init() { @@ -11,4 +11,7 @@ func init() {
11 11
12 web.Router("/v1/web/excel/import/company-user", &web_client.ExcelDataController{}, "Post:ImportCompanyUser") 12 web.Router("/v1/web/excel/import/company-user", &web_client.ExcelDataController{}, "Post:ImportCompanyUser")
13 web.Router("/v1/web/excel/import/cooperation-user", &web_client.ExcelDataController{}, "Post:ImportCooperationUser") 13 web.Router("/v1/web/excel/import/cooperation-user", &web_client.ExcelDataController{}, "Post:ImportCooperationUser")
  14 +
  15 + web.Router("/v1/web/excel/import/dividends-orders", &web_client.ExcelDataController{}, "Post:ImportDividendsOrder")
  16 + web.Router("/v1/web/excel/import/dividends-returned-orders", &web_client.ExcelDataController{}, "Post:ImportDividendsReturnedOrder")
14 } 17 }