作者 tangxuhui

调整 导出共创用户信息列表

... ... @@ -11,4 +11,5 @@ type CooperationUserListQuery struct {
UserName string `json:"userName"`
//共创公司
CooperationCompany string `json:"cooperationCompany"`
SelectedField []string `json:"selectedField"`
}
... ...
... ... @@ -49,5 +49,5 @@ func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.Co
if err != nil {
return ExportCooperationUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
}
return ExportCooperationUserData(result.Users), nil
return ExportCooperationUserData{SourceData: result.Users, SelectedField: companyUserListQuery.SelectedField}, nil
}
... ...
... ... @@ -19,7 +19,7 @@ type ExportCompanyUserData struct {
var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil)
func (data ExportCompanyUserData) AllField() []DataFieldOptions {
func (data ExportCompanyUserData) AllFields() []DataFieldOptions {
return []DataFieldOptions{
{EnName: "UserCode", CnName: "用户编码"},
{EnName: "UserName", CnName: "用户姓名"},
... ... @@ -32,7 +32,7 @@ func (data ExportCompanyUserData) AllField() []DataFieldOptions {
func (data ExportCompanyUserData) DataFieldList() []excel.DataField {
fields := []excel.DataField{}
allFields := data.AllField()
allFields := data.AllFields()
for _, value2 := range allFields {
if len(data.SelectedField) == 0 || value2.IsDefault {
fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
... ... @@ -96,21 +96,39 @@ func (data ExportCompanyUserData) TableTitle() []string {
}
//ExportCooperationUserData 导出共创用户数据
type ExportCooperationUserData []allied_creation_user.UserDetail
type ExportCooperationUserData struct {
SourceData []allied_creation_user.UserDetail
SelectedField []string
}
var _ excel.ExcelMaker = (*ExportCooperationUserData)(nil)
func (data ExportCooperationUserData) DataFieldList() []excel.DataField {
return []excel.DataField{
func (data ExportCooperationUserData) AllFields() []DataFieldOptions {
return []DataFieldOptions{
{EnName: "UserCode", CnName: "用户编码"},
{EnName: "UserName", CnName: "用户姓名"},
{EnName: "Phone", CnName: "手机号"},
{EnName: "CooperationCompany", CnName: "共创公司"},
{EnName: "CooperationDeadline", CnName: "共创到期"},
{EnName: "EnableStatus", CnName: "状态"},
}
}
//{EnName: "Email", CnName: "邮箱"},
func (data ExportCooperationUserData) DataFieldList() []excel.DataField {
fields := []excel.DataField{}
allFields := data.AllFields()
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 ExportCooperationUserData) CellValue(index int, enName string) (value interface{}) {
... ... @@ -119,22 +137,22 @@ func (data ExportCooperationUserData) CellValue(index int, enName string) (value
}
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 "CooperationCompany":
return data[index].CooperationInfo.CooperationCompany
return data.SourceData[index].CooperationInfo.CooperationCompany
case "CooperationDeadline":
if data[index].CooperationInfo.CooperationDeadline.IsZero() || data[index].CooperationInfo.CooperationDeadline.Unix() == 0 {
if data.SourceData[index].CooperationInfo.CooperationDeadline.IsZero() || data.SourceData[index].CooperationInfo.CooperationDeadline.Unix() == 0 {
return ""
}
return data[index].CooperationInfo.CooperationDeadline.Format("2006-01-02")
return data.SourceData[index].CooperationInfo.CooperationDeadline.Format("2006-01-02")
case "Phone":
return data[index].UserInfo.Phone
return data.SourceData[index].UserInfo.Phone
case "Email":
return data[index].UserInfo.Email
return data.SourceData[index].UserInfo.Email
case "EnableStatus":
status := data[index].EnableStatus
status := data.SourceData[index].EnableStatus
statusName := ""
// 状态(1:启用 2:禁用 3:注销)
switch status {
... ... @@ -151,7 +169,7 @@ func (data ExportCooperationUserData) CellValue(index int, enName string) (value
}
func (data ExportCooperationUserData) DataListLen() int {
return len(data)
return len(data.SourceData)
}
func (data ExportCooperationUserData) TableTitle() []string {
... ...