Sfoglia il codice sorgente

定时任务:查询任务开始一小时后状态仍为 待执行5和准备中6

并修改状态为任务失败
pull/359/head
suqin 10 mesi fa
parent
commit
6e94506b32
1 ha cambiato i file con 52 aggiunte e 0 eliminazioni
  1. +52
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/task/InspectionTimeOutTask.java

+ 52
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/task/InspectionTimeOutTask.java Vedi File

@@ -0,0 +1,52 @@
package com.tuoheng.admin.task;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.admin.entity.Inspection;
import com.tuoheng.admin.enums.InspectionStatusEnum;
import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.mapper.InspectionMapper;
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 org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.*;

@Slf4j
@Component
public class InspectionTimeOutTask {


@Resource
private InspectionMapper inspectionMapper;

@XxlJob("inspectionTimeOutTaskHandler")
public void inspectionExecuteHandler() {

Date startTime = null; //当前时间
String taskBeginTime = null; //一小时之前
try {
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);
}

//以现在时间为节点 查询一小时之前的所有机场里的状态为 准备中,飞行中的已开始执行的任务
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) //已开始执行的任务
.le(Inspection::getExecutionStartTime, taskBeginTime) //一个小时之前就开始
.eq(BaseEntity::getMark, MarkEnum.VALID.getCode()));

for (Inspection inspection : newInspections) {
inspection.setStatus(7);
inspectionMapper.updateById(inspection);
}


}
}

Loading…
Annulla
Salva