|
@@ -5,13 +5,22 @@ import ( |
|
@@ -5,13 +5,22 @@ 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
|
+type DataFieldOptions struct {
|
|
|
9
|
+ EnName string `json:"enName"`
|
|
|
10
|
+ CnName string `json:"cnName"`
|
|
|
11
|
+ IsDefault bool `json:"isDefault"`
|
|
|
12
|
+}
|
|
|
13
|
+
|
8
|
// ExportCompanyUserData 导出公司用户数据
|
14
|
// ExportCompanyUserData 导出公司用户数据
|
9
|
-type ExportCompanyUserData []allied_creation_user.UserDetail
|
15
|
+type ExportCompanyUserData struct {
|
|
|
16
|
+ SourceData []allied_creation_user.UserDetail
|
|
|
17
|
+ SelectedField []string
|
|
|
18
|
+}
|
10
|
|
19
|
|
11
|
var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil)
|
20
|
var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil)
|
12
|
|
21
|
|
13
|
-func (data ExportCompanyUserData) DataFieldList() []excel.DataField {
|
|
|
14
|
- return []excel.DataField{
|
22
|
+func (data ExportCompanyUserData) AllField() []DataFieldOptions {
|
|
|
23
|
+ return []DataFieldOptions{
|
15
|
{EnName: "UserCode", CnName: "用户编码"},
|
24
|
{EnName: "UserCode", CnName: "用户编码"},
|
16
|
{EnName: "UserName", CnName: "用户姓名"},
|
25
|
{EnName: "UserName", CnName: "用户姓名"},
|
17
|
{EnName: "Phone", CnName: "手机号"},
|
26
|
{EnName: "Phone", CnName: "手机号"},
|
|
@@ -21,25 +30,42 @@ func (data ExportCompanyUserData) DataFieldList() []excel.DataField { |
|
@@ -21,25 +30,42 @@ func (data ExportCompanyUserData) DataFieldList() []excel.DataField { |
21
|
}
|
30
|
}
|
22
|
}
|
31
|
}
|
23
|
|
32
|
|
|
|
33
|
+func (data ExportCompanyUserData) DataFieldList() []excel.DataField {
|
|
|
34
|
+ fields := []excel.DataField{}
|
|
|
35
|
+ allFields := data.AllField()
|
|
|
36
|
+ for _, value2 := range allFields {
|
|
|
37
|
+ if len(data.SelectedField) == 0 || value2.IsDefault {
|
|
|
38
|
+ fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
|
|
|
39
|
+ continue
|
|
|
40
|
+ }
|
|
|
41
|
+ for _, value3 := range data.SelectedField {
|
|
|
42
|
+ if value2.EnName == value3 {
|
|
|
43
|
+ fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
|
|
|
44
|
+ }
|
|
|
45
|
+ }
|
|
|
46
|
+ }
|
|
|
47
|
+ return fields
|
|
|
48
|
+}
|
|
|
49
|
+
|
24
|
func (data ExportCompanyUserData) CellValue(index int, enName string) (value interface{}) {
|
50
|
func (data ExportCompanyUserData) CellValue(index int, enName string) (value interface{}) {
|
25
|
if index > data.DataListLen() {
|
51
|
if index > data.DataListLen() {
|
26
|
return ""
|
52
|
return ""
|
27
|
}
|
53
|
}
|
28
|
switch enName {
|
54
|
switch enName {
|
29
|
case "UserCode":
|
55
|
case "UserCode":
|
30
|
- return data[index].UserCode
|
56
|
+ return data.SourceData[index].UserCode
|
31
|
case "UserName":
|
57
|
case "UserName":
|
32
|
- return data[index].UserInfo.UserName
|
58
|
+ return data.SourceData[index].UserInfo.UserName
|
33
|
case "Phone":
|
59
|
case "Phone":
|
34
|
- return data[index].UserInfo.Phone
|
60
|
+ return data.SourceData[index].UserInfo.Phone
|
35
|
case "DepartmentName":
|
61
|
case "DepartmentName":
|
36
|
- if data[index].Department != nil {
|
|
|
37
|
- return data[index].Department.DepartmentName
|
62
|
+ if data.SourceData[index].Department != nil {
|
|
|
63
|
+ return data.SourceData[index].Department.DepartmentName
|
38
|
} else {
|
64
|
} else {
|
39
|
return ""
|
65
|
return ""
|
40
|
}
|
66
|
}
|
41
|
case "EnableStatus":
|
67
|
case "EnableStatus":
|
42
|
- status := data[index].EnableStatus
|
68
|
+ status := data.SourceData[index].EnableStatus
|
43
|
statusName := ""
|
69
|
statusName := ""
|
44
|
// 状态(1:启用 2:禁用 3:注销)
|
70
|
// 状态(1:启用 2:禁用 3:注销)
|
45
|
switch status {
|
71
|
switch status {
|
|
@@ -52,8 +78,8 @@ func (data ExportCompanyUserData) CellValue(index int, enName string) (value int |
|
@@ -52,8 +78,8 @@ func (data ExportCompanyUserData) CellValue(index int, enName string) (value int |
52
|
}
|
78
|
}
|
53
|
return statusName
|
79
|
return statusName
|
54
|
case "OrgName":
|
80
|
case "OrgName":
|
55
|
- if data[index].Org != nil {
|
|
|
56
|
- return data[index].Org.OrgName
|
81
|
+ if data.SourceData[index].Org != nil {
|
|
|
82
|
+ return data.SourceData[index].Org.OrgName
|
57
|
} else {
|
83
|
} else {
|
58
|
return ""
|
84
|
return ""
|
59
|
}
|
85
|
}
|
|
@@ -62,7 +88,7 @@ func (data ExportCompanyUserData) CellValue(index int, enName string) (value int |
|
@@ -62,7 +88,7 @@ func (data ExportCompanyUserData) CellValue(index int, enName string) (value int |
62
|
}
|
88
|
}
|
63
|
|
89
|
|
64
|
func (data ExportCompanyUserData) DataListLen() int {
|
90
|
func (data ExportCompanyUserData) DataListLen() int {
|
65
|
- return len(data)
|
91
|
+ return len(data.SourceData)
|
66
|
}
|
92
|
}
|
67
|
|
93
|
|
68
|
func (data ExportCompanyUserData) TableTitle() []string {
|
94
|
func (data ExportCompanyUserData) TableTitle() []string {
|