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

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

上级 80810f3e
package com.tykj.dev.config;
import lombok.Data;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
......@@ -8,6 +9,18 @@ import org.springframework.stereotype.Component;
@Component
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
public TaskScheduler taskScheduler() {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
......
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 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
@EnableAsync
@Data
public class SelfCheckSchedulerTask {
/**
* 月度
*/
private String cron1 = "0 0 0 1 1/1 ? ";
/**
* 季度
*/
private String cron2 = "0 0 0 1 3,6,9,12 ? ";
/**
* 年度
*/
private String cron3 = "0 0 0 1 1 ? *";
// @Async
// @Scheduled(cron = "0 0 0 1 1/1 ? ")
// public void createSelfCheckTask() {
// UnitsDao unitsDao = SpringUtils.getBean("unitsDao");
// TaskService taskService = SpringUtils.getBean("taskServiceImpl");
// if (unitsDao != null && taskService!=null) {
// List<Units> unitsList = unitsDao.findAll();
// unitsList.forEach(units -> {
// //发起待自查任务
// List<Integer> userIds = new ArrayList<>();
// userIds.add(0);
// TaskBto taskBto = new TaskBto(StatusEnum.WAIT_SELF_CHECK.id,"自查业务",null,".",0,4,units.getUnitId(),0,null,userIds);
// taskService.start(taskBto);
// });
// }
// }
private String cron = "0 0 0 1 3,6,9,12 ? ";
private UnitsDao unitsDao = SpringUtils.getBean("unitsDao");
private TaskService taskService = SpringUtils.getBean("taskServiceImpl");
private ScheduledFuture scheduledFuture;
public SelfCheckSchedulerTask() {
scheduledFuture = TaskBeanConfig.getThreadPoolTaskScheduler().schedule(new SelfCheckTask(), triggerContext -> new CronTrigger(cron).nextExecutionTime(triggerContext));
}
public class SelfCheckTask implements Runnable{
@Override
public void run() {
if (unitsDao != null && taskService!=null) {
List<Units> unitsList = unitsDao.findAll();
unitsList.forEach(units -> {
//发起待自查任务
List<Integer> userIds = new ArrayList<>();
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论