pg_task_dao.go
1.1 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
package dao
import (
"fmt"
"time"
"github.com/go-pg/pg"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
)
type TaskDao struct {
transactionContext *pgTransaction.TransactionContext
}
func (dao *TaskDao) AddRobInfo(taskId int64, receiver *domain.EmployeeInfo) error {
tx := dao.transactionContext.PgTx
_, err := tx.QueryOne(
pg.Scan(),
"INSERT INTO rob_infos (task_id, receiver, receive_time) VALUES (?, ?, ?)",
taskId, receiver, time.Now())
return err
}
func (dao *TaskDao) AddBidInfo(taskId int64, bidStartTime time.Time, bidEndTime time.Time) error {
tx := dao.transactionContext.PgTx
_, err := tx.QueryOne(
pg.Scan(),
"INSERT INTO rob_infos (task_id, bid_start_time, bid_end_time) VALUES (?, ?, ?)",
taskId, bidStartTime, bidEndTime)
return err
}
func NewTaskDao(transactionContext *pgTransaction.TransactionContext) (*TaskDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &TaskDao{
transactionContext: transactionContext,
}, nil
}
}