|
|
@@ -31,65 +31,39 @@ public class OpenSubscribedTask implements SchedulingConfigurer {
|
|
|
|
|
|
@Override
|
|
|
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
|
|
- taskRegistrar.addTriggerTask(() -> {
|
|
|
- b:
|
|
|
- if (Collections.isEmpty(collections)){
|
|
|
- return;
|
|
|
- }else {
|
|
|
- for (Collection collection : collections) {
|
|
|
- if (collection.getStartTime().isBefore(LocalDateTime.now()) && collection.getStartTime().isBefore(LocalDateTime.now().minusSeconds(2))){
|
|
|
- collectionRepo.setState(collection.getId(),"OPENSUBSCRIBE");
|
|
|
- collections.remove(0);
|
|
|
- break b;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-// //获取当前时间
|
|
|
-// LocalDateTime startTime = LocalDateTime.now().minusMinutes(1);
|
|
|
-// //获取四分钟以后的时间
|
|
|
-// LocalDateTime endTime = startTime.plusMinutes(4);
|
|
|
-// //根据开始时间和结束时间去数据库把这两个时间段中 符合的预约发布时间中获取藏品
|
|
|
-// List<Collection> collectionList = collectionRepo.selectOpenSubscribe(startTime, endTime);
|
|
|
-// //判断获取的藏品列表是否为空
|
|
|
-// if (Collections.isEmpty(collectionList)){
|
|
|
+// taskRegistrar.addTriggerTask(() -> {
|
|
|
+// b:
|
|
|
+// if (Collections.isEmpty(collections)){
|
|
|
// return;
|
|
|
-// }
|
|
|
-// collectionList.forEach(collection -> {
|
|
|
-// if (collection.getStartTime().isBefore(LocalDateTime.now()) || collection.getEndTime().isAfter(LocalDateTime.now())){
|
|
|
+// }else {
|
|
|
+// for (Collection collection : collections) {
|
|
|
+// if (collection.getStartTime().isBefore(LocalDateTime.now()) && collection.getStartTime().isBefore(LocalDateTime.now().minusSeconds(2))){
|
|
|
+// collectionRepo.setState(collection.getId(),"OPENSUBSCRIBE");
|
|
|
+// collections.remove(0);
|
|
|
+// break b;
|
|
|
+// }
|
|
|
// }
|
|
|
-//// if (collection.getEndTime().isBefore(LocalDateTime.now()) && collection.getPublishTime().isAfter(LocalDateTime.now())){
|
|
|
-//// collectionRepo.setState(collection.getId(),"CLOSESUBSCRIBE");
|
|
|
-//// }
|
|
|
-//// if (collection.getPublishTime().isBefore(LocalDateTime.now()) && collection.getPurchaseTime().isAfter(LocalDateTime.now())){
|
|
|
-//// collectionRepo.setState(collection.getId(),"PUBLISH");
|
|
|
-//// }
|
|
|
-//// if (collection.getPurchaseTime().isBefore(LocalDateTime.now())){
|
|
|
-//// collectionRepo.setState(collection.getId(),"PURCHASE");
|
|
|
-//// }
|
|
|
-// if (!Collections.isEmpty(collections)){
|
|
|
-// collections.remove(0);
|
|
|
+// }
|
|
|
+// }, triggerContext -> {
|
|
|
+// if (Collections.isEmpty(collections)){
|
|
|
+// //首先获取当前时间
|
|
|
+//// LocalDateTime startTime = LocalDateTime.now().minusMinutes(1);
|
|
|
+// LocalDateTime startTime = LocalDateTime.now();
|
|
|
+// //获取四分钟以后的时间
|
|
|
+// LocalDateTime endTime = startTime.plusMinutes(4);
|
|
|
+// //根据开始时间和结束时间去数据库把这两个时间段中 符合的预约发布时间中获取藏品
|
|
|
+// List<Collection> collectionList = collectionRepo.findAllByStartTimeGreaterThanEqual(startTime);
|
|
|
+// //判断获取的藏品列表是否为空
|
|
|
+// if (Collections.isEmpty(collectionList)) {
|
|
|
+//// return new CronTrigger("0 0/10 * * * ?").nextExecutionTime(triggerContext);
|
|
|
+// //藏品列表为空 则设置下次的时间查询为结束时间的前30秒 前10秒 前10
|
|
|
+// return Date.from(endTime.minusSeconds(5).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
// }
|
|
|
-// });
|
|
|
- }, triggerContext -> {
|
|
|
- if (Collections.isEmpty(collections)){
|
|
|
- //首先获取当前时间
|
|
|
-// LocalDateTime startTime = LocalDateTime.now().minusMinutes(1);
|
|
|
- LocalDateTime startTime = LocalDateTime.now();
|
|
|
- //获取四分钟以后的时间
|
|
|
- LocalDateTime endTime = startTime.plusMinutes(4);
|
|
|
- //根据开始时间和结束时间去数据库把这两个时间段中 符合的预约发布时间中获取藏品
|
|
|
- List<Collection> collectionList = collectionRepo.findAllByStartTimeGreaterThanEqual(startTime);
|
|
|
- //判断获取的藏品列表是否为空
|
|
|
- if (Collections.isEmpty(collectionList)) {
|
|
|
-// return new CronTrigger("0 0/10 * * * ?").nextExecutionTime(triggerContext);
|
|
|
- //藏品列表为空 则设置下次的时间查询为结束时间的前30秒 前10秒 前10
|
|
|
- return Date.from(endTime.minusSeconds(5).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
- }
|
|
|
- //藏品列表不为空则将取出来的藏品列表根据预约发布的时间排序放入等待的藏品列表
|
|
|
- collections = collectionList.stream().sorted(Comparator.comparing(Collection::getStartTime)).collect(Collectors.toList());
|
|
|
- }
|
|
|
- //取第一个藏品的预约发布时间的前10秒做下次定时任务的时间 换成五秒 两秒
|
|
|
- return Date.from(collections.get(0).getStartTime().minusSeconds(2).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
- });
|
|
|
+// //藏品列表不为空则将取出来的藏品列表根据预约发布的时间排序放入等待的藏品列表
|
|
|
+// collections = collectionList.stream().sorted(Comparator.comparing(Collection::getStartTime)).collect(Collectors.toList());
|
|
|
+// }
|
|
|
+// //取第一个藏品的预约发布时间的前10秒做下次定时任务的时间 换成五秒 两秒
|
|
|
+// return Date.from(collections.get(0).getStartTime().minusSeconds(2).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+// });
|
|
|
}
|
|
|
}
|