From aafd104dd7de1db565cd2081e8eb445d7a1bd481 Mon Sep 17 00:00:00 2001
From: zhaowenyu <35589726@qq.com>
Date: Fri, 16 Jan 2026 09:01:29 +0800
Subject: [PATCH] 2026-01-16 zwy 轨迹数据在没有任务数据的情况下清空缓存
---
ard-sample/src/main/java/com/ard/sample/wayline/service/impl/WaylineJobServiceImpl.java | 154 ++++++++++++++++++++++++++++----------------------
1 files changed, 86 insertions(+), 68 deletions(-)
diff --git a/ard-sample/src/main/java/com/ard/sample/wayline/service/impl/WaylineJobServiceImpl.java b/ard-sample/src/main/java/com/ard/sample/wayline/service/impl/WaylineJobServiceImpl.java
index e450a49..6df0ceb 100644
--- a/ard-sample/src/main/java/com/ard/sample/wayline/service/impl/WaylineJobServiceImpl.java
+++ b/ard-sample/src/main/java/com/ard/sample/wayline/service/impl/WaylineJobServiceImpl.java
@@ -1,8 +1,11 @@
package com.ard.sample.wayline.service.impl;
-import com.ard.ossdock.service.impl.OssDockServiceContext;
+import com.ard.common.config.OssConfiguration;
+import com.ard.oss.service.impl.OssServiceContext;
import com.ard.route.domain.route.ArdRouteInfo;
import com.ard.route.service.IArdRouteInfoService;
+import com.ard.sample.config.DockConfiguration;
+import com.ard.sample.utils.TimestampUtils;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -71,14 +74,16 @@
@Autowired
private IWaylineJobMapper mapper;
-// @Autowired
+ // @Autowired
// private IWaylineFileService waylineFileService;
+ @Autowired
+ private TimestampUtils _timestampUtils;
@Autowired
private IArdRouteInfoService _ardRouteInfoService;
@Resource
- private OssDockServiceContext _ossService;
+ private OssServiceContext _ossService;
@Autowired
private IDeviceService deviceService;
@@ -179,6 +184,9 @@
if (WaylineTaskTypeEnum.IMMEDIATE.getVal() == param.getTaskType()) {
param.setExecuteTime(System.currentTimeMillis());
}
+ if (param.getExecuteTime() < _timestampUtils.plusMinutesByMillis(System.currentTimeMillis(), 10) && param.getTaskType() == WaylineTaskTypeEnum.TIMED.getVal()) {
+ return ResponseResult.error(1234,"定时任务执行时间不能小于当前时间的后10分钟!");
+ }
param.setRth_mode(1);
Optional<WaylineJobDTO> waylineJobOpt = this.createWaylineJob(param, loginUser.getUsername(),
param.getExecuteTime(), param.getExecuteTime());
@@ -189,7 +197,7 @@
}
if (waylineJobOpt.isEmpty()) {
- return ResponseResult.error(314013000,"创建机场任务失败!");
+ return ResponseResult.error(314013000, "创建机场任务失败!");
}
WaylineJobDTO waylineJob = waylineJobOpt.get();
@@ -206,23 +214,26 @@
// }
// 换航线表
ArdRouteInfo ardRouteOpt = _ardRouteInfoService.selectArdRouteInfoById(waylineJob.getFileId());
- if (ardRouteOpt == null || ardRouteOpt.getPath1() == null || ardRouteOpt.getPath1().isEmpty()) {
- return ResponseResult.error(314013001,"机场任务航线不存在!");
+ if (ardRouteOpt == null || ardRouteOpt.getPath() == null || ardRouteOpt.getPath().isEmpty()) {
+ return ResponseResult.error(314013001, "机场任务航线不存在!");
}
// get file url
// URL url = waylineFileService.getObjectUrl(waylineFile.get().getWaylineId());
URL url = null;
- String minioUrl = subStringMinioUrlName(ardRouteOpt.getPath1());
+ String minioUrl = subStringMinioUrlName(ardRouteOpt.getPath());
String md5 = "";
+ String httpUrl = "";
try (InputStream inputStream = _ossService.getObject(kmzPath, minioUrl)) {
md5 = DigestUtils.md5Hex(inputStream);
- url = new URL(ardRouteOpt.getPath1());
- log.info("机场任务航线文件url地址:{}", url);
+ url = new URL(ardRouteOpt.getPath());
+ log.info("机场任务航线文件url地址转换前:{}", url);
+ httpUrl = url.toString().replace(OssConfiguration.endpoint, DockConfiguration.endpoint);
+ log.info("机场任务航线文件url地址转换后:{}", httpUrl);
log.info("机场任务航线文件md5值:{}", md5);
} catch (Exception e) {
log.error("机场任务航线文件地址错误!{}", e.getMessage());
- return ResponseResult.error(314013002,"机场任务航线文件地址错误!" + e.getMessage());
+ return ResponseResult.error(314013002, "机场任务航线文件地址错误!" + e.getMessage());
}
log.info("机场任务-rth_mode的值:{}", waylineJob.getRthMode());
@@ -240,7 +251,7 @@
// .fingerprint(waylineFile.get().getSign())
// .replace("https://", "http://")
// .replace("9001", "9011")
- .url(url.toString())
+ .url(httpUrl)
.fingerprint(md5)
.build())
// .simulateMission(WaylineSimulateMissionDTO.builder()
@@ -261,11 +272,10 @@
.build();
// 下发参数打印
- try{
+ try {
String json = objectMapper.writeValueAsString(response);
log.info("机场下发航线任务的参数response:{}", json);
- }
- catch (Exception e){
+ } catch (Exception e) {
log.error("机场下发航线任务的参数response异常:{}", e.getMessage());
}
@@ -296,7 +306,7 @@
if (WaylineTaskTypeEnum.TIMED.getVal() == waylineJob.getTaskType()) {
boolean isAdd = RedisOpsUtils.zAdd(RedisConst.WAYLINE_JOB_TIMED_EXECUTE,
- waylineJob.getDockSn() + RedisConst.DELIMITER + waylineJob.getJobId(),
+ waylineJob.getDockSn() + RedisConst.DELIMITER + waylineJob.getJobId(),
waylineJob.getBeginTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
if (!isAdd) {
return ResponseResult.error("无法创建计划作业。");
@@ -306,10 +316,10 @@
return ResponseResult.success();
}
- public ResponseResult publishFlightTaskPrepare(Optional<WaylineJobDTO> waylineJobOpt) throws SQLException{
+ public ResponseResult publishFlightTaskPrepare(Optional<WaylineJobDTO> waylineJobOpt) throws SQLException {
if (waylineJobOpt.isEmpty()) {
- return ResponseResult.error(314013000,"创建机场任务失败!");
+ return ResponseResult.error(314013000, "创建机场任务失败!");
}
WaylineJobDTO waylineJob = waylineJobOpt.get();
boolean isOnline = deviceService.checkDeviceOnline(waylineJob.getDockSn());
@@ -318,21 +328,24 @@
}
// 换航线表
ArdRouteInfo ardRouteOpt = _ardRouteInfoService.selectArdRouteInfoById(waylineJob.getFileId());
- if (ardRouteOpt == null || ardRouteOpt.getPath1() == null || ardRouteOpt.getPath1().isEmpty()) {
- return ResponseResult.error(314013001,"机场任务航线不存在!");
+ if (ardRouteOpt == null || ardRouteOpt.getPath() == null || ardRouteOpt.getPath().isEmpty()) {
+ return ResponseResult.error(314013001, "机场任务航线不存在!");
}
// get file url
URL url = null;
- String minioUrl = subStringMinioUrlName(ardRouteOpt.getPath1());
+ String minioUrl = subStringMinioUrlName(ardRouteOpt.getPath());
String md5 = "";
+ String httpUrl = "";
try (InputStream inputStream = _ossService.getObject(kmzPath, minioUrl)) {
md5 = DigestUtils.md5Hex(inputStream);
- url = new URL(ardRouteOpt.getPath1());
- log.info("机场任务航线文件url地址:{}", url);
+ url = new URL(ardRouteOpt.getPath());
+ log.info("机场任务航线文件url地址转换前:{}", url);
+ httpUrl = url.toString().replace(OssConfiguration.endpoint, DockConfiguration.endpoint);
+ log.info("机场任务航线文件url地址转换后:{}", httpUrl);
log.info("机场任务航线文件md5值:{}", md5);
} catch (Exception e) {
log.error("机场任务航线文件地址错误!{}", e.getMessage());
- return ResponseResult.error(314013002,"机场任务航线文件地址错误!" + e.getMessage());
+ return ResponseResult.error(314013002, "机场任务航线文件地址错误!" + e.getMessage());
}
WaylineTaskCreateDTO flightTask = WaylineTaskCreateDTO.builder()
@@ -344,7 +357,7 @@
.outOfControlAction(waylineJob.getOutOfControlAction())
.rthMode(waylineJob.getRthMode())
.file(WaylineTaskFileDTO.builder()
- .url(url.toString())
+ .url(httpUrl)
// .fingerprint(waylineFile.get().getSign())
.fingerprint(md5)
.build())
@@ -356,12 +369,11 @@
.build();
// 下发参数打印
- try{
+ try {
String json = objectMapper.writeValueAsString(flightTask);
- log.info("机场下发航线任务的参数flightTask:{}", json);
- }
- catch (Exception e){
- log.error("机场下发航线任务的参数flightTask异常:{}", e.getMessage());
+ log.info("机场下发循环任务子任务-定时任务的航线任务的参数flightTask:{}", json);
+ } catch (Exception e) {
+ log.error("机场下发循环任务子任务-定时任务的航线任务的参数flightTask异常:{}", e.getMessage());
}
String topic = TopicConst.THING_MODEL_PRE + TopicConst.PRODUCT +
@@ -376,9 +388,9 @@
ServiceReply serviceReply = messageSender.publishWithReply(topic, response);
- log.info("下发任务结果: {}", serviceReply.getResult());
- log.info("机场任务航线文件url地址:{}", url);
- log.info("机场任务航线文件md5值:{}", md5);
+ log.info("下发循环任务子任务-定时任务的结果: {}", serviceReply.getResult());
+ log.info("机场循环任务子任务-定时任务的航线文件url地址:{}", httpUrl);
+ log.info("机场循环任务子任务-定时任务的航线文件md5值:{}", md5);
if (ResponseResult.CODE_SUCCESS != serviceReply.getResult()) {
String errorMsg = CommonErrorEnum.getMsgByCode(serviceReply.getResult());
@@ -395,15 +407,15 @@
// 飞行命令先注释掉
// Issue an immediate task execution command.
- if (WaylineTaskTypeEnum.IMMEDIATE.getVal() == waylineJob.getTaskType()) {
- if (!executeFlightTask(waylineJob.getJobId())) {
- return ResponseResult.error("无法执行作业。");
- }
- }
+// if (WaylineTaskTypeEnum.IMMEDIATE.getVal() == waylineJob.getTaskType()) {
+// if (!executeFlightTask(waylineJob.getJobId())) {
+// return ResponseResult.error("无法执行作业。");
+// }
+// }
if (WaylineTaskTypeEnum.TIMED.getVal() == waylineJob.getTaskType()) {
boolean isAdd = RedisOpsUtils.zAdd(RedisConst.WAYLINE_JOB_TIMED_EXECUTE,
- waylineJob.getDockSn() + RedisConst.DELIMITER + waylineJob.getJobId(),
+ waylineJob.getDockSn() + RedisConst.DELIMITER + waylineJob.getJobId(),
waylineJob.getBeginTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
if (!isAdd) {
return ResponseResult.error("无法创建计划作业。");
@@ -449,11 +461,10 @@
.build();
// 下发参数打印
- try{
+ try {
String json = objectMapper.writeValueAsString(response);
log.info("机场下发-执行飞行任务-的参数response:{}", json);
- }
- catch (Exception e){
+ } catch (Exception e) {
log.error("机场下发-执行飞行任务-的参数response异常:{}", e.getMessage());
}
@@ -492,7 +503,9 @@
*/
@Override
public ResponseResult cancelFlightTask(Collection<String> jobIds) {
- List<WaylineJobDTO> waylineJobs = getJobsByConditions(jobIds, WaylineJobStatusEnum.PENDING);
+// List<WaylineJobDTO> waylineJobs = getJobsByConditions(jobIds, WaylineJobStatusEnum.PENDING);
+ List<WaylineJobDTO> waylineJobs = getJobsByConditions(jobIds, WaylineJobStatusEnum.IN_PROGRESS);
+
// ResponseResult.error(errorCode, CommonErrorEnum.getMsgByCode(errorCode)));
// Set<String> waylineJobIds = waylineJobs.stream().map(WaylineJobDTO::getJobId).collect(Collectors.toSet());
// // Check if the task status is correct.
@@ -508,12 +521,12 @@
.collect(Collectors.groupingBy(WaylineJobDTO::getDockSn,
Collectors.mapping(WaylineJobDTO::getJobId, Collectors.toList())));
// dockJobs.forEach((dockSn, idList) -> this.publishCancelTask(dockSn, idList));
- for(Map.Entry<String, List<String>> entry : dockJobs.entrySet()) {
+ for (Map.Entry<String, List<String>> entry : dockJobs.entrySet()) {
String docksn = entry.getKey();
List<String> jobIdList = entry.getValue();
- ResponseResult r = publishCancelTask(docksn, jobIdList);
- String a = r.getMessage();
- return r ;
+ ResponseResult r = publishCancelTask(docksn, jobIdList);
+ String a = r.getMessage();
+ return r;
}
return ResponseResult.success();
@@ -592,7 +605,7 @@
*/
@Override
public ResponseResult publishCancelTask(String dockSn, List<String> jobIds) {
- for(String jobId : jobIds) {
+ for (String jobId : jobIds) {
Optional<WaylineJobDTO> waylineJobDTO = this.getJobByJobId(jobId);
if (waylineJobDTO.isEmpty()) {
return ResponseResult.error("任务不存在,jobId: " + jobId);
@@ -666,6 +679,7 @@
new LambdaQueryWrapper<WaylineJobEntity>()
// 不过滤状态,
//.eq(Objects.nonNull(status), WaylineJobEntity::getStatus, status.getVal())
+ .ne(WaylineJobEntity::getStatus, status.getVal())
.and(!CollectionUtils.isEmpty(jobIds),
wrapper -> jobIds.forEach(id -> wrapper.eq(WaylineJobEntity::getJobId, id).or())))
.stream()
@@ -753,7 +767,7 @@
// 任务类型筛选,允许为空,为空则不进行筛选
.eq(taskType != null, WaylineJobEntity::getTaskType, taskType)
// 任务名称筛选,允许为空,为空则不进行筛选;....模糊查询
- .like(name != null, WaylineJobEntity::getName, "%"+name+"%")
+ .like(name != null, WaylineJobEntity::getName, "%" + name + "%")
// 根据是否完成筛选,允许为空,为空则不进行筛选
.eq(isComplete != null && isComplete, WaylineJobEntity::getStatus, 3)
.ne(isComplete != null && !isComplete, WaylineJobEntity::getStatus, 3)
@@ -774,18 +788,18 @@
public List<WaylineJobEntity> selectList(Long taskType, Long executeTime, String parentId) {
return mapper.selectList(new LambdaQueryWrapper<WaylineJobEntity>()
- .eq(taskType != null,WaylineJobEntity::getTaskType, taskType)
- .ne(WaylineJobEntity::getStatus, WaylineJobStatusEnum.SUCCESS.getVal())
- .eq(executeTime != null,WaylineJobEntity::getBeginTime, executeTime)
- .eq(parentId != null,WaylineJobEntity::getParentId,parentId)
- .ne(WaylineJobEntity::getStatus, 3)
+ .eq(taskType != null, WaylineJobEntity::getTaskType, taskType)
+ .ne(WaylineJobEntity::getStatus, WaylineJobStatusEnum.SUCCESS.getVal())
+ .eq(executeTime != null, WaylineJobEntity::getBeginTime, executeTime)
+ .eq(parentId != null, WaylineJobEntity::getParentId, parentId)
+ .ne(WaylineJobEntity::getStatus, 3)
.orderByDesc(WaylineJobEntity::getId));
}
/**
* 获取所有待定状态的定时任务,未执行即将要执行的。
- * */
- public List<WaylineJobEntity> selectScheduledTaskList(){
+ */
+ public List<WaylineJobEntity> selectScheduledTaskList() {
// "1":"定时任务"
return mapper.selectList(new LambdaQueryWrapper<WaylineJobEntity>()
.eq(WaylineJobEntity::getTaskType, 1)
@@ -852,12 +866,18 @@
// get file url
URL url = null;
- String minioUrl = subStringMinioUrlName(ardRouteOpt.getPath1());
+ String minioUrl = subStringMinioUrlName(ardRouteOpt.getPath());
String md5 = "";
+ String httpUrl = "";
try (InputStream inputStream = _ossService.getObject(kmzPath, minioUrl)) {
md5 = DigestUtils.md5Hex(inputStream);
- url = new URL(ardRouteOpt.getPath1());
- log.info("机场通过flightTaskResourceGet获取航线文件地址,jobId: " + jobId + " 返回信息为url:" + url.toString() + " md5:" + md5);
+ url = new URL(ardRouteOpt.getPath());
+
+ log.info("机场通过flightTaskResourceGet获取航线文件地址转换前:{}", url);
+ httpUrl = url.toString().replace(OssConfiguration.endpoint, DockConfiguration.endpoint);
+ log.info("机场通过flightTaskResourceGet获取航线文件地址转换后:{}", httpUrl);
+
+ log.info("机场通过flightTaskResourceGet获取航线文件地址,jobId: " + jobId + " 返回信息为url:" + httpUrl + " md5:" + md5);
// }
// try {
// url = waylineFileService.getObjectUrl(waylineFile.get().getWaylineId());
@@ -871,9 +891,9 @@
builder.data(RequestsReply.success(WaylineTaskCreateDTO.builder()
.file(WaylineTaskFileDTO.builder()
- .url(url.toString())
- .fingerprint(md5)
- .build())
+ .url(httpUrl)
+ .fingerprint(md5)
+ .build())
.build()));
} catch (NullPointerException | IOException e) {
@@ -884,11 +904,10 @@
}
// 下发参数打印
- try{
+ try {
String json = objectMapper.writeValueAsString(builder.build());
log.info("机场通过flighttask_resource_get获取航线文件的参数flightTask:{}", json);
- }
- catch (Exception e){
+ } catch (Exception e) {
log.error("机场通过flighttask_resource_get获取航线文件的参数flightTask异常:{}", e.getMessage());
}
@@ -926,7 +945,7 @@
.build());
if (ResponseResult.CODE_SUCCESS != reply.getResult()) {
String errorMsg = CommonErrorEnum.getMsgByCode(reply.getResult());
- throw new RuntimeException("未能设置媒体作业上传优先级. Error Code: " + reply.getResult() +", Error Msg: " + errorMsg);
+ throw new RuntimeException("未能设置媒体作业上传优先级. Error Code: " + reply.getResult() + ", Error Msg: " + errorMsg);
}
}
@@ -990,9 +1009,8 @@
fileName = Optional.ofNullable(ardRouteInfo.getName()).orElse("");
}
}
- }
- catch (Exception e) {
- log.info("获取航线名称失败,fileId:{},异常原因:{}", fileId,e.getMessage());
+ } catch (Exception e) {
+ log.info("获取航线名称失败,fileId:{},异常原因:{}", fileId, e.getMessage());
fileName = "";
}
WaylineJobDTO.WaylineJobDTOBuilder builder = WaylineJobDTO.builder()
--
Gitblit v1.9.3