zhangherong
2025-07-08 c6acf648b8bcee16df04dcc26e146c5d2dfb00b4
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package org.jeecg.modules.eam.job;
 
import cn.hutool.core.collection.CollectionUtil;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.eam.constant.InspectionStatus;
import org.jeecg.modules.eam.entity.EamInspectionOrder;
import org.jeecg.modules.eam.service.IEamInspectionOrderService;
import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness;
import org.jeecg.modules.flowable.apithird.business.service.IFlowMyBusinessService;
import org.jeecg.modules.flowable.service.IFlowTaskService;
import org.jeecg.common.util.ThrowableUtil;
import org.jeecg.modules.quartz.entity.QuartzJob;
import org.jeecg.modules.quartz.entity.SysQuartzLog;
import org.jeecg.modules.quartz.service.IQuartzJobService;
import org.jeecg.modules.quartz.service.ISysQuartzLogService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
 
@Component
@Slf4j
public class InspectionOrderExpiredJob implements Job {
 
    @Autowired
    private IEamInspectionOrderService eamInspectionOrderService;
 
    @Autowired
    private IFlowMyBusinessService flowMyBusinessService;
    @Autowired
    private IFlowTaskService flowTaskService;
    @Autowired
    private ISysQuartzLogService sysQuartzLogService;
    @Autowired
    private IQuartzJobService quartzJobService;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //任务日志
        SysQuartzLog quartzLog = new SysQuartzLog();
        quartzLog.setCreateTime(new Date());
        List<QuartzJob> byJobClassName = quartzJobService.findByJobClassName(this.getClass().getName());
        if (byJobClassName != null && !byJobClassName.isEmpty()) {
            quartzLog.setJobId(byJobClassName.get(0).getId());
        }
        long startTime = System.currentTimeMillis();
        LocalDate now = LocalDate.now();
        try {
            List<EamInspectionOrder> unCompleteOrderList = eamInspectionOrderService.selectUnCompleteOrder(now.toString());
            if (CollectionUtil.isEmpty(unCompleteOrderList)) {
                //没有需要处理的数据
                return;
            }
            for (EamInspectionOrder order : unCompleteOrderList) {
                order.setInspectionStatus(InspectionStatus.EXPIRED.name());
                if (InspectionStatus.UNDER_INSPECTION.name().equals(order.getInspectionStatus())) {
                    //强制结束流程 删除用户的此待办任务
                    FlowMyBusiness flowMyBusiness = flowMyBusinessService.selectByDataId(order.getId());
                    if (flowMyBusiness != null) {
                        flowTaskService.end(flowMyBusiness.getProcessInstanceId(), "过期删除");
                    }
                }
            }
            eamInspectionOrderService.updateBatchById(unCompleteOrderList);
            quartzLog.setIsSuccess(0);
        } catch (Exception e) {
            log.error("点检过期执行定时任务失败,{}", e.getMessage(), e);
            quartzLog.setIsSuccess(-1);
            quartzLog.setExceptionDetail(ThrowableUtil.getStackTrace(e));
        }
        long endTime = System.currentTimeMillis();
        quartzLog.setExecutionTime(Integer.parseInt(String.valueOf(endTime - startTime)));
        sysQuartzLogService.save(quartzLog);
    }
 
}