作者 陈志颖

fix:搜索任务

@@ -67,52 +67,56 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt @@ -67,52 +67,56 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt
67 startTime := time.Date(createListIntervalCommand.ListIntervalStartTime.Local().Year(), createListIntervalCommand.ListIntervalStartTime.Local().Month(), createListIntervalCommand.ListIntervalStartTime.Local().Day(), 0, 0, 0, 0, time.Local) 67 startTime := time.Date(createListIntervalCommand.ListIntervalStartTime.Local().Year(), createListIntervalCommand.ListIntervalStartTime.Local().Month(), createListIntervalCommand.ListIntervalStartTime.Local().Day(), 0, 0, 0, 0, time.Local)
68 endTime := time.Date(createListIntervalCommand.ListIntervalEndTime.Local().Year(), createListIntervalCommand.ListIntervalEndTime.Local().Month(), createListIntervalCommand.ListIntervalEndTime.Local().Day(), 23, 59, 59, 0, time.Local) 68 endTime := time.Date(createListIntervalCommand.ListIntervalEndTime.Local().Year(), createListIntervalCommand.ListIntervalEndTime.Local().Month(), createListIntervalCommand.ListIntervalEndTime.Local().Day(), 23, 59, 59, 0, time.Local)
69 69
70 - ok := listIntervalDao.RankPeriodCheckTime(startTime.UnixNano() / 1e6, endTime.UnixNano() / 1e6, 0)  
71 - if !ok { 70 + startTimeCheck := time.Date(createListIntervalCommand.ListIntervalStartTime.Year(), createListIntervalCommand.ListIntervalStartTime.Month(), createListIntervalCommand.ListIntervalStartTime.Day(), 0, 0, 0, 0, time.UTC)
  71 + endTimeCheck := time.Date(createListIntervalCommand.ListIntervalEndTime.Year(), createListIntervalCommand.ListIntervalEndTime.Month(), createListIntervalCommand.ListIntervalEndTime.Day(), 23, 59, 59, 0, time.UTC)
  72 +
  73 + ok := listIntervalDao.RankPeriodCheckTime(startTimeCheck, endTimeCheck, 0, listIntervals[0].CompanyId)
  74 + fmt.Print(ok, "\n")
  75 + if ok {
72 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠") 76 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠")
73 } 77 }
74 78
  79 + // 创建排行榜时间
  80 + newListInterval := &domain.ListInterval {
  81 + CompanyId: createListIntervalCommand.CompanyId,
  82 + IntervalStartTime: startTime,
  83 + IntervalEndTime: endTime,
  84 + }
  85 + listInterval, err := listIntervalRepository.Save(newListInterval)
  86 + if err != nil {
  87 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  88 + }
  89 + if err := transactionContext.CommitTransaction(); err != nil {
  90 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  91 + }
  92 + return listInterval, nil
  93 +
