1
|
package service
|
1
|
package service
|
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
|
|
4
|
+ "fmt"
|
|
|
5
|
+
|
|
|
6
|
+ "github.com/linmadan/egglib-go/core/application"
|
4
|
"github.com/xuri/excelize/v2"
|
7
|
"github.com/xuri/excelize/v2"
|
|
|
8
|
+ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
|
5
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
|
|
|
10
|
+ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
6
|
)
|
11
|
)
|
7
|
|
12
|
|
8
|
// 导出数据
|
13
|
// 导出数据
|
9
|
// 综合管理-周期评估
|
14
|
// 综合管理-周期评估
|
10
|
func (srv *SummaryEvaluationService) ExportAllEvaluationSuper(param *command.QueryEvaluationList) (*excelize.File, error) {
|
15
|
func (srv *SummaryEvaluationService) ExportAllEvaluationSuper(param *command.QueryEvaluationList) (*excelize.File, error) {
|
11
|
- return nil, nil
|
16
|
+ transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
17
|
+ if err != nil {
|
|
|
18
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
19
|
+ }
|
|
|
20
|
+ if err := transactionContext.StartTransaction(); err != nil {
|
|
|
21
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
22
|
+ }
|
|
|
23
|
+ defer func() {
|
|
|
24
|
+ _ = transactionContext.RollbackTransaction()
|
|
|
25
|
+ }()
|
|
|
26
|
+ evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
|
|
|
27
|
+ "transactionContext": transactionContext,
|
|
|
28
|
+ })
|
|
|
29
|
+ userRepo := factory.CreateUserRepository(map[string]interface{}{
|
|
|
30
|
+ "transactionContext": transactionContext,
|
|
|
31
|
+ })
|
|
|
32
|
+ positionRepo := factory.CreatePositionRepository(map[string]interface{}{
|
|
|
33
|
+ "transactionContext": transactionContext,
|
|
|
34
|
+ })
|
|
|
35
|
+ limit := param.PageSize
|
|
|
36
|
+ offset := (param.PageNumber - 1) * param.PageSize
|
|
|
37
|
+
|
|
|
38
|
+ //获取评估列表信息
|
|
|
39
|
+ condition1 := map[string]interface{}{
|
|
|
40
|
+ "cycleId": param.CycleId,
|
|
|
41
|
+ "types": int(domain.EvaluationSuper),
|
|
|
42
|
+ "limit": limit,
|
|
|
43
|
+ }
|
|
|
44
|
+ if offset > 0 {
|
|
|
45
|
+ condition1["offset"] = offset
|
|
|
46
|
+ }
|
|
|
47
|
+ if len(param.TargetUserName) == 0 {
|
|
|
48
|
+ condition1["targetUserName"] = "%" + param.TargetUserName + "%"
|
|
|
49
|
+ }
|
|
|
50
|
+ //获取评估列表信息
|
|
|
51
|
+ _, evaluationList, err := evaluationRepo.Find(condition1)
|
|
|
52
|
+ if err != nil {
|
|
|
53
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
54
|
+ }
|
|
|
55
|
+ targetUserIds := []int{}
|
|
|
56
|
+ //获取员工信息
|
|
|
57
|
+ userMap := map[int64]*domain.User{}
|
|
|
58
|
+ for _, v := range evaluationList {
|
|
|
59
|
+ if _, ok := userMap[int64(v.TargetUser.UserId)]; ok {
|
|
|
60
|
+ continue
|
|
|
61
|
+ }
|
|
|
62
|
+ userMap[int64(v.TargetUser.UserId)] = nil
|
|
|
63
|
+ targetUserIds = append(targetUserIds, v.TargetUser.UserId)
|
|
|
64
|
+
|
|
|
65
|
+ }
|
|
|
66
|
+ if len(targetUserIds) > 0 {
|
|
|
67
|
+ _, userList, err := userRepo.Find(map[string]interface{}{
|
|
|
68
|
+ "ids": targetUserIds,
|
|
|
69
|
+ })
|
|
|
70
|
+ if err != nil {
|
|
|
71
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
72
|
+ }
|
|
|
73
|
+ for _, v := range userList {
|
|
|
74
|
+ userMap[v.Id] = v
|
|
|
75
|
+ }
|
|
|
76
|
+ }
|
|
|
77
|
+ var positionIds []int
|
|
|
78
|
+ //获取职位列表
|
|
|
79
|
+ positionMap := map[int64]*domain.Position{}
|
|
|
80
|
+ for _, v := range userMap {
|
|
|
81
|
+ for _, v2 := range v.DepartmentId {
|
|
|
82
|
+ if _, ok := positionMap[int64(v2)]; ok {
|
|
|
83
|
+ continue
|
|
|
84
|
+ }
|
|
|
85
|
+ positionMap[int64(v2)] = nil
|
|
|
86
|
+ positionIds = append(positionIds, v2)
|
|
|
87
|
+ }
|
|
|
88
|
+ }
|
|
|
89
|
+ if len(positionIds) > 0 {
|
|
|
90
|
+ _, positionList, err := positionRepo.Find(map[string]interface{}{"ids": positionIds})
|
|
|
91
|
+ if err != nil {
|
|
|
92
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取部门信息"+err.Error())
|
|
|
93
|
+ }
|
|
|
94
|
+ for _, v := range positionList {
|
|
|
95
|
+ positionMap[v.Id] = v
|
|
|
96
|
+ }
|
|
|
97
|
+ }
|
|
|
98
|
+ if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
99
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
100
|
+ }
|
|
|
101
|
+ ratingHeader := []string{} //动态列,评级内容
|
|
|
102
|
+ ratingMap := map[string]struct{}{} //过滤重复code
|
|
|
103
|
+ evaluationRatingMap := map[int]map[string]int{}
|
|
|
104
|
+ for _, v := range evaluationList {
|
|
|
105
|
+ evaluationRatingMap[v.Id] = map[string]int{}
|
|
|
106
|
+ for _, v2 := range v.TotalRating {
|
|
|
107
|
+ if _, ok := ratingMap[v2.Code]; !ok {
|
|
|
108
|
+ ratingMap[v2.Code] = struct{}{}
|
|
|
109
|
+ ratingHeader = append(ratingHeader, v2.Code)
|
|
|
110
|
+ }
|
|
|
111
|
+ evaluationRatingMap[v.Id][v2.Code] = v2.Number
|
|
|
112
|
+ }
|
|
|
113
|
+ }
|
|
|
114
|
+
|
|
|
115
|
+ xlsxFile := excelize.NewFile()
|
|
|
116
|
+ //设置默认的第一个sheet
|
|
|
117
|
+ sheetIndex := xlsxFile.GetActiveSheetIndex()
|
|
|
118
|
+ firstSheetName := xlsxFile.GetSheetName(sheetIndex)
|
|
|
119
|
+ tableHead := []string{"姓名", "部门", "职位", "最终绩效得分"}
|
|
|
120
|
+ tableHead = append(tableHead, ratingHeader...)
|
|
|
121
|
+ xlsxFile.SetSheetRow(firstSheetName, "A1", &tableHead)
|
|
|
122
|
+ for i, v := range evaluationList {
|
|
|
123
|
+ departmentName := ""
|
|
|
124
|
+ for _, dep := range v.TargetDepartment {
|
|
|
125
|
+ departmentName += dep.DepartmentName + " "
|
|
|
126
|
+ }
|
|
|
127
|
+ //填充员工信息
|
|
|
128
|
+ positinName := ""
|
|
|
129
|
+ if targetUser, ok := userMap[int64(v.TargetUser.UserId)]; ok {
|
|
|
130
|
+ //填充职位信息
|
|
|
131
|
+ for _, positionId := range targetUser.PositionId {
|
|
|
132
|
+ if position, ok := positionMap[int64(positionId)]; ok {
|
|
|
133
|
+ positinName += position.Name + " "
|
|
|
134
|
+ }
|
|
|
135
|
+ }
|
|
|
136
|
+ }
|
|
|
137
|
+ dataRaw := []string{
|
|
|
138
|
+ v.TargetUser.UserName,
|
|
|
139
|
+ departmentName,
|
|
|
140
|
+ positinName,
|
|
|
141
|
+ v.TotalScore,
|
|
|
142
|
+ }
|
|
|
143
|
+ for _, v2 := range ratingHeader {
|
|
|
144
|
+ if num, ok := evaluationRatingMap[v.Id][v2]; ok {
|
|
|
145
|
+ dataRaw = append(dataRaw, fmt.Sprintf("%d", num))
|
|
|
146
|
+ } else {
|
|
|
147
|
+ dataRaw = append(dataRaw, "0")
|
|
|
148
|
+ }
|
|
|
149
|
+ }
|
|
|
150
|
+ xlsxFile.SetSheetRow(firstSheetName, fmt.Sprintf("A%d", i+2), &dataRaw)
|
|
|
151
|
+ }
|
|
|
152
|
+ return xlsxFile, nil
|
12
|
} |
153
|
} |