提交 4f01d03b authored 作者: 邓砥奕's avatar 邓砥奕

[自查模块]增加自查定时任务

上级 80810f3e
package com.tykj.dev.config; package com.tykj.dev.config;
import lombok.Data;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
...@@ -8,6 +9,18 @@ import org.springframework.stereotype.Component; ...@@ -8,6 +9,18 @@ import org.springframework.stereotype.Component;
@Component @Component
public class TaskBeanConfig { public class TaskBeanConfig {
private static final ThreadPoolTaskScheduler THREAD_POOL_TASK_SCHEDULER;
static {
THREAD_POOL_TASK_SCHEDULER = new ThreadPoolTaskScheduler();
THREAD_POOL_TASK_SCHEDULER.setPoolSize(10);
THREAD_POOL_TASK_SCHEDULER.initialize();
}
public static ThreadPoolTaskScheduler getThreadPoolTaskScheduler() {
return THREAD_POOL_TASK_SCHEDULER;
}
@Bean @Bean
public TaskScheduler taskScheduler() { public TaskScheduler taskScheduler() {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
......
package com.tykj.dev.device.selfcheck.base; package com.tykj.dev.device.selfcheck.base;
import com.tykj.dev.config.GlobalMap;
import com.tykj.dev.config.TaskBeanConfig;
import com.tykj.dev.device.task.service.TaskService;
import com.tykj.dev.device.task.subject.bto.TaskBto;
import com.tykj.dev.device.user.subject.dao.UnitsDao;
import com.tykj.dev.device.user.subject.entity.Units;
import com.tykj.dev.misc.base.BeanHelper;
import com.tykj.dev.misc.base.StatusEnum;
import com.tykj.dev.misc.utils.SpringUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledFuture;
/**
* @author dengdiyi
*/
@Slf4j
@Component @Component
@EnableAsync
@Data
public class SelfCheckSchedulerTask { public class SelfCheckSchedulerTask {
/** private String cron = "0 0 0 1 3,6,9,12 ? ";
* 月度
*/ private UnitsDao unitsDao = SpringUtils.getBean("unitsDao");
private String cron1 = "0 0 0 1 1/1 ? ";
/** private TaskService taskService = SpringUtils.getBean("taskServiceImpl");
* 季度
*/ private ScheduledFuture scheduledFuture;
private String cron2 = "0 0 0 1 3,6,9,12 ? ";
/** public SelfCheckSchedulerTask() {
* 年度 scheduledFuture = TaskBeanConfig.getThreadPoolTaskScheduler().schedule(new SelfCheckTask(), triggerContext -> new CronTrigger(cron).nextExecutionTime(triggerContext));
*/ }
private String cron3 = "0 0 0 1 1 ? *";
public class SelfCheckTask implements Runnable{
// @Async @Override
// @Scheduled(cron = "0 0 0 1 1/1 ? ") public void run() {
// public void createSelfCheckTask() { if (unitsDao != null && taskService!=null) {
// UnitsDao unitsDao = SpringUtils.getBean("unitsDao"); List<Units> unitsList = unitsDao.findAll();
// TaskService taskService = SpringUtils.getBean("taskServiceImpl"); unitsList.forEach(units -> {
// if (unitsDao != null && taskService!=null) { //发起待自查任务
// List<Units> unitsList = unitsDao.findAll(); List<Integer> userIds = new ArrayList<>();
// unitsList.forEach(units -> { userIds.add(0);
// //发起待自查任务 TaskBto taskBto = new TaskBto(StatusEnum.WAIT_SELF_CHECK.id,"自查业务",null,".",0,4,units.getUnitId(),0,null,userIds);
// List<Integer> userIds = new ArrayList<>(); taskService.start(taskBto);
// userIds.add(0); });
// TaskBto taskBto = new TaskBto(StatusEnum.WAIT_SELF_CHECK.id,"自查业务",null,".",0,4,units.getUnitId(),0,null,userIds); }
// taskService.start(taskBto); log.info("[自查模块]:自查定时任务执行了");
// }); }
// } }
// }
public void startTask(){
scheduledFuture = TaskBeanConfig.getThreadPoolTaskScheduler().schedule(new SelfCheckTask(), triggerContext -> new CronTrigger(cron).nextExecutionTime(triggerContext));
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论