| | |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jeecg.modules.eam.constant.SecondMaintenanceStatusEnum; |
| | | import org.jeecg.common.util.DateUtils; |
| | | import org.jeecg.modules.eam.constant.ThirdMaintenanceStatusEnum; |
| | | import org.jeecg.modules.eam.constant.WeekMaintenanceStatusEnum; |
| | | import org.jeecg.modules.eam.entity.EamSecondMaintenanceOrder; |
| | | import org.jeecg.modules.eam.entity.EamEquipmentExtend; |
| | | import org.jeecg.modules.eam.entity.EamThirdMaintenanceOrder; |
| | | import org.jeecg.modules.eam.service.IEamSecondMaintenanceOrderService; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentExtendService; |
| | | import org.jeecg.modules.eam.service.IEamThirdMaintenanceOrderService; |
| | | 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.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Author: Lius |
| | | * @CreateTime: 2025-07-29 |
| | | * @Description: 三保工单过期 |
| | | */ |
| | | @Component |
| | | @Slf4j |
| | | public class ThirdMaintenanceOrderExpiredJob implements Job { |
| | | |
| | | @Autowired |
| | | private IEamThirdMaintenanceOrderService eamThirdMaintenanceOrderService; |
| | | |
| | | @Autowired |
| | | private IFlowMyBusinessService flowMyBusinessService; |
| | | @Autowired |
| | | private IFlowTaskService flowTaskService; |
| | | @Autowired |
| | | private ISysQuartzLogService sysQuartzLogService; |
| | | @Autowired |
| | | private IQuartzJobService quartzJobService; |
| | | @Autowired |
| | | private IEamEquipmentExtendService equipmentExtendService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | quartzLog.setJobId(byJobClassName.get(0).getId()); |
| | | } |
| | | long startTime = System.currentTimeMillis(); |
| | | LocalDate now = LocalDate.now(); |
| | | try { |
| | | |
| | | List<EamThirdMaintenanceOrder> unCompleteOrderList = eamThirdMaintenanceOrderService.lambdaQuery() |
| | | .lt(EamThirdMaintenanceOrder::getMaintenanceDate, now.toString()) |
| | | .in(EamThirdMaintenanceOrder::getMaintenanceStatus, ThirdMaintenanceStatusEnum.WAIT_MAINTENANCE, ThirdMaintenanceStatusEnum.UNDER_MAINTENANCE) |
| | | .orderByDesc(EamThirdMaintenanceOrder::getMaintenanceDate) |
| | | .list(); |
| | | |
| | | if (CollectionUtil.isEmpty(unCompleteOrderList)) { |
| | | //没有需要处理的数据 |
| | | return; |
| | | } |
| | | for (EamThirdMaintenanceOrder order : unCompleteOrderList) { |
| | | if (ThirdMaintenanceStatusEnum.WAIT_MAINTENANCE.name().equals(order.getMaintenanceStatus())) { |
| | | order.setMaintenanceStatus(ThirdMaintenanceStatusEnum.ABOLISH.name()); |
| | | } else if (ThirdMaintenanceStatusEnum.UNDER_MAINTENANCE.name().equals(order.getMaintenanceStatus())) { |
| | | //已经被接单 但未执行完成 |
| | | order.setMaintenanceStatus(ThirdMaintenanceStatusEnum.ABOLISH.name()); |
| | | //强制结束流程 删除用户的此待办任务 |
| | | FlowMyBusiness flowMyBusiness = flowMyBusinessService.selectByDataId(order.getId()); |
| | | if (flowMyBusiness != null) { |
| | | flowTaskService.end(flowMyBusiness.getProcessInstanceId(), "过期删除"); |
| | | } |
| | | } |
| | | } |
| | | eamThirdMaintenanceOrderService.updateBatchById(unCompleteOrderList); |
| | | List<EamThirdMaintenanceOrder> list = eamThirdMaintenanceOrderService.selectUnCompletedThirdMaintenanceOrderList(); |
| | | if (CollectionUtil.isEmpty(list)) { |
| | | log.info("没有需要过期的工单!日期:{}", DateUtils.date2Str(DateUtils.date_sdf.get())); |
| | | 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))); |
| | | quartzLog.setExceptionDetail("没有需要过期的工单,日期:" + DateUtils.date2Str(DateUtils.date_sdf.get())); |
| | | sysQuartzLogService.save(quartzLog); |
| | | return; |
| | | } |
| | | int expiredCount = 0; |
| | | for (EamThirdMaintenanceOrder order : list) { |
| | | EamEquipmentExtend extend = equipmentExtendService.getById(order.getEquipmentId()); |
| | | if (extend == null) { |
| | | log.error("设备信息不存在,请检查! 设备ID:{}, 日期:{}", order.getEquipmentId(), DateUtils.date2Str(DateUtils.date_sdf.get())); |
| | | continue; |
| | | } |
| | | if (ThirdMaintenanceStatusEnum.WAIT_MAINTENANCE.name().equals(order.getMaintenanceStatus()) || ThirdMaintenanceStatusEnum.FREEZE.name().equals(order.getMaintenanceStatus())) { |
| | | order.setMaintenanceStatus(ThirdMaintenanceStatusEnum.EXPIRED.name()); |
| | | eamThirdMaintenanceOrderService.updateById(order); |
| | | } |
| | | } |
| | | quartzLog.setIsSuccess(0); |
| | | long endTime = System.currentTimeMillis(); |
| | | quartzLog.setExecutionTime(Integer.parseInt(String.valueOf(endTime - startTime))); |
| | | quartzLog.setExceptionDetail("过期了{" + expiredCount + "}个工单,还有{" + (list.size() - expiredCount) + "}个工单正在执行中,禁用了{" + list.size() + "}台设备, 日期:" + DateUtils.date2Str(DateUtils.date_sdf.get())); |
| | | sysQuartzLogService.save(quartzLog); |
| | | } |
| | | |