郑永安
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
50
package com.gk.hotwork.doublePrevention.scheduls;
 
import com.gk.hotwork.doublePrevention.entity.PreventDangerCheckTask;
import com.gk.hotwork.doublePrevention.entity.PreventDangerCheckWork;
import com.gk.hotwork.doublePrevention.service.baseService.PreventDangerCheckTaskService;
import com.gk.hotwork.doublePrevention.service.baseService.PreventDangerCheckWorkService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.List;
 
@Component
public class PreventSearchWorkStatusSchedule {
 
    private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(PreventSearchWorkStatusSchedule.class);
 
    @Autowired
    private PreventDangerCheckTaskService preventDangerCheckTaskService;
    @Autowired
    private PreventDangerCheckWorkService preventDangerCheckWorkService;
 
    @Scheduled(cron = "0 0/20 * * * ?")
    //@PostConstruct
    public void searchTask(){
        logger.info("【】重置任务状态开始执行....");
        Date date = new Date();
        Date startTime = null;
        Date endTime = null;
 
        startTime = date;
        endTime = new Date(date.getTime() + 60 * 60 * 1000L);
        //检查后面30分钟内的所有work,看是否有未关闭,且未生成任务的,如果
        //检索所有即将到时间的任务 ,nextExecTime
        List<PreventDangerCheckWork> checkWorkList = preventDangerCheckWorkService.listExecCheckWork(startTime, endTime);
 
        for (PreventDangerCheckWork checkWork : checkWorkList) {
            PreventDangerCheckTask task = preventDangerCheckTaskService.getTaskByCheckWorkIdAndStartTime(checkWork.getId(), checkWork.getNextCheckTime());
            if (ObjectUtils.isEmpty(task)){
                preventDangerCheckWorkService.resetCheckWorkStatus(checkWork.getId());
            }
        }
        logger.info("【】重置任务状态执行结束");
 
    }
 
}