|
1
|
-package web_client
|
|
|
|
2
|
-
|
|
|
|
3
|
-import (
|
|
|
|
4
|
- "path/filepath"
|
|
|
|
5
|
-
|
|
|
|
6
|
- "github.com/beego/beego/v2/server/web/context"
|
|
|
|
7
|
- "github.com/linmadan/egglib-go/utils/excel"
|
|
|
|
8
|
- "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
|
|
|
|
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"
|
|
|
|
11
|
- "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
|
|
|
|
12
|
-)
|
|
|
|
13
|
-
|
|
|
|
14
|
-type ExcelDataController struct {
|
|
|
|
15
|
- baseController
|
|
|
|
16
|
-}
|
|
|
|
17
|
-
|
|
|
|
18
|
-func (controller *ExcelDataController) responseExcelByFile(ctx *context.Context, excelExport *excel.ExcelExport, fileName string) error {
|
|
|
|
19
|
- ctx.Output.Header("Content-Disposition", "attachment; filename="+fileName)
|
|
|
|
20
|
- ctx.Output.Header("Content-Description", "File Transfer")
|
|
|
|
21
|
- ctx.Output.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
|
|
|
22
|
- ctx.Output.Header("Content-Transfer-Encoding", "binary")
|
|
|
|
23
|
- ctx.Output.Header("Expires", "0")
|
|
|
|
24
|
- ctx.Output.Header("Cache-Control", "must-revalidate")
|
|
|
|
25
|
- ctx.Output.Header("Pragma", "public")
|
|
|
|
26
|
- //跳过保存文件,直接写入ctx.ResponseWriter
|
|
|
|
27
|
- excelExport.ExcelFile.Write(ctx.ResponseWriter)
|
|
|
|
28
|
- return nil
|
|
|
|
29
|
-}
|
|
|
|
30
|
-
|
|
|
|
31
|
-//导出公司用户
|
|
|
|
32
|
-func (controller ExcelDataController) ExportCompanyUser() {
|
|
|
|
33
|
- excelService := service.NewExcelDataService(nil)
|
|
|
|
34
|
- companyUserListQuery := &query.CompanyUserListQuery{}
|
|
|
|
35
|
- err := controller.Unmarshal(companyUserListQuery)
|
|
|
|
36
|
- if err != nil {
|
|
|
|
37
|
- log.Logger.Debug("json err:" + err.Error())
|
|
|
|
38
|
- controller.Response(nil, err)
|
|
|
|
39
|
- return
|
|
|
|
40
|
- }
|
|
|
|
41
|
- companyUserListQuery.Operator = controller.GetOperator()
|
|
|
|
42
|
- data, err := excelService.ExportCompanyUser(companyUserListQuery)
|
|
|
|
43
|
- if err != nil {
|
|
|
|
44
|
- log.Logger.Debug("excelService.ExportCompanyUser err:" + err.Error())
|
|
|
|
45
|
- controller.Response(nil, err)
|
|
|
|
46
|
- return
|
|
|
|
47
|
- }
|
|
|
|
48
|
- excelTool := excel.NewExcelExport()
|
|
|
|
49
|
- err = excelTool.ExportData(data, "")
|
|
|
|
50
|
- if err != nil {
|
|
|
|
51
|
- log.Logger.Debug("excelTool.ExportData err:" + err.Error())
|
|
|
|
52
|
- controller.Response(nil, err)
|
|
|
|
53
|
- return
|
|
|
|
54
|
- }
|
|
|
|
55
|
- controller.responseExcelByFile(controller.Ctx, excelTool, "导出公司用户")
|
|
|
|
56
|
-}
|
|
|
|
57
|
-
|
|
|
|
58
|
-//导出共创用户
|
|
|
|
59
|
-func (controller ExcelDataController) ExportCooperationUser() {
|
|
|
|
60
|
- excelService := service.NewExcelDataService(nil)
|
|
|
|
61
|
- companyUserListQuery := &query.CompanyUserListQuery{}
|
|
|
|
62
|
- err := controller.Unmarshal(companyUserListQuery)
|
|
|
|
63
|
- if err != nil {
|
|
|
|
64
|
- log.Logger.Debug("json err:" + err.Error())
|
|
|
|
65
|
- controller.Response(nil, err)
|
|
|
|
66
|
- return
|
|
|
|
67
|
- }
|
|
|
|
68
|
- companyUserListQuery.Operator = controller.GetOperator()
|
|
|
|
69
|
- data, err := excelService.ExportCooperationUser(companyUserListQuery)
|
|
|
|
70
|
- if err != nil {
|
|
|
|
71
|
- log.Logger.Debug("excelService.ExportCompanyUser err:" + err.Error())
|
|
|
|
72
|
- controller.Response(nil, err)
|
|
|
|
73
|
- return
|
|
|
|
74
|
- }
|
|
|
|
75
|
- excelTool := excel.NewExcelExport()
|
|
|
|
76
|
- err = excelTool.ExportData(data, "")
|
|
|
|
77
|
- if err != nil {
|
|
|
|
78
|
- log.Logger.Debug("excelTool.ExportData err:" + err.Error())
|
|
|
|
79
|
- controller.Response(nil, err)
|
|
|
|
80
|
- return
|
|
|
|
81
|
- }
|
|
|
|
82
|
- controller.responseExcelByFile(controller.Ctx, excelTool, "导出共创用户")
|
|
|
|
83
|
-}
|
|
|
|
84
|
-
|
|
|
|
85
|
-func (controller ExcelDataController) ImportDividendsReturnedOrder() {
|
|
|
|
86
|
- excelFile, fileHeader, err := controller.GetFile("file")
|
|
|
|
87
|
- if err != nil {
|
|
|
|
88
|
- log.Logger.Error("接收文件失败," + err.Error())
|
|
|
|
89
|
- controller.Response(nil, err)
|
|
|
|
90
|
- return
|
|
|
|
91
|
- }
|
|
|
|
92
|
- if filepath.Ext(fileHeader.Filename) == "" {
|
|
|
|
93
|
- //TODO 判断文件类型
|
|
|
|
94
|
- log.Logger.Error("获取到的文件:" + fileHeader.Filename)
|
|
|
|
95
|
- }
|
|
|
|
96
|
- excelImport := excel.NewExcelImport()
|
|
|
|
97
|
- excelImport.RowBegin = 2 //第二行开始读取
|
|
|
|
98
|
- excelImport.DataFields = []excel.DataField{
|
|
|
|
99
|
- {EnName: "OriginalOrderNum", CnName: "*来源源单号"},
|
|
|
|
100
|
- {EnName: "DividendsReturnedCustomerName", CnName: "*客户名称"},
|
|
|
|
101
|
- {EnName: "OrderGoodName", CnName: "*产品名称"},
|
|
|
|
102
|
- {EnName: "DividendsReturnedDate", CnName: "*退货日期"},
|
|
|
|
103
|
- {EnName: "OrderTime", CnName: "*订单日期"},
|
|
|
|
104
|
- {EnName: "RegionName", CnName: "*退货区域"},
|
|
|
|
105
|
- {EnName: "OrderGoodQuantity", CnName: "*退货数量"},
|
|
|
|
106
|
- {EnName: "OrderGoodPrice", CnName: "*退货价格"},
|
|
|
|
107
|
- {EnName: "CooperationContractNumber", CnName: "项目合约编号"},
|
|
|
|
108
|
- }
|
|
|
|
109
|
- excelData, err := excelImport.OpenExcelFromIoReader(excelFile)
|
|
|
|
110
|
- if err != nil {
|
|
|
|
111
|
- log.Logger.Error("解析excel文件失败," + err.Error())
|
|
|
|
112
|
- controller.Response(nil, err)
|
|
|
|
113
|
- return
|
|
|
|
114
|
- }
|
|
|
|
115
|
- //退货单数据
|
|
|
|
116
|
- returnedOrderData := []allied_creation_cooperation.ImportDividendsReturnedOrderData{}
|
|
|
|
117
|
- for _, v := range excelData {
|
|
|
|
118
|
- //TODO 按需转化
|
|
|
|
119
|
- item := allied_creation_cooperation.ImportDividendsReturnedOrderData{
|
|
|
|
120
|
- OriginalOrderNum: v["OriginalOrderNum"],
|
|
|
|
121
|
- DividendsReturnedCustomerName: v["DividendsReturnedCustomerName"],
|
|
|
|
122
|
- OrderGoodName: v["OrderGoodName"],
|
|
|
|
123
|
- DividendsReturnedDate: v["DividendsReturnedDate"],
|
|
|
|
124
|
- OrderTime: v["OrderTime"],
|
|
|
|
125
|
- RegionName: v["RegionName"],
|
|
|
|
126
|
- OrderGoodQuantity: v["OrderGoodQuantity"],
|
|
|
|
127
|
- OrderGoodPrice: v["OrderGoodPrice"],
|
|
|
|
128
|
- CooperationContractNumber: v["CooperationContractNumber"],
|
|
|
|
129
|
- }
|
|
|
|
130
|
- returnedOrderData = append(returnedOrderData, item)
|
|
|
|
131
|
- }
|
|
|
|
132
|
- creationCooperationGate := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(controller.GetOperator())
|
|
|
|
133
|
- result, err := creationCooperationGate.ImportDividendsReturnedOrder(allied_creation_cooperation.ReqImportDividendsReturnedOrder{
|
|
|
|
134
|
- DividendsReturnedOrderData: returnedOrderData,
|
|
|
|
135
|
- })
|
|
|
|
136
|
- if err != nil {
|
|
|
|
137
|
- controller.Response(nil, err)
|
|
|
|
138
|
- return
|
|
|
|
139
|
- }
|
|
|
|
140
|
- controller.Response(result, nil)
|
|
|
|
141
|
-} |
1
|
+package web_client
|
|
|
|
2
|
+
|
|
|
|
3
|
+import (
|
|
|
|
4
|
+ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command"
|
|
|
|
5
|
+ "path/filepath"
|
|
|
|
6
|
+
|
|
|
|
7
|
+ "github.com/beego/beego/v2/server/web/context"
|
|
|
|
8
|
+ "github.com/linmadan/egglib-go/utils/excel"
|
|
|
|
9
|
+ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
|
|
|
|
10
|
+ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/service"
|
|
|
|
11
|
+ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
|
|
|
|
12
|
+ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
|
|
|
|
13
|
+)
|
|
|
|
14
|
+
|
|
|
|
15
|
+type ExcelDataController struct {
|
|
|
|
16
|
+ baseController
|
|
|
|
17
|
+}
|
|
|
|
18
|
+
|
|
|
|
19
|
+func (controller *ExcelDataController) responseExcelByFile(ctx *context.Context, excelExport *excel.ExcelExport, fileName string) error {
|
|
|
|
20
|
+ ctx.Output.Header("Content-Disposition", "attachment; filename="+fileName)
|
|
|
|
21
|
+ ctx.Output.Header("Content-Description", "File Transfer")
|
|
|
|
22
|
+ ctx.Output.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
|
|
|
23
|
+ ctx.Output.Header("Content-Transfer-Encoding", "binary")
|
|
|
|
24
|
+ ctx.Output.Header("Expires", "0")
|
|
|
|
25
|
+ ctx.Output.Header("Cache-Control", "must-revalidate")
|
|
|
|
26
|
+ ctx.Output.Header("Pragma", "public")
|
|
|
|
27
|
+ //跳过保存文件,直接写入ctx.ResponseWriter
|
|
|
|
28
|
+ excelExport.ExcelFile.Write(ctx.ResponseWriter)
|
|
|
|
29
|
+ return nil
|
|
|
|
30
|
+}
|
|
|
|
31
|
+
|
|
|
|
32
|
+//导出公司用户
|
|
|
|
33
|
+func (controller ExcelDataController) ExportCompanyUser() {
|
|
|
|
34
|
+ excelService := service.NewExcelDataService(nil)
|
|
|
|
35
|
+ companyUserListQuery := &query.CompanyUserListQuery{}
|
|
|
|
36
|
+ err := controller.Unmarshal(companyUserListQuery)
|
|
|
|
37
|
+ if err != nil {
|
|
|
|
38
|
+ log.Logger.Debug("json err:" + err.Error())
|
|
|
|
39
|
+ controller.Response(nil, err)
|
|
|
|
40
|
+ return
|
|
|
|
41
|
+ }
|
|
|
|
42
|
+ companyUserListQuery.Operator = controller.GetOperator()
|
|
|
|
43
|
+ data, err := excelService.ExportCompanyUser(companyUserListQuery)
|
|
|
|
44
|
+ if err != nil {
|
|
|
|
45
|
+ log.Logger.Debug("excelService.ExportCompanyUser err:" + err.Error())
|
|
|
|
46
|
+ controller.Response(nil, err)
|
|
|
|
47
|
+ return
|
|
|
|
48
|
+ }
|
|
|
|
49
|
+ excelTool := excel.NewExcelExport()
|
|
|
|
50
|
+ err = excelTool.ExportData(data, "")
|
|
|
|
51
|
+ if err != nil {
|
|
|
|
52
|
+ log.Logger.Debug("excelTool.ExportData err:" + err.Error())
|
|
|
|
53
|
+ controller.Response(nil, err)
|
|
|
|
54
|
+ return
|
|
|
|
55
|
+ }
|
|
|
|
56
|
+ controller.responseExcelByFile(controller.Ctx, excelTool, "导出公司用户")
|
|
|
|
57
|
+}
|
|
|
|
58
|
+
|
|
|
|
59
|
+//导出共创用户
|
|
|
|
60
|
+func (controller ExcelDataController) ExportCooperationUser() {
|
|
|
|
61
|
+ excelService := service.NewExcelDataService(nil)
|
|
|
|
62
|
+ companyUserListQuery := &query.CompanyUserListQuery{}
|
|
|
|
63
|
+ err := controller.Unmarshal(companyUserListQuery)
|
|
|
|
64
|
+ if err != nil {
|
|
|
|
65
|
+ log.Logger.Debug("json err:" + err.Error())
|
|
|
|
66
|
+ controller.Response(nil, err)
|
|
|
|
67
|
+ return
|
|
|
|
68
|
+ }
|
|
|
|
69
|
+ companyUserListQuery.Operator = controller.GetOperator()
|
|
|
|
70
|
+ data, err := excelService.ExportCooperationUser(companyUserListQuery)
|
|
|
|
71
|
+ if err != nil {
|
|
|
|
72
|
+ log.Logger.Debug("excelService.ExportCompanyUser err:" + err.Error())
|
|
|
|
73
|
+ controller.Response(nil, err)
|
|
|
|
74
|
+ return
|
|
|
|
75
|
+ }
|
|
|
|
76
|
+ excelTool := excel.NewExcelExport()
|
|
|
|
77
|
+ err = excelTool.ExportData(data, "")
|
|
|
|
78
|
+ if err != nil {
|
|
|
|
79
|
+ log.Logger.Debug("excelTool.ExportData err:" + err.Error())
|
|
|
|
80
|
+ controller.Response(nil, err)
|
|
|
|
81
|
+ return
|
|
|
|
82
|
+ }
|
|
|
|
83
|
+ controller.responseExcelByFile(controller.Ctx, excelTool, "导出共创用户")
|
|
|
|
84
|
+}
|
|
|
|
85
|
+
|
|
|
|
86
|
+func (controller ExcelDataController) ImportDividendsReturnedOrder() {
|
|
|
|
87
|
+ excelFile, fileHeader, err := controller.GetFile("file")
|
|
|
|
88
|
+ if err != nil {
|
|
|
|
89
|
+ log.Logger.Error("接收文件失败," + err.Error())
|
|
|
|
90
|
+ controller.Response(nil, err)
|
|
|
|
91
|
+ return
|
|
|
|
92
|
+ }
|
|
|
|
93
|
+ if filepath.Ext(fileHeader.Filename) == "" {
|
|
|
|
94
|
+ //TODO 判断文件类型
|
|
|
|
95
|
+ log.Logger.Error("获取到的文件:" + fileHeader.Filename)
|
|
|
|
96
|
+ }
|
|
|
|
97
|
+ excelImport := excel.NewExcelImport()
|
|
|
|
98
|
+ excelImport.RowBegin = 2 //第二行开始读取
|
|
|
|
99
|
+ excelImport.DataFields = []excel.DataField{
|
|
|
|
100
|
+ {EnName: "OriginalOrderNum", CnName: "*来源源单号"},
|
|
|
|
101
|
+ {EnName: "DividendsReturnedCustomerName", CnName: "*客户名称"},
|
|
|
|
102
|
+ {EnName: "OrderGoodName", CnName: "*产品名称"},
|
|
|
|
103
|
+ {EnName: "DividendsReturnedDate", CnName: "*退货日期"},
|
|
|
|
104
|
+ {EnName: "OrderTime", CnName: "*订单日期"},
|
|
|
|
105
|
+ {EnName: "RegionName", CnName: "*退货区域"},
|
|
|
|
106
|
+ {EnName: "OrderGoodQuantity", CnName: "*退货数量"},
|
|
|
|
107
|
+ {EnName: "OrderGoodPrice", CnName: "*退货价格"},
|
|
|
|
108
|
+ {EnName: "CooperationContractNumber", CnName: "项目合约编号"},
|
|
|
|
109
|
+ }
|
|
|
|
110
|
+ excelData, err := excelImport.OpenExcelFromIoReader(excelFile)
|
|
|
|
111
|
+ if err != nil {
|
|
|
|
112
|
+ log.Logger.Error("解析excel文件失败," + err.Error())
|
|
|
|
113
|
+ controller.Response(nil, err)
|
|
|
|
114
|
+ return
|
|
|
|
115
|
+ }
|
|
|
|
116
|
+ //退货单数据
|
|
|
|
117
|
+ returnedOrderData := []allied_creation_cooperation.ImportDividendsReturnedOrderData{}
|
|
|
|
118
|
+ for _, v := range excelData {
|
|
|
|
119
|
+ //TODO 按需转化
|
|
|
|
120
|
+ item := allied_creation_cooperation.ImportDividendsReturnedOrderData{
|
|
|
|
121
|
+ OriginalOrderNum: v["OriginalOrderNum"],
|
|
|
|
122
|
+ DividendsReturnedCustomerName: v["DividendsReturnedCustomerName"],
|
|
|
|
123
|
+ OrderGoodName: v["OrderGoodName"],
|
|
|
|
124
|
+ DividendsReturnedDate: v["DividendsReturnedDate"],
|
|
|
|
125
|
+ OrderTime: v["OrderTime"],
|
|
|
|
126
|
+ RegionName: v["RegionName"],
|
|
|
|
127
|
+ OrderGoodQuantity: v["OrderGoodQuantity"],
|
|
|
|
128
|
+ OrderGoodPrice: v["OrderGoodPrice"],
|
|
|
|
129
|
+ CooperationContractNumber: v["CooperationContractNumber"],
|
|
|
|
130
|
+ }
|
|
|
|
131
|
+ returnedOrderData = append(returnedOrderData, item)
|
|
|
|
132
|
+ }
|
|
|
|
133
|
+ creationCooperationGate := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(controller.GetOperator())
|
|
|
|
134
|
+ result, err := creationCooperationGate.ImportDividendsReturnedOrder(allied_creation_cooperation.ReqImportDividendsReturnedOrder{
|
|
|
|
135
|
+ DividendsReturnedOrderData: returnedOrderData,
|
|
|
|
136
|
+ })
|
|
|
|
137
|
+ if err != nil {
|
|
|
|
138
|
+ controller.Response(nil, err)
|
|
|
|
139
|
+ return
|
|
|
|
140
|
+ }
|
|
|
|
141
|
+ controller.Response(result, nil)
|
|
|
|
142
|
+}
|
|
|
|
143
|
+
|
|
|
|
144
|
+func (controller ExcelDataController) ImportCompanyUser() {
|
|
|
|
145
|
+ excelService := service.NewExcelDataService(nil)
|
|
|
|
146
|
+ r, err := controller.GetExcelFile()
|
|
|
|
147
|
+ if err != nil {
|
|
|
|
148
|
+ controller.Response(nil, err)
|
|
|
|
149
|
+ return
|
|
|
|
150
|
+ }
|
|
|
|
151
|
+ cmd := &command.ImportDataCommand{}
|
|
|
|
152
|
+ cmd.Operator = controller.GetOperator()
|
|
|
|
153
|
+ cmd.Reader = r
|
|
|
|
154
|
+ data, err := excelService.ImportCompanyUser(cmd)
|
|
|
|
155
|
+ controller.Response(data, err)
|
|
|
|
156
|
+}
|
|
|
|
157
|
+
|
|
|
|
158
|
+func (controller ExcelDataController) ImportCooperationUser() {
|
|
|
|
159
|
+ excelService := service.NewExcelDataService(nil)
|
|
|
|
160
|
+ r, err := controller.GetExcelFile()
|
|
|
|
161
|
+ if err != nil {
|
|
|
|
162
|
+ controller.Response(nil, err)
|
|
|
|
163
|
+ return
|
|
|
|
164
|
+ }
|
|
|
|
165
|
+ cmd := &command.ImportDataCommand{}
|
|
|
|
166
|
+ cmd.Operator = controller.GetOperator()
|
|
|
|
167
|
+ cmd.Reader = r
|
|
|
|
168
|
+ data, err := excelService.ImportCooperationUser(cmd)
|
|
|
|
169
|
+ controller.Response(data, err)
|
|
|
|
170
|
+} |