|
|
@@ -25,7 +25,6 @@ import java.util.*; |
|
|
|
@Component |
|
|
|
public class InspectionTimeOutTask { |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
private InspectionMapper inspectionMapper; |
|
|
|
|
|
|
@@ -35,15 +34,11 @@ public class InspectionTimeOutTask { |
|
|
|
@XxlJob("inspectionTimeOutTaskHandler") |
|
|
|
public void inspectionExecuteHandler() { |
|
|
|
log.info("=================================开始执行超时任务定时器任务调度================================="); |
|
|
|
|
|
|
|
Date startTime = null; //当前时间 |
|
|
|
String taskBeginTime = null; //一小时之前 |
|
|
|
String msg = ""; |
|
|
|
|
|
|
|
Date startTime; |
|
|
|
String taskBeginTime = null; |
|
|
|
try { |
|
|
|
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z"); |
|
|
|
startTime = new Date(System.currentTimeMillis()); |
|
|
|
// startTime = DateUtils.parseDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.now()), DateUtils.YYYY_MM_DD); |
|
|
|
taskBeginTime = DateUtils.addDateTimeToStr(startTime, 0, -1, 0, 0); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("获取开始时间异常:{}", e); |
|
|
@@ -52,38 +47,36 @@ public class InspectionTimeOutTask { |
|
|
|
//以现在时间为节点 查询一小时之前的所有机场里的状态为 准备中,飞行中的已开始执行的任务 |
|
|
|
List<Inspection> newInspections = inspectionMapper.selectList(Wrappers.<Inspection>lambdaQuery() |
|
|
|
.in(Inspection::getStatus, InspectionStatusEnum.PREPARING.getCode(), InspectionStatusEnum.IN_FLIGHT.getCode()) |
|
|
|
.eq(Inspection::getInspectionType, AirPortTaskStatusEnum.FLIGHT.getCode()) //机场巡逻 |
|
|
|
.eq(Inspection::getExecutionStatus, InspectionExecutionStatusEnum.EXECUTED.getCode()) //已开始执行的任务 |
|
|
|
.le(Inspection::getExecutionStartTime, taskBeginTime) //一个小时之前就开始 |
|
|
|
.eq(Inspection::getInspectionType, AirPortTaskStatusEnum.FLIGHT.getCode()) |
|
|
|
.eq(Inspection::getExecutionStatus, InspectionExecutionStatusEnum.EXECUTED.getCode()) |
|
|
|
.le(Inspection::getExecutionStartTime, taskBeginTime) |
|
|
|
.eq(BaseEntity::getMark, MarkEnum.VALID.getCode())); |
|
|
|
log.info("执行定时执行飞行任务:机场任务数" + newInspections.size()); |
|
|
|
|
|
|
|
for (Inspection inspection : newInspections) { |
|
|
|
log.info("修改任务状态为失败" + inspection.getStatus()); |
|
|
|
inspection.setStatus(InspectionStatusEnum.FLIGHT_FAILED.getCode()); |
|
|
|
inspectionMapper.updateById(inspection); |
|
|
|
log.info("修改结果: 任务状态为" + inspection.getStatus()); |
|
|
|
msg = "任务执行超过一小时 默认失败"; |
|
|
|
log.info("超时任务保存到历史记录表中"); |
|
|
|
this.insertInspectionHistory(inspection,msg); |
|
|
|
this.insertInspectionHistory(inspection); |
|
|
|
} |
|
|
|
log.info("=================================结束执行超时任务定时器任务调度================================="); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 保存到历史记录表 |
|
|
|
* @param inspection |
|
|
|
* @param msg |
|
|
|
*/ |
|
|
|
private void insertInspectionHistory(Inspection inspection, String msg) { |
|
|
|
private void insertInspectionHistory(Inspection inspection) { |
|
|
|
InspectionHistory inspectionHistory = new InspectionHistory(); |
|
|
|
inspectionHistory.setTenantId(inspection.getTenantId()); |
|
|
|
inspectionHistory.setInspectionId(inspection.getId()); |
|
|
|
inspectionHistory.setHistoryName(msg); |
|
|
|
inspectionHistory.setHistoryName("任务执行超过一小时 默认失败"); |
|
|
|
inspectionHistory.setCreateUser(inspection.getCreateUser()); |
|
|
|
inspectionHistory.setCreateTime(DateUtils.now()); |
|
|
|
inspectionHistoryMapper.insert(inspectionHistory); |
|
|
|
Integer count = inspectionHistoryMapper.insert(inspectionHistory); |
|
|
|
if (count <= 0) { |
|
|
|
log.info("超时任务保存到历史记录表中失败,inspectionId:{}", inspection.getId()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |