作者 陈志颖

feat:增加分红订单导入

@@ -8,7 +8,37 @@ import ( @@ -8,7 +8,37 @@ import (
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
9 ) 9 )
10 10
11 -//ReqImportDividendsReturnedOrder 导入退货数据 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 导入退货单数据
12 type ( 42 type (
13 ImportDividendsReturnedOrderData struct { 43 ImportDividendsReturnedOrderData struct {
14 DividendsReturnedCustomerName string `json:"dividendsReturnedCustomerName"` //退货客户名称 44 DividendsReturnedCustomerName string `json:"dividendsReturnedCustomerName"` //退货客户名称
@@ -21,12 +51,12 @@ type ( @@ -21,12 +51,12 @@ type (
21 CooperationContractNumber string `json:"cooperationContractNumber"` //合约编号 51 CooperationContractNumber string `json:"cooperationContractNumber"` //合约编号
22 OrderTime string `json:"orderTime"` //订单日期 52 OrderTime string `json:"orderTime"` //订单日期
23 } 53 }
24 - //请求参数 54 + // ReqImportDividendsReturnedOrder 请求参数
25 ReqImportDividendsReturnedOrder struct { 55 ReqImportDividendsReturnedOrder struct {
26 // 分红退货单数据 56 // 分红退货单数据
27 DividendsReturnedOrderData []ImportDividendsReturnedOrderData `json:"dividendsReturnedOrderData"` //分红退货单数据列表 57 DividendsReturnedOrderData []ImportDividendsReturnedOrderData `json:"dividendsReturnedOrderData"` //分红退货单数据列表
28 } 58 }
29 - //响应参数 59 + // DataImportDividendsReturnedOrder 响应参数
30 DataImportDividendsReturnedOrder struct { 60 DataImportDividendsReturnedOrder struct {
31 SuccessCount int `json:"successCount"` 61 SuccessCount int `json:"successCount"`
32 Fail struct { 62 Fail struct {
@@ -38,14 +68,42 @@ type ( @@ -38,14 +68,42 @@ type (
38 } 68 }
39 ) 69 )
40 70
41 -// ImportDividendsReturnedOrder 导入退货数据  
42 -func (gateway HttplibAlliedCreationCooperation) ImportDividendsReturnedOrder(param ReqImportDividendsReturnedOrder) (*DataImportDividendsReturnedOrder, error) { 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 +}
43 99
  100 +// ImportDividendsReturnedOrder 导入退货单数据
  101 +func (gateway HttplibAlliedCreationCooperation) ImportDividendsReturnedOrder(param ReqImportDividendsReturnedOrder) (*DataImportDividendsReturnedOrder, error) {
44 url := gateway.baseUrL + "/dividends-returned-orders/import" 102 url := gateway.baseUrL + "/dividends-returned-orders/import"
45 method := "POST" 103 method := "POST"
46 req := gateway.CreateRequest(url, method) 104 req := gateway.CreateRequest(url, method)
47 // oneDemo 105 // oneDemo
48 - log.Logger.Debug("向业务模块请求数据:导入退货数据。", map[string]interface{}{ 106 + log.Logger.Debug("向业务模块请求数据:导入退货单数据。", map[string]interface{}{
49 "api": method + ":" + url, 107 "api": method + ":" + url,
50 }) 108 })
51 req, err := req.JSONBody(param) 109 req, err := req.JSONBody(param)
@@ -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 }