| | |
| | | package org.jeecg.modules.eam.job; |
| | | |
| | | public class TechnicalStatusEvaluationExpiredJob { |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jeecg.common.util.DateUtils; |
| | | import org.jeecg.modules.eam.constant.TechnicalStatusEvaluationOrderStatusEnum; |
| | | import org.jeecg.modules.eam.constant.TechnologyStatusEnum; |
| | | import org.jeecg.modules.eam.entity.EamEquipmentExtend; |
| | | import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationOrder; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentExtendService; |
| | | import org.jeecg.modules.eam.service.IEamTechnicalStatusEvaluationOrderService; |
| | | 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.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Component |
| | | @Slf4j |
| | | public class TechnicalStatusEvaluationExpiredJob implements Job { |
| | | @Autowired |
| | | private IEamTechnicalStatusEvaluationOrderService evaluationOrderService; |
| | | @Autowired |
| | | private IEamEquipmentExtendService equipmentExtendService; |
| | | @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> jobClassName = quartzJobService.findByJobClassName(this.getClass().getName()); |
| | | if (jobClassName != null && !jobClassName.isEmpty()) { |
| | | quartzLog.setJobId(jobClassName.get(0).getId()); |
| | | } |
| | | long startTime = System.currentTimeMillis(); |
| | | List<EamTechnicalStatusEvaluationOrder> list = evaluationOrderService.selectUncompletedEvaluationOrderList(); |
| | | if (CollectionUtil.isEmpty(list)) { |
| | | log.info("没有需要过期的工单!日期:{}", DateUtils.date2Str(DateUtils.date_sdf.get())); |
| | | quartzLog.setIsSuccess(0); |
| | | 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 (EamTechnicalStatusEvaluationOrder order : list) { |
| | | EamEquipmentExtend extend = equipmentExtendService.getById(order.getEquipmentId()); |
| | | if (extend == null) { |
| | | log.error("设备信息不存在,请检查! 设备ID:{}, 日期:{}", order.getEquipmentId(), DateUtils.date2Str(DateUtils.date_sdf.get())); |
| | | continue; |
| | | } |
| | | if (TechnicalStatusEvaluationOrderStatusEnum.WAIT_EVALUATION.name().equals(order.getEvaluationStatus()) || TechnicalStatusEvaluationOrderStatusEnum.LOCKED.name().equals(order.getEvaluationStatus())) { |
| | | order.setEvaluationStatus(TechnicalStatusEvaluationOrderStatusEnum.EXPIRED.name()); |
| | | evaluationOrderService.updateById(order); |
| | | expiredCount++; |
| | | } |
| | | extend.setTechnologyStatus(TechnologyStatusEnum.PROHIBITED.name()); |
| | | equipmentExtendService.updateById(extend); |
| | | } |
| | | 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); |
| | | } |
| | | } |