|
|
@@ -2,13 +2,19 @@ package com.tuoheng.admin.task; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.tuoheng.admin.entity.Inspection; |
|
|
|
import com.tuoheng.admin.entity.InspectionHistory; |
|
|
|
import com.tuoheng.admin.enums.AirPortTaskStatusEnum; |
|
|
|
import com.tuoheng.admin.enums.InspectionExecutionStatusEnum; |
|
|
|
import com.tuoheng.admin.enums.InspectionStatusEnum; |
|
|
|
import com.tuoheng.admin.enums.MarkEnum; |
|
|
|
import com.tuoheng.admin.mapper.InspectionHistoryMapper; |
|
|
|
import com.tuoheng.admin.mapper.InspectionMapper; |
|
|
|
import com.tuoheng.admin.utils.CurrentUserUtil; |
|
|
|
import com.tuoheng.common.core.common.BaseEntity; |
|
|
|
import com.tuoheng.common.core.utils.DateUtils; |
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import net.sf.saxon.functions.Current; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
@@ -22,11 +28,16 @@ public class InspectionTimeOutTask { |
|
|
|
@Resource |
|
|
|
private InspectionMapper inspectionMapper; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private InspectionHistoryMapper inspectionHistoryMapper; |
|
|
|
|
|
|
|
@XxlJob("inspectionTimeOutTaskHandler") |
|
|
|
public void inspectionExecuteHandler() { |
|
|
|
|
|
|
|
Date startTime = null; //当前时间 |
|
|
|
String taskBeginTime = null; //一小时之前 |
|
|
|
String msg = ""; |
|
|
|
|
|
|
|
try { |
|
|
|
startTime = DateUtils.parseDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.now()), DateUtils.YYYY_MM_DD); |
|
|
|
taskBeginTime = DateUtils.addDateTimeToStr(startTime, 0, -1, 0, 0); |
|
|
@@ -37,16 +48,32 @@ public class InspectionTimeOutTask { |
|
|
|
//以现在时间为节点 查询一小时之前的所有机场里的状态为 准备中,飞行中的已开始执行的任务 |
|
|
|
List<Inspection> newInspections = inspectionMapper.selectList(Wrappers.<Inspection>lambdaQuery() |
|
|
|
.in(Inspection::getStatus, InspectionStatusEnum.PREPARING.getCode(), InspectionStatusEnum.IN_FLIGHT.getCode()) |
|
|
|
.eq(Inspection::getInspectionType, 2) //机场巡逻 |
|
|
|
.eq(Inspection::getExecutionStatus, 2) //已开始执行的任务 |
|
|
|
.eq(Inspection::getInspectionType, AirPortTaskStatusEnum.FLIGHT.getCode()) //机场巡逻 |
|
|
|
.eq(Inspection::getExecutionStatus, InspectionExecutionStatusEnum.EXECUTED.getCode()) //已开始执行的任务 |
|
|
|
.le(Inspection::getExecutionStartTime, taskBeginTime) //一个小时之前就开始 |
|
|
|
.eq(BaseEntity::getMark, MarkEnum.VALID.getCode())); |
|
|
|
|
|
|
|
for (Inspection inspection : newInspections) { |
|
|
|
inspection.setStatus(7); |
|
|
|
inspection.setStatus(InspectionStatusEnum.FLIGHT_FAILED.getCode()); |
|
|
|
inspectionMapper.updateById(inspection); |
|
|
|
msg = "任务执行超过一小时 默认失败"; |
|
|
|
this.insertInspectionHistory(inspection,msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 保存到历史记录表 |
|
|
|
* @param inspection |
|
|
|
* @param msg |
|
|
|
*/ |
|
|
|
private void insertInspectionHistory(Inspection inspection, String msg) { |
|
|
|
InspectionHistory inspectionHistory = new InspectionHistory(); |
|
|
|
inspectionHistory.setTenantId(inspection.getTenantId()); |
|
|
|
inspectionHistory.setInspectionId(inspection.getId()); |
|
|
|
inspectionHistory.setHistoryName(msg); |
|
|
|
inspectionHistory.setCreateUser(inspection.getCreateUser()); |
|
|
|
inspectionHistory.setCreateTime(DateUtils.now()); |
|
|
|
inspectionHistoryMapper.insert(inspectionHistory); |
|
|
|
} |
|
|
|
|
|
|
|
} |