list_evaluation.go
5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package service
import (
"fmt"
"strings"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
)
//获取周期评估的列表 ,根据页面需要提供不同的结构变体
// 人资稽查 页面列表数据输出
// 根据周期id 获取类型为"EvaluationFinish" 的全部周期评估
func (srv *SummaryEvaluationService) ListEvaluationShow1(param command.QueryEvaluationList) (result map[string]interface{}, err error) {
transactionContext, err := factory.ValidateStartTransaction(param)
if err != nil {
return nil, err
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
staffAssessDaoRepo := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext})
userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
positionRepo := factory.CreatePositionRepository(map[string]interface{}{"transactionContext": transactionContext})
staffAssessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{"transactionContext": transactionContext})
limit := param.PageSize
offset := limit * (param.PageNumber - 1)
if offset < 0 {
offset = 0
}
condition := map[string]interface{}{
"companyId": param.CompanyId,
"cycleId": param.CycleId,
"types": domain.EvaluationFinish,
"limit": limit,
"offset": offset,
}
if len(param.TargetUserName) > 0 {
condition["targetUserName"] = "%" + param.TargetUserName + "%"
}
count, list, err := evaluationRepo.Find(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
userIds := make([]int, 0)
projectIds := make([]int, 0)
projectCountMap := map[string]int{} // 自评逾期数量
userMap := map[int64]*domain.User{} // 用户
positionMap := map[int64]*domain.Position{} // 职位
for i := range list {
it := list[i]
userIds = append(userIds, it.TargetUser.UserId)
projectIds = append(projectIds, list[i].EvaluationProjectId)
}
if len(userIds) > 0 {
_, users, err := userRepo.Find(map[string]interface{}{"ids": userIds, "companyId": param.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
positionIds := make([]int, 0)
for i := range users {
userMap[users[i].Id] = users[i]
positionIds = append(positionIds, users[i].PositionId...)
}
if len(positionIds) > 0 {
_, positions, err := positionRepo.Find(map[string]interface{}{"ids": positionIds, "companyId": param.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range positions {
positionMap[positions[i].Id] = positions[i]
}
}
}
if len(projectIds) > 0 {
targetCount, err := staffAssessDaoRepo.CountUncompletedSelfAssess(param.CompanyId, projectIds)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range targetCount {
key := fmt.Sprintf("%d-%d", targetCount[i].EvaluationProjectId, targetCount[i].TargetUserId)
projectCountMap[key] = targetCount[i].Cnt
}
}
resultList := make([]*adapter.EvaluationItemAdapter2, 0)
for i := range list {
v := list[i]
endTime := v.EndTime.Local()
// 检查15日自评 完成情况状态
statusVal := "未完成"
_, assessList, err := staffAssessRepo.Find(map[string]interface{}{
"cycleId": v.CycleId,
"targetUserId": v.TargetUser.UserId,
"beginDayNumber": 15,
})
if err == nil && len(assessList) > 0 {
if assessList[0].Status == domain.StaffAssessCompleted {
statusVal = "已完成"
}
}
// 部门拼接
var departmentBuild strings.Builder
departmentBuild.WriteString("")
for i2 := range v.TargetDepartment {
departmentBuild.WriteString(v.TargetDepartment[i2].DepartmentName)
if i2 != len(v.TargetDepartment)-1 {
departmentBuild.WriteString(",")
}
}
// 入职时间
entryTime := ""
// 职位拼接
var positionBuild strings.Builder
positionBuild.WriteString("")
if user, ok := userMap[int64(v.TargetUser.UserId)]; ok {
for i2 := range user.PositionId {
if position, ok := positionMap[int64(user.PositionId[i2])]; ok {
positionBuild.WriteString(position.Name)
if i2 != len(user.PositionId)-1 {
departmentBuild.WriteString(",")
}
}
}
entryTime = user.EntryTime
}
// 自评逾期数量
overdueCount := 0
key := fmt.Sprintf("%d-%d", v.EvaluationProjectId, v.TargetUser.UserId)
if cnt, ok := projectCountMap[key]; ok {
overdueCount = cnt
}
result := &adapter.EvaluationItemAdapter2{
CycleId: int(v.CycleId),
EvaluationId: v.Id,
TargetUserId: v.TargetUser.UserId,
TargetUserName: v.TargetUser.UserName,
Department: departmentBuild.String(),
Position: positionBuild.String(),
DutyTime: entryTime,
Status: statusVal,
EndTime: endTime.Local().Format("2006-01-02 15:04"),
OverdueCount: overdueCount,
}
resultList = append(resultList, result)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 外层显示截止时间
endTime := ""
if len(list) > 0 {
endTime = list[0].EndTime.Local().Format("2006-01-02 15:04:05")
}
grid := tool_funs.SimpleWrapGridMap(int64(count), resultList)
grid["endTime"] = endTime
return grid, nil
}