郑永安
2023-09-19 69185134fcfaf913ea45f1255677225a2cc311a4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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<TaskInfo> 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();
        }
 
    }
 
 
}