1
|
-package dao
|
|
|
2
|
-
|
|
|
3
|
-import (
|
|
|
4
|
- "fmt"
|
|
|
5
|
- "strconv"
|
|
|
6
|
-
|
|
|
7
|
- "github.com/go-pg/pg/v10"
|
|
|
8
|
- pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
|
|
9
|
- "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
|
|
10
|
-)
|
|
|
11
|
-
|
|
|
12
|
-type StaffAssessDao struct {
|
|
|
13
|
- transactionContext *pgTransaction.TransactionContext
|
|
|
14
|
-}
|
|
|
15
|
-
|
|
|
16
|
-func NewStaffAssessDao(options map[string]interface{}) *StaffAssessDao {
|
|
|
17
|
- var transactionContext *pgTransaction.TransactionContext
|
|
|
18
|
- if value, ok := options["transactionContext"]; ok {
|
|
|
19
|
- transactionContext = value.(*pgTransaction.TransactionContext)
|
|
|
20
|
- }
|
|
|
21
|
- return &StaffAssessDao{
|
|
|
22
|
- transactionContext: transactionContext,
|
|
|
23
|
- }
|
|
|
24
|
-}
|
|
|
25
|
-
|
|
|
26
|
-type CountData struct {
|
|
|
27
|
- TargetUserId int
|
|
|
28
|
- InviteTotal int
|
|
|
29
|
- InviteCompleted int
|
|
|
30
|
-}
|
|
|
31
|
-
|
|
|
32
|
-// 获取员工邀请的人完成360评估的数量
|
|
|
33
|
-func (d *StaffAssessDao) CountInviteAssessByTargetUser(userIds []int, assessTaskId int) ([]CountData, error) {
|
|
|
34
|
- sqlStr := `SELECT staff_assess.target_user->>'userId' as target_user_id,
|
|
|
35
|
- count(staff_assess."id") AS invite_total,
|
|
|
36
|
- sum(
|
|
|
37
|
- case WHEN staff_assess.status='completed' THEN 1
|
|
|
38
|
- ELSE 0 END
|
|
|
39
|
- ) as invite_completed
|
|
|
40
|
- FROM staff_assess
|
|
|
41
|
- WHERE staff_assess.target_user->>'userId' IN(?)
|
|
|
42
|
- AND staff_assess.types IN ('invite_same_super','invite_diff_super')
|
|
|
43
|
- AND staff_assess.staff_assess_task_id = ?
|
|
|
44
|
- GROUP BY target_user_id`
|
|
|
45
|
-
|
|
|
46
|
- userIdList := []string{}
|
|
|
47
|
- for _, v := range userIds {
|
|
|
48
|
- uid := strconv.Itoa(v)
|
|
|
49
|
- userIdList = append(userIdList, uid)
|
|
|
50
|
- }
|
|
|
51
|
- condition := []interface{}{
|
|
|
52
|
- pg.In(userIdList), assessTaskId,
|
|
|
53
|
- }
|
|
|
54
|
- tx := d.transactionContext.PgTx
|
|
|
55
|
- result := []CountData{}
|
|
|
56
|
- _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
57
|
- return result, err
|
|
|
58
|
-}
|
|
|
59
|
-
|
|
|
60
|
-func (d *StaffAssessDao) CountTargetUserInviteAssess1(userIds []int, cycleId int, beginDay string) ([]CountData, error) {
|
|
|
61
|
- sqlStr := `SELECT
|
|
|
62
|
- staff_assess.target_user->>'userId' as target_user_id,
|
|
|
63
|
- count(staff_assess."id") AS invite_total,
|
|
|
64
|
- sum(
|
|
|
65
|
- case WHEN staff_assess.status='completed' THEN 1
|
|
|
66
|
- ELSE 0 END
|
|
|
67
|
- ) as invite_completed
|
|
|
68
|
- FROM staff_assess
|
|
|
69
|
- WHERE staff_assess.target_user->>'userId' IN(?)
|
|
|
70
|
- AND staff_assess.types IN ('invite_same_super','invite_diff_super')
|
|
|
71
|
- and to_char(staff_assess.begin_time at time zone 'PRC','YYYY-MM-DD') = ?
|
|
|
72
|
- and staff_assess.cycle_id =?
|
|
|
73
|
- GROUP BY target_user_id`
|
|
|
74
|
- userIdStr := []string{}
|
|
|
75
|
- for _, v := range userIds {
|
|
|
76
|
- str := strconv.Itoa(v)
|
|
|
77
|
- userIdStr = append(userIdStr, str)
|
|
|
78
|
- }
|
|
|
79
|
- condition := []interface{}{
|
|
|
80
|
- pg.In(userIdStr), beginDay, cycleId,
|
|
|
81
|
- }
|
|
|
82
|
- tx := d.transactionContext.PgTx
|
|
|
83
|
- result := []CountData{}
|
|
|
84
|
- _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
85
|
- return result, err
|
|
|
86
|
-}
|
|
|
87
|
-
|
|
|
88
|
-// 根据评估的人执行人id,搜索 executorId参与的评估任务
|
|
|
89
|
-func (d *StaffAssessDao) SearchAssessTaskMe(executorId int, companyId int, limit int, offset int) ([]*domain.StaffAssessTask, error) {
|
|
|
90
|
-
|
|
|
91
|
- if limit < 0 {
|
|
|
92
|
- limit = 20
|
|
|
93
|
- }
|
|
|
94
|
- if offset < 0 {
|
|
|
95
|
- offset = 0
|
|
|
96
|
- }
|
|
|
97
|
-
|
|
|
98
|
- sqlStr := `SELECT DISTINCT staff_assess_task.* FROM staff_assess_task
|
|
|
99
|
- JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id"
|
|
|
100
|
- WHERE staff_assess.company_id=?
|
|
|
101
|
- and staff_assess_task.deleted_at isnull
|
|
|
102
|
- and staff_assess.executor->>'userId'='?'
|
|
|
103
|
- order by staff_assess_task.id desc
|
|
|
104
|
- limit ? offset ?
|
|
|
105
|
- `
|
|
|
106
|
- tx := d.transactionContext.PgTx
|
|
|
107
|
- condition := []interface{}{
|
|
|
108
|
- companyId, executorId, limit, offset,
|
|
|
109
|
- }
|
|
|
110
|
- result := []*domain.StaffAssessTask{}
|
|
|
111
|
- _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
112
|
- return result, err
|
|
|
113
|
-
|
|
|
114
|
-}
|
|
|
115
|
-
|
|
|
116
|
-// 搜索 executorId 参与的评估任务
|
|
|
117
|
-func (d *StaffAssessDao) CountAssessTaskMe(executorId int, companyId int) (int, error) {
|
|
|
118
|
- sqlStr := `SELECT count( DISTINCT staff_assess_task."id") FROM staff_assess_task
|
|
|
119
|
- JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id"
|
|
|
120
|
- WHERE staff_assess.company_id=?
|
|
|
121
|
- and staff_assess_task.deleted_at isnull
|
|
|
122
|
- and staff_assess.executor->>'userId'='?'
|
|
|
123
|
- `
|
|
|
124
|
- tx := d.transactionContext.PgTx
|
|
|
125
|
- condition := []interface{}{
|
|
|
126
|
- companyId, executorId,
|
|
|
127
|
- }
|
|
|
128
|
- result := 0
|
|
|
129
|
- _, err := tx.QueryOne(pg.Scan(&result), sqlStr, condition...)
|
|
|
130
|
- return result, err
|
|
|
131
|
-}
|
|
|
132
|
-
|
|
|
133
|
-// 获取所以已经执行的评估周期
|
|
|
134
|
-type AssessCycle struct {
|
|
|
135
|
- CycleId string `json:"cycleId"` //周期id
|
|
|
136
|
- CompanyId string `json:"companyId"`
|
|
|
137
|
- CycleName string `json:"cycleName"` //周期名称
|
|
|
138
|
-}
|
|
|
139
|
-
|
|
|
140
|
-// 获取所以已经执行的评估周期
|
|
|
141
|
-func (d *StaffAssessDao) AllAssessCycleList(companyId int) ([]AssessCycle, error) {
|
|
|
142
|
- sqlStr := `select
|
|
|
143
|
- distinct
|
|
|
144
|
- staff_assess_task.cycle_id ,
|
|
|
145
|
- staff_assess_task.company_id ,
|
|
|
146
|
- staff_assess_task.cycle_name
|
|
|
147
|
- from staff_assess_task
|
|
|
148
|
- where staff_assess_task.company_id = ?
|
|
|
149
|
- and staff_assess_task.deleted_at isnull
|
|
|
150
|
- order by staff_assess_task.cycle_id desc
|
|
|
151
|
- `
|
|
|
152
|
-
|
|
|
153
|
- tx := d.transactionContext.PgTx
|
|
|
154
|
- condition := []interface{}{
|
|
|
155
|
- companyId,
|
|
|
156
|
- }
|
|
|
157
|
- result := []AssessCycle{}
|
|
|
158
|
- _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
159
|
- return result, err
|
|
|
160
|
-}
|
|
|
161
|
-
|
|
|
162
|
-// 获取评估周期中的绩效考核日期
|
|
|
163
|
-type AssessCycleDay struct {
|
|
|
164
|
- BeginDay string `json:"beginDay"`
|
|
|
165
|
- CycleId int `json:"cycleId"`
|
|
|
166
|
- CycleName string `json:"cycleName"`
|
|
|
167
|
- CompanyId string `json:"companyId"`
|
|
|
168
|
-}
|
|
|
169
|
-
|
|
|
170
|
-// 获取评估周期中的绩效考核日期
|
|
|
171
|
-func (d *StaffAssessDao) AllAssessCycleDayList(companyId int, cycleId int) ([]AssessCycleDay, error) {
|
|
|
172
|
- sqlStr := `select distinct staff_assess_task.begin_day ,
|
|
|
173
|
- staff_assess_task.cycle_id ,
|
|
|
174
|
- staff_assess_task.cycle_name,
|
|
|
175
|
- staff_assess_task.company_id
|
|
|
176
|
- from staff_assess_task
|
|
|
177
|
- where staff_assess_task.cycle_id = ?
|
|
|
178
|
- and company_id =?
|
|
|
179
|
- and staff_assess_task.deleted_at isnull
|
|
|
180
|
- order by staff_assess_task.begin_day desc `
|
|
|
181
|
-
|
|
|
182
|
- tx := d.transactionContext.PgTx
|
|
|
183
|
- condition := []interface{}{
|
|
|
184
|
- cycleId, companyId,
|
|
|
185
|
- }
|
|
|
186
|
- result := []AssessCycleDay{}
|
|
|
187
|
- _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
188
|
- return result, err
|
|
|
189
|
-}
|
|
|
190
|
-
|
|
|
191
|
-// 获取员工填写评估内容
|
|
|
192
|
-type UserAssessContent struct {
|
|
|
193
|
- AssessId string `json:"assessId"`
|
|
|
194
|
- ContentId int `json:"contentId"`
|
|
|
195
|
- TargetUserId string `json:"targetUserId"` //被评估人的id
|
|
|
196
|
- TargetUserName string `json:"targetUserName"` //被评估人的名称
|
|
|
197
|
- BeginDay string `json:"beginDay"` //评估的日期
|
|
|
198
|
- EvaluationProjectId string `json:"evaluationProjectId"` //项目id
|
|
|
199
|
- Value string `json:"value"` //评估填写的值
|
|
|
200
|
- LevelValue string `json:"levelValue"` //评级的值
|
|
|
201
|
- Rule domain.EvaluationRule `json:"rule"` //规则
|
|
|
202
|
- SortBy int `json:"sortBy"` //评估项顺序
|
|
|
203
|
- Category string `json:"category"` //评估项分类
|
|
|
204
|
- ContentName string `json:"contentName"` //评估项名称
|
|
|
205
|
- Weight float64 `json:"weight"` //权重
|
|
|
206
|
- CycleId string `json:"cycleId"` //周期id
|
|
|
207
|
-}
|
|
|
208
|
-
|
|
|
209
|
-type SearchConditin1 struct {
|
|
|
210
|
- CompanyId int //公司id
|
|
|
211
|
- AssessId int //评估任务id
|
|
|
212
|
- CycleId int //周期id
|
|
|
213
|
- BeginDay string //评估的日期
|
|
|
214
|
- TargetUserName string //被评估人的名称
|
|
|
215
|
- TargetUserId []string //查询指定的人
|
|
|
216
|
- Limit int //分页
|
|
|
217
|
- Offset int //分页
|
|
|
218
|
- OperaterId int //用户的id是谁在搜索数据
|
|
|
219
|
- Hrbp int //
|
|
|
220
|
-}
|
|
|
221
|
-
|
|
|
222
|
-// 项目管理-成员列表 根据周期的id和日期获取员工填写的评估内容
|
|
|
223
|
-// companyId int 公司id
|
|
|
224
|
-// cycleId int, 评估周期id
|
|
|
225
|
-// userId int, 用户id,谁要查看数据
|
|
|
226
|
-// beginDay string, 周期中执行项目的时间
|
|
|
227
|
-// hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
|
|
|
228
|
-// limit int, 分页条数
|
|
|
229
|
-// offset int 分页偏移
|
|
|
230
|
-func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserAssessContent, error) {
|
|
|
231
|
- if param.Offset < 0 {
|
|
|
232
|
- param.Offset = 0
|
|
|
233
|
- }
|
|
|
234
|
- if param.Limit < 0 {
|
|
|
235
|
- param.Limit = 20
|
|
|
236
|
- }
|
|
|
237
|
- sqlStr := ` select
|
|
|
238
|
- t_staff_assess_1.target_user_id,t_staff_assess_1.target_user_name,t_staff_assess_1.begin_day,
|
|
|
239
|
- t_staff_assess_1.assess_id,staff_assess_content.id as content_id,
|
|
|
240
|
- staff_assess_content.value ,staff_assess_content.sort_by ,t_staff_assess_1.cycle_id,
|
|
|
241
|
- staff_assess_content.category ,staff_assess_content."name" as content_name ,
|
|
|
242
|
- staff_assess_content.weight,staff_assess_content.level_value,staff_assess_content."rule"
|
|
|
243
|
- from t_staff_assess_1
|
|
|
244
|
- left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
|
|
|
245
|
- where 1=1
|
|
|
246
|
- `
|
|
|
247
|
- condition := []interface{}{}
|
|
|
248
|
- if len(param.TargetUserName) > 0 {
|
|
|
249
|
- sqlStr += ` and t_staff_assess_1.target_user_name like ? `
|
|
|
250
|
- condition = append(condition, "%"+param.TargetUserName+"%")
|
|
|
251
|
- }
|
|
|
252
|
- //加入排序
|
|
|
253
|
- sqlStr += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'),staff_assess_content.sort_by `
|
|
|
254
|
- //获取前置sql语句
|
|
|
255
|
- sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, param.Limit, param.Offset, string(domain.AssessSelf))
|
|
|
256
|
- sqlStr = sqlStr0 + sqlStr
|
|
|
257
|
- tx := d.transactionContext.PgTx
|
|
|
258
|
- result := []UserAssessContent{}
|
|
|
259
|
- _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
260
|
- return result, err
|
|
|
261
|
-}
|
|
|
262
|
-
|
|
|
263
|
-// 项目管理-成员列表 根据周期的id和日期获取员工填写的评估内容,数量统计
|
|
|
264
|
-// companyId int 公司id
|
|
|
265
|
-// cycleId int, 评估周期id
|
|
|
266
|
-// userId int, 用户id,谁要查看数据
|
|
|
267
|
-// beginDay string, 周期中执行项目的时间
|
|
|
268
|
-// hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
|
|
|
269
|
-// limit int, 分页条数
|
|
|
270
|
-// offset int 分页偏移
|
|
|
271
|
-func (d *StaffAssessDao) CountUserAssess(param SearchConditin1) (int, error) {
|
|
|
272
|
- sqlStr := ` select
|
|
|
273
|
- count( distinct t_staff_assess_1.target_user_id) cnt
|
|
|
274
|
- from t_staff_assess_1
|
|
|
275
|
- where 1=1 `
|
|
|
276
|
- condition := []interface{}{}
|
|
|
277
|
- if len(param.TargetUserName) > 0 {
|
|
|
278
|
- sqlStr += ` and t_staff_assess_1.target_user_name like ? `
|
|
|
279
|
- condition = append(condition, "%"+param.TargetUserName+"%")
|
|
|
280
|
- }
|
|
|
281
|
- //获取前置sql语句
|
|
|
282
|
- sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, 5000, 0, string(domain.AssessSelf))
|
|
|
283
|
- sqlStr = sqlStr0 + sqlStr
|
|
|
284
|
- tx := d.transactionContext.PgTx
|
|
|
285
|
- var result int
|
|
|
286
|
- _, err := tx.QueryOne(pg.Scan(&result), sqlStr, condition...)
|
|
|
287
|
- return result, err
|
|
|
288
|
-}
|
|
|
289
|
-
|
|
|
290
|
-// 生成的sql 根据用户的查看权限 ,获取可查看的评估任务,
|
|
|
291
|
-// companyId int 公司id
|
|
|
292
|
-// cycleId int, 评估周期id
|
|
|
293
|
-// userId int, 用户id,谁要查看数据
|
|
|
294
|
-// beginDay string, 周期中执行项目的时间
|
|
|
295
|
-// hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
|
|
|
296
|
-// limit int, 分页条数
|
|
|
297
|
-// offset int 分页偏移
|
|
|
298
|
-// assessType string 评估的类型
|
|
|
299
|
-func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int, beginDay string, hrbp int, limit int, offset int, assessType string) string {
|
|
|
300
|
- sqlstr := `
|
|
|
301
|
- set time zone 'PRC';
|
|
|
302
|
- with t_user_department as (
|
|
|
303
|
- select "user".id as user_id ,jsonb_array_elements_text ("user".department_id) as depart_id from "user"
|
|
|
304
|
- where "user".company_id= %d and "user".deleted_at isnull
|
|
|
305
|
- ),
|
|
|
306
|
- t_department as (
|
|
|
307
|
- select department.id::text as depart_id from department where charge_user_ids @>'[%d]'
|
|
|
308
|
- and "department".deleted_at isnull
|
|
|
309
|
- ),
|
|
|
310
|
- -- 部门主管
|
|
|
311
|
- t_user_1 as (
|
|
|
312
|
- select t_user_department.user_id::text from t_user_department
|
|
|
313
|
- join t_department on t_user_department.depart_id = t_department.depart_id
|
|
|
314
|
- ),
|
|
|
315
|
- -- 如果是hrbp
|
|
|
316
|
- t_project_1 as(
|
|
|
317
|
- select evaluation_project.id as project_id
|
|
|
318
|
- from evaluation_project
|
|
|
319
|
- where evaluation_project.cycle_id =%d
|
|
|
320
|
- and evaluation_project.hr_bp = %d
|
|
|
321
|
- and evaluation_project.deleted_at isnull
|
|
|
322
|
- ),
|
|
|
323
|
- -- 如果的项目管理员
|
|
|
324
|
- t_project_2 as(
|
|
|
325
|
- select evaluation_project.id as project_id
|
|
|
326
|
- from evaluation_project
|
|
|
327
|
- where evaluation_project.cycle_id =%d
|
|
|
328
|
- and evaluation_project.pmp =1
|
|
|
329
|
- and evaluation_project.pmp_ids @>'["%d"]'
|
|
|
330
|
- and evaluation_project.deleted_at isnull
|
|
|
331
|
- ),
|
|
|
332
|
- -- 合并数据
|
|
|
333
|
- t_project_3 as (
|
|
|
334
|
- select t_project_2.project_id from t_project_2
|
|
|
335
|
- union
|
|
|
336
|
- select t_project_1.project_id from t_project_1
|
|
|
337
|
- ),
|
|
|
338
|
- -- 初步过滤数据
|
|
|
339
|
- t_staff_assess_0 as (
|
|
|
340
|
- select staff_assess.id as assess_id,
|
|
|
341
|
- staff_assess.cycle_id,
|
|
|
342
|
- staff_assess.target_user->>'userId' as target_user_id,
|
|
|
343
|
- staff_assess.target_user->>'userName' as target_user_name,
|
|
|
344
|
- to_char(staff_assess.begin_time,'YYYY-MM-DD') as begin_day,
|
|
|
345
|
- staff_assess.evaluation_project_id
|
|
|
346
|
- from staff_assess
|
|
|
347
|
- join staff_assess_task on staff_assess.staff_assess_task_id = staff_assess_task.id
|
|
|
348
|
- and staff_assess_task.deleted_at isnull
|
|
|
349
|
- where staff_assess.cycle_id = %d
|
|
|
350
|
- and to_char(staff_assess.begin_time,'YYYY-MM-DD')='%s'
|
|
|
351
|
- and staff_assess."types" ='%s'
|
|
|
352
|
- ),
|
|
|
353
|
- -- 根据查看权限过滤合并数据
|
|
|
354
|
- t_staff_assess_1 as (
|
|
|
355
|
- (select t_staff_assess_0.assess_id,
|
|
|
356
|
- t_staff_assess_0.target_user_id,
|
|
|
357
|
- t_staff_assess_0.target_user_name,
|
|
|
358
|
- t_staff_assess_0.begin_day,
|
|
|
359
|
- t_staff_assess_0.cycle_id
|
|
|
360
|
- from t_staff_assess_0
|
|
|
361
|
- join t_project_3 on t_staff_assess_0.evaluation_project_id = t_project_3.project_id
|
|
|
362
|
- ) union (select t_staff_assess_0.assess_id,
|
|
|
363
|
- t_staff_assess_0.target_user_id,
|
|
|
364
|
- t_staff_assess_0.target_user_name,
|
|
|
365
|
- t_staff_assess_0.begin_day,
|
|
|
366
|
- t_staff_assess_0.cycle_id
|
|
|
367
|
- from t_staff_assess_0
|
|
|
368
|
- join t_user_1 on t_staff_assess_0.target_user_id=t_user_1.user_id
|
|
|
369
|
- )
|
|
|
370
|
- limit %d offset %d
|
|
|
371
|
- )
|
|
|
372
|
- `
|
|
|
373
|
- params := []interface{}{
|
|
|
374
|
- companyId, userId, cycleId, hrbp, cycleId, userId, cycleId, beginDay, assessType, limit, offset,
|
|
|
375
|
- }
|
|
|
376
|
-
|
|
|
377
|
- sqlstr = fmt.Sprintf(sqlstr, params...)
|
|
|
378
|
- return sqlstr
|
|
|
379
|
-}
|
|
|
380
|
-
|
|
|
381
|
-type ExportData1 struct {
|
|
|
382
|
- AssessId string
|
|
|
383
|
- ContentId int
|
|
|
384
|
- TargetUserId string //被评估人的id
|
|
|
385
|
- TargetUserName string //被评估人的名称
|
|
|
386
|
- BeginDay string //评估的日期
|
|
|
387
|
- EvaluationProjectId string //项目id
|
|
|
388
|
- Value string //评估填写的值
|
|
|
389
|
- SortBy int //评估项顺序
|
|
|
390
|
- Category string //评估项分类
|
|
|
391
|
- ContentName string //评估项名称
|
|
|
392
|
- Weight float64 //权重
|
|
|
393
|
- PromptText string //评估标准
|
|
|
394
|
- Remark []domain.AssessContemtRemark
|
|
|
395
|
-}
|
|
|
396
|
-
|
|
|
397
|
-// 项目管理-成员列表 导出数据
|
|
|
398
|
-func (d *StaffAssessDao) ExportDataUserAssess(param SearchConditin1) ([]ExportData1, error) {
|
|
|
399
|
- if param.Offset < 0 {
|
|
|
400
|
- param.Offset = 0
|
|
|
401
|
- }
|
|
|
402
|
- if param.Limit < 0 {
|
|
|
403
|
- param.Limit = 5000
|
|
|
404
|
- }
|
|
|
405
|
- sqlStr := ` select
|
|
|
406
|
- t_staff_assess_1.target_user_id,t_staff_assess_1.target_user_name,t_staff_assess_1.begin_day,
|
|
|
407
|
- t_staff_assess_1.assess_id,staff_assess_content.id as content_id,
|
|
|
408
|
- staff_assess_content.value ,staff_assess_content.sort_by ,
|
|
|
409
|
- staff_assess_content.category ,staff_assess_content."name" as content_name ,
|
|
|
410
|
- staff_assess_content.weight,staff_assess_content.prompt_text ,staff_assess_content.remark
|
|
|
411
|
- from t_staff_assess_1
|
|
|
412
|
- left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
|
|
|
413
|
- where 1=1
|
|
|
414
|
- `
|
|
|
415
|
- condition := []interface{}{}
|
|
|
416
|
- if len(param.TargetUserName) > 0 {
|
|
|
417
|
- sqlStr += ` and t_staff_assess_1.target_user_name like ? `
|
|
|
418
|
- condition = append(condition, "%"+param.TargetUserName+"%")
|
|
|
419
|
- }
|
|
|
420
|
- if len(param.TargetUserId) > 0 {
|
|
|
421
|
- sqlStr += ` and t_staff_assess_1.target_user_id in (?) `
|
|
|
422
|
- condition = append(condition, pg.In(param.TargetUserId))
|
|
|
423
|
- }
|
|
|
424
|
- //加入排序
|
|
|
425
|
- sqlStr += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'),staff_assess_content.sort_by `
|
|
|
426
|
- //获取前置sql语句
|
|
|
427
|
- sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, param.Limit, param.Offset, string(domain.AssessSelf))
|
|
|
428
|
- sqlStr = sqlStr0 + sqlStr
|
|
|
429
|
- tx := d.transactionContext.PgTx
|
|
|
430
|
- var result []ExportData1
|
|
|
431
|
- _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
432
|
- return result, err
|
|
|
433
|
-}
|
|
|
434
|
-
|
|
|
435
|
-type AssessCycleDayMe struct {
|
|
|
436
|
- BeginDay string
|
|
|
437
|
- CycleId string
|
|
|
438
|
- CycleName string
|
|
|
439
|
- EndTime string
|
|
|
440
|
- BeginTime string
|
|
|
441
|
-}
|
|
|
442
|
-
|
|
|
443
|
-// 根据评估的人执行人id,搜索 executorId参与的评估周期
|
|
|
444
|
-func (d *StaffAssessDao) SearchAssessCycleMe(executorId int, companyId int, limit int, offset int) ([]AssessCycleDayMe, error) {
|
|
|
445
|
- if limit < 0 {
|
|
|
446
|
- limit = 20
|
|
|
447
|
- }
|
|
|
448
|
- if offset < 0 {
|
|
|
449
|
- offset = 0
|
|
|
450
|
- }
|
|
|
451
|
- sqlStr := `
|
|
|
452
|
- SELECT
|
|
|
453
|
- distinct on(staff_assess_task.cycle_id,staff_assess_task.begin_day)
|
|
|
454
|
- staff_assess_task.cycle_id,staff_assess_task.cycle_name ,
|
|
|
455
|
- staff_assess_task.begin_day,
|
|
|
456
|
- to_char(staff_assess_task.end_time at time zone 'PRC','YYYY-MM-DD HH24:MI:SS') as end_time,
|
|
|
457
|
- to_char(staff_assess_task.begin_time at time zone 'PRC','YYYY-MM-DD HH24:MI:SS') as begin_time
|
|
|
458
|
- FROM staff_assess_task
|
|
|
459
|
- JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id"
|
|
|
460
|
- WHERE staff_assess.company_id=?
|
|
|
461
|
- and staff_assess_task.deleted_at isnull
|
|
|
462
|
- and staff_assess.executor->>'userId'='?'
|
|
|
463
|
- order by staff_assess_task.begin_day desc
|
|
|
464
|
- limit ? offset ?
|
|
|
465
|
- `
|
|
|
466
|
- tx := d.transactionContext.PgTx
|
|
|
467
|
- condition := []interface{}{
|
|
|
468
|
- companyId, executorId, limit, offset,
|
|
|
469
|
- }
|
|
|
470
|
- result := []AssessCycleDayMe{}
|
|
|
471
|
- _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
472
|
- return result, err
|
|
|
473
|
-}
|
|
|
474
|
-
|
|
|
475
|
-// 根据评估的人执行人id,统计executorId参与的评估周期
|
|
|
476
|
-func (d *StaffAssessDao) CountAssessCycleMe(executorId int, companyId int) (int, error) {
|
|
|
477
|
- sqlStr := `
|
|
|
478
|
- select count(DISTINCT (staff_assess_task.cycle_id,staff_assess_task.begin_day )) as cnt
|
|
|
479
|
- FROM staff_assess_task
|
|
|
480
|
- JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id"
|
|
|
481
|
- WHERE staff_assess.company_id=?
|
|
|
482
|
- and staff_assess_task.deleted_at isnull
|
|
|
483
|
- and staff_assess.executor->>'userId'='?'
|
|
|
484
|
- `
|
|
|
485
|
- tx := d.transactionContext.PgTx
|
|
|
486
|
- condition := []interface{}{
|
|
|
487
|
- companyId, executorId,
|
|
|
488
|
- }
|
|
|
489
|
- var result int
|
|
|
490
|
- _, err := tx.QueryOne(pg.Scan(&result), sqlStr, condition...)
|
|
|
491
|
- return result, err
|
|
|
492
|
-} |
1
|
+package dao
|
|
|
2
|
+
|
|
|
3
|
+import (
|
|
|
4
|
+ "fmt"
|
|
|
5
|
+ "strconv"
|
|
|
6
|
+ "time"
|
|
|
7
|
+
|
|
|
8
|
+ "github.com/go-pg/pg/v10"
|
|
|
9
|
+ pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
|
|
10
|
+ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
|
|
11
|
+)
|
|
|
12
|
+
|
|
|
13
|
+type StaffAssessDao struct {
|
|
|
14
|
+ transactionContext *pgTransaction.TransactionContext
|
|
|
15
|
+}
|
|
|
16
|
+
|
|
|
17
|
+func NewStaffAssessDao(options map[string]interface{}) *StaffAssessDao {
|
|
|
18
|
+ var transactionContext *pgTransaction.TransactionContext
|
|
|
19
|
+ if value, ok := options["transactionContext"]; ok {
|
|
|
20
|
+ transactionContext = value.(*pgTransaction.TransactionContext)
|
|
|
21
|
+ }
|
|
|
22
|
+ return &StaffAssessDao{
|
|
|
23
|
+ transactionContext: transactionContext,
|
|
|
24
|
+ }
|
|
|
25
|
+}
|
|
|
26
|
+
|
|
|
27
|
+type CountData struct {
|
|
|
28
|
+ TargetUserId int
|
|
|
29
|
+ InviteTotal int
|
|
|
30
|
+ InviteCompleted int
|
|
|
31
|
+}
|
|
|
32
|
+
|
|
|
33
|
+// 获取员工邀请的人完成360评估的数量
|
|
|
34
|
+func (d *StaffAssessDao) CountInviteAssessByTargetUser(userIds []int, assessTaskId int) ([]CountData, error) {
|
|
|
35
|
+ sqlStr := `SELECT staff_assess.target_user->>'userId' as target_user_id,
|
|
|
36
|
+ count(staff_assess."id") AS invite_total,
|
|
|
37
|
+ sum(
|
|
|
38
|
+ case WHEN staff_assess.status='completed' THEN 1
|
|
|
39
|
+ ELSE 0 END
|
|
|
40
|
+ ) as invite_completed
|
|
|
41
|
+ FROM staff_assess
|
|
|
42
|
+ WHERE staff_assess.target_user->>'userId' IN(?)
|
|
|
43
|
+ AND staff_assess.types IN ('invite_same_super','invite_diff_super')
|
|
|
44
|
+ AND staff_assess.staff_assess_task_id = ?
|
|
|
45
|
+ GROUP BY target_user_id`
|
|
|
46
|
+
|
|
|
47
|
+ userIdList := []string{}
|
|
|
48
|
+ for _, v := range userIds {
|
|
|
49
|
+ uid := strconv.Itoa(v)
|
|
|
50
|
+ userIdList = append(userIdList, uid)
|
|
|
51
|
+ }
|
|
|
52
|
+ condition := []interface{}{
|
|
|
53
|
+ pg.In(userIdList), assessTaskId,
|
|
|
54
|
+ }
|
|
|
55
|
+ tx := d.transactionContext.PgTx
|
|
|
56
|
+ result := []CountData{}
|
|
|
57
|
+ _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
58
|
+ return result, err
|
|
|
59
|
+}
|
|
|
60
|
+
|
|
|
61
|
+func (d *StaffAssessDao) CountTargetUserInviteAssess1(userIds []int, cycleId int, beginDay string) ([]CountData, error) {
|
|
|
62
|
+ sqlStr := `SELECT
|
|
|
63
|
+ staff_assess.target_user->>'userId' as target_user_id,
|
|
|
64
|
+ count(staff_assess."id") AS invite_total,
|
|
|
65
|
+ sum(
|
|
|
66
|
+ case WHEN staff_assess.status='completed' THEN 1
|
|
|
67
|
+ ELSE 0 END
|
|
|
68
|
+ ) as invite_completed
|
|
|
69
|
+ FROM staff_assess
|
|
|
70
|
+ WHERE staff_assess.target_user->>'userId' IN(?)
|
|
|
71
|
+ AND staff_assess.types IN ('invite_same_super','invite_diff_super')
|
|
|
72
|
+ and to_char(staff_assess.begin_time at time zone 'PRC','YYYY-MM-DD') = ?
|
|
|
73
|
+ and staff_assess.cycle_id =?
|
|
|
74
|
+ GROUP BY target_user_id`
|
|
|
75
|
+ userIdStr := []string{}
|
|
|
76
|
+ for _, v := range userIds {
|
|
|
77
|
+ str := strconv.Itoa(v)
|
|
|
78
|
+ userIdStr = append(userIdStr, str)
|
|
|
79
|
+ }
|
|
|
80
|
+ condition := []interface{}{
|
|
|
81
|
+ pg.In(userIdStr), beginDay, cycleId,
|
|
|
82
|
+ }
|
|
|
83
|
+ tx := d.transactionContext.PgTx
|
|
|
84
|
+ result := []CountData{}
|
|
|
85
|
+ _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
86
|
+ return result, err
|
|
|
87
|
+}
|
|
|
88
|
+
|
|
|
89
|
+// 根据评估的人执行人id,搜索 executorId参与的评估任务
|
|
|
90
|
+func (d *StaffAssessDao) SearchAssessTaskMe(executorId int, companyId int, limit int, offset int) ([]*domain.StaffAssessTask, error) {
|
|
|
91
|
+
|
|
|
92
|
+ if limit < 0 {
|
|
|
93
|
+ limit = 20
|
|
|
94
|
+ }
|
|
|
95
|
+ if offset < 0 {
|
|
|
96
|
+ offset = 0
|
|
|
97
|
+ }
|
|
|
98
|
+
|
|
|
99
|
+ sqlStr := `SELECT DISTINCT staff_assess_task.* FROM staff_assess_task
|
|
|
100
|
+ JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id"
|
|
|
101
|
+ WHERE staff_assess.company_id=?
|
|
|
102
|
+ and staff_assess_task.deleted_at isnull
|
|
|
103
|
+ and staff_assess.executor->>'userId'='?'
|
|
|
104
|
+ order by staff_assess_task.id desc
|
|
|
105
|
+ limit ? offset ?
|
|
|
106
|
+ `
|
|
|
107
|
+ tx := d.transactionContext.PgTx
|
|
|
108
|
+ condition := []interface{}{
|
|
|
109
|
+ companyId, executorId, limit, offset,
|
|
|
110
|
+ }
|
|
|
111
|
+ result := []*domain.StaffAssessTask{}
|
|
|
112
|
+ _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
113
|
+ return result, err
|
|
|
114
|
+
|
|
|
115
|
+}
|
|
|
116
|
+
|
|
|
117
|
+// 搜索 executorId 参与的评估任务
|
|
|
118
|
+func (d *StaffAssessDao) CountAssessTaskMe(executorId int, companyId int) (int, error) {
|
|
|
119
|
+ sqlStr := `SELECT count( DISTINCT staff_assess_task."id") FROM staff_assess_task
|
|
|
120
|
+ JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id"
|
|
|
121
|
+ WHERE staff_assess.company_id=?
|
|
|
122
|
+ and staff_assess_task.deleted_at isnull
|
|
|
123
|
+ and staff_assess.executor->>'userId'='?'
|
|
|
124
|
+ `
|
|
|
125
|
+ tx := d.transactionContext.PgTx
|
|
|
126
|
+ condition := []interface{}{
|
|
|
127
|
+ companyId, executorId,
|
|
|
128
|
+ }
|
|
|
129
|
+ result := 0
|
|
|
130
|
+ _, err := tx.QueryOne(pg.Scan(&result), sqlStr, condition...)
|
|
|
131
|
+ return result, err
|
|
|
132
|
+}
|
|
|
133
|
+
|
|
|
134
|
+// 获取所以已经执行的评估周期
|
|
|
135
|
+type AssessCycle struct {
|
|
|
136
|
+ CycleId string `json:"cycleId"` //周期id
|
|
|
137
|
+ CompanyId string `json:"companyId"`
|
|
|
138
|
+ CycleName string `json:"cycleName"` //周期名称
|
|
|
139
|
+}
|
|
|
140
|
+
|
|
|
141
|
+// 获取所以已经执行的评估周期
|
|
|
142
|
+func (d *StaffAssessDao) AllAssessCycleList(companyId int) ([]AssessCycle, error) {
|
|
|
143
|
+ sqlStr := `select
|
|
|
144
|
+ distinct
|
|
|
145
|
+ staff_assess_task.cycle_id ,
|
|
|
146
|
+ staff_assess_task.company_id ,
|
|
|
147
|
+ staff_assess_task.cycle_name
|
|
|
148
|
+ from staff_assess_task
|
|
|
149
|
+ where staff_assess_task.company_id = ?
|
|
|
150
|
+ and staff_assess_task.deleted_at isnull
|
|
|
151
|
+ order by staff_assess_task.cycle_id desc
|
|
|
152
|
+ `
|
|
|
153
|
+
|
|
|
154
|
+ tx := d.transactionContext.PgTx
|
|
|
155
|
+ condition := []interface{}{
|
|
|
156
|
+ companyId,
|
|
|
157
|
+ }
|
|
|
158
|
+ result := []AssessCycle{}
|
|
|
159
|
+ _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
160
|
+ return result, err
|
|
|
161
|
+}
|
|
|
162
|
+
|
|
|
163
|
+// 获取评估周期中的绩效考核日期
|
|
|
164
|
+type AssessCycleDay struct {
|
|
|
165
|
+ BeginDay string `json:"beginDay"`
|
|
|
166
|
+ CycleId int `json:"cycleId"`
|
|
|
167
|
+ CycleName string `json:"cycleName"`
|
|
|
168
|
+ CompanyId string `json:"companyId"`
|
|
|
169
|
+}
|
|
|
170
|
+
|
|
|
171
|
+// 获取评估周期中的绩效考核日期
|
|
|
172
|
+func (d *StaffAssessDao) AllAssessCycleDayList(companyId int, cycleId int) ([]AssessCycleDay, error) {
|
|
|
173
|
+ sqlStr := `select distinct staff_assess_task.begin_day ,
|
|
|
174
|
+ staff_assess_task.cycle_id ,
|
|
|
175
|
+ staff_assess_task.cycle_name,
|
|
|
176
|
+ staff_assess_task.company_id
|
|
|
177
|
+ from staff_assess_task
|
|
|
178
|
+ where staff_assess_task.cycle_id = ?
|
|
|
179
|
+ and company_id =?
|
|
|
180
|
+ and staff_assess_task.deleted_at isnull
|
|
|
181
|
+ order by staff_assess_task.begin_day desc `
|
|
|
182
|
+
|
|
|
183
|
+ tx := d.transactionContext.PgTx
|
|
|
184
|
+ condition := []interface{}{
|
|
|
185
|
+ cycleId, companyId,
|
|
|
186
|
+ }
|
|
|
187
|
+ result := []AssessCycleDay{}
|
|
|
188
|
+ _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
189
|
+ return result, err
|
|
|
190
|
+}
|
|
|
191
|
+
|
|
|
192
|
+// 获取员工填写评估内容
|
|
|
193
|
+type UserAssessContent struct {
|
|
|
194
|
+ AssessId string `json:"assessId"`
|
|
|
195
|
+ ContentId int `json:"contentId"`
|
|
|
196
|
+ TargetUserId string `json:"targetUserId"` //被评估人的id
|
|
|
197
|
+ TargetUserName string `json:"targetUserName"` //被评估人的名称
|
|
|
198
|
+ BeginDay string `json:"beginDay"` //评估的日期
|
|
|
199
|
+ EvaluationProjectId string `json:"evaluationProjectId"` //项目id
|
|
|
200
|
+ Value string `json:"value"` //评估填写的值
|
|
|
201
|
+ LevelValue string `json:"levelValue"` //评级的值
|
|
|
202
|
+ Rule domain.EvaluationRule `json:"rule"` //规则
|
|
|
203
|
+ SortBy int `json:"sortBy"` //评估项顺序
|
|
|
204
|
+ Category string `json:"category"` //评估项分类
|
|
|
205
|
+ ContentName string `json:"contentName"` //评估项名称
|
|
|
206
|
+ Weight float64 `json:"weight"` //权重
|
|
|
207
|
+ CycleId string `json:"cycleId"` //周期id
|
|
|
208
|
+}
|
|
|
209
|
+
|
|
|
210
|
+type SearchConditin1 struct {
|
|
|
211
|
+ CompanyId int //公司id
|
|
|
212
|
+ AssessId int //评估任务id
|
|
|
213
|
+ CycleId int //周期id
|
|
|
214
|
+ BeginDay string //评估的日期
|
|
|
215
|
+ TargetUserName string //被评估人的名称
|
|
|
216
|
+ TargetUserId []string //查询指定的人
|
|
|
217
|
+ Limit int //分页
|
|
|
218
|
+ Offset int //分页
|
|
|
219
|
+ OperaterId int //用户的id是谁在搜索数据
|
|
|
220
|
+ Hrbp int //
|
|
|
221
|
+}
|
|
|
222
|
+
|
|
|
223
|
+// 项目管理-成员列表 根据周期的id和日期获取员工填写的评估内容
|
|
|
224
|
+// companyId int 公司id
|
|
|
225
|
+// cycleId int, 评估周期id
|
|
|
226
|
+// userId int, 用户id,谁要查看数据
|
|
|
227
|
+// beginDay string, 周期中执行项目的时间
|
|
|
228
|
+// hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
|
|
|
229
|
+// limit int, 分页条数
|
|
|
230
|
+// offset int 分页偏移
|
|
|
231
|
+func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserAssessContent, error) {
|
|
|
232
|
+ if param.Offset < 0 {
|
|
|
233
|
+ param.Offset = 0
|
|
|
234
|
+ }
|
|
|
235
|
+ if param.Limit < 0 {
|
|
|
236
|
+ param.Limit = 20
|
|
|
237
|
+ }
|
|
|
238
|
+ sqlStr := ` select
|
|
|
239
|
+ t_staff_assess_1.target_user_id,t_staff_assess_1.target_user_name,t_staff_assess_1.begin_day,
|
|
|
240
|
+ t_staff_assess_1.assess_id,staff_assess_content.id as content_id,
|
|
|
241
|
+ staff_assess_content.value ,staff_assess_content.sort_by ,t_staff_assess_1.cycle_id,
|
|
|
242
|
+ staff_assess_content.category ,staff_assess_content."name" as content_name ,
|
|
|
243
|
+ staff_assess_content.weight,staff_assess_content.level_value,staff_assess_content."rule"
|
|
|
244
|
+ from t_staff_assess_1
|
|
|
245
|
+ left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
|
|
|
246
|
+ where 1=1
|
|
|
247
|
+ `
|
|
|
248
|
+ condition := []interface{}{}
|
|
|
249
|
+ if len(param.TargetUserName) > 0 {
|
|
|
250
|
+ sqlStr += ` and t_staff_assess_1.target_user_name like ? `
|
|
|
251
|
+ condition = append(condition, "%"+param.TargetUserName+"%")
|
|
|
252
|
+ }
|
|
|
253
|
+ //加入排序
|
|
|
254
|
+ sqlStr += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'),staff_assess_content.sort_by `
|
|
|
255
|
+ //获取前置sql语句
|
|
|
256
|
+ sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, param.Limit, param.Offset, string(domain.AssessSelf))
|
|
|
257
|
+ sqlStr = sqlStr0 + sqlStr
|
|
|
258
|
+ tx := d.transactionContext.PgTx
|
|
|
259
|
+ result := []UserAssessContent{}
|
|
|
260
|
+ _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
261
|
+ return result, err
|
|
|
262
|
+}
|
|
|
263
|
+
|
|
|
264
|
+// 项目管理-成员列表 根据周期的id和日期获取员工填写的评估内容,数量统计
|
|
|
265
|
+// companyId int 公司id
|
|
|
266
|
+// cycleId int, 评估周期id
|
|
|
267
|
+// userId int, 用户id,谁要查看数据
|
|
|
268
|
+// beginDay string, 周期中执行项目的时间
|
|
|
269
|
+// hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
|
|
|
270
|
+// limit int, 分页条数
|
|
|
271
|
+// offset int 分页偏移
|
|
|
272
|
+func (d *StaffAssessDao) CountUserAssess(param SearchConditin1) (int, error) {
|
|
|
273
|
+ sqlStr := ` select
|
|
|
274
|
+ count( distinct t_staff_assess_1.target_user_id) cnt
|
|
|
275
|
+ from t_staff_assess_1
|
|
|
276
|
+ where 1=1 `
|
|
|
277
|
+ condition := []interface{}{}
|
|
|
278
|
+ if len(param.TargetUserName) > 0 {
|
|
|
279
|
+ sqlStr += ` and t_staff_assess_1.target_user_name like ? `
|
|
|
280
|
+ condition = append(condition, "%"+param.TargetUserName+"%")
|
|
|
281
|
+ }
|
|
|
282
|
+ //获取前置sql语句
|
|
|
283
|
+ sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, 5000, 0, string(domain.AssessSelf))
|
|
|
284
|
+ sqlStr = sqlStr0 + sqlStr
|
|
|
285
|
+ tx := d.transactionContext.PgTx
|
|
|
286
|
+ var result int
|
|
|
287
|
+ _, err := tx.QueryOne(pg.Scan(&result), sqlStr, condition...)
|
|
|
288
|
+ return result, err
|
|
|
289
|
+}
|
|
|
290
|
+
|
|
|
291
|
+// 生成的sql 根据用户的查看权限 ,获取可查看的评估任务,
|
|
|
292
|
+// companyId int 公司id
|
|
|
293
|
+// cycleId int, 评估周期id
|
|
|
294
|
+// userId int, 用户id,谁要查看数据
|
|
|
295
|
+// beginDay string, 周期中执行项目的时间
|
|
|
296
|
+// hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
|
|
|
297
|
+// limit int, 分页条数
|
|
|
298
|
+// offset int 分页偏移
|
|
|
299
|
+// assessType string 评估的类型
|
|
|
300
|
+func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int, beginDay string, hrbp int, limit int, offset int, assessType string) string {
|
|
|
301
|
+ sqlstr := `
|
|
|
302
|
+ set time zone 'PRC';
|
|
|
303
|
+ with t_user_department as (
|
|
|
304
|
+ select "user".id as user_id ,jsonb_array_elements_text ("user".department_id) as depart_id from "user"
|
|
|
305
|
+ where "user".company_id= %d and "user".deleted_at isnull
|
|
|
306
|
+ ),
|
|
|
307
|
+ t_department as (
|
|
|
308
|
+ select department.id::text as depart_id from department where charge_user_ids @>'[%d]'
|
|
|
309
|
+ and "department".deleted_at isnull
|
|
|
310
|
+ ),
|
|
|
311
|
+ -- 部门主管
|
|
|
312
|
+ t_user_1 as (
|
|
|
313
|
+ select t_user_department.user_id::text from t_user_department
|
|
|
314
|
+ join t_department on t_user_department.depart_id = t_department.depart_id
|
|
|
315
|
+ ),
|
|
|
316
|
+ -- 如果是hrbp
|
|
|
317
|
+ t_project_1 as(
|
|
|
318
|
+ select evaluation_project.id as project_id
|
|
|
319
|
+ from evaluation_project
|
|
|
320
|
+ where evaluation_project.cycle_id =%d
|
|
|
321
|
+ and evaluation_project.hr_bp = %d
|
|
|
322
|
+ and evaluation_project.deleted_at isnull
|
|
|
323
|
+ ),
|
|
|
324
|
+ -- 如果的项目管理员
|
|
|
325
|
+ t_project_2 as(
|
|
|
326
|
+ select evaluation_project.id as project_id
|
|
|
327
|
+ from evaluation_project
|
|
|
328
|
+ where evaluation_project.cycle_id =%d
|
|
|
329
|
+ and evaluation_project.pmp =1
|
|
|
330
|
+ and evaluation_project.pmp_ids @>'["%d"]'
|
|
|
331
|
+ and evaluation_project.deleted_at isnull
|
|
|
332
|
+ ),
|
|
|
333
|
+ -- 合并数据
|
|
|
334
|
+ t_project_3 as (
|
|
|
335
|
+ select t_project_2.project_id from t_project_2
|
|
|
336
|
+ union
|
|
|
337
|
+ select t_project_1.project_id from t_project_1
|
|
|
338
|
+ ),
|
|
|
339
|
+ -- 初步过滤数据
|
|
|
340
|
+ t_staff_assess_0 as (
|
|
|
341
|
+ select staff_assess.id as assess_id,
|
|
|
342
|
+ staff_assess.cycle_id,
|
|
|
343
|
+ staff_assess.target_user->>'userId' as target_user_id,
|
|
|
344
|
+ staff_assess.target_user->>'userName' as target_user_name,
|
|
|
345
|
+ to_char(staff_assess.begin_time,'YYYY-MM-DD') as begin_day,
|
|
|
346
|
+ staff_assess.evaluation_project_id
|
|
|
347
|
+ from staff_assess
|
|
|
348
|
+ join staff_assess_task on staff_assess.staff_assess_task_id = staff_assess_task.id
|
|
|
349
|
+ and staff_assess_task.deleted_at isnull
|
|
|
350
|
+ where staff_assess.cycle_id = %d
|
|
|
351
|
+ and to_char(staff_assess.begin_time,'YYYY-MM-DD')='%s'
|
|
|
352
|
+ and staff_assess."types" ='%s'
|
|
|
353
|
+ ),
|
|
|
354
|
+ -- 根据查看权限过滤合并数据
|
|
|
355
|
+ t_staff_assess_1 as (
|
|
|
356
|
+ (select t_staff_assess_0.assess_id,
|
|
|
357
|
+ t_staff_assess_0.target_user_id,
|
|
|
358
|
+ t_staff_assess_0.target_user_name,
|
|
|
359
|
+ t_staff_assess_0.begin_day,
|
|
|
360
|
+ t_staff_assess_0.cycle_id
|
|
|
361
|
+ from t_staff_assess_0
|
|
|
362
|
+ join t_project_3 on t_staff_assess_0.evaluation_project_id = t_project_3.project_id
|
|
|
363
|
+ ) union (select t_staff_assess_0.assess_id,
|
|
|
364
|
+ t_staff_assess_0.target_user_id,
|
|
|
365
|
+ t_staff_assess_0.target_user_name,
|
|
|
366
|
+ t_staff_assess_0.begin_day,
|
|
|
367
|
+ t_staff_assess_0.cycle_id
|
|
|
368
|
+ from t_staff_assess_0
|
|
|
369
|
+ join t_user_1 on t_staff_assess_0.target_user_id=t_user_1.user_id
|
|
|
370
|
+ )
|
|
|
371
|
+ limit %d offset %d
|
|
|
372
|
+ )
|
|
|
373
|
+ `
|
|
|
374
|
+ params := []interface{}{
|
|
|
375
|
+ companyId, userId, cycleId, hrbp, cycleId, userId, cycleId, beginDay, assessType, limit, offset,
|
|
|
376
|
+ }
|
|
|
377
|
+
|
|
|
378
|
+ sqlstr = fmt.Sprintf(sqlstr, params...)
|
|
|
379
|
+ return sqlstr
|
|
|
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
|
+
|
|
|
505
|
+type ExportData1 struct {
|
|
|
506
|
+ AssessId string
|
|
|
507
|
+ ContentId int
|
|
|
508
|
+ TargetUserId string //被评估人的id
|
|
|
509
|
+ TargetUserName string //被评估人的名称
|
|
|
510
|
+ BeginDay string //评估的日期
|
|
|
511
|
+ EvaluationProjectId string //项目id
|
|
|
512
|
+ Value string //评估填写的值
|
|
|
513
|
+ SortBy int //评估项顺序
|
|
|
514
|
+ Category string //评估项分类
|
|
|
515
|
+ ContentName string //评估项名称
|
|
|
516
|
+ Weight float64 //权重
|
|
|
517
|
+ PromptText string //评估标准
|
|
|
518
|
+ Remark []domain.AssessContemtRemark
|
|
|
519
|
+}
|
|
|
520
|
+
|
|
|
521
|
+// 项目管理-成员列表 导出数据
|
|
|
522
|
+func (d *StaffAssessDao) ExportDataUserAssess(param SearchConditin1) ([]ExportData1, error) {
|
|
|
523
|
+ if param.Offset < 0 {
|
|
|
524
|
+ param.Offset = 0
|
|
|
525
|
+ }
|
|
|
526
|
+ if param.Limit < 0 {
|
|
|
527
|
+ param.Limit = 5000
|
|
|
528
|
+ }
|
|
|
529
|
+ sqlStr := ` select
|
|
|
530
|
+ t_staff_assess_1.target_user_id,t_staff_assess_1.target_user_name,t_staff_assess_1.begin_day,
|
|
|
531
|
+ t_staff_assess_1.assess_id,staff_assess_content.id as content_id,
|
|
|
532
|
+ staff_assess_content.value ,staff_assess_content.sort_by ,
|
|
|
533
|
+ staff_assess_content.category ,staff_assess_content."name" as content_name ,
|
|
|
534
|
+ staff_assess_content.weight,staff_assess_content.prompt_text ,staff_assess_content.remark
|
|
|
535
|
+ from t_staff_assess_1
|
|
|
536
|
+ left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
|
|
|
537
|
+ where 1=1
|
|
|
538
|
+ `
|
|
|
539
|
+ condition := []interface{}{}
|
|
|
540
|
+ if len(param.TargetUserName) > 0 {
|
|
|
541
|
+ sqlStr += ` and t_staff_assess_1.target_user_name like ? `
|
|
|
542
|
+ condition = append(condition, "%"+param.TargetUserName+"%")
|
|
|
543
|
+ }
|
|
|
544
|
+ if len(param.TargetUserId) > 0 {
|
|
|
545
|
+ sqlStr += ` and t_staff_assess_1.target_user_id in (?) `
|
|
|
546
|
+ condition = append(condition, pg.In(param.TargetUserId))
|
|
|
547
|
+ }
|
|
|
548
|
+ //加入排序
|
|
|
549
|
+ sqlStr += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'),staff_assess_content.sort_by `
|
|
|
550
|
+ //获取前置sql语句
|
|
|
551
|
+ sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, param.Limit, param.Offset, string(domain.AssessSelf))
|
|
|
552
|
+ sqlStr = sqlStr0 + sqlStr
|
|
|
553
|
+ tx := d.transactionContext.PgTx
|
|
|
554
|
+ var result []ExportData1
|
|
|
555
|
+ _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
556
|
+ return result, err
|
|
|
557
|
+}
|
|
|
558
|
+
|
|
|
559
|
+type AssessCycleDayMe struct {
|
|
|
560
|
+ BeginDay string
|
|
|
561
|
+ CycleId string
|
|
|
562
|
+ CycleName string
|
|
|
563
|
+ EndTime string
|
|
|
564
|
+ BeginTime string
|
|
|
565
|
+}
|
|
|
566
|
+
|
|
|
567
|
+// 根据评估的人执行人id,搜索 executorId参与的评估周期
|
|
|
568
|
+func (d *StaffAssessDao) SearchAssessCycleMe(executorId int, companyId int, limit int, offset int) ([]AssessCycleDayMe, error) {
|
|
|
569
|
+ if limit < 0 {
|
|
|
570
|
+ limit = 20
|
|
|
571
|
+ }
|
|
|
572
|
+ if offset < 0 {
|
|
|
573
|
+ offset = 0
|
|
|
574
|
+ }
|
|
|
575
|
+ sqlStr := `
|
|
|
576
|
+ SELECT
|
|
|
577
|
+ distinct on(staff_assess_task.cycle_id,staff_assess_task.begin_day)
|
|
|
578
|
+ staff_assess_task.cycle_id,staff_assess_task.cycle_name ,
|
|
|
579
|
+ staff_assess_task.begin_day,
|
|
|
580
|
+ to_char(staff_assess_task.end_time at time zone 'PRC','YYYY-MM-DD HH24:MI:SS') as end_time,
|
|
|
581
|
+ to_char(staff_assess_task.begin_time at time zone 'PRC','YYYY-MM-DD HH24:MI:SS') as begin_time
|
|
|
582
|
+ FROM staff_assess_task
|
|
|
583
|
+ JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id"
|
|
|
584
|
+ WHERE staff_assess.company_id=?
|
|
|
585
|
+ and staff_assess_task.deleted_at isnull
|
|
|
586
|
+ and staff_assess.executor->>'userId'='?'
|
|
|
587
|
+ order by staff_assess_task.begin_day desc
|
|
|
588
|
+ limit ? offset ?
|
|
|
589
|
+ `
|
|
|
590
|
+ tx := d.transactionContext.PgTx
|
|
|
591
|
+ condition := []interface{}{
|
|
|
592
|
+ companyId, executorId, limit, offset,
|
|
|
593
|
+ }
|
|
|
594
|
+ result := []AssessCycleDayMe{}
|
|
|
595
|
+ _, err := tx.Query(&result, sqlStr, condition...)
|
|
|
596
|
+ return result, err
|
|
|
597
|
+}
|
|
|
598
|
+
|
|
|
599
|
+// 根据评估的人执行人id,统计executorId参与的评估周期
|
|
|
600
|
+func (d *StaffAssessDao) CountAssessCycleMe(executorId int, companyId int) (int, error) {
|
|
|
601
|
+ sqlStr := `
|
|
|
602
|
+ select count(DISTINCT (staff_assess_task.cycle_id,staff_assess_task.begin_day )) as cnt
|
|
|
603
|
+ FROM staff_assess_task
|
|
|
604
|
+ JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id"
|
|
|
605
|
+ WHERE staff_assess.company_id=?
|
|
|
606
|
+ and staff_assess_task.deleted_at isnull
|
|
|
607
|
+ and staff_assess.executor->>'userId'='?'
|
|
|
608
|
+ `
|
|
|
609
|
+ tx := d.transactionContext.PgTx
|
|
|
610
|
+ condition := []interface{}{
|
|
|
611
|
+ companyId, executorId,
|
|
|
612
|
+ }
|
|
|
613
|
+ var result int
|
|
|
614
|
+ _, err := tx.QueryOne(pg.Scan(&result), sqlStr, condition...)
|
|
|
615
|
+ return result, err
|
|
|
616
|
+} |