IntelligentRecognition/ah-jjsp-service/.svn/pristine/1b/1bd648c3a02a830c8ef9cc7436e...

51 lines
1.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.securityControl.task.schedule.task;
import com.securityControl.task.service.impl.CatchPictureService;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.TriggerContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.Date;
@Slf4j
//@Component
//@EnableScheduling
public class DownloadPictureTask implements SchedulingConfigurer {
@Value("${jobs.cron.downloadPicture}")
private String cron;
@Autowired
private CatchPictureService catchPictureService;
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
// 动态使用cron表达式设置循环间隔
taskRegistrar.addTriggerTask(new Runnable() {
@Override
public void run() {
log.info("=======DownloadPicture Current time {}", LocalDateTime.now());
log.info("=======DownloadPicture End time {}", LocalDateTime.now());
}
}, new Trigger() {
@Override
public Date nextExecutionTime(@NotNull TriggerContext triggerContext) {
// 使用CronTrigger触发器可动态修改cron表达式来操作循环规则
CronTrigger cronTrigger = new CronTrigger(cron);
return cronTrigger.nextExecutionTime(triggerContext);
}
});
}
}