1
|
package web_client
|
1
|
package web_client
|
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
4
|
- "errors"
|
|
|
5
|
- "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
|
|
|
6
|
- "path/filepath"
|
|
|
7
|
"strings"
|
4
|
"strings"
|
8
|
|
5
|
|
|
|
6
|
+ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
|
|
|
7
|
+
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command"
|
8
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command"
|
10
|
|
9
|
|
11
|
"github.com/beego/beego/v2/server/web/context"
|
10
|
"github.com/beego/beego/v2/server/web/context"
|
|
@@ -100,18 +99,16 @@ func (controller ExcelDataController) ExportCooperationUser() { |
|
@@ -100,18 +99,16 @@ func (controller ExcelDataController) ExportCooperationUser() { |
100
|
|
99
|
|
101
|
// ImportDividendsOrder TODO 导入分红订单
|
100
|
// ImportDividendsOrder TODO 导入分红订单
|
102
|
func (controller ExcelDataController) ImportDividendsOrder() {
|
101
|
func (controller ExcelDataController) ImportDividendsOrder() {
|
103
|
- excelFile, fileHeader, err := controller.GetFile("file")
|
102
|
+ importDividendsOrder(controller)
|
|
|
103
|
+}
|
|
|
104
|
+
|
|
|
105
|
+func importDividendsOrder(controller ExcelDataController) {
|
|
|
106
|
+
|
|
|
107
|
+ fileReader, err := controller.GetExcelFile()
|
104
|
if err != nil {
|
108
|
if err != nil {
|
105
|
- log.Logger.Error("接收文件失败," + err.Error())
|
|
|
106
|
controller.Response(nil, err)
|
109
|
controller.Response(nil, err)
|
107
|
return
|
110
|
return
|
108
|
}
|
111
|
}
|
109
|
- if filepath.Ext(fileHeader.Filename) != ".xlsx" {
|
|
|
110
|
- //TODO 判断文件类型
|
|
|
111
|
- log.Logger.Error("获取到的文件:" + fileHeader.Filename)
|
|
|
112
|
- controller.Response(nil, errors.New("上传到的文件类型错误"))
|
|
|
113
|
- return
|
|
|
114
|
- }
|
|
|
115
|
excelImport := excel.NewExcelImport()
|
112
|
excelImport := excel.NewExcelImport()
|
116
|
excelImport.RowBegin = 2 //第2行开始读取
|
113
|
excelImport.RowBegin = 2 //第2行开始读取
|
117
|
excelImport.DataFields = []excel.DataField{
|
114
|
excelImport.DataFields = []excel.DataField{
|
|
@@ -125,7 +122,7 @@ func (controller ExcelDataController) ImportDividendsOrder() { |
|
@@ -125,7 +122,7 @@ func (controller ExcelDataController) ImportDividendsOrder() { |
125
|
{EnName: "Expense", CnName: "费用"},
|
122
|
{EnName: "Expense", CnName: "费用"},
|
126
|
{EnName: "CooperationContractNumber", CnName: "项目合约编号"},
|
123
|
{EnName: "CooperationContractNumber", CnName: "项目合约编号"},
|
127
|
}
|
124
|
}
|
128
|
- excelData, err := excelImport.OpenExcelFromIoReader(excelFile)
|
125
|
+ excelData, err := excelImport.OpenExcelFromIoReader(fileReader)
|
129
|
if err != nil {
|
126
|
if err != nil {
|
130
|
log.Logger.Error("解析excel文件失败," + err.Error())
|
127
|
log.Logger.Error("解析excel文件失败," + err.Error())
|
131
|
controller.Response(nil, err)
|
128
|
controller.Response(nil, err)
|
|
@@ -165,18 +162,16 @@ func (controller ExcelDataController) ImportDividendsOrder() { |
|
@@ -165,18 +162,16 @@ func (controller ExcelDataController) ImportDividendsOrder() { |
165
|
|
162
|
|
166
|
// ImportDividendsReturnedOrder 导入分红退货单
|
163
|
// ImportDividendsReturnedOrder 导入分红退货单
|
167
|
func (controller ExcelDataController) ImportDividendsReturnedOrder() {
|
164
|
func (controller ExcelDataController) ImportDividendsReturnedOrder() {
|
168
|
- excelFile, fileHeader, err := controller.GetFile("file")
|
165
|
+ importDividendsReturnedOrder(controller)
|
|
|
166
|
+}
|
|
|
167
|
+
|
|
|
168
|
+func importDividendsReturnedOrder(controller ExcelDataController) {
|
|
|
169
|
+
|
|
|
170
|
+ fileReader, err := controller.GetExcelFile()
|
169
|
if err != nil {
|
171
|
if err != nil {
|
170
|
- log.Logger.Error("接收文件失败," + err.Error())
|
|
|
171
|
controller.Response(nil, err)
|
172
|
controller.Response(nil, err)
|
172
|
return
|
173
|
return
|
173
|
}
|
174
|
}
|
174
|
- if filepath.Ext(fileHeader.Filename) != ".xlsx" {
|
|
|
175
|
- //TODO 判断文件类型
|
|
|
176
|
- log.Logger.Error("获取到的文件:" + filepath.Ext(fileHeader.Filename))
|
|
|
177
|
- controller.Response(nil, errors.New("上传的文件类型错误"))
|
|
|
178
|
- return
|
|
|
179
|
- }
|
|
|
180
|
excelImport := excel.NewExcelImport()
|
175
|
excelImport := excel.NewExcelImport()
|
181
|
excelImport.RowBegin = 2 //第2行表头开始读取
|
176
|
excelImport.RowBegin = 2 //第2行表头开始读取
|
182
|
excelImport.DataFields = []excel.DataField{
|
177
|
excelImport.DataFields = []excel.DataField{
|
|
@@ -190,7 +185,7 @@ func (controller ExcelDataController) ImportDividendsReturnedOrder() { |
|
@@ -190,7 +185,7 @@ func (controller ExcelDataController) ImportDividendsReturnedOrder() { |
190
|
{EnName: "OrderGoodPrice", CnName: "*退货价格"},
|
185
|
{EnName: "OrderGoodPrice", CnName: "*退货价格"},
|
191
|
{EnName: "CooperationContractNumber", CnName: "项目合约编号"},
|
186
|
{EnName: "CooperationContractNumber", CnName: "项目合约编号"},
|
192
|
}
|
187
|
}
|
193
|
- excelData, err := excelImport.OpenExcelFromIoReader(excelFile)
|
188
|
+ excelData, err := excelImport.OpenExcelFromIoReader(fileReader)
|
194
|
if err != nil {
|
189
|
if err != nil {
|
195
|
log.Logger.Error("解析excel文件失败," + err.Error())
|
190
|
log.Logger.Error("解析excel文件失败," + err.Error())
|
196
|
controller.Response(nil, err)
|
191
|
controller.Response(nil, err)
|
|
@@ -229,6 +224,9 @@ func (controller ExcelDataController) ImportDividendsReturnedOrder() { |
|
@@ -229,6 +224,9 @@ func (controller ExcelDataController) ImportDividendsReturnedOrder() { |
229
|
}
|
224
|
}
|
230
|
|
225
|
|
231
|
func (controller ExcelDataController) ImportCompanyUser() {
|
226
|
func (controller ExcelDataController) ImportCompanyUser() {
|
|
|
227
|
+ importCompanyUser(controller)
|
|
|
228
|
+}
|
|
|
229
|
+func importCompanyUser(controller ExcelDataController) {
|
232
|
excelService := service.NewExcelDataService(nil)
|
230
|
excelService := service.NewExcelDataService(nil)
|
233
|
r, err := controller.GetExcelFile()
|
231
|
r, err := controller.GetExcelFile()
|
234
|
if err != nil {
|
232
|
if err != nil {
|
|
@@ -243,6 +241,9 @@ func (controller ExcelDataController) ImportCompanyUser() { |
|
@@ -243,6 +241,9 @@ func (controller ExcelDataController) ImportCompanyUser() { |
243
|
}
|
241
|
}
|
244
|
|
242
|
|
245
|
func (controller ExcelDataController) ImportCooperationUser() {
|
243
|
func (controller ExcelDataController) ImportCooperationUser() {
|
|
|
244
|
+ importCooperationUser(controller)
|
|
|
245
|
+}
|
|
|
246
|
+func importCooperationUser(controller ExcelDataController) {
|
246
|
excelService := service.NewExcelDataService(nil)
|
247
|
excelService := service.NewExcelDataService(nil)
|
247
|
r, err := controller.GetExcelFile()
|
248
|
r, err := controller.GetExcelFile()
|
248
|
if err != nil {
|
249
|
if err != nil {
|
|
@@ -271,26 +272,37 @@ func (controller ExcelDataController) ImportOrganization() { |
|
@@ -271,26 +272,37 @@ func (controller ExcelDataController) ImportOrganization() { |
271
|
}
|
272
|
}
|
272
|
|
273
|
|
273
|
func (controller ExcelDataController) FileImport() {
|
274
|
func (controller ExcelDataController) FileImport() {
|
274
|
- excelService := service.NewExcelDataService(nil)
|
|
|
275
|
- r, err := controller.GetExcelFile()
|
|
|
276
|
- if err != nil {
|
|
|
277
|
- controller.Response(nil, err)
|
|
|
278
|
- return
|
|
|
279
|
- }
|
|
|
280
|
- cmd := &command.ImportDataCommand{}
|
275
|
+ // excelService := service.NewExcelDataService(nil)
|
|
|
276
|
+ // r, err := controller.GetExcelFile()
|
|
|
277
|
+ // if err != nil {
|
|
|
278
|
+ // controller.Response(nil, err)
|
|
|
279
|
+ // return
|
|
|
280
|
+ // }
|
|
|
281
|
+ // cmd := &command.ImportDataCommand{}
|
281
|
//controller.Unmarshal(cmd)
|
282
|
//controller.Unmarshal(cmd)
|
282
|
- controller.ParseForm(cmd)
|
|
|
283
|
- cmd.Operator = controller.GetOperator()
|
|
|
284
|
- cmd.Reader = r
|
|
|
285
|
- var data interface{}
|
|
|
286
|
- switch cmd.Code {
|
283
|
+ // controller.ParseForm(cmd)
|
|
|
284
|
+ // cmd.Operator = controller.GetOperator()
|
|
|
285
|
+ // cmd.Reader = r
|
|
|
286
|
+ // var (
|
|
|
287
|
+ // data interface{}
|
|
|
288
|
+ // err error
|
|
|
289
|
+ // )
|
|
|
290
|
+ code := controller.GetString("code")
|
|
|
291
|
+ switch code {
|
287
|
case domain.ImportCompanyUser:
|
292
|
case domain.ImportCompanyUser:
|
288
|
- data, err = excelService.ImportCompanyUser(cmd)
|
293
|
+ importCompanyUser(controller)
|
|
|
294
|
+ case domain.ImportCooperationUser:
|
|
|
295
|
+ importCooperationUser(controller)
|
|
|
296
|
+ case domain.ImportDividendsOrders:
|
|
|
297
|
+ importDividendsOrder(controller)
|
|
|
298
|
+ case domain.ImportOrganization:
|
|
|
299
|
+ importDividendsReturnedOrder(controller)
|
289
|
}
|
300
|
}
|
290
|
- controller.Response(data, err)
|
301
|
+ // controller.Response(data, err)
|
291
|
}
|
302
|
}
|
292
|
|
303
|
|
293
|
func (controller ExcelDataController) FileImportTemplate() {
|
304
|
func (controller ExcelDataController) FileImportTemplate() {
|
|
|
305
|
+
|
294
|
excelService := service.NewExcelDataService(nil)
|
306
|
excelService := service.NewExcelDataService(nil)
|
295
|
cmd := &command.ImportDataCommand{}
|
307
|
cmd := &command.ImportDataCommand{}
|
296
|
//controller.Unmarshal(cmd)
|
308
|
//controller.Unmarshal(cmd)
|