package com.gk.hotwork.Scheduls.TaskPdf; import com.gk.hotwork.Domain.TaskInfo; import com.gk.hotwork.Service.TaskService; import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @Component @EnableScheduling @ConditionalOnProperty(prefix = "scheduling", name = "enabled", havingValue = "true") public class TaskPdfRobot { private Logger logger = LogManager.getLogger(TaskPdfRobot.class); @Autowired private TaskService taskService; @Scheduled(cron = "0/20 * * * * ?") //每隔30秒执行一次 public void AllTaskCertRobot(){ try { //1.所有状态为7的单子编号 List toPdfData = taskService.selectAllWorkCertUndone(); for (TaskInfo task : toPdfData) { String relativePath = taskService.generateAllWorkCert(task.getCode()); task.setPath(relativePath); //更新path taskService.updateById(task); logger.info("===票证生成:" + task.getCode() +"==="); } } catch (Exception e) { e.printStackTrace(); } } }