service_2.go
10.8 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
package service
import (
"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/staff_assess/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
"strconv"
)
// 调试用,手动调用CreateStaffAssessTask
func (srv StaffAssessServeice) InvokCreateStaffAssessTask(param *command.CreateStaffAssessTask) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
data, err := srv.CreateStaffAssessTask(transactionContext, param)
if err != nil {
return nil, err
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return data, nil
}
func (srv StaffAssessServeice) QuerySummary(in *query.SummaryCommand) (map[string]interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
hrbp, err := srv.getHRBP(transactionContext, in.CompanyId, in.OperatorId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext})
data, err := assessDao.SummaryAssess(in.CompanyId, in.OperatorId, in.CycleId, in.BeginDay, hrbp)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
}
self := adapter.SummaryBlock{Name: "填写反馈自评"}
invite := adapter.SummaryBlock{Name: "360°邀请"}
inviteAssess := adapter.SummaryBlock{Name: "360°评估"}
supper := adapter.SummaryBlock{Name: "上级评估"}
inviteTargetIdMap := map[string]int{} // 过滤相同的目标用户ID
for i := range data {
d := data[i]
d.EndTime = d.EndTime.Local() // 输出本地时间
switch d.Types {
case domain.AssessSelf:
self.Total++
if d.Status == domain.StaffAssessCompleted {
self.Completed++
}
if self.EndTime == nil {
self.EndTime = &d.EndTime
}
invite.Total++ // 发起360邀请的人数 = 自评人数
if invite.EndTime == nil {
invite.EndTime = &d.EndTime
}
break
case domain.AssessSuper:
supper.Total++
if d.Status == domain.StaffAssessCompleted {
supper.Completed++
}
if supper.EndTime == nil {
supper.EndTime = &d.EndTime
}
break
case domain.AssessInviteDiffSuper, domain.AssessInviteSameSuper:
inviteAssess.Total++
if d.Status == domain.StaffAssessCompleted {
inviteAssess.Completed++
}
if inviteAssess.EndTime == nil {
inviteAssess.EndTime = &d.EndTime
}
inviteTargetIdMap[d.TargetUserId] = 0 // 360评估类型都是被人邀请的评估,过滤相同的目标用户后,就是完成邀请的数量
break
}
}
invite.Completed = len(inviteTargetIdMap)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return map[string]interface{}{"list": []adapter.SummaryBlock{self, invite, inviteAssess, supper}}, nil
}
func (srv StaffAssessServeice) QueryMemberSummary(in *query.MemberSummaryListCommand) (map[string]interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
hrbp, err := srv.getHRBP(transactionContext, in.CompanyId, in.OperatorId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext})
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
departmentRepository := factory.CreateDepartmentRepository(map[string]interface{}{"transactionContext": transactionContext})
positionRepository := factory.CreatePositionRepository(map[string]interface{}{"transactionContext": transactionContext})
total, list, err := assessDao.MemberSummaryList(in.UserName, in.CompanyId, in.OperatorId, in.CycleId, hrbp, in.PageNumber, in.PageSize)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
userMap := map[int]*domain.User{}
departmentMap := map[int]*domain.Department{}
positionMap := map[int]*domain.Position{}
userIds := make([]int, 0)
for i := range list {
id, _ := strconv.Atoi(list[i].TargetUserId)
userIds = append(userIds, id)
}
if len(userIds) > 0 {
_, users, err := userRepository.Find(map[string]interface{}{"ids": userIds})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range users {
user := users[i]
userMap[int(user.Id)] = user
for i2 := range user.DepartmentId {
departmentMap[user.DepartmentId[i2]] = nil
}
for i2 := range user.PositionId {
positionMap[user.PositionId[i2]] = nil
}
}
departmentIds := make([]int, 0)
positionIds := make([]int, 0)
for k := range departmentMap {
departmentIds = append(departmentIds, k)
}
for k := range positionMap {
positionIds = append(positionIds, k)
}
if len(departmentIds) > 0 {
_, departments, err := departmentRepository.Find(map[string]interface{}{"ids": departmentIds})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range departments {
departmentMap[int(departments[i].Id)] = departments[i]
}
}
if len(positionIds) > 0 {
_, positions, err := positionRepository.Find(map[string]interface{}{"ids": positionIds})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range positions {
positionMap[int(positions[i].Id)] = positions[i]
}
}
}
adapters := make([]adapter.MemberSummaryAdapter, 0)
for i := range list {
it := list[i]
id, _ := strconv.Atoi(it.TargetUserId)
out := adapter.MemberSummaryAdapter{MemberSummaryAssess: it}
if v := userMap[id]; v != nil {
out.DepartmentNames = make([]string, 0)
out.PositionNames = make([]string, 0)
for i := range v.DepartmentId {
if v := departmentMap[v.DepartmentId[i]]; v != nil {
out.DepartmentNames = append(out.DepartmentNames, v.Name)
}
}
for i := range v.PositionId {
if v := positionMap[v.PositionId[i]]; v != nil {
out.PositionNames = append(out.PositionNames, v.Name)
}
}
}
adapters = append(adapters, out)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(int64(total), adapters), nil
}
func (srv StaffAssessServeice) QueryMemberPerformanceIndicator(in *query.MemberPerformanceIndicatorCommand) (map[string]interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
hrbp, err := srv.getHRBP(transactionContext, in.CompanyId, in.OperatorId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext})
list, err := assessDao.MemberPerformanceIndicator(
in.UserName,
in.CompanyId,
in.OperatorId,
in.CycleId,
hrbp,
string(domain.AssessSelf),
in.UserIds)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// (全部周期数据)筛选出第一个周期的数据,减少后续数据遍历
dupleMap := map[string]string{}
dupleList := make([]dao.PerformanceIndicatorAssess, 0)
for i := range list {
it := list[i]
if v, ok := dupleMap[it.TargetUserId]; ok {
if v == it.BeginDay {
dupleList = append(dupleList, it)
}
} else {
dupleMap[it.TargetUserId] = it.BeginDay
dupleList = append(dupleList, it)
}
}
piaMap := map[string]*adapter.PerformanceIndicatorAdapter{}
categoryMap := map[string]int{} // 内容分类
//categoryNameMap := map[string]int{} // 内容分类下的名称
adapterList := make([]*adapter.PerformanceIndicatorAdapter, 0)
for i := range dupleList {
it := dupleList[i]
var pia *adapter.PerformanceIndicatorAdapter
if v, ok := piaMap[it.TargetUserId]; ok {
pia = v
} else {
pia = &adapter.PerformanceIndicatorAdapter{
TargetUserId: it.TargetUserId,
TargetUserName: it.TargetUserName,
PIContents: make([]adapter.PIContent, 0),
}
piaMap[it.TargetUserId] = pia
adapterList = append(adapterList, pia)
}
// 分类名称有值才能合并分类数组
if len(it.ContentCategory) > 0 {
onlyKey1 := it.TargetUserId + it.ContentCategory
if _, ok := categoryMap[onlyKey1]; !ok {
categoryMap[onlyKey1] = 0
// 不存在分类时,创建分类内容
pia.PIContents = append(pia.PIContents, adapter.PIContent{
Category: it.ContentCategory,
Names: make([]string, 0),
})
}
// 内容名称有值合并到数组
if len(it.ContentName) > 0 {
// 周期筛选过的,不再需要唯一值验证判断,直接添加到对应的分类下
for index := range pia.PIContents {
piContent := &pia.PIContents[index]
if piContent.Category == it.ContentCategory {
piContent.Names = append(piContent.Names, it.ContentName)
break
}
}
//onlyKey2 := it.TargetUserId + it.ContentCategory + it.ContentName
//if _, ok := categoryNameMap[onlyKey2]; !ok {
// categoryNameMap[onlyKey2] = 0
//
// for index := range pia.PIContents {
// piContent := pia.PIContents[index]
// if piContent.Category == it.ContentCategory {
// piContent.Names = append(piContent.Names, it.ContentName)
// break
// }
// }
//}
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(int64(len(adapterList)), adapterList), nil
}