|
@@ -8,6 +8,7 @@ import ( |
|
@@ -8,6 +8,7 @@ import ( |
8
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/command"
|
8
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/command"
|
9
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/query"
|
9
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/listInterval/query"
|
10
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
|
10
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
|
|
|
11
|
+ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
|
11
|
"time"
|
12
|
"time"
|
12
|
)
|
13
|
)
|
13
|
|
14
|
|
|
@@ -40,6 +41,16 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt |
|
@@ -40,6 +41,16 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt |
40
|
listIntervalRepository = value
|
41
|
listIntervalRepository = value
|
41
|
}
|
42
|
}
|
42
|
|
43
|
|
|
|
44
|
+ // 排行榜管理DAO初始化
|
|
|
45
|
+ var listIntervalDao *dao.ListIntervalDao
|
|
|
46
|
+ if value, err := factory.CreateListIntervalDao(map[string]interface{}{
|
|
|
47
|
+ "transactionContext": transactionContext,
|
|
|
48
|
+ }); err != nil {
|
|
|
49
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
50
|
+ } else {
|
|
|
51
|
+ listIntervalDao = value
|
|
|
52
|
+ }
|
|
|
53
|
+
|
43
|
// 获取当前最新排行榜时间
|
54
|
// 获取当前最新排行榜时间
|
44
|
listListIntervalQuery := &query.ListListIntervalQuery {
|
55
|
listListIntervalQuery := &query.ListListIntervalQuery {
|
45
|
CompanyId: createListIntervalCommand.CompanyId,
|
56
|
CompanyId: createListIntervalCommand.CompanyId,
|
|
@@ -56,6 +67,10 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt |
|
@@ -56,6 +67,10 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt |
56
|
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)
|
57
|
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)
|
58
|
|
69
|
|
|
|
70
|
+ ok := listIntervalDao.RankPeriodCheckTime(startTime.UnixNano() / 1e6, endTime.UnixNano() / 1e6, 0)
|
|
|
71
|
+ if !ok {
|
|
|
72
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠")
|
|
|
73
|
+ }
|
59
|
|
74
|
|
60
|
// 判断年榜时间是否和上个年榜重叠
|
75
|
// 判断年榜时间是否和上个年榜重叠
|
61
|
if len(listIntervals) > 0 {
|
76
|
if len(listIntervals) > 0 {
|
|
@@ -193,6 +208,7 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt |
|
@@ -193,6 +208,7 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt |
193
|
transactionContext.RollbackTransaction()
|
208
|
transactionContext.RollbackTransaction()
|
194
|
}()
|
209
|
}()
|
195
|
|
210
|
|
|
|
211
|
+ // 排行榜管理仓储初始化
|
196
|
var listIntervalRepository domain.ListIntervalRepository
|
212
|
var listIntervalRepository domain.ListIntervalRepository
|
197
|
if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
|
213
|
if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
|
198
|
"transactionContext": transactionContext,
|
214
|
"transactionContext": transactionContext,
|
|
@@ -202,6 +218,16 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt |
|
@@ -202,6 +218,16 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt |
202
|
listIntervalRepository = value
|
218
|
listIntervalRepository = value
|
203
|
}
|
219
|
}
|
204
|
|
220
|
|
|
|
221
|
+ // 排行榜管理DAO初始化
|
|
|
222
|
+ var listIntervalDao *dao.ListIntervalDao
|
|
|
223
|
+ if value, err := factory.CreateListIntervalDao(map[string]interface{}{
|
|
|
224
|
+ "transactionContext": transactionContext,
|
|
|
225
|
+ }); err != nil {
|
|
|
226
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
227
|
+ } else {
|
|
|
228
|
+ listIntervalDao = value
|
|
|
229
|
+ }
|
|
|
230
|
+
|
205
|
// 获取当前年榜
|
231
|
// 获取当前年榜
|
206
|
listIntervalFound, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": updateListIntervalCommand.ListIntervalId})
|
232
|
listIntervalFound, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": updateListIntervalCommand.ListIntervalId})
|
207
|
if err != nil {
|
233
|
if err != nil {
|
|
@@ -211,64 +237,28 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt |
|
@@ -211,64 +237,28 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt |
211
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateListIntervalCommand.ListIntervalId)))
|
237
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateListIntervalCommand.ListIntervalId)))
|
212
|
}
|
238
|
}
|
213
|
|
239
|
|
214
|
- // 获取榜单命令
|
|
|
215
|
- listListIntervalQuery := &query.ListListIntervalQuery {
|
|
|
216
|
- CompanyId: listIntervalFound.CompanyId,
|
|
|
217
|
- }
|
|
|
218
|
-
|
|
|
219
|
- //获取所有年榜
|
|
|
220
|
- _, listIntervals, err := listIntervalRepository.Find(tool_funs.SimpleStructToMap(listListIntervalQuery))
|
|
|
221
|
- if err != nil {
|
|
|
222
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
223
|
- }
|
|
|
224
|
-
|
|
|
225
|
- var currentListIntervalIndex int
|
240
|
+ //// 获取所有年榜
|
|
|
241
|
+ //listListIntervalQuery := &query.ListListIntervalQuery {
|
|
|
242
|
+ // CompanyId: listIntervalFound.CompanyId,
|
|
|
243
|
+ //}
|
|
|
244
|
+ ////获取所有年榜
|
|
|
245
|
+ //_, listIntervals, err := listIntervalRepository.Find(tool_funs.SimpleStructToMap(listListIntervalQuery))
|
|
|
246
|
+ //if err != nil {
|
|
|
247
|
+ // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
248
|
+ //}
|
|
|
249
|
+ //
|
|
|
250
|
+ //var currentListIntervalIndex int
|
226
|
|
251
|
|
227
|
// 当前更新的开始结束时间
|
252
|
// 当前更新的开始结束时间
|
228
|
startTime := time.Date(updateListIntervalCommand.ListIntervalStartTime.Local().Year(), updateListIntervalCommand.ListIntervalStartTime.Local().Month(), updateListIntervalCommand.ListIntervalStartTime.Local().Day(), 0, 0, 0, 0, time.Local)
|
253
|
startTime := time.Date(updateListIntervalCommand.ListIntervalStartTime.Local().Year(), updateListIntervalCommand.ListIntervalStartTime.Local().Month(), updateListIntervalCommand.ListIntervalStartTime.Local().Day(), 0, 0, 0, 0, time.Local)
|
229
|
endTime := time.Date(updateListIntervalCommand.ListIntervalEndTime.Local().Year(), updateListIntervalCommand.ListIntervalEndTime.Local().Month(), updateListIntervalCommand.ListIntervalEndTime.Local().Day(), 23, 59, 59, 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)
|
230
|
-
|
|
|
231
|
updateListIntervalCommand.ListIntervalStartTime = startTime
|
255
|
updateListIntervalCommand.ListIntervalStartTime = startTime
|
232
|
updateListIntervalCommand.ListIntervalEndTime = endTime
|
256
|
updateListIntervalCommand.ListIntervalEndTime = endTime
|
233
|
|
257
|
|
234
|
- // 判断年榜时间是否和上个年榜重叠
|
|
|
235
|
- if len(listIntervals) > 0 {
|
|
|
236
|
-
|
|
|
237
|
- // 找到当前排行榜所处位置
|
|
|
238
|
- for i, listInterval := range listIntervals {
|
|
|
239
|
- if listInterval.ListIntervalId == listIntervalFound.ListIntervalId {
|
|
|
240
|
- currentListIntervalIndex = i
|
|
|
241
|
- }
|
|
|
242
|
- }
|
|
|
243
|
-
|
|
|
244
|
- if currentListIntervalIndex == 0 && len(listIntervals) > 1 { // 当前排行榜在首位,且不止一个活动
|
|
|
245
|
- // 上一个活动开始结束时间
|
|
|
246
|
- //lastIntervalStartTime := listIntervals[currentListIntervalIndex + 1].IntervalStartTime.Local()
|
|
|
247
|
- lastIntervalEndTime := listIntervals[currentListIntervalIndex + 1].IntervalEndTime.Local()
|
|
|
248
|
-
|
|
|
249
|
- if startTime.Before(lastIntervalEndTime) || startTime.Equal(lastIntervalEndTime) { // 开始时间重叠判断
|
258
|
+ ok := listIntervalDao.RankPeriodCheckTime(startTime.UnixNano() / 1e6, endTime.UnixNano() / 1e6, listIntervalFound.ListIntervalId)
|
|
|
259
|
+ if !ok {
|
250
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠")
|
260
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠")
|
251
|
}
|
261
|
}
|
252
|
- } else if currentListIntervalIndex != 0 { // 当前排行榜不在首位
|
|
|
253
|
- fmt.Print(currentListIntervalIndex, "\n")
|
|
|
254
|
-
|
|
|
255
|
- // 上一个年榜开始结束时间
|
|
|
256
|
- lastIntervalStartTime := listIntervals[currentListIntervalIndex + 1].IntervalStartTime.Local()
|
|
|
257
|
- lastIntervalEndTime := listIntervals[currentListIntervalIndex + 1].IntervalEndTime.Local()
|
|
|
258
|
- fmt.Print(lastIntervalEndTime,"\n")
|
|
|
259
|
-
|
|
|
260
|
- // 下一个年榜开始结束时间
|
|
|
261
|
- nextIntervalStartTime := listIntervals[currentListIntervalIndex - 1].IntervalStartTime.Local()
|
|
|
262
|
- fmt.Print(nextIntervalStartTime, "\n")
|
|
|
263
|
- nextIntervalEndTime := listIntervals[currentListIntervalIndex - 1].IntervalEndTime.Local()
|
|
|
264
|
-
|
|
|
265
|
- fmt.Print(startTime, "\n")
|
|
|
266
|
- fmt.Print(endTime, "\n")
|
|
|
267
|
-
|
|
|
268
|
- if startTime.After(lastIntervalStartTime) && startTime.Before(lastIntervalEndTime) || endTime.After(nextIntervalStartTime) && endTime.Before(nextIntervalEndTime) {
|
|
|
269
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠")
|
|
|
270
|
- }
|
|
|
271
|
- }
|
|
|
272
|
|
262
|
|
273
|
if err := listIntervalFound.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil {
|
263
|
if err := listIntervalFound.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil {
|
274
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
264
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
@@ -281,19 +271,69 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt |
|
@@ -281,19 +271,69 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt |
281
|
}
|
271
|
}
|
282
|
return listIntervalUpdated, nil
|
272
|
return listIntervalUpdated, nil
|
283
|
}
|
273
|
}
|
284
|
- } else { // 正常更新
|
|
|
285
|
- if err := listIntervalFound.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil {
|
|
|
286
|
- return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
287
|
- }
|
|
|
288
|
- if listIntervalUpdated, err := listIntervalRepository.Save(listIntervalFound); err != nil {
|
|
|
289
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
290
|
- } else {
|
|
|
291
|
- if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
292
|
- return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
293
|
- }
|
|
|
294
|
- return listIntervalUpdated, nil
|
|
|
295
|
- }
|
|
|
296
|
- }
|
274
|
+
|
|
|
275
|
+ // 判断年榜时间是否和上个年榜重叠
|
|
|
276
|
+ //if len(listIntervals) > 0 {
|
|
|
277
|
+ // // 找到当前排行榜所处位置
|
|
|
278
|
+ // for i, listInterval := range listIntervals {
|
|
|
279
|
+ // if listInterval.ListIntervalId == listIntervalFound.ListIntervalId {
|
|
|
280
|
+ // currentListIntervalIndex = i
|
|
|
281
|
+ // }
|
|
|
282
|
+ // }
|
|
|
283
|
+ //
|
|
|
284
|
+ // if currentListIntervalIndex == 0 && len(listIntervals) > 1 { // 当前排行榜在首位,且不止一个活动
|
|
|
285
|
+ // // 上一个活动开始结束时间
|
|
|
286
|
+ // //lastIntervalStartTime := listIntervals[currentListIntervalIndex + 1].IntervalStartTime.Local()
|
|
|
287
|
+ // lastIntervalEndTime := listIntervals[currentListIntervalIndex + 1].IntervalEndTime.Local()
|
|
|
288
|
+ //
|
|
|
289
|
+ // if startTime.Before(lastIntervalEndTime) || startTime.Equal(lastIntervalEndTime) { // 开始时间重叠判断
|
|
|
290
|
+ // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠")
|
|
|
291
|
+ // }
|
|
|
292
|
+ // } else if currentListIntervalIndex != 0 { // 当前排行榜不在首位
|
|
|
293
|
+ // fmt.Print(currentListIntervalIndex, "\n")
|
|
|
294
|
+ //
|
|
|
295
|
+ // // 上一个年榜开始结束时间
|
|
|
296
|
+ // lastIntervalStartTime := listIntervals[currentListIntervalIndex + 1].IntervalStartTime.Local()
|
|
|
297
|
+ // lastIntervalEndTime := listIntervals[currentListIntervalIndex + 1].IntervalEndTime.Local()
|
|
|
298
|
+ // fmt.Print(lastIntervalEndTime,"\n")
|
|
|
299
|
+ //
|
|
|
300
|
+ // // 下一个年榜开始结束时间
|
|
|
301
|
+ // nextIntervalStartTime := listIntervals[currentListIntervalIndex - 1].IntervalStartTime.Local()
|
|
|
302
|
+ // fmt.Print(nextIntervalStartTime, "\n")
|
|
|
303
|
+ // nextIntervalEndTime := listIntervals[currentListIntervalIndex - 1].IntervalEndTime.Local()
|
|
|
304
|
+ //
|
|
|
305
|
+ // fmt.Print(startTime, "\n")
|
|
|
306
|
+ // fmt.Print(endTime, "\n")
|
|
|
307
|
+ //
|
|
|
308
|
+ // if startTime.After(lastIntervalStartTime) && startTime.Before(lastIntervalEndTime) || endTime.After(nextIntervalStartTime) && endTime.Before(nextIntervalEndTime) {
|
|
|
309
|
+ // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠")
|
|
|
310
|
+ // }
|
|
|
311
|
+ // }
|
|
|
312
|
+ //
|
|
|
313
|
+ // if err := listIntervalFound.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil {
|
|
|
314
|
+ // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
315
|
+ // }
|
|
|
316
|
+ // if listIntervalUpdated, err := listIntervalRepository.Save(listIntervalFound); err != nil {
|
|
|
317
|
+ // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
318
|
+ // } else {
|
|
|
319
|
+ // if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
320
|
+ // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
321
|
+ // }
|
|
|
322
|
+ // return listIntervalUpdated, nil
|
|
|
323
|
+ // }
|
|
|
324
|
+ //} else { // 正常更新
|
|
|
325
|
+ // if err := listIntervalFound.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil {
|
|
|
326
|
+ // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
327
|
+ // }
|
|
|
328
|
+ // if listIntervalUpdated, err := listIntervalRepository.Save(listIntervalFound); err != nil {
|
|
|
329
|
+ // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
330
|
+ // } else {
|
|
|
331
|
+ // if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
332
|
+ // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
333
|
+ // }
|
|
|
334
|
+ // return listIntervalUpdated, nil
|
|
|
335
|
+ // }
|
|
|
336
|
+ //}
|
297
|
}
|
337
|
}
|
298
|
|
338
|
|
299
|
// 移除排行榜时间
|
339
|
// 移除排行榜时间
|