staff_assess_dao.go
9.6 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
package dao
import (
"strconv"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type StaffAssessDao struct {
transactionContext *pgTransaction.TransactionContext
}
func NewStaffAssessDao(options map[string]interface{}) *StaffAssessDao {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return &StaffAssessDao{
transactionContext: transactionContext,
}
}
type CountData struct {
TargetUserId int
InviteTotal int
InviteCompleted int
}
// 获取员工邀请的人完成360评估的数量
func (d *StaffAssessDao) CountInviteAssessByTargetUser(userIds []int, assessTaskId int) ([]CountData, error) {
sqlStr := `SELECT staff_assess.target_user->>'userId' as target_user_id,
count(staff_assess."id") AS invite_total,
sum(
case WHEN staff_assess.status='completed' THEN 1
ELSE 0 END
) as invite_completed
FROM staff_assess
WHERE staff_assess.target_user->>'userId' IN(?)
AND staff_assess.types IN ('invite_same_super','invite_diff_super')
AND staff_assess.staff_assess_task_id = ?
GROUP BY target_user_id`
userIdList := []string{}
for _, v := range userIds {
uid := strconv.Itoa(v)
userIdList = append(userIdList, uid)
}
condition := []interface{}{
pg.In(userIdList), assessTaskId,
}
tx := d.transactionContext.PgTx
result := []CountData{}
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
// 根据评估的人执行人id,搜索 executorId参与的评估任务
func (d *StaffAssessDao) SearchAssessTaskMe(executorId int, companyId int, limit int, offset int) ([]*domain.StaffAssessTask, error) {
if limit < 0 {
limit = 20
}
if offset < 0 {
offset = 0
}
sqlStr := `SELECT DISTINCT staff_assess_task.* FROM staff_assess_task
JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id"
WHERE staff_assess.company_id=?
and staff_assess_task.deleted_at isnull
and staff_assess.executor->>'userId'='?'
order by staff_assess_task.id desc
limit ? offset ?
`
tx := d.transactionContext.PgTx
condition := []interface{}{
companyId, executorId, limit, offset,
}
result := []*domain.StaffAssessTask{}
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
// 搜索 executorId 参与的评估任务
func (d *StaffAssessDao) CountAssessTaskMe(executorId int, companyId int) (int, error) {
sqlStr := `SELECT count( DISTINCT staff_assess_task."id") FROM staff_assess_task
JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id"
WHERE staff_assess.company_id=?
and staff_assess_task.deleted_at isnull
and staff_assess.executor->>'userId'='?'
`
tx := d.transactionContext.PgTx
condition := []interface{}{
companyId, executorId,
}
result := 0
_, err := tx.QueryOne(pg.Scan(&result), sqlStr, condition...)
return result, err
}
//获取所以已经执行的评估周期
type AssessCycle struct {
CycleId string `json:"cycleId"` //周期id
CompanyId string `json:"companyId"`
CycleName string `json:"cycleName"` //周期名称
}
//获取所以已经执行的评估周期
func (d *StaffAssessDao) AllAssessCycleList(companyId int) ([]AssessCycle, error) {
sqlStr := `select
distinct
staff_assess_task.cycle_id ,
staff_assess_task.company_id ,
staff_assess_task.cycle_name
from staff_assess_task
where staff_assess_task.company_id = ?`
tx := d.transactionContext.PgTx
condition := []interface{}{
companyId,
}
result := []AssessCycle{}
_, err := tx.QueryOne(&result, sqlStr, condition...)
return result, err
}
//获取评估周期中的绩效考核日期
type AssessCycleDay struct {
BeginDay string `json:"beginDay"`
CycleId string `json:"cycleId"`
CompanyId string `json:"companyId"`
}
//获取评估周期中的绩效考核日期
func (d *StaffAssessDao) AllAssessCycleDayList(companyId int, cycleId int) ([]AssessCycleDay, error) {
sqlStr := `select distinct staff_assess_task.begin_day ,
staff_assess_task.cycle_id ,
staff_assess_task.company_id
from staff_assess_task
where staff_assess_task.cycle_id = ?
and company_id =? `
tx := d.transactionContext.PgTx
condition := []interface{}{
cycleId, companyId,
}
result := []AssessCycleDay{}
_, err := tx.QueryOne(&result, sqlStr, condition...)
return result, err
}
//根据周期的id和日期获取员工填写的评估内容
/**
with assess_list as(
select
staff_assess.id as staff_assess_id,
staff_assess.target_user ->>'userId' as target_user_id,
staff_assess.target_user ->>'userName' as target_user_name,
staff_assess.evaluation_project_id,
to_char( staff_assess.begin_time,'YYYY-MM-DD') as begin_day
from staff_assess
where staff_assess.cycle_id = 1594521861704650752
and to_char( staff_assess.begin_time,'YYYY-MM-DD') ='2022-11-22'
and staff_assess."types" ='self'
limit 5 offset 0
)
select
assess_list.target_user_id,
assess_list.target_user_name,
assess_list.begin_day,
assess_list.evaluation_project_id,
staff_assess_content.value ,
staff_assess_content.sort_by ,
staff_assess_content.category ,
staff_assess_content."name" ,
staff_assess_content.weight
from staff_assess_content
right join assess_list on assess_list.staff_assess_id = staff_assess_content.staff_assess_id
**/
//获取员工填写评估内容
type UserAssessContent struct {
TargetUserId string //被评估人的id
TargetUserName string //被评估人的名称
BeginDay string //评估的日期
EvaluationProjectId string //项目id
Value string //评估填写的值
SortBy int //评估项顺序
Category string //分类
Name string //名称
Weight int //权重
}
type SearchConditin1 struct {
CycleId int //周期id
BeginDay string //评估的日期
UserName string //被评估人的名称
Limit int //分页
Offset int //分页
DepartmentId []int //
OperaterId int //用户的id是谁在搜索数据
IsHrBp bool //
}
//根据周期的id和日期获取员工填写的评估内容
//cycleId 周期id
//beginDay 评估任务的生成日期
//userName 被评估的员工名称,
// limit offset 分页搜索
func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserAssessContent, error) {
sqlStr := `with assess_list as(
select
staff_assess.id as staff_assess_id,
staff_assess.target_user ->>'userId' as target_user_id,
staff_assess.target_user ->>'userName' as target_user_name,
staff_assess.evaluation_project_id,
to_char( staff_assess.begin_time,'YYYY-MM-DD') as begin_day
from staff_assess
where staff_assess.cycle_id = ?
and to_char( staff_assess.begin_time,'YYYY-MM-DD') ='?'
and staff_assess."types" ='self'
and staff_assess.target_user ->>'userName' like '?'
limit ? offset ?
)
select
assess_list.target_user_id,
assess_list.target_user_name,
assess_list.begin_day,
assess_list.evaluation_project_id,
staff_assess_content.value ,
staff_assess_content.sort_by ,
staff_assess_content.category ,
staff_assess_content."name" ,
staff_assess_content.weight
from staff_assess_content
right join assess_list on assess_list.staff_assess_id = staff_assess_content.staff_assess_id
order by convert_to(assess_list.target_user_name,'GBK') `
tx := d.transactionContext.PgTx
condition := []interface{}{
param.CycleId, param.BeginDay, "%" + param.UserName + "%", param.Limit, param.Offset,
}
var result []UserAssessContent
_, err := tx.QueryOne(&result, sqlStr, condition...)
return result, err
}
// 根据用户的查看权限 合并用户
// with t_user_department as (
// select "user".id as user_id ,jsonb_array_elements_text ("user".department_id) as depart_id from "user"
// where "user".company_id= 526
// ),
// t_department as (
// select department.id::text as depart_id from department where charge_user_ids @>'[3330208201102336]'
// ),
// -- 如果是部门管理员 获取用户列表
// t_user_1 as (
// select t_user_department.user_id from t_user_department
// join t_department on t_user_department.depart_id = t_department.depart_id
// ),
// -- 如果是hrbp
// t_user_2 as(
// select jsonb_array_elements_text (evaluation_project.recipients) as user_id
// from evaluation_project
// where evaluation_project.cycle_id =1592787960795762688
// and evaluation_project.hr_bp = 1
// ),
// -- 如果是项目管理员
// t_user_3 as(
// select jsonb_array_elements_text (evaluation_project.recipients) as user_id
// from evaluation_project
// where evaluation_project.cycle_id =1592787960795762688
// and evaluation_project.pmp =1
// and evaluation_project.pmp_ids @>'[3330208201102336]'
// ),
// -- 合并用户
// t_user_all as(
// select t_user_1.user_id::text from t_user_1
// union
// select t_user_2.user_id::text from t_user_2
// union
// select t_user_3.user_id::text from t_user_3
// ),
// -- 根据用户提取评估列表
// t_staff_assess as(
// select staff_assess.id as assess_id,
// staff_assess.target_user->>'userId' as user_id,
// staff_assess.target_user->>'userName' as user_name
// from staff_assess
// join t_user_all on staff_assess.target_user->>'userId'= t_user_all.user_id
// where staff_assess.cycle_id = 1592787960795762688
// and to_char(staff_assess.begin_time,'YYYY-MM-DD')='2022-11-24'
// and staff_assess."types" ='self'
// limit 1 offset 0
// )