作者 yangfu

导出共创用户列表

1 -package service  
2 -  
3 -import (  
4 - "fmt"  
5 -  
6 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"  
7 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"  
8 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"  
9 -)  
10 -  
11 -type ExcelDataService struct {  
12 -}  
13 -  
14 -func NewExcelDataService(param map[string]interface{}) *ExcelDataService {  
15 - return &ExcelDataService{}  
16 -}  
17 -  
18 -// 导出公司用户信息列表  
19 -func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCompanyUserData, error) {  
20 - creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)  
21 - result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{  
22 - Limit: 10000,  
23 - CompanyId: companyUserListQuery.Operator.CompanyId,  
24 - OrganizationId: 0,  
25 - DepartmentId: 0,  
26 - UserName: companyUserListQuery.UserName,  
27 - DepName: companyUserListQuery.DepartmentName,  
28 - Phone: "",  
29 - UserType: domain.UserTypeEmployee,  
30 - InOrgIds: companyUserListQuery.Operator.OrgIds,  
31 - })  
32 - if err != nil {  
33 - return ExportCompanyUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)  
34 - }  
35 - return ExportCompanyUserData(result.Users), nil  
36 -} 1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
  9 +)
  10 +
  11 +type ExcelDataService struct {
  12 +}
  13 +
  14 +func NewExcelDataService(param map[string]interface{}) *ExcelDataService {
  15 + return &ExcelDataService{}
  16 +}
  17 +
  18 +// 导出公司用户信息列表
  19 +func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCompanyUserData, error) {
  20 + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)
  21 + result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
  22 + Limit: 10000,
  23 + CompanyId: companyUserListQuery.Operator.CompanyId,
  24 + OrganizationId: 0,
  25 + DepartmentId: 0,
  26 + UserName: companyUserListQuery.UserName,
  27 + DepName: companyUserListQuery.DepartmentName,
  28 + Phone: "",
  29 + UserType: domain.UserTypeEmployee,
  30 + InOrgIds: companyUserListQuery.Operator.OrgIds,
  31 + })
  32 + if err != nil {
  33 + return ExportCompanyUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
  34 + }
  35 + return ExportCompanyUserData(result.Users), nil
  36 +}
  37 +
  38 +// 导出共创用户信息列表
  39 +func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCooperationUserData, error) {
  40 + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)
  41 + result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
  42 + Limit: 10000,
  43 + CompanyId: companyUserListQuery.Operator.CompanyId,
  44 + OrganizationId: 0,
  45 + DepartmentId: 0,
  46 + UserName: companyUserListQuery.UserName,
  47 + DepName: companyUserListQuery.DepartmentName,
  48 + Phone: "",
  49 + UserType: domain.UserTypeCooperation,
  50 + InOrgIds: companyUserListQuery.Operator.OrgIds,
  51 + })
  52 + if err != nil {
  53 + return ExportCooperationUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
  54 + }
  55 + return ExportCooperationUserData(result.Users), nil
  56 +}
