Browse Source

fix: 修复因计划任务过多判断,导致任务错过下发时间未执行

master
yinhuaiwei 3 weeks ago
parent
commit
dc85d605c0
1 changed files with 16 additions and 21 deletions
  1. +16
    -21
      inspect-job/src/main/java/com/inspect/job/task/JobMainTask.java

+ 16
- 21
inspect-job/src/main/java/com/inspect/job/task/JobMainTask.java View File

@ -35,6 +35,7 @@ import java.net.URLConnection;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
@ -1173,16 +1174,11 @@ public class JobMainTask {
.isEnable("1") .isEnable("1")
.build(); .build();
List<PatrolPresetPos> presetPosList = taskExecClient.selectPatrolPresetPosList(patrolPresetPos); List<PatrolPresetPos> presetPosList = taskExecClient.selectPatrolPresetPosList(patrolPresetPos);
PatrolPresetPos presetPos = !presetPosList.isEmpty() ? presetPosList.get(0) :
PatrolPresetPos.builder().presetPosId("1")
.presetPosCode("1")
.channelCode("ffffffffffffffffff#ffffffffffffffffffffffffffffffff")
.channelId("999999")
.patrolPointId(1234567890L)
.channelType("vl")
.isEnable("1")
.eqpBookId("1")
.build();
if (presetPosList.isEmpty()) {
log.info("getInfosByRecord: {} PatrolPresetPos no found", patrolTaskInfo.getDeviceId());
continue;
}
PatrolPresetPos presetPos = presetPosList.get(0);
String deviceCode = "ffffffffffffffffff"; String deviceCode = "ffffffffffffffffff";
try { try {
String[] channelCodeList = presetPos.getChannelCode().split(StringUtils.HASHTAG); String[] channelCodeList = presetPos.getChannelCode().split(StringUtils.HASHTAG);
@ -1291,7 +1287,6 @@ public class JobMainTask {
// } // }
// } // }
// } // }
// 任务分拆异步执行V1.0 // 任务分拆异步执行V1.0
// private void prePointExecImmediate(final PatrolTaskExecRecord patrolTaskExecRecord, List<PatrolTaskInfo> patrolTaskInfoList) { // private void prePointExecImmediate(final PatrolTaskExecRecord patrolTaskExecRecord, List<PatrolTaskInfo> patrolTaskInfoList) {
// int batchSize = taskBatchSize; // int batchSize = taskBatchSize;
@ -1308,7 +1303,6 @@ public class JobMainTask {
// index++; // index++;
// } // }
// } // }
private int calcTaskAlgorithmTotalNumber(List<PatrolTaskInfo> patrolTaskInfoList, String specifiedAlg) { private int calcTaskAlgorithmTotalNumber(List<PatrolTaskInfo> patrolTaskInfoList, String specifiedAlg) {
int totalAlgorithmNumber = 0; int totalAlgorithmNumber = 0;
for (PatrolTaskInfo patrolTaskInfo : patrolTaskInfoList) { for (PatrolTaskInfo patrolTaskInfo : patrolTaskInfoList) {
@ -1517,7 +1511,6 @@ public class JobMainTask {
// try (InputStream in = connection.getInputStream()) { // try (InputStream in = connection.getInputStream()) {
// Files.copy(in, Paths.get("/test.jpg")); // Files.copy(in, Paths.get("/test.jpg"));
// } // }
/** /**
* 将图片上传到ftp * 将图片上传到ftp
*/ */
@ -2039,12 +2032,14 @@ public class JobMainTask {
List<PatrolTask> patrolTaskControlList = new ArrayList<>(); List<PatrolTask> patrolTaskControlList = new ArrayList<>();
for (PatrolTask patrolTask : patrolTaskList) { for (PatrolTask patrolTask : patrolTaskList) {
log.debug("EXTRACT_REDIS_TASK devType: {}", patrolTask.getDevType()); log.debug("EXTRACT_REDIS_TASK devType: {}", patrolTask.getDevType());
if(StringUtils.isNotEmpty(patrolTask.getDevType())
// 添加可见光任务
if (StringUtils.isNotEmpty(patrolTask.getDevType())
&& patrolTask.getDevType().contains("2")) { && patrolTask.getDevType().contains("2")) {
patrolTaskListEx.add(patrolTask); patrolTaskListEx.add(patrolTask);
} }
if(StringUtils.isNotEmpty(patrolTask.getDevType())
// 添加无人机/机器狗任务
if (StringUtils.isNotEmpty(patrolTask.getDevType())
&& (patrolTask.getDevType().contains("0") || patrolTask.getDevType().contains("1"))) { && (patrolTask.getDevType().contains("0") || patrolTask.getDevType().contains("1"))) {
patrolTaskControlList.add(patrolTask); patrolTaskControlList.add(patrolTask);
} }
@ -2093,8 +2088,10 @@ public class JobMainTask {
@SuppressWarnings({"unused"}) @SuppressWarnings({"unused"})
public void execEveryDayTask() { public void execEveryDayTask() {
log.debug("***************************** JobTaskTimer execEveryDayTask *************************************"); log.debug("***************************** JobTaskTimer execEveryDayTask *************************************");
Collection<String> redisKeys = redisService.keys(RedisConst.TASK_CODE_EX);
String today = LocalDate.now().toString();
String key = RedisConst.TASK_CODE_EX + today + "*";
Collection<String> redisKeys = redisService.keys(key);
log.info("TodayTask key:{}, size:{}", key, redisKeys.size());
for (String redisKey : redisKeys) { for (String redisKey : redisKeys) {
try { try {
//redisKey = RedisConst.TASK_CODE + task.getTaskCode() + StringUtils.AT + DateUtils.format(DateUtils.yyyyMMddHHmmss2, task.getFixedStartTime()) //redisKey = RedisConst.TASK_CODE + task.getTaskCode() + StringUtils.AT + DateUtils.format(DateUtils.yyyyMMddHHmmss2, task.getFixedStartTime())
@ -2106,7 +2103,7 @@ public class JobMainTask {
continue; continue;
} }
String isEnable = patrolTasks.get(0).getIsEnable(); String isEnable = patrolTasks.get(0).getIsEnable();
log.debug("---execEveryDayTask isEnable: {}, taskCode: {}", isEnable, taskCode);
log.debug("---execEveryDayTask isEnable: {}, taskCode: {}", isEnable, taskCode);
if (isTaskSlotEmpty(taskCode) && "0".equals(isEnable)) { if (isTaskSlotEmpty(taskCode) && "0".equals(isEnable)) {
log.debug(Color.YELLOW + "[JOB] TASK_CODE: {}" + Color.END, taskCode); log.debug(Color.YELLOW + "[JOB] TASK_CODE: {}" + Color.END, taskCode);
// long currentTime = System.currentTimeMillis(); // long currentTime = System.currentTimeMillis();
@ -2117,14 +2114,12 @@ public class JobMainTask {
// long planTime = DateUtils.parse(DateUtils.yyyyMMddHHmmss2, fixedStartTime).getTime(); // long planTime = DateUtils.parse(DateUtils.yyyyMMddHHmmss2, fixedStartTime).getTime();
// long fixedDays = TimeUnit.MILLISECONDS.toDays(planTime); // long fixedDays = TimeUnit.MILLISECONDS.toDays(planTime);
// long fixedStartMinutes = TimeUnit.MILLISECONDS.toMinutes(planTime); // long fixedStartMinutes = TimeUnit.MILLISECONDS.toMinutes(planTime);
String fixedStartTime = keywords[2]; String fixedStartTime = keywords[2];
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 解析字符串为 Date // 解析字符串为 Date
Date fixedDate = sdf.parse(fixedStartTime); Date fixedDate = sdf.parse(fixedStartTime);
Date currentDate = new Date(); // 当前时间 Date currentDate = new Date(); // 当前时间
// 比较时间精确到分钟 // 比较时间精确到分钟
SimpleDateFormat minuteFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); SimpleDateFormat minuteFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String fixedMinute = minuteFormat.format(fixedDate); String fixedMinute = minuteFormat.format(fixedDate);
@ -2159,4 +2154,4 @@ public class JobMainTask {
log.error("error", e); log.error("error", e);
} }
} }
}
}

Loading…
Cancel
Save