commit
This commit is contained in:
@@ -48,4 +48,6 @@ public interface TaskPlatformService {
|
||||
* @return
|
||||
*/
|
||||
List<String> getCronExeTimes(String cronExpression) throws Exception;
|
||||
|
||||
List<String> getCronExeTimesPlus(String cronExpression) throws Exception;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.nutz.integration.quartz.QuartzJob;
|
||||
import org.nutz.integration.quartz.QuartzManager;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.quartz.CronExpression;
|
||||
import org.quartz.JobKey;
|
||||
import org.quartz.TriggerUtils;
|
||||
import org.quartz.impl.triggers.CronTriggerImpl;
|
||||
@@ -96,4 +97,22 @@ public class TaskPlatformServiceImpl implements TaskPlatformService {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> getCronExeTimesPlus(String cronExpression) throws Exception {
|
||||
// 创建一个列表来存储执行时间
|
||||
List<String> executionTimes = new ArrayList<>();
|
||||
// 创建 CronTriggerImpl 对象,并设置 cron 表达式
|
||||
CronTriggerImpl cronTrigger = new CronTriggerImpl();
|
||||
cronTrigger.setCronExpression(new CronExpression(cronExpression));
|
||||
// 计算未来的执行时间
|
||||
List<Date> nextExecutionTimes = TriggerUtils.computeFireTimes(cronTrigger, null, 5);
|
||||
// 格式化日期并添加到执行时间列表中
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
for (Date date : nextExecutionTimes) {
|
||||
executionTimes.add(dateFormat.format(date));
|
||||
}
|
||||
return executionTimes;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user