evaluation_project.go
1.4 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
package dao
import (
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
)
type EvaluationProjectDao struct {
transactionContext *pgTransaction.TransactionContext
}
func NewEvaluationProjectDao(options map[string]interface{}) *EvaluationProjectDao {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return &EvaluationProjectDao{
transactionContext: transactionContext,
}
}
func (d *EvaluationProjectDao) UpdateSummaryState(id int64, status domain.ProjectSummaryState) error {
db := d.transactionContext.PgTx
_, err := db.Model(&models.EvaluationProject{}).
Where("id=?", id).
Set("summary_state=?", int(status)).
Update()
return err
}
// 检查每日评估是否存在关联的(EvaluationProject)项目数据
func (d *EvaluationProjectDao) ExistRelationProject(staffAssessId int) (bool, error) {
sqlStr := `select count(*) from evaluation_project
where id=any (
select staff_assess.evaluation_project_id
from staff_assess where id=?
)
and evaluation_project.deleted_at isnull `
tx := d.transactionContext.PgTx
result := 0
_, err := tx.QueryOne(pg.Scan(&result), sqlStr, staffAssessId)
return result > 0, err
}