75 // 判断年榜时间是否和上个年榜重叠 94 // 判断年榜时间是否和上个年榜重叠
76 - if len(listIntervals) > 0 {  
77 - if startTime.Before(listIntervals[0].IntervalEndTime.Local()) || startTime.Equal(listIntervals[0].IntervalEndTime.Local()){  
78 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜开始时间必须大于上一个年榜结束时间")  
79 - } else {  
80 - // 创建排行榜时间命令  
81 - newListInterval := &domain.ListInterval {  
82 - CompanyId: createListIntervalCommand.CompanyId,  
83 - IntervalStartTime: startTime,  
84 - IntervalEndTime: endTime,  
85 - }  
86 -  
87 - // 保存排行榜时间  
88 - listInterval, err := listIntervalRepository.Save(newListInterval)  
89 - if err != nil {  
90 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
91 - }  
92 - if err := transactionContext.CommitTransaction(); err != nil {  
93 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
94 - }  
95 -  
96 - return listInterval, nil  
97 - }  
98 - } else {  
99 - // 创建排行榜时间命令  
100 - newListInterval := &domain.ListInterval {  
101 - CompanyId: createListIntervalCommand.CompanyId,  
102 - IntervalStartTime: startTime,  
103 - IntervalEndTime: endTime,  
104 - } 95 + //if len(listIntervals) > 0 {
  96 + //if startTime.Before(listIntervals[0].IntervalEndTime.Local()) || startTime.Equal(listIntervals[0].IntervalEndTime.Local()){
  97 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜开始时间必须大于上一个年榜结束时间")
  98 + //} else {
  99 + // // 创建排行榜时间命令
  100 + // newListInterval := &domain.ListInterval {
  101 + // CompanyId: createListIntervalCommand.CompanyId,
  102 + // IntervalStartTime: startTime,
  103 + // IntervalEndTime: endTime,
  104 + // }
  105 + //
  106 + // // 保存排行榜时间
  107 + // listInterval, err := listIntervalRepository.Save(newListInterval)
  108 + // if err != nil {
  109 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  110 + // }
  111 + // if err := transactionContext.CommitTransaction(); err != nil {
  112 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  113 + // }
  114 + //
  115 + // return listInterval, nil
  116 + //}
  117 + //} else {
105 118
106 - // 保存排行榜时间  
107 - listInterval, err := listIntervalRepository.Save(newListInterval)  
108 - if err != nil {  
109 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
110 - }  
111 - if err := transactionContext.CommitTransaction(); err != nil {  
112 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
113 - }  
114 - return listInterval, nil  
115 - } 119 + //}
116 } 120 }
117 121
118 // 返回排行榜时间列表 122 // 返回排行榜时间列表
@@ -252,11 +256,15 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt @@ -252,11 +256,15 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt
252 // 当前更新的开始结束时间 256 // 当前更新的开始结束时间
253 startTime := time.Date(updateListIntervalCommand.ListIntervalStartTime.Local().Year(), updateListIntervalCommand.ListIntervalStartTime.Local().Month(), updateListIntervalCommand.ListIntervalStartTime.Local().Day(), 0, 0, 0, 0, time.Local) 257 startTime := time.Date(updateListIntervalCommand.ListIntervalStartTime.Local().Year(), updateListIntervalCommand.ListIntervalStartTime.Local().Month(), updateListIntervalCommand.ListIntervalStartTime.Local().Day(), 0, 0, 0, 0, time.Local)
254 endTime := time.Date(updateListIntervalCommand.ListIntervalEndTime.Local().Year(), updateListIntervalCommand.ListIntervalEndTime.Local().Month(), updateListIntervalCommand.ListIntervalEndTime.Local().Day(), 23, 59, 59, 0, time.Local) 258 endTime := time.Date(updateListIntervalCommand.ListIntervalEndTime.Local().Year(), updateListIntervalCommand.ListIntervalEndTime.Local().Month(), updateListIntervalCommand.ListIntervalEndTime.Local().Day(), 23, 59, 59, 0, time.Local)
  259 +
