summary_evaluation_dao.go
1.8 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
package dao
import (
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)
type SummaryEvaluationDao struct {
transactionContext *pgTransaction.TransactionContext
}
func NewSummaryEvaluationDao(options map[string]interface{}) *SummaryEvaluationDao {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return &SummaryEvaluationDao{
transactionContext: transactionContext,
}
}
type PersonalCycle struct {
ExecutorId string `pg:"executor_id" ` //
CycleId string `pg:"cycle_id" ` //
CycleName string `pg:"cycle_name"` //
}
// GetPersonalCycleList 获取执行人拥有的周期列表
func (d *SummaryEvaluationDao) GetPersonalCycleList(executorId int, offset int, limit int) ([]PersonalCycle, error) {
sqlStr := `select
distinct
summary_evaluation.cycle_id ,
summary_evaluation.cycle_name ,
summary_evaluation.executor ->>'userId' as executor_id
from summary_evaluation
where summary_evaluation.executor ->>'userId'='?'
offset ? limit ?`
tx := d.transactionContext.PgTx
condition := []interface{}{
executorId, offset, limit,
}
result := []PersonalCycle{}
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
// CountPersonalCycleList 统计执行人拥有的周期列表
func (d *SummaryEvaluationDao) CountPersonalCycleList(executorId int) (int, error) {
sqlStr := `select count(
distinct summary_evaluation.cycle_id
) as cnt
from summary_evaluation
where summary_evaluation.executor ->>'userId'='?' `
tx := d.transactionContext.PgTx
condition := []interface{}{
executorId,
}
var cnt int
_, err := tx.QueryOne(pg.Scan(&cnt), sqlStr, condition...)
return cnt, err
}