service.go
10.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
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
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"
roleService "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
"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"
)
type SummaryEvaluationServeice struct {
}
func NewStaffAssessServeice() *SummaryEvaluationServeice {
newService := &SummaryEvaluationServeice{}
return newService
}
// GetCycleList
// 获取周期列表
func (srv *SummaryEvaluationServeice) GetCycleList(param *command.QueryCycleList) (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()
}()
evaluationDao := dao.NewSummaryEvaluationDao(map[string]interface{}{
"transactionContext": transactionContext,
})
limit := 300
offset := 0
if param.PageSize > 0 {
limit = param.PageSize
}
if param.PageNumber > 0 {
offset = (param.PageNumber - 1) * param.PageSize
}
cycleData, err := evaluationDao.GetPersonalCycleList(param.UserId, offset, limit)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取周期列表"+err.Error())
}
cnt, err := evaluationDao.CountPersonalCycleList(param.UserId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
cycleList := []adapter.CycleListAdapter{}
for _, v := range cycleData {
m := adapter.CycleListAdapter{
CycleId: v.CycleId,
CycleName: v.CycleName,
ExecutorId: v.ExecutorId,
}
cycleList = append(cycleList, m)
}
return tool_funs.SimpleWrapGridMap(int64(cnt), cycleList), nil
}
// GetMenu
// 根据周期获取菜单显示
func (srv *SummaryEvaluationServeice) GetMenu(param *command.QueryMenu) (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()
}()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//查找我的绩效
_, selfEvaluation, err := evaluationRepo.Find(map[string]interface{}{
"types": int(domain.EvaluationSelf),
"executorId": param.UserId,
"limit": 1,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//查找360评估,统计未完成的
cnt360, _, err := evaluationRepo.Find(map[string]interface{}{
"types": int(domain.Evaluation360),
"executorId": param.UserId,
"limit": 1,
"status": string(domain.EvaluationUncompleted),
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//查询上级评估,统计未完成
cntSuper, _, err := evaluationRepo.Find(map[string]interface{}{
"types": int(domain.EvaluationSelf),
"executorId": param.UserId,
"limit": 1,
"status": string(domain.EvaluationUncompleted),
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//查询人资评估,统计未完成
cntHrbp, _, err := evaluationRepo.Find(map[string]interface{}{
"types": int(domain.EvaluationHrbp),
"executorId": param.UserId,
"limit": 1,
"status": string(domain.EvaluationUncompleted),
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
isHrbp, err := roleService.GetHRBP(transactionContext, param.CompanyId, param.UserId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
menuList := []adapter.MenuListAdapter{}
//模块-我的绩效
menu1 := adapter.MenuListAdapter{
CycleId: 0,
NodeName: "我的绩效",
StatusName: "",
Types: "",
Child: []adapter.MenuListAdapter{},
}
menu1_1 := adapter.MenuListAdapter{
CycleId: param.CycleId,
NodeName: "填写综合自评",
StatusName: "",
Types: "填写综合自评",
}
menu1_2 := adapter.MenuListAdapter{
CycleId: param.CycleId,
NodeName: "查看综合自评",
StatusName: "",
Types: "查看综合自评",
}
if len(selfEvaluation) > 0 {
if selfEvaluation[0].Status == domain.EvaluationCompleted {
menu1_1.StatusName = "已完成"
} else {
menu1_1.StatusName = "未完成"
}
if selfEvaluation[0].CheckResult == domain.EvaluationCheckCompleted {
menu1_2.StatusName = "已完成"
} else {
menu1_2.StatusName = "未完成"
}
}
menu1.Child = append(menu1.Child, menu1_1, menu1_2)
menuList = append(menuList, menu1)
menu2 := adapter.MenuListAdapter{
CycleId: 0,
NodeName: "给他人评估",
StatusName: "",
Types: "",
Child: []adapter.MenuListAdapter{},
}
menu2_1 := adapter.MenuListAdapter{
CycleId: param.CycleId,
NodeName: "360综评",
StatusName: "",
Types: "360综评",
}
if cnt360 > 0 {
menu2_1.StatusName = "未完成"
} else {
menu2_1.StatusName = "已完成"
}
menu2.Child = append(menu2.Child, menu2_1)
menuList = append(menuList, menu2)
menu3 := adapter.MenuListAdapter{
CycleId: 0,
NodeName: "人资评估",
StatusName: "",
Types: "",
Child: []adapter.MenuListAdapter{},
}
menu3_1 := adapter.MenuListAdapter{
CycleId: param.CycleId,
NodeName: "上级综评",
StatusName: "",
Types: "上级综评",
}
if cntHrbp > 0 {
menu3_1.StatusName = "未完成"
} else {
menu3_1.StatusName = "已完成"
}
menu3.Child = append(menu3.Child, menu3_1)
//hrbp 才有这个菜单
if isHrbp > 0 {
menuList = append(menuList, menu3)
}
menu4 := adapter.MenuListAdapter{
CycleId: 0,
NodeName: "我的团队绩效",
StatusName: "",
Types: "",
Child: []adapter.MenuListAdapter{},
}
menu4_1 := adapter.MenuListAdapter{
CycleId: param.CycleId,
NodeName: "上级综评",
StatusName: "",
Types: "上级综评",
}
if cntSuper > 0 {
menu4_1.StatusName = "未完成"
} else {
menu4_1.StatusName = "已完成"
}
menu4.Child = append(menu4.Child, menu4_1)
menuList = append(menuList, menu4)
result := map[string]interface{}{
"menus": menuList,
}
return result, nil
}
// buildSummaryItemValue 将填写值填充进评估项
func (srv *SummaryEvaluationServeice) buildSummaryItemValue(itemList []*domain.EvaluationItemUsed, valueList []*domain.SummaryEvaluationValue) (
itemValues []adapter.EvaluationItemAdapter) {
itemValues = []adapter.EvaluationItemAdapter{}
valueMap := map[int]*domain.SummaryEvaluationValue{}
for _, v := range valueList {
valueMap[v.EvaluationItemId] = v
}
for _, v := range itemList {
item := adapter.EvaluationItemAdapter{
EvaluationItemId: v.Id,
SortBy: v.SortBy,
Category: v.Category,
Name: v.Name,
PromptTitle: v.PromptTitle,
PromptText: v.PromptText,
EntryItems: v.EntryItems,
RuleType: v.RuleType,
Rule: v.Rule,
Weight: v.Weight,
Required: v.Required,
Value: "",
Score: "",
Remark: "",
}
value, ok := valueMap[v.Id]
if !ok {
continue
}
item.Score = value.Score
item.Value = value.Value
item.Remark = value.Remark
itemValues = append(itemValues, item)
}
return itemValues
}
// 获取综合自评详情
func (srv *SummaryEvaluationServeice) GetEvaluationSelf(param *command.QueryEvaluationInfo) (*adapter.EvaluationInfoAdapter, 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()
}()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
itemValueRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"limit": 1,
"cycleId": param.CompanyId,
"executorId": param.ExecutorId,
"types": domain.EvaluationSelf,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) == 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationData := evaluationList[0]
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
"evaluationProjectId": evaluationData.EvaluationProjectId,
"nodeType": int(domain.LinkNodeSelfAssessment),
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
_ = itemList
_ = itemValueRepo
return nil, nil
}
// 编辑综合自评详情
func (srv *SummaryEvaluationServeice) EditEvaluationSelf() (map[string][]adapter.EvaluationItemAdapter, 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()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil, nil
}