作者 tangxuhui

调整excel导出

... ... @@ -11,4 +11,5 @@ type CompanyUserListQuery struct {
DepartmentName string `json:"departmentName"`
//操作人
Operator domain.Operator `json:"-"`
SelectedField []string `json:"selectedField"`
}
... ...
... ... @@ -2,6 +2,7 @@ package service
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
... ... @@ -25,7 +26,10 @@ func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.Compan
if err != nil {
return ExportCompanyUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
}
return ExportCompanyUserData(result.Users), nil
return ExportCompanyUserData{
SourceData: result.Users,
SelectedField: companyUserListQuery.SelectedField,
}, nil
}
// ExportCooperationUser 导出共创用户信息列表
... ...
... ... @@ -5,13 +5,22 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
type DataFieldOptions struct {
EnName string `json:"enName"`
CnName string `json:"cnName"`
IsDefault bool `json:"isDefault"`
}
// ExportCompanyUserData 导出公司用户数据
type ExportCompanyUserData []allied_creation_user.UserDetail
type ExportCompanyUserData struct {
SourceData []allied_creation_user.UserDetail
SelectedField []string
}
var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil)
func (data ExportCompanyUserData) DataFieldList() []excel.DataField {
return []excel.DataField{
func (data ExportCompanyUserData) AllField() []DataFieldOptions {
return []DataFieldOptions{
{EnName: "UserCode", CnName: "用户编码"},
{EnName: "UserName", CnName: "用户姓名"},
{EnName: "Phone", CnName: "手机号"},
... ... @@ -21,25 +30,42 @@ func (data ExportCompanyUserData) DataFieldList() []excel.DataField {
}
}
func (data ExportCompanyUserData) DataFieldList() []excel.DataField {
fields := []excel.DataField{}
allFields := data.AllField()
for _, value2 := range allFields {
if len(data.SelectedField) == 0 || value2.IsDefault {
fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
continue
}
for _, value3 := range data.SelectedField {
if value2.EnName == value3 {
fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
}
}
}
return fields
}
func (data ExportCompanyUserData) CellValue(index int, enName string) (value interface{}) {
if index > data.DataListLen() {
return ""
}
switch enName {
case "UserCode":
return data[index].UserCode
return data.SourceData[index].UserCode
case "UserName":
return data[index].UserInfo.UserName
return data.SourceData[index].UserInfo.UserName
case "Phone":
return data[index].UserInfo.Phone
return data.SourceData[index].UserInfo.Phone
case "DepartmentName":
if data[index].Department != nil {
return data[index].Department.DepartmentName
if data.SourceData[index].Department != nil {
return data.SourceData[index].Department.DepartmentName
} else {
return ""
}
case "EnableStatus":
status := data[index].EnableStatus
status := data.SourceData[index].EnableStatus
statusName := ""
// 状态(1:启用 2:禁用 3:注销)
switch status {
... ... @@ -52,8 +78,8 @@ func (data ExportCompanyUserData) CellValue(index int, enName string) (value int
}
return statusName
case "OrgName":
if data[index].Org != nil {
return data[index].Org.OrgName
if data.SourceData[index].Org != nil {
return data.SourceData[index].Org.OrgName
} else {
return ""
}
... ... @@ -62,7 +88,7 @@ func (data ExportCompanyUserData) CellValue(index int, enName string) (value int
}
func (data ExportCompanyUserData) DataListLen() int {
return len(data)
return len(data.SourceData)
}
func (data ExportCompanyUserData) TableTitle() []string {
... ...