pg_task_dao.go 1.1 KB
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
	}
}