pg_list_interval_dao.go 1.3 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) bool {
	tx := dao.transactionContext.PgTx
	cnt, err := tx.Query(
		pg.Scan(),
		`SELECT count(*) FROM list_interval
			WHERE id <> ?
			AND 
			(
			(UNIX_TIMESTAMP(start_time) BETWEEN ? AND ?) 
			OR 
			(UNIX_TIMESTAMP(end_time) BETWEEN ? AND ?) 
			OR
			(? BETWEEN CAST(list_interval_start_time AS TIMESTAMP) AND CAST(list_interval_end_time AS TIMESTAMP)) 
			OR
			(? BETWEEN CAST(list_interval_start_time AS TIMESTAMP) AND CAST(list_interval_end_time AS TIMESTAMP)) 
			)
			LIMIT 1 `,
		idNot, startTime, endTime, startTime, endTime, startTime, endTime)
	if err != nil {
		fmt.Errorf(err.Error())
		return false
	}
	if cnt != nil {
		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
	}
}