作者 tangxuhui

导入分红单修正数据处理逻辑

@@ -66,6 +66,7 @@ func (cooperationModeService *CooperationModeService) ListCooperationMode(listCo @@ -66,6 +66,7 @@ func (cooperationModeService *CooperationModeService) ListCooperationMode(listCo
66 OrganizationName: listCooperationModeQuery.OrganizationName, 66 OrganizationName: listCooperationModeQuery.OrganizationName,
67 CompanyId: listCooperationModeQuery.Operator.CompanyId, 67 CompanyId: listCooperationModeQuery.Operator.CompanyId,
68 UserId: 0, 68 UserId: 0,
  69 + OrgIds: listCooperationModeQuery.Operator.OrgIds,
69 OrgId: 0, 70 OrgId: 0,
70 UserBaseId: 0, 71 UserBaseId: 0,
71 }) 72 })
@@ -160,11 +160,12 @@ type ( @@ -160,11 +160,12 @@ type (
160 //模式名称 160 //模式名称
161 CooperationModeName string `json:"cooperationModeName"` 161 CooperationModeName string `json:"cooperationModeName"`
162 //组织名称 162 //组织名称
163 - OrganizationName string `json:"organizationName"`  
164 - CompanyId int64 `json:"companyId"`  
165 - OrgId int64 `json:"orgId"`  
166 - UserId int64 `json:"userId"`  
167 - UserBaseId int64 `json:"userBaseId"` 163 + OrganizationName string `json:"organizationName"`
  164 + CompanyId int64 `json:"companyId"`
  165 + OrgId int64 `json:"orgId"`
  166 + UserId int64 `json:"userId"`
  167 + UserBaseId int64 `json:"userBaseId"`
  168 + OrgIds []int64 `json:"orgIds"`
168 //模式编码列表 169 //模式编码列表
169 CooperationModeNumbers []string `cname:"模式编码列表" json:"cooperationModeNumbers,omitempty"` 170 CooperationModeNumbers []string `cname:"模式编码列表" json:"cooperationModeNumbers,omitempty"`
170 } 171 }
1 package web_client 1 package web_client
2 2
3 import ( 3 import (
4 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command" 4 + "errors"
5 "path/filepath" 5 "path/filepath"
  6 + "strings"
  7 +
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command"
6 9
7 "github.com/beego/beego/v2/server/web/context" 10 "github.com/beego/beego/v2/server/web/context"
8 "github.com/linmadan/egglib-go/utils/excel" 11 "github.com/linmadan/egglib-go/utils/excel"
@@ -29,6 +32,17 @@ func (controller *ExcelDataController) responseExcelByFile(ctx *context.Context, @@ -29,6 +32,17 @@ func (controller *ExcelDataController) responseExcelByFile(ctx *context.Context,
29 return nil 32 return nil
30 } 33 }
31 34
  35 +func (controller *ExcelDataController) fieldValueAllEmpty(param map[string]string) bool {
  36 + isAllEmpty := true
  37 + for _, v := range param {
  38 + value := strings.TrimSpace(v)
  39 + if len(value) > 0 {
  40 + isAllEmpty = false
  41 + }
  42 + }
  43 + return isAllEmpty
  44 +}
  45 +
32 //导出公司用户 46 //导出公司用户
33 func (controller ExcelDataController) ExportCompanyUser() { 47 func (controller ExcelDataController) ExportCompanyUser() {
34 excelService := service.NewExcelDataService(nil) 48 excelService := service.NewExcelDataService(nil)
@@ -91,12 +105,14 @@ func (controller ExcelDataController) ImportDividendsOrder() { @@ -91,12 +105,14 @@ func (controller ExcelDataController) ImportDividendsOrder() {
91 controller.Response(nil, err) 105 controller.Response(nil, err)
92 return 106 return
93 } 107 }
94 - if filepath.Ext(fileHeader.Filename) == "" { 108 + if filepath.Ext(fileHeader.Filename) != ".xlsx" {
95 //TODO 判断文件类型 109 //TODO 判断文件类型
96 log.Logger.Error("获取到的文件:" + fileHeader.Filename) 110 log.Logger.Error("获取到的文件:" + fileHeader.Filename)
  111 + controller.Response(nil, errors.New("上传到的文件类型错误"))
  112 + return
97 } 113 }
98 excelImport := excel.NewExcelImport() 114 excelImport := excel.NewExcelImport()
99 - excelImport.RowBegin = 3 //第三行开始读取 115 + excelImport.RowBegin = 2 //第2行开始读取
100 excelImport.DataFields = []excel.DataField{ 116 excelImport.DataFields = []excel.DataField{
101 {EnName: "OriginalOrderNum", CnName: "*来源单号"}, 117 {EnName: "OriginalOrderNum", CnName: "*来源单号"},
102 {EnName: "DividendsCustomerName", CnName: "*客户名称"}, 118 {EnName: "DividendsCustomerName", CnName: "*客户名称"},
@@ -117,17 +133,21 @@ func (controller ExcelDataController) ImportDividendsOrder() { @@ -117,17 +133,21 @@ func (controller ExcelDataController) ImportDividendsOrder() {
117 //订单数据 133 //订单数据
118 var returnedOrderData []allied_creation_cooperation.ImportDividendsOrderData 134 var returnedOrderData []allied_creation_cooperation.ImportDividendsOrderData
119 for _, v := range excelData { 135 for _, v := range excelData {
  136 + if allEmpty := controller.fieldValueAllEmpty(v); allEmpty {
  137 + //以全字段空跳过
  138 + continue
  139 + }
120 //TODO 按需转化 140 //TODO 按需转化
121 item := allied_creation_cooperation.ImportDividendsOrderData{ 141 item := allied_creation_cooperation.ImportDividendsOrderData{
122 - OriginalOrderNum: v["OriginalOrderNum"],  
123 - DividendsCustomerName: v["DividendsCustomerName"],  
124 - OrderGoodName: v["OrderGoodName"],  
125 - OrderTime: v["OrderTime"],  
126 - RegionName: v["RegionName"],  
127 - OrderGoodQuantity: v["OrderGoodQuantity"],  
128 - OrderGoodPrice: v["OrderGoodPrice"],  
129 - Expense: v["Expense"],  
130 - CooperationContractNumber: v["CooperationContractNumber"], 142 + OriginalOrderNum: strings.TrimSpace(v["OriginalOrderNum"]),
  143 + DividendsCustomerName: strings.TrimSpace(v["DividendsCustomerName"]),
  144 + OrderGoodName: strings.TrimSpace(v["OrderGoodName"]),
  145 + OrderTime: strings.TrimSpace(v["OrderTime"]),
  146 + RegionName: strings.TrimSpace(v["RegionName"]),
  147 + OrderGoodQuantity: strings.TrimSpace(v["OrderGoodQuantity"]),
  148 + OrderGoodPrice: strings.TrimSpace(v["OrderGoodPrice"]),
  149 + Expense: strings.TrimSpace(v["Expense"]),
  150 + CooperationContractNumber: strings.TrimSpace(v["CooperationContractNumber"]),
131 } 151 }
132 returnedOrderData = append(returnedOrderData, item) 152 returnedOrderData = append(returnedOrderData, item)
133 } 153 }
@@ -150,12 +170,14 @@ func (controller ExcelDataController) ImportDividendsReturnedOrder() { @@ -150,12 +170,14 @@ func (controller ExcelDataController) ImportDividendsReturnedOrder() {
150 controller.Response(nil, err) 170 controller.Response(nil, err)
151 return 171 return
152 } 172 }
153 - if filepath.Ext(fileHeader.Filename) == "" { 173 + if filepath.Ext(fileHeader.Filename) != ".xlsx" {
154 //TODO 判断文件类型 174 //TODO 判断文件类型
155 - log.Logger.Error("获取到的文件:" + fileHeader.Filename) 175 + log.Logger.Error("获取到的文件:" + filepath.Ext(fileHeader.Filename))
  176 + controller.Response(nil, errors.New("上传的文件类型错误"))
  177 + return
156 } 178 }
157 excelImport := excel.NewExcelImport() 179 excelImport := excel.NewExcelImport()
158 - excelImport.RowBegin = 3 //第三行开始读取 180 + excelImport.RowBegin = 2 //第2行表头开始读取
159 excelImport.DataFields = []excel.DataField{ 181 excelImport.DataFields = []excel.DataField{
160 {EnName: "OriginalOrderNum", CnName: "*来源单号"}, 182 {EnName: "OriginalOrderNum", CnName: "*来源单号"},
161 {EnName: "DividendsReturnedCustomerName", CnName: "*客户名称"}, 183 {EnName: "DividendsReturnedCustomerName", CnName: "*客户名称"},
@@ -176,17 +198,21 @@ func (controller ExcelDataController) ImportDividendsReturnedOrder() { @@ -176,17 +198,21 @@ func (controller ExcelDataController) ImportDividendsReturnedOrder() {
176 //退货单数据 198 //退货单数据
177 returnedOrderData := []allied_creation_cooperation.ImportDividendsReturnedOrderData{} 199 returnedOrderData := []allied_creation_cooperation.ImportDividendsReturnedOrderData{}
178 for _, v := range excelData { 200 for _, v := range excelData {
  201 + if allEmpty := controller.fieldValueAllEmpty(v); allEmpty {
  202 + //以全字段空跳过
  203 + continue
  204 + }
179 //TODO 按需转化 205 //TODO 按需转化
180 item := allied_creation_cooperation.ImportDividendsReturnedOrderData{ 206 item := allied_creation_cooperation.ImportDividendsReturnedOrderData{
181 - OriginalOrderNum: v["OriginalOrderNum"],  
182 - DividendsReturnedCustomerName: v["DividendsReturnedCustomerName"],  
183 - OrderGoodName: v["OrderGoodName"],  
184 - DividendsReturnedDate: v["DividendsReturnedDate"],  
185 - OrderTime: v["OrderTime"],  
186 - RegionName: v["RegionName"],  
187 - OrderGoodQuantity: v["OrderGoodQuantity"],  
188 - OrderGoodPrice: v["OrderGoodPrice"],  
189 - CooperationContractNumber: v["CooperationContractNumber"], 207 + OriginalOrderNum: strings.TrimSpace(v["OriginalOrderNum"]),
  208 + DividendsReturnedCustomerName: strings.TrimSpace(v["DividendsReturnedCustomerName"]),
  209 + OrderGoodName: strings.TrimSpace(v["OrderGoodName"]),
  210 + DividendsReturnedDate: strings.TrimSpace(v["DividendsReturnedDate"]),
  211 + OrderTime: strings.TrimSpace(v["OrderTime"]),
  212 + RegionName: strings.TrimSpace(v["RegionName"]),
  213 + OrderGoodQuantity: strings.TrimSpace(v["OrderGoodQuantity"]),
  214 + OrderGoodPrice: strings.TrimSpace(v["OrderGoodPrice"]),
  215 + CooperationContractNumber: strings.TrimSpace(v["CooperationContractNumber"]),
190 } 216 }
191 returnedOrderData = append(returnedOrderData, item) 217 returnedOrderData = append(returnedOrderData, item)
192 } 218 }