pg_list_interval_dao.go 1.4 KB
package dao

import (
	"fmt"
	"github.com/go-pg/pg"
	pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)

type ListIntervalDao struct {
	transactionContext *pgTransaction.TransactionContext
}

// 榜单时间管理
func (dao *ListIntervalDao) RankPeriodCheckTime(startTime int64, endTime int64, idNot int, companyId int) bool {
	fmt.Print(startTime, "\n")
	fmt.Print(endTime, "\n")
	var count int
	tx := dao.transactionContext.PgTx
	_, err := tx.QueryOne(
		pg.Scan(&count),
		`SELECT count(*) FROM list_intervals
			WHERE id <> ?
			AND company_id = ?
			AND 
			(
			( extract(epoch from list_interval_start_time) BETWEEN ? AND ?) 
			OR 
			( extract(epoch from list_interval_end_time) BETWEEN ? AND ?) 
			OR
			(? BETWEEN extract(epoch from list_interval_start_time) AND extract(epoch from list_interval_end_time)) 
			OR
			(? BETWEEN extract(epoch from list_interval_start_time) AND extract(epoch from list_interval_end_time)) 
			)
			LIMIT 1 `,
		idNot, companyId, startTime, endTime, startTime, endTime, startTime, endTime)
	if err != nil {
		fmt.Errorf(err.Error())
		return false
	}
	if count > 0 {
		fmt.Print(count, "\n")
		return false
	}
	return true
}

func NewListIntervalDao(transactionContext *pgTransaction.TransactionContext) (*ListIntervalDao, error) {
	if transactionContext == nil {
		return nil, fmt.Errorf("transactionContext参数不能为nil")
	} else {
		return &ListIntervalDao{
			transactionContext: transactionContext,
		}, nil
	}
}