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.modules.mdc.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) {
|
if (InspectionStatus.WAIT_INSPECTION.name().equals(order.getInspectionStatus())) {
|
order.setInspectionStatus(InspectionStatus.EXPIRED.name());
|
} else if (InspectionStatus.UNDER_INSPECTION.name().equals(order.getInspectionStatus())) {
|
//已经被接单 但未执行完成
|
order.setInspectionStatus(InspectionStatus.EXPIRED.name());
|
//强制结束流程 删除用户的此待办任务
|
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);
|
}
|
|
}
|