正在显示
6 个修改的文件
包含
181 行增加
和
112 行删除
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + "fmt" | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" | ||
8 | +) | ||
9 | + | ||
10 | +type ExportDataCommand struct { | ||
11 | + //操作人 | ||
12 | + Operator domain.Operator `json:"-"` | ||
13 | + // 业务编码 | ||
14 | + Ids []string `json:"ids"` | ||
15 | + Where json.RawMessage `json:"where"` | ||
16 | + // 业务编码 | ||
17 | + Code string `form:"code"` | ||
18 | +} | ||
19 | + | ||
20 | +func (exportDataCommand *ExportDataCommand) Valid(validation *validation.Validation) { | ||
21 | + | ||
22 | +} | ||
23 | + | ||
24 | +func (exportDataCommand *ExportDataCommand) ValidateCommand() error { | ||
25 | + valid := validation.Validation{} | ||
26 | + b, err := valid.Valid(exportDataCommand) | ||
27 | + if err != nil { | ||
28 | + return err | ||
29 | + } | ||
30 | + if !b { | ||
31 | + for _, validErr := range valid.Errors { | ||
32 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
33 | + } | ||
34 | + } | ||
35 | + return nil | ||
36 | +} | ||
37 | + | ||
38 | +func (exportDataCommand *ExportDataCommand) UnmarshalQuery(query interface{}) error { | ||
39 | + return json.Unmarshal(exportDataCommand.Where, query) | ||
40 | +} |
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" | ||
8 | +) | ||
9 | + | ||
10 | +// ExportCompanyUser 导出公司用户信息列表 | ||
11 | +func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCompanyUserData, error) { | ||
12 | + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator) | ||
13 | + result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{ | ||
14 | + Limit: 10000, | ||
15 | + CompanyId: companyUserListQuery.Operator.CompanyId, | ||
16 | + OrganizationId: 0, | ||
17 | + DepartmentId: 0, | ||
18 | + UserName: companyUserListQuery.UserName, | ||
19 | + DepName: companyUserListQuery.DepartmentName, | ||
20 | + Phone: "", | ||
21 | + UserType: domain.UserTypeEmployee, | ||
22 | + InOrgIds: companyUserListQuery.Operator.OrgIds, | ||
23 | + }) | ||
24 | + if err != nil { | ||
25 | + return ExportCompanyUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err) | ||
26 | + } | ||
27 | + return ExportCompanyUserData(result.Users), nil | ||
28 | +} | ||
29 | + | ||
30 | +// ExportCooperationUser 导出共创用户信息列表 | ||
31 | +func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCooperationUserData, error) { | ||
32 | + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator) | ||
33 | + result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{ | ||
34 | + Limit: 10000, | ||
35 | + CompanyId: companyUserListQuery.Operator.CompanyId, | ||
36 | + OrganizationId: 0, | ||
37 | + DepartmentId: 0, | ||
38 | + UserName: companyUserListQuery.UserName, | ||
39 | + DepName: companyUserListQuery.DepartmentName, | ||
40 | + Phone: "", | ||
41 | + UserType: domain.UserTypeCooperation, | ||
42 | + InOrgIds: companyUserListQuery.Operator.OrgIds, | ||
43 | + }) | ||
44 | + if err != nil { | ||
45 | + return ExportCooperationUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err) | ||
46 | + } | ||
47 | + return ExportCooperationUserData(result.Users), nil | ||
48 | +} |
@@ -7,7 +7,6 @@ import ( | @@ -7,7 +7,6 @@ import ( | ||
7 | "github.com/linmadan/egglib-go/core/application" | 7 | "github.com/linmadan/egglib-go/core/application" |
8 | "github.com/linmadan/egglib-go/utils/excel" | 8 | "github.com/linmadan/egglib-go/utils/excel" |
9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command" |
10 | - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query" | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" | 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" |
12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/domainService" | 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/domainService" |
13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" | 12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" |
@@ -20,104 +19,6 @@ func NewExcelDataService(param map[string]interface{}) *ExcelDataService { | @@ -20,104 +19,6 @@ func NewExcelDataService(param map[string]interface{}) *ExcelDataService { | ||
20 | return &ExcelDataService{} | 19 | return &ExcelDataService{} |
21 | } | 20 | } |
22 | 21 | ||
23 | -// ExportCompanyUser 导出公司用户信息列表 | ||
24 | -func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCompanyUserData, error) { | ||
25 | - creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator) | ||
26 | - result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{ | ||
27 | - Limit: 10000, | ||
28 | - CompanyId: companyUserListQuery.Operator.CompanyId, | ||
29 | - OrganizationId: 0, | ||
30 | - DepartmentId: 0, | ||
31 | - UserName: companyUserListQuery.UserName, | ||
32 | - DepName: companyUserListQuery.DepartmentName, | ||
33 | - Phone: "", | ||
34 | - UserType: domain.UserTypeEmployee, | ||
35 | - InOrgIds: companyUserListQuery.Operator.OrgIds, | ||
36 | - }) | ||
37 | - if err != nil { | ||
38 | - return ExportCompanyUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err) | ||
39 | - } | ||
40 | - return ExportCompanyUserData(result.Users), nil | ||
41 | -} | ||
42 | - | ||
43 | -// ExportCooperationUser 导出共创用户信息列表 | ||
44 | -func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCooperationUserData, error) { | ||
45 | - creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator) | ||
46 | - result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{ | ||
47 | - Limit: 10000, | ||
48 | - CompanyId: companyUserListQuery.Operator.CompanyId, | ||
49 | - OrganizationId: 0, | ||
50 | - DepartmentId: 0, | ||
51 | - UserName: companyUserListQuery.UserName, | ||
52 | - DepName: companyUserListQuery.DepartmentName, | ||
53 | - Phone: "", | ||
54 | - UserType: domain.UserTypeCooperation, | ||
55 | - InOrgIds: companyUserListQuery.Operator.OrgIds, | ||
56 | - }) | ||
57 | - if err != nil { | ||
58 | - return ExportCooperationUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err) | ||
59 | - } | ||
60 | - return ExportCooperationUserData(result.Users), nil | ||
61 | -} | ||
62 | - | ||
63 | -// ImportCompanyUser 导入公司用户信息 | ||
64 | -func (srv ExcelDataService) ImportCompanyUser2(importDataCommand *command.ImportDataCommand) (interface{}, error) { | ||
65 | - //initPassword, _, err := domainService.GetInitPassword(importDataCommand.Operator) | ||
66 | - //if err != nil { | ||
67 | - // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
68 | - //} | ||
69 | - //excelImport := excel.NewExcelImport() | ||
70 | - //excelImport.RowBegin = 2 //第二行开始读取 | ||
71 | - //excelImport.DataFields = []excel.DataField{ | ||
72 | - // {EnName: "UserCode", CnName: "*用户编号"}, | ||
73 | - // {EnName: "UserName", CnName: "*用户姓名"}, | ||
74 | - // {EnName: "OrganizationID", CnName: "*组织机构"}, | ||
75 | - // {EnName: "DepartmentID", CnName: "*所属部门"}, | ||
76 | - // {EnName: "Phone", CnName: "*手机号"}, | ||
77 | - // {EnName: "Email", CnName: "邮箱"}, | ||
78 | - // {EnName: "Status", CnName: "状态"}, | ||
79 | - //} | ||
80 | - //excelData, err := excelImport.OpenExcelFromIoReader(importDataCommand.Reader) | ||
81 | - //if err != nil { | ||
82 | - // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
83 | - //} | ||
84 | - //users := make([]allied_creation_user.BatchAddUserItem, 0) | ||
85 | - //for _, v := range excelData { | ||
86 | - // item := allied_creation_user.BatchAddUserItem{ | ||
87 | - // CompanyID: importDataCommand.Operator.CompanyId, | ||
88 | - // UserType: domain.UserTypeEmployee, | ||
89 | - // UserCode: v["UserCode"], | ||
90 | - // OrganizationID: 0, | ||
91 | - // DepartmentID: 0, | ||
92 | - // UserInfo: allied_creation_user.BatchAddUserItemUserInfo{ | ||
93 | - // UserName: v["UserName"], | ||
94 | - // Phone: v["Phone"], | ||
95 | - // Email: v["Email"], | ||
96 | - // }, | ||
97 | - // CooperationInfo: allied_creation_user.BatchAddUserItemCooperationInfo{}, | ||
98 | - // } | ||
99 | - // item.OrganizationID, err = strconv.Atoi(v["OrganizationID"]) | ||
100 | - // if err != nil { | ||
101 | - // return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("用户:%v 组织值:%v 类型无效(数值类型)", item.UserInfo.UserName, item.OrganizationID)) | ||
102 | - // } | ||
103 | - // item.DepartmentID, err = strconv.Atoi(v["DepartmentID"]) | ||
104 | - // if err != nil { | ||
105 | - // return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("用户:%v 部门值:%v 类型无效(数值类型)", item.UserInfo.UserName, item.DepartmentID)) | ||
106 | - // } | ||
107 | - // users = append(users, item) | ||
108 | - //} | ||
109 | - //userGateway := allied_creation_user.NewHttplibAlliedCreationUser(importDataCommand.Operator) | ||
110 | - //result, err := userGateway.UserBatchAdd(allied_creation_user.ReqBatchAddUser{ | ||
111 | - // Users: users, | ||
112 | - // Password: initPassword, | ||
113 | - //}) | ||
114 | - //if err != nil { | ||
115 | - // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
116 | - //} | ||
117 | - //return result, nil | ||
118 | - return nil, nil | ||
119 | -} | ||
120 | - | ||
121 | // ImportCooperationUser 导入共创用户信息 | 22 | // ImportCooperationUser 导入共创用户信息 |
122 | func (srv ExcelDataService) ImportCooperationUser(importDataCommand *command.ImportDataCommand) (interface{}, error) { | 23 | func (srv ExcelDataService) ImportCooperationUser(importDataCommand *command.ImportDataCommand) (interface{}, error) { |
123 | initPassword, _, err := domainService.GetInitPassword(importDataCommand.Operator) | 24 | initPassword, _, err := domainService.GetInitPassword(importDataCommand.Operator) |
@@ -226,6 +127,7 @@ func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportD | @@ -226,6 +127,7 @@ func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportD | ||
226 | return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(users)), nil | 127 | return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(users)), nil |
227 | } | 128 | } |
228 | 129 | ||
130 | +// ImportOrganization 导入组织 | ||
229 | func (srv ExcelDataService) ImportOrganization(importDataCommand *command.ImportDataCommand) (interface{}, error) { | 131 | func (srv ExcelDataService) ImportOrganization(importDataCommand *command.ImportDataCommand) (interface{}, error) { |
230 | excelImport := excel.NewExcelImport() | 132 | excelImport := excel.NewExcelImport() |
231 | excelImport.RowBegin = 3 //第二行开始读取 | 133 | excelImport.RowBegin = 3 //第二行开始读取 |
@@ -296,14 +198,14 @@ func (srv ExcelDataService) fieldValueAllEmpty(param map[string]string) bool { | @@ -296,14 +198,14 @@ func (srv ExcelDataService) fieldValueAllEmpty(param map[string]string) bool { | ||
296 | return isAllEmpty | 198 | return isAllEmpty |
297 | } | 199 | } |
298 | 200 | ||
299 | -// ImportCompanyUser 导入公司用户信息 | 201 | +// FileImportTemplate 导入模板 |
300 | func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.ImportDataCommand) (interface{}, error) { | 202 | func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.ImportDataCommand) (interface{}, error) { |
301 | var mapTemplate = map[string]string{ | 203 | var mapTemplate = map[string]string{ |
302 | domain.ImportCompanyUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807485_EaxECeRz23WpzrMZmbwdEPRJ3Pdxpx5X.xlsx", | 204 | domain.ImportCompanyUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807485_EaxECeRz23WpzrMZmbwdEPRJ3Pdxpx5X.xlsx", |
303 | domain.ImportOrganization: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807490_r2XWhGmbWWmpbeePBkZ3EJQFKcZEMpEm.xlsx", | 205 | domain.ImportOrganization: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807490_r2XWhGmbWWmpbeePBkZ3EJQFKcZEMpEm.xlsx", |
304 | domain.ImportDividendsOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210917/object/1631843469_DykNwexeYYtzxzbwsER5RrzCS7QRwGmd.xlsx", | 206 | domain.ImportDividendsOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210917/object/1631843469_DykNwexeYYtzxzbwsER5RrzCS7QRwGmd.xlsx", |
305 | domain.ImportCooperationUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210924/object/1632465394_kRTz5FfjXABF2hb6d2Nd3JMJ3Xz7zBE2.xlsx", | 207 | domain.ImportCooperationUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210924/object/1632465394_kRTz5FfjXABF2hb6d2Nd3JMJ3Xz7zBE2.xlsx", |
306 | - domain.ImportDividendsReturnOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210924/object/1632465400_ndAJycEn2jxnPFdzjMnsE6rT3xWb22xk.xlsx", | 208 | + domain.ImportDividendsReturnOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210924/object/1632472672_hbFG5Ad3JFZM7fCerb5eShaRneCRkHsY.xlsx", |
307 | } | 209 | } |
308 | var url string | 210 | var url string |
309 | var ok bool | 211 | var ok bool |
@@ -5,7 +5,7 @@ import ( | @@ -5,7 +5,7 @@ import ( | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" | 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" |
6 | ) | 6 | ) |
7 | 7 | ||
8 | -//exportCompanyUserData 导出公司用户数据 | 8 | +// ExportCompanyUserData 导出公司用户数据 |
9 | type ExportCompanyUserData []allied_creation_user.UserDetail | 9 | type ExportCompanyUserData []allied_creation_user.UserDetail |
10 | 10 | ||
11 | var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil) | 11 | var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil) |
@@ -14,10 +14,10 @@ func (data ExportCompanyUserData) DataFieldList() []excel.DataField { | @@ -14,10 +14,10 @@ func (data ExportCompanyUserData) DataFieldList() []excel.DataField { | ||
14 | return []excel.DataField{ | 14 | return []excel.DataField{ |
15 | {EnName: "UserCode", CnName: "用户编码"}, | 15 | {EnName: "UserCode", CnName: "用户编码"}, |
16 | {EnName: "UserName", CnName: "用户姓名"}, | 16 | {EnName: "UserName", CnName: "用户姓名"}, |
17 | - {EnName: "Phone", CnName: "手机号"}, | 17 | + {EnName: "OrgName", CnName: "组织机构"}, |
18 | {EnName: "DepartmentName", CnName: "所属部门"}, | 18 | {EnName: "DepartmentName", CnName: "所属部门"}, |
19 | {EnName: "EnableStatus", CnName: "状态"}, | 19 | {EnName: "EnableStatus", CnName: "状态"}, |
20 | - {EnName: "OrgName", CnName: "组织机构"}, | 20 | + {EnName: "Phone", CnName: "手机号"}, |
21 | } | 21 | } |
22 | } | 22 | } |
23 | 23 | ||
@@ -69,7 +69,7 @@ func (data ExportCompanyUserData) TableTitle() []string { | @@ -69,7 +69,7 @@ func (data ExportCompanyUserData) TableTitle() []string { | ||
69 | return nil | 69 | return nil |
70 | } | 70 | } |
71 | 71 | ||
72 | -//exportCompanyUserData 导出共创用户数据 | 72 | +//ExportCooperationUserData 导出共创用户数据 |
73 | type ExportCooperationUserData []allied_creation_user.UserDetail | 73 | type ExportCooperationUserData []allied_creation_user.UserDetail |
74 | 74 | ||
75 | var _ excel.ExcelMaker = (*ExportCooperationUserData)(nil) | 75 | var _ excel.ExcelMaker = (*ExportCooperationUserData)(nil) |
@@ -47,21 +47,58 @@ func (controller *ExcelDataController) fieldValueAllEmpty(param map[string]strin | @@ -47,21 +47,58 @@ func (controller *ExcelDataController) fieldValueAllEmpty(param map[string]strin | ||
47 | 47 | ||
48 | // ExportCompanyUser 导出公司用户 | 48 | // ExportCompanyUser 导出公司用户 |
49 | func (controller ExcelDataController) ExportCompanyUser() { | 49 | func (controller ExcelDataController) ExportCompanyUser() { |
50 | - excelService := service.NewExcelDataService(nil) | ||
51 | - companyUserListQuery := &query.CompanyUserListQuery{} | ||
52 | - err := controller.Unmarshal(companyUserListQuery) | 50 | + //excelService := service.NewExcelDataService(nil) |
51 | + //companyUserListQuery := &query.CompanyUserListQuery{} | ||
52 | + //err := controller.Unmarshal(companyUserListQuery) | ||
53 | + //if err != nil { | ||
54 | + // log.Logger.Debug("json err:" + err.Error()) | ||
55 | + // controller.Response(nil, err) | ||
56 | + // return | ||
57 | + //} | ||
58 | + //companyUserListQuery.Operator = controller.GetOperator() | ||
59 | + //data, err := excelService.ExportCompanyUser(companyUserListQuery) | ||
60 | + //if err != nil { | ||
61 | + // log.Logger.Debug("excelService.ExportCompanyUser err:" + err.Error()) | ||
62 | + // controller.Response(nil, err) | ||
63 | + // return | ||
64 | + //} | ||
65 | + //excelTool := excel.NewExcelExport() | ||
66 | + //err = excelTool.ExportData(data, "") | ||
67 | + //if err != nil { | ||
68 | + // log.Logger.Debug("excelTool.ExportData err:" + err.Error()) | ||
69 | + // controller.Response(nil, err) | ||
70 | + // return | ||
71 | + //} | ||
72 | + //controller.responseExcelByFile(controller.Ctx, excelTool, "导出公司用户") | ||
73 | + // 1.读取command | ||
74 | + exportDataCommand := &command.ExportDataCommand{} | ||
75 | + err := controller.Unmarshal(exportDataCommand) | ||
53 | if err != nil { | 76 | if err != nil { |
54 | log.Logger.Debug("json err:" + err.Error()) | 77 | log.Logger.Debug("json err:" + err.Error()) |
55 | controller.Response(nil, err) | 78 | controller.Response(nil, err) |
56 | return | 79 | return |
57 | } | 80 | } |
58 | - companyUserListQuery.Operator = controller.GetOperator() | ||
59 | - data, err := excelService.ExportCompanyUser(companyUserListQuery) | 81 | + exportDataCommand.Operator = controller.GetOperator() |
82 | + | ||
83 | + // 2.读取data | ||
84 | + var data excel.ExcelMaker | ||
85 | + var filename string | ||
86 | + var excelService = service.NewExcelDataService(nil) | ||
87 | + switch exportDataCommand.Code { | ||
88 | + default: | ||
89 | + companyUserListQuery := &query.CompanyUserListQuery{} | ||
90 | + exportDataCommand.UnmarshalQuery(companyUserListQuery) | ||
91 | + companyUserListQuery.Operator = exportDataCommand.Operator | ||
92 | + data, err = excelService.ExportCompanyUser(companyUserListQuery) | ||
93 | + filename = "导出公司用户" | ||
94 | + } | ||
60 | if err != nil { | 95 | if err != nil { |
61 | - log.Logger.Debug("excelService.ExportCompanyUser err:" + err.Error()) | 96 | + log.Logger.Debug("excelService.Export err:" + err.Error()) |
62 | controller.Response(nil, err) | 97 | controller.Response(nil, err) |
63 | return | 98 | return |
64 | } | 99 | } |
100 | + | ||
101 | + // 3.返回文件 | ||
65 | excelTool := excel.NewExcelExport() | 102 | excelTool := excel.NewExcelExport() |
66 | err = excelTool.ExportData(data, "") | 103 | err = excelTool.ExportData(data, "") |
67 | if err != nil { | 104 | if err != nil { |
@@ -69,7 +106,7 @@ func (controller ExcelDataController) ExportCompanyUser() { | @@ -69,7 +106,7 @@ func (controller ExcelDataController) ExportCompanyUser() { | ||
69 | controller.Response(nil, err) | 106 | controller.Response(nil, err) |
70 | return | 107 | return |
71 | } | 108 | } |
72 | - controller.responseExcelByFile(controller.Ctx, excelTool, "导出公司用户") | 109 | + controller.responseExcelByFile(controller.Ctx, excelTool, filename) |
73 | } | 110 | } |
74 | 111 | ||
75 | // ExportCooperationUser 导出共创用户 | 112 | // ExportCooperationUser 导出共创用户 |
@@ -276,3 +313,44 @@ func (controller ExcelDataController) FileImportTemplate() { | @@ -276,3 +313,44 @@ func (controller ExcelDataController) FileImportTemplate() { | ||
276 | data, err := excelService.FileImportTemplate(cmd) | 313 | data, err := excelService.FileImportTemplate(cmd) |
277 | controller.Response(data, err) | 314 | controller.Response(data, err) |
278 | } | 315 | } |
316 | + | ||
317 | +// FileExport 文件导出 | ||
318 | +func (controller ExcelDataController) FileExport() { | ||
319 | + // 1.读取command | ||
320 | + exportDataCommand := &command.ExportDataCommand{} | ||
321 | + err := controller.Unmarshal(exportDataCommand) | ||
322 | + if err != nil { | ||
323 | + log.Logger.Debug("json err:" + err.Error()) | ||
324 | + controller.Response(nil, err) | ||
325 | + return | ||
326 | + } | ||
327 | + exportDataCommand.Operator = controller.GetOperator() | ||
328 | + | ||
329 | + // 2.读取data | ||
330 | + var data excel.ExcelMaker | ||
331 | + var filename string | ||
332 | + var excelService = service.NewExcelDataService(nil) | ||
333 | + switch exportDataCommand.Code { | ||
334 | + default: | ||
335 | + companyUserListQuery := &query.CompanyUserListQuery{} | ||
336 | + exportDataCommand.UnmarshalQuery(companyUserListQuery) | ||
337 | + companyUserListQuery.Operator = exportDataCommand.Operator | ||
338 | + data, err = excelService.ExportCompanyUser(companyUserListQuery) | ||
339 | + filename = "导出公司用户" | ||
340 | + } | ||
341 | + if err != nil { | ||
342 | + log.Logger.Debug("excelService.Export err:" + err.Error()) | ||
343 | + controller.Response(nil, err) | ||
344 | + return | ||
345 | + } | ||
346 | + | ||
347 | + // 3.返回文件 | ||
348 | + excelTool := excel.NewExcelExport() | ||
349 | + err = excelTool.ExportData(data, "") | ||
350 | + if err != nil { | ||
351 | + log.Logger.Debug("excelTool.ExportData err:" + err.Error()) | ||
352 | + controller.Response(nil, err) | ||
353 | + return | ||
354 | + } | ||
355 | + controller.responseExcelByFile(controller.Ctx, excelTool, filename) | ||
356 | +} |
@@ -13,5 +13,6 @@ func init() { | @@ -13,5 +13,6 @@ func init() { | ||
13 | web.Router("/v1/web/excel/import/dividends-returned-orders", &web_client.ExcelDataController{}, "Post:ImportDividendsReturnedOrder") | 13 | web.Router("/v1/web/excel/import/dividends-returned-orders", &web_client.ExcelDataController{}, "Post:ImportDividendsReturnedOrder") |
14 | 14 | ||
15 | web.Router("/v1/web/file-import", &web_client.ExcelDataController{}, "Post:FileImport") | 15 | web.Router("/v1/web/file-import", &web_client.ExcelDataController{}, "Post:FileImport") |
16 | + web.Router("/v1/web/file-export", &web_client.ExcelDataController{}, "Post:FileExport") | ||
16 | web.Router("/v1/web/file-import-template/:code", &web_client.ExcelDataController{}, "Get:FileImportTemplate") | 17 | web.Router("/v1/web/file-import-template/:code", &web_client.ExcelDataController{}, "Get:FileImportTemplate") |
17 | } | 18 | } |
-
请 注册 或 登录 后发表评论