正在显示
6 个修改的文件
包含
258 行增加
和
0 行删除
@@ -3,7 +3,11 @@ package service | @@ -3,7 +3,11 @@ package service | ||
3 | import ( | 3 | import ( |
4 | "github.com/linmadan/egglib-go/core/application" | 4 | "github.com/linmadan/egglib-go/core/application" |
5 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | 5 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" |
6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter" | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command" | 7 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command" |
8 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao" | ||
7 | ) | 11 | ) |
8 | 12 | ||
9 | //调试用,手动调用CreateStaffAssessTask | 13 | //调试用,手动调用CreateStaffAssessTask |
@@ -28,3 +32,98 @@ func (srv StaffAssessServeice) InvokCreateStaffAssessTask(param *command.CreateS | @@ -28,3 +32,98 @@ func (srv StaffAssessServeice) InvokCreateStaffAssessTask(param *command.CreateS | ||
28 | } | 32 | } |
29 | return data, nil | 33 | return data, nil |
30 | } | 34 | } |
35 | + | ||
36 | +func (srv StaffAssessServeice) QuerySummary(in *query.SummaryCommand) (map[string]interface{}, error) { | ||
37 | + transactionContext, err := factory.ValidateStartTransaction(in) | ||
38 | + if err != nil { | ||
39 | + return nil, err | ||
40 | + } | ||
41 | + defer func() { | ||
42 | + transactionContext.RollbackTransaction() | ||
43 | + }() | ||
44 | + | ||
45 | + roleRepo := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
46 | + roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
47 | + _, roleList, err := roleRepo.Find(map[string]interface{}{"type": domain.RoleTypeSystem, "companyId": in.CompanyId}) | ||
48 | + if err != nil { | ||
49 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error()) | ||
50 | + } | ||
51 | + _, userRoleList, err := roleUserRepo.Find(map[string]interface{}{"companyId": in.CompanyId, "userId": in.OperatorId}) | ||
52 | + if err != nil { | ||
53 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error()) | ||
54 | + } | ||
55 | + // 拥有HRBP权限 | ||
56 | + hrbp := -1 | ||
57 | + for _, v := range userRoleList { | ||
58 | + for _, v2 := range roleList { | ||
59 | + if v.RoleId == v2.Id { | ||
60 | + hrbp = 1 | ||
61 | + break | ||
62 | + } | ||
63 | + } | ||
64 | + if hrbp == 1 { | ||
65 | + break | ||
66 | + } | ||
67 | + } | ||
68 | + | ||
69 | + assessDao := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext}) | ||
70 | + data, err := assessDao.SummaryAssess(in.CompanyId, in.OperatorId, in.CycleId, in.BeginDay, hrbp) | ||
71 | + if err != nil { | ||
72 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error()) | ||
73 | + } | ||
74 | + | ||
75 | + self := adapter.SummaryBlock{Name: "填写反馈自评"} | ||
76 | + invite := adapter.SummaryBlock{Name: "360°邀请"} | ||
77 | + inviteAssess := adapter.SummaryBlock{Name: "360°评估"} | ||
78 | + supper := adapter.SummaryBlock{Name: "上级评估"} | ||
79 | + | ||
80 | + inviteTargetIdMap := map[string]int{} // 过滤相同的目标用户ID | ||
81 | + | ||
82 | + for i := range data { | ||
83 | + d := data[i] | ||
84 | + d.EndTime = d.EndTime.Local() // 输出本地时间 | ||
85 | + | ||
86 | + switch d.Types { | ||
87 | + case domain.AssessSelf: | ||
88 | + self.Total++ | ||
89 | + if d.Status == domain.StaffAssessCompleted { | ||
90 | + self.Completed++ | ||
91 | + } | ||
92 | + if self.EndTime == nil { | ||
93 | + self.EndTime = &d.EndTime | ||
94 | + } | ||
95 | + | ||
96 | + invite.Total++ // 发起360邀请的人数 = 自评人数 | ||
97 | + if invite.EndTime == nil { | ||
98 | + invite.EndTime = &d.EndTime | ||
99 | + } | ||
100 | + break | ||
101 | + case domain.AssessSuper: | ||
102 | + supper.Total++ | ||
103 | + if d.Status == domain.StaffAssessCompleted { | ||
104 | + supper.Completed++ | ||
105 | + } | ||
106 | + if supper.EndTime == nil { | ||
107 | + supper.EndTime = &d.EndTime | ||
108 | + } | ||
109 | + break | ||
110 | + case domain.AssessInviteDiffSuper, domain.AssessInviteSameSuper: | ||
111 | + inviteAssess.Total++ | ||
112 | + if d.Status == domain.StaffAssessCompleted { | ||
113 | + inviteAssess.Completed++ | ||
114 | + } | ||
115 | + if inviteAssess.EndTime == nil { | ||
116 | + inviteAssess.EndTime = &d.EndTime | ||
117 | + } | ||
118 | + | ||
119 | + inviteTargetIdMap[d.TargetUserId] = 0 // 360评估类型都是被人邀请的评估,过滤相同的目标用户后,就是完成邀请的数量 | ||
120 | + break | ||
121 | + } | ||
122 | + } | ||
123 | + invite.Completed = len(inviteTargetIdMap) | ||
124 | + | ||
125 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
126 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
127 | + } | ||
128 | + return map[string]interface{}{"list": []adapter.SummaryBlock{self, invite, inviteAssess, supper}}, nil | ||
129 | +} |
@@ -3,6 +3,7 @@ package dao | @@ -3,6 +3,7 @@ package dao | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | "strconv" | 5 | "strconv" |
6 | + "time" | ||
6 | 7 | ||
7 | "github.com/go-pg/pg/v10" | 8 | "github.com/go-pg/pg/v10" |
8 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 9 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
@@ -378,6 +379,129 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int, | @@ -378,6 +379,129 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int, | ||
378 | return sqlstr | 379 | return sqlstr |
379 | } | 380 | } |
380 | 381 | ||
382 | +type SummaryAssess struct { | ||
383 | + AssessId string `json:"assessId"` | ||
384 | + TargetUserId string `json:"targetUserId"` // 被评估人的id | ||
385 | + TargetUserName string `json:"targetUserName"` // 被评估人的名称 | ||
386 | + BeginDay string `json:"beginDay"` // 评估的开始日期 | ||
387 | + EndTime time.Time `json:"endTime"` // 评估的截止日期 | ||
388 | + EvaluationProjectId string `json:"evaluationProjectId"` // 项目id | ||
389 | + CycleId string `json:"cycleId"` // 周期id | ||
390 | + Types domain.StaffAssessType `json:"types"` // 评估类型 | ||
391 | + Status domain.StaffAssessStatus `json:"status"` // 评估状态 | ||
392 | +} | ||
393 | + | ||
394 | +func (d *StaffAssessDao) SummaryAssess(companyId int, operatorId int, cycleId int, beginDay string, hrbp int) ([]SummaryAssess, error) { | ||
395 | + sqlString := ` | ||
396 | + set time zone 'PRC'; | ||
397 | + with t_user_department as ( | ||
398 | + select "user".id as user_id ,jsonb_array_elements_text ("user".department_id) as depart_id from "user" | ||
399 | + where "user".company_id= %d and "user".deleted_at isnull | ||
400 | + ), | ||
401 | + t_department as ( | ||
402 | + select department.id::text as depart_id from department where charge_user_ids @>'[%d]' | ||
403 | + and "department".deleted_at isnull | ||
404 | + ), | ||
405 | + -- 部门主管(所有下级用户ID) | ||
406 | + t_user_1 as ( | ||
407 | + select t_user_department.user_id::text from t_user_department | ||
408 | + join t_department on t_user_department.depart_id = t_department.depart_id | ||
409 | + ), | ||
410 | + -- 如果是HRBP | ||
411 | + t_project_1 as( | ||
412 | + select evaluation_project.id as project_id | ||
413 | + from evaluation_project | ||
414 | + where evaluation_project.cycle_id =%d | ||
415 | + and evaluation_project.hr_bp = %d | ||
416 | + and evaluation_project.deleted_at isnull | ||
417 | + ), | ||
418 | + -- 如果的项目管理员 | ||
419 | + t_project_2 as( | ||
420 | + select evaluation_project.id as project_id | ||
421 | + from evaluation_project | ||
422 | + where evaluation_project.cycle_id =%d | ||
423 | + and evaluation_project.pmp =1 | ||
424 | + and evaluation_project.pmp_ids @>'["%d"]' | ||
425 | + and evaluation_project.deleted_at isnull | ||
426 | + ), | ||
427 | + -- 合并数据 | ||
428 | + t_project_3 as ( | ||
429 | + select t_project_2.project_id from t_project_2 | ||
430 | + union | ||
431 | + select t_project_1.project_id from t_project_1 | ||
432 | + ), | ||
433 | + -- 初步过滤数据 | ||
434 | + t_staff_assess_0 as ( | ||
435 | + select | ||
436 | + staff_assess.id as assess_id, | ||
437 | + staff_assess.cycle_id, | ||
438 | + staff_assess.target_user->>'userId' as target_user_id, | ||
439 | + staff_assess.target_user->>'userName' as target_user_name, | ||
440 | + to_char(staff_assess.begin_time,'YYYY-MM-DD') as begin_day, | ||
441 | + staff_assess.evaluation_project_id, | ||
442 | + staff_assess.types, | ||
443 | + staff_assess.status, | ||
444 | + staff_assess.end_time | ||
445 | + from staff_assess | ||
446 | + join staff_assess_task on staff_assess.staff_assess_task_id = staff_assess_task.id | ||
447 | + and staff_assess_task.deleted_at isnull | ||
448 | + where staff_assess.cycle_id = %d | ||
449 | + and to_char(staff_assess.begin_time,'YYYY-MM-DD')='%s' | ||
450 | + ), | ||
451 | + -- 根据查看权限过滤合并数据 | ||
452 | + t_staff_assess_1 as ( | ||
453 | + ( select | ||
454 | + t_staff_assess_0.assess_id, | ||
455 | + t_staff_assess_0.target_user_id, | ||
456 | + t_staff_assess_0.target_user_name, | ||
457 | + t_staff_assess_0.begin_day, | ||
458 | + t_staff_assess_0.cycle_id, | ||
459 | + t_staff_assess_0.evaluation_project_id, | ||
460 | + t_staff_assess_0.types, | ||
461 | + t_staff_assess_0.status, | ||
462 | + t_staff_assess_0.end_time | ||
463 | + from t_staff_assess_0 | ||
464 | + join t_project_3 on t_staff_assess_0.evaluation_project_id = t_project_3.project_id | ||
465 | + ) union | ||
466 | + ( select | ||
467 | + t_staff_assess_0.assess_id, | ||
468 | + t_staff_assess_0.target_user_id, | ||
469 | + t_staff_assess_0.target_user_name, | ||
470 | + t_staff_assess_0.begin_day, | ||
471 | + t_staff_assess_0.cycle_id, | ||
472 | + t_staff_assess_0.evaluation_project_id, | ||
473 | + t_staff_assess_0.types, | ||
474 | + t_staff_assess_0.status, | ||
475 | + t_staff_assess_0.end_time | ||
476 | + from t_staff_assess_0 | ||
477 | + join t_user_1 on t_staff_assess_0.target_user_id = t_user_1.user_id | ||
478 | + ) | ||
479 | + ) | ||
480 | + ` | ||
481 | + params := []interface{}{companyId, operatorId, cycleId, hrbp, cycleId, operatorId, cycleId, beginDay} | ||
482 | + | ||
483 | + sqlString = fmt.Sprintf(sqlString, params...) | ||
484 | + | ||
485 | + sqlString = sqlString + ` select | ||
486 | + t_staff_assess_1.target_user_id, | ||
487 | + t_staff_assess_1.target_user_name, | ||
488 | + t_staff_assess_1.begin_day, | ||
489 | + t_staff_assess_1.cycle_id, | ||
490 | + t_staff_assess_1.assess_id, | ||
491 | + t_staff_assess_1.evaluation_project_id, | ||
492 | + t_staff_assess_1.types, | ||
493 | + t_staff_assess_1.status, | ||
494 | + t_staff_assess_1.end_time | ||
495 | + from t_staff_assess_1 | ||
496 | + where 1=1 | ||
497 | + ` | ||
498 | + | ||
499 | + tx := d.transactionContext.PgTx | ||
500 | + var result = make([]SummaryAssess, 0) | ||
501 | + _, err := tx.Query(&result, sqlString) | ||
502 | + return result, err | ||
503 | +} | ||
504 | + | ||
381 | type ExportData1 struct { | 505 | type ExportData1 struct { |
382 | AssessId string | 506 | AssessId string |
383 | ContentId int | 507 | ContentId int |
@@ -359,6 +359,21 @@ func (c *StaffAssessController) SaveAssessCache() { | @@ -359,6 +359,21 @@ func (c *StaffAssessController) SaveAssessCache() { | ||
359 | } | 359 | } |
360 | } | 360 | } |
361 | 361 | ||
362 | +// QuerySummary 项目管理-查询总览 | ||
363 | +func (c *StaffAssessController) QuerySummary() { | ||
364 | + srv := service.NewStaffAssessServeice() | ||
365 | + in := &query.SummaryCommand{} | ||
366 | + if err := c.Unmarshal(in); err != nil { | ||
367 | + c.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | ||
368 | + } else { | ||
369 | + if user := middlewares.GetUser(c.Ctx); user != nil { | ||
370 | + in.CompanyId = int(user.CompanyId) | ||
371 | + in.OperatorId = int(user.UserId) | ||
372 | + } | ||
373 | + c.Response(srv.QuerySummary(in)) | ||
374 | + } | ||
375 | +} | ||
376 | + | ||
362 | // 员工绩效-项目管理-矩阵分析 | 377 | // 员工绩效-项目管理-矩阵分析 |
363 | func (c *StaffAssessController) AnalysisData() { | 378 | func (c *StaffAssessController) AnalysisData() { |
364 | srv := service.NewStaffAssessServeice() | 379 | srv := service.NewStaffAssessServeice() |
@@ -32,6 +32,7 @@ func init() { | @@ -32,6 +32,7 @@ func init() { | ||
32 | web.NSCtrlPost("/info", (*controllers.StaffAssessController).GetAssessInfo), //通用获取员工评估的详情 | 32 | web.NSCtrlPost("/info", (*controllers.StaffAssessController).GetAssessInfo), //通用获取员工评估的详情 |
33 | web.NSCtrlPut("/info", (*controllers.StaffAssessController).SaveAssessInfo), //通用保存员工评估的详情 | 33 | web.NSCtrlPut("/info", (*controllers.StaffAssessController).SaveAssessInfo), //通用保存员工评估的详情 |
34 | web.NSCtrlPut("/info-cache", (*controllers.StaffAssessController).SaveAssessCache), //通用保存员工评估的详情(缓存) | 34 | web.NSCtrlPut("/info-cache", (*controllers.StaffAssessController).SaveAssessCache), //通用保存员工评估的详情(缓存) |
35 | + web.NSCtrlPost("/summary", (*controllers.StaffAssessController).QuerySummary), //项目管理-总览 | ||
35 | // web.NSCtrlPost("/target-user/invite/list", (*controllers.StaffAssessController).ListTargetUserInviteAssess), //获取被评估员工360评估的列表 | 36 | // web.NSCtrlPost("/target-user/invite/list", (*controllers.StaffAssessController).ListTargetUserInviteAssess), //获取被评估员工360评估的列表 |
36 | //web.NSCtrlPost("/me/target-user/supper/list", (*controllers.StaffAssessController).ListTargetUserMeSupperAssess), //获取我被上级评估的列表 | 37 | //web.NSCtrlPost("/me/target-user/supper/list", (*controllers.StaffAssessController).ListTargetUserMeSupperAssess), //获取我被上级评估的列表 |
37 | // web.NSCtrlPost("/target-user/self/info", (*controllers.StaffAssessController).GetAssessTargetUserSelfInfo), //获取被评估员工的自评反馈详情 | 38 | // web.NSCtrlPost("/target-user/self/info", (*controllers.StaffAssessController).GetAssessTargetUserSelfInfo), //获取被评估员工的自评反馈详情 |
-
请 注册 或 登录 后发表评论