1 -package service  
2 -  
3 -import (  
4 - "github.com/linmadan/egglib-go/utils/excel"  
5 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"  
6 -)  
7 -  
8 -//exportCompanyUserData 导出公司用户数据  
9 -type ExportCompanyUserData []allied_creation_user.UserDetail  
10 -  
11 -var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil)  
12 -  
13 -func (data ExportCompanyUserData) DataFieldList() []excel.DataField {  
14 - return []excel.DataField{  
15 - {EnName: "UserCode", CnName: "用户编码"},  
16 - {EnName: "UserName", CnName: "用户姓名"},  
17 - {EnName: "Phone", CnName: "手机号"},  
18 - {EnName: "DepartmentName", CnName: "所属部门"},  
19 - {EnName: "EnableStatus", CnName: "状态"},  
20 - {EnName: "OrgName", CnName: "组织机构"},  
21 - }  
22 -}  
23 -  
24 -func (data ExportCompanyUserData) CellValue(index int, enName string) (value interface{}) {  
25 - if index > data.DataListLen() {  
26 - return ""  
27 - }  
28 - switch enName {  
29 - case "UserCode":  
30 - return data[index].UserCode  
31 - case "UserName":  
32 - return data[index].UserInfo.UserName  
33 - case "Phone":  
34 - return data[index].UserInfo.Phone  
35 - case "DepartmentName":  
36 - if data[index].Department != nil {  
37 - return data[index].Department.DepartmentName  
38 - } else {  
39 - return ""  
40 - }  
41 - case "EnableStatus":  
42 - status := data[index].EnableStatus  
43 - statusName := ""  
44 - // 状态(1:启用 2:禁用 3:注销)  
45 - switch status {  
46 - case 1:  
47 - statusName = "启用"  
48 - case 2:  
49 - statusName = "禁用"  
50 - case 3:  
51 - statusName = "注销"  
52 - }  
53 - return statusName  
54 - case "OrgName":  
55 - if data[index].Org != nil {  
56 - return data[index].Org.OrgName  
57 - } else {  
58 - return ""  
59 - }  
60 - }  
61 - return nil  
62 -}  
63 -  
64 -func (data ExportCompanyUserData) DataListLen() int {  
65 - return len(data)  
66 -}  
67 -  
68 -func (data ExportCompanyUserData) TableTitle() []string {  
69 - return nil  
70 -} 1 +package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/utils/excel"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
  6 +)
  7 +
  8 +//exportCompanyUserData 导出公司用户数据
  9 +type ExportCompanyUserData []allied_creation_user.UserDetail
  10 +
  11 +var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil)
  12 +
  13 +func (data ExportCompanyUserData) DataFieldList() []excel.DataField {
  14 + return []excel.DataField{
  15 + {EnName: "UserCode", CnName: "用户编码"},
  16 + {EnName: "UserName", CnName: "用户姓名"},
  17 + {EnName: "Phone", CnName: "手机号"},
  18 + {EnName: "DepartmentName", CnName: "所属部门"},
  19 + {EnName: "EnableStatus", CnName: "状态"},
  20 + {EnName: "OrgName", CnName: "组织机构"},
  21 + }
  22 +}
  23 +
  24 +func (data ExportCompanyUserData) CellValue(index int, enName string) (value interface{}) {
  25 + if index > data.DataListLen() {
  26 + return ""
  27 + }
  28 + switch enName {
  29 + case "UserCode":
  30 + return data[index].UserCode
  31 + case "UserName":
  32 + return data[index].UserInfo.UserName
  33 + case "Phone":
  34 + return data[index].UserInfo.Phone
  35 + case "DepartmentName":
  36 + if data[index].Department != nil {
  37 + return data[index].Department.DepartmentName
  38 + } else {
  39 + return ""
  40 + }
  41 + case "EnableStatus":
  42 + status := data[index].EnableStatus
  43 + statusName := ""
  44 + // 状态(1:启用 2:禁用 3:注销)
  45 + switch status {
  46 + case 1:
  47 + statusName = "启用"
  48 + case 2:
  49 + statusName = "禁用"
  50 + case 3:
  51 + statusName = "注销"
  52 + }
  53 + return statusName
  54 + case "OrgName":
  55 + if data[index].Org != nil {
  56 + return data[index].Org.OrgName
  57 + } else {
  58 + return ""
  59 + }
  60 + }
  61 + return nil
  62 +}
  63 +
  64 +func (data ExportCompanyUserData) DataListLen() int {
  65 + return len(data)
  66 +}
  67 +
  68 +func (data ExportCompanyUserData) TableTitle() []string {
  69 + return nil
  70 +}
  71 +
  72 +//exportCompanyUserData 导出共创用户数据
  73 +type ExportCooperationUserData []allied_creation_user.UserDetail
  74 +
  75 +var _ excel.ExcelMaker = (*ExportCooperationUserData)(nil)
  76 +
  77 +func (data ExportCooperationUserData) DataFieldList() []excel.DataField {
  78 + return []excel.DataField{
  79 + {EnName: "UserCode", CnName: "用户编码"},
  80 + {EnName: "UserName", CnName: "用户姓名"},
  81 + {EnName: "CooperationCompany", CnName: "合作公司"},
  82 + {EnName: "CooperationDeadline", CnName: "合作到期"},
  83 + {EnName: "Phone", CnName: "手机号"},
  84 + {EnName: "Email", CnName: "邮箱"},
  85 + }
  86 +}
  87 +
  88 +func (data ExportCooperationUserData) CellValue(index int, enName string) (value interface{}) {
  89 + if index > data.DataListLen() {
  90 + return ""
  91 + }
  92 + switch enName {
  93 + case "UserCode":
  94 + return data[index].UserCode
  95 + case "UserName":
  96 + return data[index].UserInfo.UserName
  97 + case "CooperationCompany":
  98 + return data[index].CooperationInfo.CooperationCompany
  99 + case "CooperationDeadline":
  100 + return data[index].CooperationInfo.CooperationDeadline.Format("2006-01-02")
  101 + case "Phone":
  102 + return data[index].UserInfo.Phone
  103 + case "Email":
  104 + return data[index].UserInfo.Email
  105 + }
  106 + return nil
  107 +}
  108 +
  109 +func (data ExportCooperationUserData) DataListLen() int {
  110 + return len(data)
  111 +}
  112 +
  113 +func (data ExportCooperationUserData) TableTitle() []string {
  114 + return nil
  115 +}
