作者 陈志颖

fix:搜索任务

... ... @@ -67,24 +67,21 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt
startTime := time.Date(createListIntervalCommand.ListIntervalStartTime.Local().Year(), createListIntervalCommand.ListIntervalStartTime.Local().Month(), createListIntervalCommand.ListIntervalStartTime.Local().Day(), 0, 0, 0, 0, time.Local)
endTime := time.Date(createListIntervalCommand.ListIntervalEndTime.Local().Year(), createListIntervalCommand.ListIntervalEndTime.Local().Month(), createListIntervalCommand.ListIntervalEndTime.Local().Day(), 23, 59, 59, 0, time.Local)
ok := listIntervalDao.RankPeriodCheckTime(startTime.UnixNano() / 1e6, endTime.UnixNano() / 1e6, 0)
if !ok {
startTimeCheck := time.Date(createListIntervalCommand.ListIntervalStartTime.Year(), createListIntervalCommand.ListIntervalStartTime.Month(), createListIntervalCommand.ListIntervalStartTime.Day(), 0, 0, 0, 0, time.UTC)
endTimeCheck := time.Date(createListIntervalCommand.ListIntervalEndTime.Year(), createListIntervalCommand.ListIntervalEndTime.Month(), createListIntervalCommand.ListIntervalEndTime.Day(), 23, 59, 59, 0, time.UTC)
ok := listIntervalDao.RankPeriodCheckTime(startTimeCheck, endTimeCheck, 0, listIntervals[0].CompanyId)
fmt.Print(ok, "\n")
if ok {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠")
}
// 判断年榜时间是否和上个年榜重叠
if len(listIntervals) > 0 {
if startTime.Before(listIntervals[0].IntervalEndTime.Local()) || startTime.Equal(listIntervals[0].IntervalEndTime.Local()){
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜开始时间必须大于上一个年榜结束时间")
} else {
// 创建排行榜时间命令
// 创建排行榜时间
newListInterval := &domain.ListInterval {
CompanyId: createListIntervalCommand.CompanyId,
IntervalStartTime: startTime,
IntervalEndTime: endTime,
}
// 保存排行榜时间
listInterval, err := listIntervalRepository.Save(newListInterval)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -92,27 +89,34 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return listInterval, nil
}
} else {
// 创建排行榜时间命令
newListInterval := &domain.ListInterval {
CompanyId: createListIntervalCommand.CompanyId,
IntervalStartTime: startTime,
IntervalEndTime: endTime,
}
// 保存排行榜时间
listInterval, err := listIntervalRepository.Save(newListInterval)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return listInterval, nil
}
// 判断年榜时间是否和上个年榜重叠
//if len(listIntervals) > 0 {
//if startTime.Before(listIntervals[0].IntervalEndTime.Local()) || startTime.Equal(listIntervals[0].IntervalEndTime.Local()){
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜开始时间必须大于上一个年榜结束时间")
//} else {
// // 创建排行榜时间命令
// newListInterval := &domain.ListInterval {
// CompanyId: createListIntervalCommand.CompanyId,
// IntervalStartTime: startTime,
// IntervalEndTime: endTime,
// }
//
// // 保存排行榜时间
// listInterval, err := listIntervalRepository.Save(newListInterval)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
//
// return listInterval, nil
//}
//} else {
//}
}
// 返回排行榜时间列表
... ... @@ -252,11 +256,15 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt
// 当前更新的开始结束时间
startTime := time.Date(updateListIntervalCommand.ListIntervalStartTime.Local().Year(), updateListIntervalCommand.ListIntervalStartTime.Local().Month(), updateListIntervalCommand.ListIntervalStartTime.Local().Day(), 0, 0, 0, 0, time.Local)
endTime := time.Date(updateListIntervalCommand.ListIntervalEndTime.Local().Year(), updateListIntervalCommand.ListIntervalEndTime.Local().Month(), updateListIntervalCommand.ListIntervalEndTime.Local().Day(), 23, 59, 59, 0, time.Local)
updateListIntervalCommand.ListIntervalStartTime = startTime
updateListIntervalCommand.ListIntervalEndTime = endTime
ok := listIntervalDao.RankPeriodCheckTime(startTime.UnixNano() / 1e6, endTime.UnixNano() / 1e6, listIntervalFound.ListIntervalId)
if !ok {
startTimeCheck := time.Date(updateListIntervalCommand.ListIntervalStartTime.Year(), updateListIntervalCommand.ListIntervalStartTime.Month(), updateListIntervalCommand.ListIntervalStartTime.Day(), 0, 0, 0, 0, time.UTC)
endTimeCheck := time.Date(updateListIntervalCommand.ListIntervalEndTime.Year(), updateListIntervalCommand.ListIntervalEndTime.Month(), updateListIntervalCommand.ListIntervalEndTime.Day(), 23, 59, 59, 0, time.UTC)
ok := listIntervalDao.RankPeriodCheckTime(startTimeCheck, endTimeCheck, listIntervalFound.ListIntervalId, listIntervalFound.CompanyId)
if ok {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠")
}
... ...
... ... @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/go-pg/pg"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"time"
)
type ListIntervalDao struct {
... ... @@ -11,32 +12,32 @@ type ListIntervalDao struct {
}
// 榜单时间管理
func (dao *ListIntervalDao) RankPeriodCheckTime(startTime int64, endTime int64, idNot int) bool {
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
cnt, err := tx.Query(
_, err := tx.Query(
pg.Scan(),
`SELECT count(*) FROM list_interval
`SELECT count(*) FROM list_intervals
WHERE id <> ?
AND company_id = ?
AND
(
(UNIX_TIMESTAMP(start_time) BETWEEN ? AND ?)
(list_interval_start_time BETWEEN ? AND ?)
OR
(UNIX_TIMESTAMP(end_time) BETWEEN ? AND ?)
(list_interval_end_time BETWEEN ? AND ?)
OR
(? BETWEEN CAST(list_interval_start_time AS TIMESTAMP) AND CAST(list_interval_end_time AS TIMESTAMP))
(? BETWEEN list_interval_start_time AND list_interval_end_time)
OR
(? BETWEEN CAST(list_interval_start_time AS TIMESTAMP) AND CAST(list_interval_end_time AS TIMESTAMP))
(? BETWEEN list_interval_start_time AND list_interval_end_time)
)
LIMIT 1 `,
idNot, startTime, endTime, startTime, endTime, startTime, endTime)
idNot, companyId, startTime, endTime, startTime, endTime, startTime, endTime)
if err != nil {
fmt.Errorf(err.Error())
return false
return true
}
if cnt != nil {
return false
}
return true
}
func NewListIntervalDao(transactionContext *pgTransaction.TransactionContext) (*ListIntervalDao, error) {
... ...
... ... @@ -131,7 +131,7 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int
// }
// return q, nil
//})
query = query.Where(`task.task_status IN (?)`, pg.In(taskStatuss.([]int64)))
query = query.Where(`task.task_status IN (?)`, pg.In(taskStatuss.([]int)))
}
if taskType, ok := queryOptions["taskType"]; ok && (taskType != 0) {
query = query.Where(`task.task_type = ?`, taskType)
... ...