1
|
package dao
|
1
|
package dao
|
2
|
|
2
|
|
3
|
-// SearchStaffAssessByCycle 按照周期id获取评估任务,并进行人员可查看权限的过滤
|
3
|
+import (
|
|
|
4
|
+ "fmt"
|
|
|
5
|
+
|
|
|
6
|
+ "github.com/go-pg/pg/v10"
|
|
|
7
|
+ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
|
|
8
|
+)
|
|
|
9
|
+
|
|
|
10
|
+type DataStaffAssessContent2 struct {
|
|
|
11
|
+ CycleId string `pg:"cycle_id"` //周期id
|
|
|
12
|
+ CycleName string `pg:"cycle_name"` //周期名称
|
|
|
13
|
+ EvaluationProjectId string `pg:"evaluation_project_id"` //
|
|
|
14
|
+ TargetUserId string `pg:"target_user_id"` //被评估人的id
|
|
|
15
|
+ TargetUserName string `pg:"target_user_name"` //被评估人的名称
|
|
|
16
|
+ BeginDay string `pg:"begin_day"` //评估的日期
|
|
|
17
|
+ Value string `pg:"value"` //评估填写的值
|
|
|
18
|
+ Category string `pg:"category"` //评估项分类
|
|
|
19
|
+ ContentName string `pg:"content_name"` //评估项名称
|
|
|
20
|
+ Weight float64 `pg:"weight"` //权重
|
|
|
21
|
+ PromptText string `pg:"prompt_text"` //评估标准
|
|
|
22
|
+ Remark []domain.AssessContemtRemark `pg:"remark"`
|
|
|
23
|
+}
|
|
|
24
|
+
|
|
|
25
|
+// SearchStaffAssessContent2 用于员工绩效-综合管理-导出绩效-个人
|
|
|
26
|
+// 获取所有评估的填写内容
|
4
|
// companyId 公司id
|
27
|
// companyId 公司id
|
5
|
// cycleId 周期id
|
28
|
// cycleId 周期id
|
6
|
// operaterId 操作人、查看人的id
|
29
|
// operaterId 操作人、查看人的id
|
7
|
// hrbp 操作人、查看人是否hrbp 1:是;-1:否
|
30
|
// hrbp 操作人、查看人是否hrbp 1:是;-1:否
|
8
|
-func (d *StaffAssessDao) SearchStaffAssessByCycle(companyId int, cycleId int, operaterId int, hrbp int, exportUserIds []string) {
|
31
|
+func (d *StaffAssessDao) SearchStaffAssessContent2(companyId int, cycleId int, operaterId int, hrbp int, exportUserIds []string) (
|
|
|
32
|
+ []DataStaffAssessContent2, error) {
|
|
|
33
|
+ withSql := d.catchProjectIdByPermission(companyId, cycleId, operaterId, hrbp)
|
|
|
34
|
+ sqlStr := ` select
|
|
|
35
|
+ staff_assess.target_user ->>'userId' as target_user_id,
|
|
|
36
|
+ staff_assess.evaluation_project_id,
|
|
|
37
|
+ staff_assess.target_user ->>'userName' as target_user_name,
|
|
|
38
|
+ to_char(staff_assess.begin_time,'YYYY-MM-DD') as begin_day,
|
|
|
39
|
+ staff_assess.cycle_id,
|
|
|
40
|
+ staff_assess.cycle_name,
|
|
|
41
|
+ staff_assess_content.value ,
|
|
|
42
|
+ staff_assess_content.category ,
|
|
|
43
|
+ staff_assess_content."name" as content_name ,
|
|
|
44
|
+ staff_assess_content.weight,
|
|
|
45
|
+ staff_assess_content.prompt_text ,
|
|
|
46
|
+ staff_assess_content.remark
|
|
|
47
|
+from staff_assess
|
|
|
48
|
+join staff_assess_content on staff_assess.id = staff_assess_content.staff_assess_id
|
|
|
49
|
+where 1=1
|
|
|
50
|
+and staff_assess.cycle_id =? and "types" ='self'
|
|
|
51
|
+and staff_assess.evaluation_project_id in (
|
|
|
52
|
+ select t_project_4.project_id from t_project_4
|
|
|
53
|
+) `
|
|
|
54
|
+
|
|
|
55
|
+ condition := []interface{}{cycleId}
|
|
|
56
|
+ if len(exportUserIds) > 0 {
|
|
|
57
|
+ sqlStr += ` and staff_assess.target_user->>'userId' in(?) `
|
|
|
58
|
+ condition = append(condition, pg.In(exportUserIds))
|
|
|
59
|
+ }
|
|
|
60
|
+
|
|
|
61
|
+ sqlStr = withSql + sqlStr
|
|
|
62
|
+ result := []DataStaffAssessContent2{}
|
|
|
63
|
+ tx := d.transactionContext.PgTx
|
|
|
64
|
+ _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
65
|
+ return result, err
|
|
|
66
|
+}
|
9
|
|
67
|
|
|
|
68
|
+type DataEvaluationItemUsed2 struct {
|
|
|
69
|
+ CycleId string `pg:"cycle_id"` //周期id
|
|
|
70
|
+ CycleName string `pg:"cycle_name"` //周期名称
|
|
|
71
|
+ EvaluationProjectId string `pg:"evaluation_project_id"` //评估的项目
|
|
|
72
|
+ TargetUserId string `pg:"target_user_id"` //被评估人的id
|
|
|
73
|
+ TargetUserName string `pg:"target_user_name"` //被评估人的名称
|
|
|
74
|
+ BeginDay string `pg:"begin_day"` //评估的日期
|
|
|
75
|
+ Category string `pg:"category"` //评估项分类
|
|
|
76
|
+ ContentName string `pg:"content_name"` //评估项名称
|
|
|
77
|
+ Weight float64 `pg:"weight"` //权重
|
|
|
78
|
+ PromptText string `pg:"prompt_text"` //评估标准
|
|
|
79
|
+}
|
|
|
80
|
+
|
|
|
81
|
+// SearchEvaluationItemUsed2 用于员工绩效-综合管理-导出绩效-个人
|
|
|
82
|
+// 获取所有评估的填写项
|
|
|
83
|
+// companyId 公司id
|
|
|
84
|
+// cycleId 周期id
|
|
|
85
|
+// operaterId 操作人、查看人的id
|
|
|
86
|
+// hrbp 操作人、查看人是否hrbp 1:是;-1:否
|
|
|
87
|
+func (d *StaffAssessDao) SearchEvaluationItemUsed2(companyId int, cycleId int, operaterId int, hrbp int, exportUserIds []string) (
|
|
|
88
|
+ []DataEvaluationItemUsed2, error) {
|
|
|
89
|
+ withSql := d.catchProjectIdByPermission(companyId, cycleId, operaterId, hrbp)
|
|
|
90
|
+ sqlStr := `select
|
|
|
91
|
+ staff_assess.target_user ->>'userId' as target_user_id,
|
|
|
92
|
+ staff_assess.evaluation_project_id ,
|
|
|
93
|
+ staff_assess.target_user ->>'userName' as target_user_name,
|
|
|
94
|
+ to_char(staff_assess.begin_time,'YYYY-MM-DD') as begin_day,
|
|
|
95
|
+ staff_assess.cycle_id,
|
|
|
96
|
+ staff_assess.cycle_name,
|
|
|
97
|
+ evaluation_item_used.category ,
|
|
|
98
|
+ evaluation_item_used."name" as content_name ,
|
|
|
99
|
+ evaluation_item_used.weight,
|
|
|
100
|
+ evaluation_item_used.prompt_text
|
|
|
101
|
+from staff_assess
|
|
|
102
|
+join evaluation_item_used on evaluation_item_used.evaluation_project_id = staff_assess.evaluation_project_id
|
|
|
103
|
+where 1=1
|
|
|
104
|
+and staff_assess.cycle_id =? and "types" ='self'
|
|
|
105
|
+and staff_assess.evaluation_project_id in (
|
|
|
106
|
+ select evaluation_project.id from evaluation_project limit 10
|
|
|
107
|
+) `
|
|
|
108
|
+ condition := []interface{}{cycleId}
|
|
|
109
|
+ if len(exportUserIds) > 0 {
|
|
|
110
|
+ sqlStr += ` and staff_assess.target_user->>'userId' in(?) `
|
|
|
111
|
+ condition = append(condition, pg.In(exportUserIds))
|
|
|
112
|
+ }
|
|
|
113
|
+ sqlStr = withSql + sqlStr
|
|
|
114
|
+ result := []DataEvaluationItemUsed2{}
|
|
|
115
|
+ tx := d.transactionContext.PgTx
|
|
|
116
|
+ _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
117
|
+ return result, err
|
10
|
}
|
118
|
}
|
11
|
|
119
|
|
12
|
// sql 语句片段
|
120
|
// sql 语句片段
|
13
|
// 按照人员可查看权限的过滤
|
121
|
// 按照人员可查看权限的过滤
|
14
|
-func (d *StaffAssessDao) catchProjectByPermission(companyId int, cycleId int, operaterId int, hrbp int) string {
|
|
|
15
|
- return ""
|
122
|
+// companyId int 公司id (必填)
|
|
|
123
|
+// cycleId int, 评估周期id (必填)
|
|
|
124
|
+// userId int, 用户id,谁要查看数据 (必填)
|
|
|
125
|
+// hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否 (必填)
|
|
|
126
|
+func (d *StaffAssessDao) catchProjectIdByPermission(companyId int, cycleId int, operaterId int, hrbp int) string {
|
|
|
127
|
+ withSql := `
|
|
|
128
|
+ with
|
|
|
129
|
+ t_project_0 as(
|
|
|
130
|
+ select evaluation_project.id as project_id,
|
|
|
131
|
+ jsonb_array_elements_text(evaluation_project.recipients) as target_user_id,
|
|
|
132
|
+ evaluation_project.pmp,
|
|
|
133
|
+ evaluation_project.pmp_ids,
|
|
|
134
|
+ evaluation_project.hr_bp
|
|
|
135
|
+ from evaluation_project
|
|
|
136
|
+ where evaluation_project.cycle_id =%d
|
|
|
137
|
+ and evaluation_project.deleted_at isnull
|
|
|
138
|
+ ),
|
|
|
139
|
+ -- 查我的下级员工
|
|
|
140
|
+ t_user_1 as (
|
|
|
141
|
+ select "user".id::text as user_id from "user"
|
|
|
142
|
+ where "user".parent_id =%d and company_id=%d
|
|
|
143
|
+ ),
|
|
|
144
|
+ -- 如果是HRBP
|
|
|
145
|
+ t_project_1 as(
|
|
|
146
|
+ select t_project_0.project_id,t_project_0.target_user_id
|
|
|
147
|
+ from t_project_0
|
|
|
148
|
+ where t_project_0.hr_bp =%d
|
|
|
149
|
+ ),
|
|
|
150
|
+ -- 如果的项目管理员
|
|
|
151
|
+ t_project_2 as(
|
|
|
152
|
+ select t_project_0.project_id,t_project_0.target_user_id
|
|
|
153
|
+ from t_project_0
|
|
|
154
|
+ where t_project_0.pmp =1
|
|
|
155
|
+ and t_project_0.pmp_ids @>'["%d"]'
|
|
|
156
|
+ ),
|
|
|
157
|
+ -- 如果是上级员工
|
|
|
158
|
+ t_project_3 as (
|
|
|
159
|
+ select t_project_0.project_id,t_project_0.target_user_id
|
|
|
160
|
+ from t_project_0
|
|
|
161
|
+ join t_user_1 on t_user_1.user_id = t_project_0.target_user_id
|
|
|
162
|
+ ),
|
|
|
163
|
+ -- 合并数据
|
|
|
164
|
+ t_project_4 as (
|
|
|
165
|
+ select t_project_2.project_id,t_project_2.target_user_id from t_project_2
|
|
|
166
|
+ union
|
|
|
167
|
+ select t_project_1.project_id,t_project_1.target_user_id from t_project_1
|
|
|
168
|
+ union
|
|
|
169
|
+ select t_project_3.project_id,t_project_3.target_user_id from t_project_3
|
|
|
170
|
+ )`
|
|
|
171
|
+ params := []interface{}{cycleId, operaterId, companyId, hrbp, operaterId}
|
|
|
172
|
+
|
|
|
173
|
+ return fmt.Sprintf(withSql, params...)
|
16
|
} |
174
|
} |