1 -package web_client  
2 -  
3 -import (  
4 - "github.com/beego/beego/v2/server/web/context"  
5 -  
6 - "github.com/linmadan/egglib-go/utils/excel"  
7 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"  
8 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/service"  
9 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"  
10 -)  
11 -  
12 -type ExcelDataController struct {  
13 - baseController  
14 -}  
15 -  
16 -func (controller *ExcelDataController) responseExcelByFile(ctx *context.Context, excelExport *excel.ExcelExport, fileName string) error {  
17 - ctx.Output.Header("Content-Disposition", "attachment; filename="+fileName)  
18 - ctx.Output.Header("Content-Description", "File Transfer")  
19 - ctx.Output.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")  
20 - ctx.Output.Header("Content-Transfer-Encoding", "binary")  
21 - ctx.Output.Header("Expires", "0")  
22 - ctx.Output.Header("Cache-Control", "must-revalidate")  
23 - ctx.Output.Header("Pragma", "public")  
24 - //跳过保存文件,直接写入ctx.ResponseWriter  
25 - excelExport.ExcelFile.Write(ctx.ResponseWriter)  
26 - return nil  
27 -}  
28 -  
29 -//导出公司用户  
30 -func (controller ExcelDataController) ExportCompanyUser() {  
31 - excelService := service.NewExcelDataService(nil)  
32 - companyUserListQuery := &query.CompanyUserListQuery{}  
33 - err := controller.Unmarshal(companyUserListQuery)  
34 - if err != nil {  
35 - log.Logger.Debug("json err:" + err.Error())  
36 - controller.Response(nil, err)  
37 - return  
38 - }  
39 - companyUserListQuery.Operator = controller.GetOperator()  
40 - data, err := excelService.ExportCompanyUser(companyUserListQuery)  
41 - if err != nil {  
42 - log.Logger.Debug("excelService.ExportCompanyUser err:" + err.Error())  
43 - controller.Response(nil, err)  
44 - return  
45 - }  
46 - excelTool := excel.NewExcelExport()  
47 - err = excelTool.ExportData(data, "")  
48 - if err != nil {  
49 - log.Logger.Debug("excelTool.ExportData err:" + err.Error())  
50 - controller.Response(nil, err)  
51 - return  
52 - }  
53 - controller.responseExcelByFile(controller.Ctx, excelTool, "导出公司用户")  
54 -} 1 +package web_client
  2 +
  3 +import (
  4 + "github.com/beego/beego/v2/server/web/context"
  5 +
  6 + "github.com/linmadan/egglib-go/utils/excel"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/service"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
  10 +)
  11 +
  12 +type ExcelDataController struct {
  13 + baseController
  14 +}
  15 +
  16 +func (controller *ExcelDataController) responseExcelByFile(ctx *context.Context, excelExport *excel.ExcelExport, fileName string) error {
  17 + ctx.Output.Header("Content-Disposition", "attachment; filename="+fileName)
  18 + ctx.Output.Header("Content-Description", "File Transfer")
  19 + ctx.Output.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  20 + ctx.Output.Header("Content-Transfer-Encoding", "binary")
  21 + ctx.Output.Header("Expires", "0")
  22 + ctx.Output.Header("Cache-Control", "must-revalidate")
  23 + ctx.Output.Header("Pragma", "public")
  24 + //跳过保存文件,直接写入ctx.ResponseWriter
  25 + excelExport.ExcelFile.Write(ctx.ResponseWriter)
  26 + return nil
  27 +}
  28 +
  29 +//导出公司用户
  30 +func (controller ExcelDataController) ExportCompanyUser() {
  31 + excelService := service.NewExcelDataService(nil)
  32 + companyUserListQuery := &query.CompanyUserListQuery{}
  33 + err := controller.Unmarshal(companyUserListQuery)
  34 + if err != nil {
  35 + log.Logger.Debug("json err:" + err.Error())
  36 + controller.Response(nil, err)
  37 + return
  38 + }
  39 + companyUserListQuery.Operator = controller.GetOperator()
  40 + data, err := excelService.ExportCompanyUser(companyUserListQuery)
  41 + if err != nil {
  42 + log.Logger.Debug("excelService.ExportCompanyUser err:" + err.Error())
  43 + controller.Response(nil, err)
  44 + return
  45 + }
  46 + excelTool := excel.NewExcelExport()
  47 + err = excelTool.ExportData(data, "")
  48 + if err != nil {
  49 + log.Logger.Debug("excelTool.ExportData err:" + err.Error())
  50 + controller.Response(nil, err)
  51 + return
  52 + }
  53 + controller.responseExcelByFile(controller.Ctx, excelTool, "导出公司用户")
  54 +}
  55 +
  56 +//导出共创用户
  57 +func (controller ExcelDataController) ExportCooperationUser() {
  58 + excelService := service.NewExcelDataService(nil)
  59 + companyUserListQuery := &query.CompanyUserListQuery{}
  60 + err := controller.Unmarshal(companyUserListQuery)
  61 + if err != nil {
  62 + log.Logger.Debug("json err:" + err.Error())
  63 + controller.Response(nil, err)
  64 + return
  65 + }
  66 + companyUserListQuery.Operator = controller.GetOperator()
  67 + data, err := excelService.ExportCooperationUser(companyUserListQuery)
  68 + if err != nil {
  69 + log.Logger.Debug("excelService.ExportCompanyUser err:" + err.Error())
  70 + controller.Response(nil, err)
  71 + return
  72 + }
  73 + excelTool := excel.NewExcelExport()
  74 + err = excelTool.ExportData(data, "")
  75 + if err != nil {
  76 + log.Logger.Debug("excelTool.ExportData err:" + err.Error())
  77 + controller.Response(nil, err)
  78 + return
  79 + }
  80 + controller.responseExcelByFile(controller.Ctx, excelTool, "导出共创用户")
  81 +}
1 -package routers  
2 -  
3 -import (  
4 - "github.com/beego/beego/v2/server/web"  
5 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/web_client"  
6 -)  
7 -  
8 -func init() {  
9 - web.Router("/v1/web/excel/export/company-user", &web_client.ExcelDataController{}, "Post:ExportCompanyUser")  
10 -} 1 +package routers
  2 +
  3 +import (
  4 + "github.com/beego/beego/v2/server/web"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/web_client"
  6 +)
  7 +
  8 +func init() {
  9 + web.Router("/v1/web/excel/export/company-user", &web_client.ExcelDataController{}, "Post:ExportCompanyUser")
  10 + web.Router("/v1/web/excel/export/cooperation-user", &web_client.ExcelDataController{}, "Post:ExportCooperationUser")
  11 +}