package org.jeecg.modules.eam.job; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.util.DateUtils; import org.jeecg.modules.eam.constant.ThirdMaintenanceStatusEnum; import org.jeecg.modules.eam.entity.EamThirdMaintenanceOrder; import org.jeecg.modules.eam.service.IEamThirdMaintenanceOrderService; 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; /** * @Author: Lius * @CreateTime: 2025-07-29 * @Description: 三保工单锁定 */ @Component @Slf4j public class ThirdMaintenanceOrderLockedJob implements Job { @Autowired private ISysQuartzLogService sysQuartzLogService; @Autowired private IQuartzJobService quartzJobService; @Autowired private IEamThirdMaintenanceOrderService eamThirdMaintenanceOrderService; @Override @Transactional(rollbackFor = Exception.class) public void execute(JobExecutionContext context) throws JobExecutionException { //任务日志 SysQuartzLog quartzLog = new SysQuartzLog(); quartzLog.setCreateTime(new Date()); List jobClassName = quartzJobService.findByJobClassName(this.getClass().getName()); if (jobClassName != null && !jobClassName.isEmpty()) { quartzLog.setJobId(jobClassName.get(0).getId()); } long startTime = System.currentTimeMillis(); List list = eamThirdMaintenanceOrderService.selectWaitMaintenanceOrderList(); if (CollectionUtils.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; } for (EamThirdMaintenanceOrder order : list) { order.setMaintenanceStatus(ThirdMaintenanceStatusEnum.FREEZE.name()); eamThirdMaintenanceOrderService.updateById(order); } quartzLog.setIsSuccess(0); long endTime = System.currentTimeMillis(); quartzLog.setExecutionTime(Integer.parseInt(String.valueOf(endTime - startTime))); quartzLog.setExceptionDetail("锁定了{" + list.size() + "}条工单,日期:" + DateUtils.date2Str(DateUtils.date_sdf.get())); sysQuartzLogService.save(quartzLog); } }