package org.jeecg.modules.eam.job; import cn.hutool.core.collection.CollectionUtil; import lombok.extern.slf4j.Slf4j; import org.jeecg.modules.eam.constant.WeekMaintenanceStatusEnum; import org.jeecg.modules.eam.entity.EamWeekMaintenanceOrder; import org.jeecg.modules.eam.service.IEamWeekMaintenanceOrderService; 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 WeekMaintenanceOrderExpiredJob implements Job { @Autowired private IEamWeekMaintenanceOrderService eamWeekMaintenanceOrderService; @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 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 unCompleteOrderList = eamWeekMaintenanceOrderService.selectUnCompleteOrder(now.toString()); if (CollectionUtil.isEmpty(unCompleteOrderList)) { //没有需要处理的数据 return; } for (EamWeekMaintenanceOrder order : unCompleteOrderList) { if (WeekMaintenanceStatusEnum.WAIT_MAINTENANCE.name().equals(order.getMaintenanceStatus())) { order.setMaintenanceStatus(WeekMaintenanceStatusEnum.EXPIRED.name()); } else if (WeekMaintenanceStatusEnum.UNDER_MAINTENANCE.name().equals(order.getMaintenanceStatus())) { //已经被接单 但未执行完成 order.setMaintenanceStatus(WeekMaintenanceStatusEnum.EXPIRED.name()); //强制结束流程 删除用户的此待办任务 FlowMyBusiness flowMyBusiness = flowMyBusinessService.selectByDataId(order.getId()); if (flowMyBusiness != null) { flowTaskService.end(flowMyBusiness.getProcessInstanceId(), "过期删除"); } } } eamWeekMaintenanceOrderService.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); } }