255 updateListIntervalCommand.ListIntervalStartTime = startTime 260 updateListIntervalCommand.ListIntervalStartTime = startTime
256 updateListIntervalCommand.ListIntervalEndTime = endTime 261 updateListIntervalCommand.ListIntervalEndTime = endTime
257 262
258 - ok := listIntervalDao.RankPeriodCheckTime(startTime.UnixNano() / 1e6, endTime.UnixNano() / 1e6, listIntervalFound.ListIntervalId)  
259 - if !ok { 263 + startTimeCheck := time.Date(updateListIntervalCommand.ListIntervalStartTime.Year(), updateListIntervalCommand.ListIntervalStartTime.Month(), updateListIntervalCommand.ListIntervalStartTime.Day(), 0, 0, 0, 0, time.UTC)
  264 + endTimeCheck := time.Date(updateListIntervalCommand.ListIntervalEndTime.Year(), updateListIntervalCommand.ListIntervalEndTime.Month(), updateListIntervalCommand.ListIntervalEndTime.Day(), 23, 59, 59, 0, time.UTC)
  265 +
  266 + ok := listIntervalDao.RankPeriodCheckTime(startTimeCheck, endTimeCheck, listIntervalFound.ListIntervalId, listIntervalFound.CompanyId)
  267 + if ok {
260 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠") 268 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠")
261 } 269 }
262 270
@@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
4 "fmt" 4 "fmt"
5 "github.com/go-pg/pg" 5 "github.com/go-pg/pg"
6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  7 + "time"
7 ) 8 )
8 9
9 type ListIntervalDao struct { 10 type ListIntervalDao struct {
@@ -11,32 +12,32 @@ type ListIntervalDao struct { @@ -11,32 +12,32 @@ type ListIntervalDao struct {
11 } 12 }
12 13
13 // 榜单时间管理 14 // 榜单时间管理
14 -func (dao *ListIntervalDao) RankPeriodCheckTime(startTime int64, endTime int64, idNot int) bool { 15 +func (dao *ListIntervalDao) RankPeriodCheckTime(startTime time.Time, endTime time.Time, idNot int, companyId int) bool {
  16 + fmt.Print(startTime, "\n")
  17 + fmt.Print(endTime, "\n")
15 tx := dao.transactionContext.PgTx 18 tx := dao.transactionContext.PgTx
16 - cnt, err := tx.Query( 19 + _, err := tx.Query(
17 pg.Scan(), 20 pg.Scan(),
18 - `SELECT count(*) FROM list_interval 21 + `SELECT count(*) FROM list_intervals
19 WHERE id <> ? 22 WHERE id <> ?
  23 + AND company_id = ?
20 AND 24 AND
21 ( 25 (
22 - (UNIX_TIMESTAMP(start_time) BETWEEN ? AND ?) 26 + (list_interval_start_time BETWEEN ? AND ?)
23 OR 27 OR
24 - (UNIX_TIMESTAMP(end_time) BETWEEN ? AND ?) 28 + (list_interval_end_time BETWEEN ? AND ?)
25 OR 29 OR
26 - (? BETWEEN CAST(list_interval_start_time AS TIMESTAMP) AND CAST(list_interval_end_time AS TIMESTAMP)) 30 + (? BETWEEN list_interval_start_time AND list_interval_end_time)
27 OR 31 OR
28 - (? BETWEEN CAST(list_interval_start_time AS TIMESTAMP) AND CAST(list_interval_end_time AS TIMESTAMP)) 32 + (? BETWEEN list_interval_start_time AND list_interval_end_time)
29 ) 33 )
30 LIMIT 1 `, 34 LIMIT 1 `,
31 - idNot, startTime, endTime, startTime, endTime, startTime, endTime) 35 + idNot, companyId, startTime, endTime, startTime, endTime, startTime, endTime)
32 if err != nil { 36 if err != nil {
33 fmt.Errorf(err.Error()) 37 fmt.Errorf(err.Error())
34 - return false 38 + return true
35 } 39 }
36 - if cnt != nil {  
37 - return false  
38 - }  
39 - return true 40 + return false
40 } 41 }
41 42
42 func NewListIntervalDao(transactionContext *pgTransaction.TransactionContext) (*ListIntervalDao, error) { 43 func NewListIntervalDao(transactionContext *pgTransaction.TransactionContext) (*ListIntervalDao, error) {
@@ -131,7 +131,7 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int @@ -131,7 +131,7 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int
131 // } 131 // }
132 // return q, nil 132 // return q, nil
133 //}) 133 //})
134 - query = query.Where(`task.task_status IN (?)`, pg.In(taskStatuss.([]int64))) 134 + query = query.Where(`task.task_status IN (?)`, pg.In(taskStatuss.([]int)))
135 } 135 }
136 if taskType, ok := queryOptions["taskType"]; ok && (taskType != 0) { 136 if taskType, ok := queryOptions["taskType"]; ok && (taskType != 0) {
137 query = query.Where(`task.task_type = ?`, taskType) 137 query = query.Where(`task.task_type = ?`, taskType)