staff_assess_dao.go
3.0 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
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.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.executor->>'userId'='?'
`
tx := d.transactionContext.PgTx
condition := []interface{}{
companyId, executorId,
}
result := 0
_, err := tx.QueryOne(pg.Scan(&result), sqlStr, condition...)
return result, err
}