Commit 7eaddd16f9cec7a4eab5bf036fb56e9efd2b20f0

Authored by YunaiV
1 parent e06fc835

【修复】定时任务指定某一年执行时,只会执行一次,后台查看任务详细会报错

yudao-framework/yudao-spring-boot-starter-job/src/main/java/cn/iocoder/yudao/framework/quartz/core/util/CronUtils.java
@@ -34,24 +34,24 @@ public class CronUtils { @@ -34,24 +34,24 @@ public class CronUtils {
34 * @return 满足条件的执行时间 34 * @return 满足条件的执行时间
35 */ 35 */
36 public static List<LocalDateTime> getNextTimes(String cronExpression, int n) { 36 public static List<LocalDateTime> getNextTimes(String cronExpression, int n) {
37 - // 获得 CronExpression 对象 37 + // 1. 获得 CronExpression 对象
38 CronExpression cron; 38 CronExpression cron;
39 try { 39 try {
40 cron = new CronExpression(cronExpression); 40 cron = new CronExpression(cronExpression);
41 } catch (ParseException e) { 41 } catch (ParseException e) {
42 throw new IllegalArgumentException(e.getMessage()); 42 throw new IllegalArgumentException(e.getMessage());
43 } 43 }
44 - // 从当前开始计算,n 个满足条件的 44 + // 2. 从当前开始计算,n 个满足条件的
45 Date now = new Date(); 45 Date now = new Date();
46 List<LocalDateTime> nextTimes = new ArrayList<>(n); 46 List<LocalDateTime> nextTimes = new ArrayList<>(n);
47 for (int i = 0; i < n; i++) { 47 for (int i = 0; i < n; i++) {
48 Date nextTime = cron.getNextValidTimeAfter(now); 48 Date nextTime = cron.getNextValidTimeAfter(now);
  49 + // 2.1 如果 nextTime 为 null,说明没有更多的有效时间,退出循环
49 if (nextTime == null) { 50 if (nextTime == null) {
50 - // 如果 nextTime 为 null,说明没有更多的有效时间,退出循环  
51 break; 51 break;
52 } 52 }
53 nextTimes.add(LocalDateTimeUtil.of(nextTime)); 53 nextTimes.add(LocalDateTimeUtil.of(nextTime));
54 - // 切换现在,为下一个触发时间; 54 + // 2.2 切换现在,为下一个触发时间;
55 now = nextTime; 55 now = nextTime;
56 } 56 }
57 return nextTimes; 57 return nextTimes;