pg_list_interval_dao.go 1.6 KB
package dao

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

type ListIntervalDao struct {
	transactionContext *pgTransaction.TransactionContext
}

// 榜单时间管理
func (dao *ListIntervalDao) RankPeriodCheckTime(startTime time.Time, endTime time.Time, idNot int, companyId int) bool {
	fmt.Print(startTime, "\n")
	fmt.Print(endTime, "\n")
	tx := dao.transactionContext.PgTx
	_, err := tx.Query(
		pg.Scan(),
		`SELECT count(*) FROM list_intervals
			WHERE id <> ?
			AND company_id = ?
			AND 
			(
			( to_char(list_interval_start_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') BETWEEN ? AND ?) 
			OR 
			( to_char(list_interval_end_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') BETWEEN ? AND ?) 
			OR
			(? BETWEEN to_char(list_interval_start_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AND to_char(list_interval_end_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS')) 
			OR
			(? BETWEEN to_char(list_interval_start_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AND to_char(list_interval_end_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS')) 
			)
			LIMIT 1 `,
		idNot, companyId, startTime, endTime, startTime, endTime, startTime, endTime)
	if err != nil {
		fmt.Errorf(err.Error())
		fmt.Print(err.Error(), "\n")
		return true
	}
	return false
}

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