|
@@ -40,22 +40,54 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt |
|
@@ -40,22 +40,54 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt |
40
|
}
|
40
|
}
|
41
|
|
41
|
|
42
|
// 获取当前最新排行榜时间
|
42
|
// 获取当前最新排行榜时间
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
- // 判断排行榜时间是否重叠
|
|
|
46
|
-
|
|
|
47
|
-
|
|
|
48
|
- // 创建排行榜时间命令
|
|
|
49
|
- newListInterval := &domain.ListInterval {
|
43
|
+ listListIntervalQuery := &query.ListListIntervalQuery {
|
50
|
CompanyId: createListIntervalCommand.CompanyId,
|
44
|
CompanyId: createListIntervalCommand.CompanyId,
|
51
|
- IntervalStartTime: createListIntervalCommand.ListIntervalStartTime,
|
|
|
52
|
- IntervalEndTime: createListIntervalCommand.ListIntervalEndTime,
|
45
|
+ Offset: 0,
|
|
|
46
|
+ Limit: 1,
|
53
|
}
|
47
|
}
|
54
|
|
48
|
|
55
|
- // 保存排行榜时间
|
|
|
56
|
- if listInterval, err := listIntervalRepository.Save(newListInterval); err != nil {
|
49
|
+ // 获取上个年榜时间
|
|
|
50
|
+ _, listIntervals, err := listIntervalRepository.Find(tool_funs.SimpleStructToMap(listListIntervalQuery))
|
|
|
51
|
+ if err != nil {
|
57
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
52
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
53
|
+ }
|
|
|
54
|
+
|
|
|
55
|
+ // 判断年榜时间是否和上个年榜重叠
|
|
|
56
|
+ if len(listIntervals) > 0 {
|
|
|
57
|
+ if createListIntervalCommand.ListIntervalStartTime.Before(listIntervals[0].IntervalEndTime) {
|
|
|
58
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜开始时间必须大于上一个年榜结束时间")
|
|
|
59
|
+ } else {
|
|
|
60
|
+ // 创建排行榜时间命令
|
|
|
61
|
+ newListInterval := &domain.ListInterval {
|
|
|
62
|
+ CompanyId: createListIntervalCommand.CompanyId,
|
|
|
63
|
+ IntervalStartTime: createListIntervalCommand.ListIntervalStartTime,
|
|
|
64
|
+ IntervalEndTime: createListIntervalCommand.ListIntervalEndTime,
|
|
|
65
|
+ }
|
|
|
66
|
+
|
|
|
67
|
+ // 保存排行榜时间
|
|
|
68
|
+ listInterval, err := listIntervalRepository.Save(newListInterval)
|
|
|
69
|
+ if err != nil {
|
|
|
70
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
71
|
+ }
|
|
|
72
|
+ if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
73
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
74
|
+ }
|
|
|
75
|
+
|
|
|
76
|
+ return listInterval, nil
|
|
|
77
|
+ }
|
58
|
} else {
|
78
|
} else {
|
|
|
79
|
+ // 创建排行榜时间命令
|
|
|
80
|
+ newListInterval := &domain.ListInterval {
|
|
|
81
|
+ CompanyId: createListIntervalCommand.CompanyId,
|
|
|
82
|
+ IntervalStartTime: createListIntervalCommand.ListIntervalStartTime,
|
|
|
83
|
+ IntervalEndTime: createListIntervalCommand.ListIntervalEndTime,
|
|
|
84
|
+ }
|
|
|
85
|
+
|
|
|
86
|
+ // 保存排行榜时间
|
|
|
87
|
+ listInterval, err := listIntervalRepository.Save(newListInterval)
|
|
|
88
|
+ if err != nil {
|
|
|
89
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
90
|
+ }
|
59
|
if err := transactionContext.CommitTransaction(); err != nil {
|
91
|
if err := transactionContext.CommitTransaction(); err != nil {
|
60
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
92
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
61
|
}
|
93
|
}
|