作者 tangxuhui

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

@@ -11,4 +11,5 @@ type CooperationUserListQuery struct { @@ -11,4 +11,5 @@ type CooperationUserListQuery struct {
11 UserName string `json:"userName"` 11 UserName string `json:"userName"`
12 //共创公司 12 //共创公司
13 CooperationCompany string `json:"cooperationCompany"` 13 CooperationCompany string `json:"cooperationCompany"`
  14 + SelectedField []string `json:"selectedField"`
14 } 15 }
@@ -49,5 +49,5 @@ func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.Co @@ -49,5 +49,5 @@ func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.Co
49 if err != nil { 49 if err != nil {
50 return ExportCooperationUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err) 50 return ExportCooperationUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
51 } 51 }
52 - return ExportCooperationUserData(result.Users), nil 52 + return ExportCooperationUserData{SourceData: result.Users, SelectedField: companyUserListQuery.SelectedField}, nil
53 } 53 }
@@ -19,7 +19,7 @@ type ExportCompanyUserData struct { @@ -19,7 +19,7 @@ type ExportCompanyUserData struct {
19 19
20 var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil) 20 var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil)
21 21
22 -func (data ExportCompanyUserData) AllField() []DataFieldOptions { 22 +func (data ExportCompanyUserData) AllFields() []DataFieldOptions {
23 return []DataFieldOptions{ 23 return []DataFieldOptions{
24 {EnName: "UserCode", CnName: "用户编码"}, 24 {EnName: "UserCode", CnName: "用户编码"},
25 {EnName: "UserName", CnName: "用户姓名"}, 25 {EnName: "UserName", CnName: "用户姓名"},
@@ -32,7 +32,7 @@ func (data ExportCompanyUserData) AllField() []DataFieldOptions { @@ -32,7 +32,7 @@ func (data ExportCompanyUserData) AllField() []DataFieldOptions {
32 32
33 func (data ExportCompanyUserData) DataFieldList() []excel.DataField { 33 func (data ExportCompanyUserData) DataFieldList() []excel.DataField {
34 fields := []excel.DataField{} 34 fields := []excel.DataField{}
35 - allFields := data.AllField() 35 + allFields := data.AllFields()
36 for _, value2 := range allFields { 36 for _, value2 := range allFields {
37 if len(data.SelectedField) == 0 || value2.IsDefault { 37 if len(data.SelectedField) == 0 || value2.IsDefault {
38 fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName}) 38 fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
@@ -96,21 +96,39 @@ func (data ExportCompanyUserData) TableTitle() []string { @@ -96,21 +96,39 @@ func (data ExportCompanyUserData) TableTitle() []string {
96 } 96 }
97 97
98 //ExportCooperationUserData 导出共创用户数据 98 //ExportCooperationUserData 导出共创用户数据
99 -type ExportCooperationUserData []allied_creation_user.UserDetail 99 +type ExportCooperationUserData struct {
  100 + SourceData []allied_creation_user.UserDetail
  101 + SelectedField []string
  102 +}
100 103
101 var _ excel.ExcelMaker = (*ExportCooperationUserData)(nil) 104 var _ excel.ExcelMaker = (*ExportCooperationUserData)(nil)
102 105
103 -func (data ExportCooperationUserData) DataFieldList() []excel.DataField {  
104 - return []excel.DataField{ 106 +func (data ExportCooperationUserData) AllFields() []DataFieldOptions {
  107 + return []DataFieldOptions{
105 {EnName: "UserCode", CnName: "用户编码"}, 108 {EnName: "UserCode", CnName: "用户编码"},
106 {EnName: "UserName", CnName: "用户姓名"}, 109 {EnName: "UserName", CnName: "用户姓名"},
107 {EnName: "Phone", CnName: "手机号"}, 110 {EnName: "Phone", CnName: "手机号"},
108 {EnName: "CooperationCompany", CnName: "共创公司"}, 111 {EnName: "CooperationCompany", CnName: "共创公司"},
109 {EnName: "CooperationDeadline", CnName: "共创到期"}, 112 {EnName: "CooperationDeadline", CnName: "共创到期"},
110 {EnName: "EnableStatus", CnName: "状态"}, 113 {EnName: "EnableStatus", CnName: "状态"},
  114 + }
  115 +}
111 116
112 - //{EnName: "Email", CnName: "邮箱"}, 117 +func (data ExportCooperationUserData) DataFieldList() []excel.DataField {
  118 + fields := []excel.DataField{}
  119 + allFields := data.AllFields()
  120 + for _, value2 := range allFields {
  121 + if len(data.SelectedField) == 0 || value2.IsDefault {
  122 + fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
  123 + continue
113 } 124 }
  125 + for _, value3 := range data.SelectedField {
  126 + if value2.EnName == value3 {
  127 + fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
  128 + }
  129 + }
  130 + }
  131 + return fields
114 } 132 }
115 133
116 func (data ExportCooperationUserData) CellValue(index int, enName string) (value interface{}) { 134 func (data ExportCooperationUserData) CellValue(index int, enName string) (value interface{}) {
@@ -119,22 +137,22 @@ func (data ExportCooperationUserData) CellValue(index int, enName string) (value @@ -119,22 +137,22 @@ func (data ExportCooperationUserData) CellValue(index int, enName string) (value
119 } 137 }
120 switch enName { 138 switch enName {
121 case "UserCode": 139 case "UserCode":
122 - return data[index].UserCode 140 + return data.SourceData[index].UserCode
123 case "UserName": 141 case "UserName":
124 - return data[index].UserInfo.UserName 142 + return data.SourceData[index].UserInfo.UserName
125 case "CooperationCompany": 143 case "CooperationCompany":
126 - return data[index].CooperationInfo.CooperationCompany 144 + return data.SourceData[index].CooperationInfo.CooperationCompany
127 case "CooperationDeadline": 145 case "CooperationDeadline":
128 - if data[index].CooperationInfo.CooperationDeadline.IsZero() || data[index].CooperationInfo.CooperationDeadline.Unix() == 0 { 146 + if data.SourceData[index].CooperationInfo.CooperationDeadline.IsZero() || data.SourceData[index].CooperationInfo.CooperationDeadline.Unix() == 0 {
129 return "" 147 return ""
130 } 148 }
131 - return data[index].CooperationInfo.CooperationDeadline.Format("2006-01-02") 149 + return data.SourceData[index].CooperationInfo.CooperationDeadline.Format("2006-01-02")
132 case "Phone": 150 case "Phone":
133 - return data[index].UserInfo.Phone 151 + return data.SourceData[index].UserInfo.Phone
134 case "Email": 152 case "Email":
135 - return data[index].UserInfo.Email 153 + return data.SourceData[index].UserInfo.Email
136 case "EnableStatus": 154 case "EnableStatus":
137 - status := data[index].EnableStatus 155 + status := data.SourceData[index].EnableStatus
138 statusName := "" 156 statusName := ""
139 // 状态(1:启用 2:禁用 3:注销) 157 // 状态(1:启用 2:禁用 3:注销)
140 switch status { 158 switch status {
@@ -151,7 +169,7 @@ func (data ExportCooperationUserData) CellValue(index int, enName string) (value @@ -151,7 +169,7 @@ func (data ExportCooperationUserData) CellValue(index int, enName string) (value
151 } 169 }
152 170
153 func (data ExportCooperationUserData) DataListLen() int { 171 func (data ExportCooperationUserData) DataListLen() int {
154 - return len(data) 172 + return len(data.SourceData)
155 } 173 }
156 174
157 func (data ExportCooperationUserData) TableTitle() []string { 175 func (data ExportCooperationUserData) TableTitle() []string {