From a0ae2cb2fe95630bb13795b94dd5f2cfadea7a97 Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Sat, 07 Oct 2023 14:28:47 +0800
Subject: [PATCH] 高德地图api接口请求
---
src/main/java/com/dji/sample/wayline/service/impl/WaylineJobServiceImpl.java | 36 +++++++++++++++++++++---------------
1 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/src/main/java/com/dji/sample/wayline/service/impl/WaylineJobServiceImpl.java b/src/main/java/com/dji/sample/wayline/service/impl/WaylineJobServiceImpl.java
index 796a705..6270787 100644
--- a/src/main/java/com/dji/sample/wayline/service/impl/WaylineJobServiceImpl.java
+++ b/src/main/java/com/dji/sample/wayline/service/impl/WaylineJobServiceImpl.java
@@ -171,14 +171,15 @@
LocalDateTime.of(date, LocalTime.ofInstant(Instant.ofEpochSecond(taskPeriod.get(1)), ZoneId.systemDefault()))
.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() : beginTime;
if (WaylineTaskTypeEnum.IMMEDIATE != param.getTaskType() && endTime < System.currentTimeMillis()) {
- return ResponseResult.error("The task has expired.");
+ return ResponseResult.error("任务已过期");
}
Optional<WaylineJobDTO> waylineJobOpt = this.createWaylineJob(param, customClaim.getWorkspaceId(), customClaim.getUsername(), beginTime, endTime);
if (waylineJobOpt.isEmpty()) {
- throw new SQLException("Failed to create wayline job.");
+ throw new SQLException("任务创建失败");
}
WaylineJobDTO waylineJob = waylineJobOpt.get();
// If it is a conditional task type, add conditions to the job parameters.
+ //如果是条件任务类型,需要在任务参数中添加条件。
addPreparedJob(waylineJob, param, beginTime, endTime);
ResponseResult response = this.publishOneFlightTask(waylineJob);
@@ -208,7 +209,7 @@
// value: {workspace_id}:{dock_sn}:{job_id}
boolean isAdd = waylineRedisService.addPreparedWaylineJob(waylineJob);
if (!isAdd) {
- throw new RuntimeException("Failed to create prepare job.");
+ throw new RuntimeException("创建任务失败。");
}
}
@@ -216,14 +217,15 @@
boolean isSuccess = this.prepareFlightTask(waylineJob);
if (!isSuccess) {
- return ResponseResult.error("Failed to prepare job.");
+ return ResponseResult.error("任务准备失败");
}
// Issue an immediate task execution command.
+ //发出立即任务执行命令
if (WaylineTaskTypeEnum.IMMEDIATE == waylineJob.getTaskType()) {
boolean isExecuted = executeFlightTask(waylineJob.getWorkspaceId(), waylineJob.getJobId());
if (!isExecuted) {
- return ResponseResult.error("Failed to execute job.");
+ return ResponseResult.error("执行任务失败");
}
}
@@ -244,6 +246,7 @@
}
// get file url
+ //获取航线文件地址
URL url = waylineFileService.getObjectUrl(waylineJob.getWorkspaceId(), waylineFile.get().getWaylineId());
WaylineTaskCreateDTO flightTask = WaylineTaskCreateDTO.builder()
@@ -259,6 +262,7 @@
.build())
.build();
+ //当任务类型为条件时
if (WaylineTaskTypeEnum.CONDITION == waylineJob.getTaskType()) {
if (Objects.isNull(waylineJob.getConditions())) {
throw new IllegalArgumentException();
@@ -267,10 +271,12 @@
flightTask.setExecutableConditions(waylineJob.getConditions().getExecutableConditions());
}
+ //发布飞行指令
ServiceReply serviceReply = messageSender.publishServicesTopic(
waylineJob.getDockSn(), WaylineMethodEnum.FLIGHT_TASK_PREPARE.getMethod(), flightTask, waylineJob.getJobId());
if (ResponseResult.CODE_SUCCESS != serviceReply.getResult()) {
log.info("Prepare task ====> Error code: {}", serviceReply.getResult());
+ //飞行失败,更新数据库信息
this.updateJob(WaylineJobDTO.builder()
.workspaceId(waylineJob.getWorkspaceId())
.jobId(waylineJob.getJobId())
@@ -288,12 +294,12 @@
// get job
Optional<WaylineJobDTO> waylineJob = this.getJobByJobId(workspaceId, jobId);
if (waylineJob.isEmpty()) {
- throw new IllegalArgumentException("Job doesn't exist.");
+ throw new IllegalArgumentException("任务不存在");
}
boolean isOnline = deviceRedisService.checkDeviceOnline(waylineJob.get().getDockSn());
if (!isOnline) {
- throw new RuntimeException("Dock is offline.");
+ throw new RuntimeException("设备离线");
}
WaylineJobDTO job = waylineJob.get();
@@ -334,7 +340,7 @@
// Check if the task status is correct.
boolean isErr = !jobIds.removeAll(waylineJobIds) || !jobIds.isEmpty() ;
if (isErr) {
- throw new IllegalArgumentException("These tasks have an incorrect status and cannot be canceled. " + Arrays.toString(jobIds.toArray()));
+ throw new IllegalArgumentException("以下任务状态不正确,不能取消" + Arrays.toString(jobIds.toArray()));
}
// Group job id by dock sn.
@@ -348,14 +354,14 @@
public void publishCancelTask(String workspaceId, String dockSn, List<String> jobIds) {
boolean isOnline = deviceRedisService.checkDeviceOnline(dockSn);
if (!isOnline) {
- throw new RuntimeException("Dock is offline.");
+ throw new RuntimeException("设备离线");
}
ServiceReply serviceReply = messageSender.publishServicesTopic(
dockSn, WaylineMethodEnum.FLIGHT_TASK_CANCEL.getMethod(), Map.of(MapKeyConst.FLIGHT_IDS, jobIds));
if (ResponseResult.CODE_SUCCESS != serviceReply.getResult()) {
log.info("Cancel job ====> Error code: {}", serviceReply.getResult());
- throw new RuntimeException("Failed to cancel the wayline job of " + dockSn);
+ throw new RuntimeException("航路作业取消失败 " + dockSn);
}
for (String jobId : jobIds) {
@@ -496,7 +502,7 @@
ServiceReply reply = messageSender.publishServicesTopic(
dockSn, MediaMethodEnum.UPLOAD_FLIGHT_TASK_MEDIA_PRIORITIZE.getMethod(), Map.of(MapKeyConst.FLIGHT_ID, jobId));
if (ResponseResult.CODE_SUCCESS != reply.getResult()) {
- throw new RuntimeException("Failed to set media job upload priority. Error Code: " + reply.getResult());
+ throw new RuntimeException("设置媒体作业上传优先级失败. 错误码: " + reply.getResult());
}
}
@@ -538,12 +544,12 @@
public void updateJobStatus(String workspaceId, String jobId, UpdateJobParam param) {
Optional<WaylineJobDTO> waylineJobOpt = this.getJobByJobId(workspaceId, jobId);
if (waylineJobOpt.isEmpty()) {
- throw new RuntimeException("The job does not exist.");
+ throw new RuntimeException("任务不存在");
}
WaylineJobDTO waylineJob = waylineJobOpt.get();
WaylineJobStatusEnum statusEnum = this.getWaylineState(waylineJob.getDockSn());
if (statusEnum.getEnd() || WaylineJobStatusEnum.PENDING == statusEnum) {
- throw new RuntimeException("The wayline job status does not match, and the operation cannot be performed.");
+ throw new RuntimeException("航路线作业状态不匹配,无法执行操作.");
}
switch (param.getStatus()) {
@@ -591,7 +597,7 @@
ServiceReply reply = messageSender.publishServicesTopic(
dockSn, WaylineMethodEnum.FLIGHT_TASK_PAUSE.getMethod(), "", jobId);
if (ResponseResult.CODE_SUCCESS != reply.getResult()) {
- throw new RuntimeException("Failed to pause wayline job. Error Code: " + reply.getResult());
+ throw new RuntimeException("未能恢复航路作业。错误码: " + reply.getResult());
}
waylineRedisService.delRunningWaylineJob(dockSn);
waylineRedisService.setPausedWaylineJob(dockSn, jobId);
@@ -606,7 +612,7 @@
ServiceReply reply = messageSender.publishServicesTopic(
dockSn, WaylineMethodEnum.FLIGHT_TASK_RESUME.getMethod(), "", jobId);
if (ResponseResult.CODE_SUCCESS != reply.getResult()) {
- throw new RuntimeException("Failed to resume wayline job. Error Code: " + reply.getResult());
+ throw new RuntimeException("未能恢复航路作业。错误码:: " + reply.getResult());
}
runningDataOpt.ifPresent(runningData -> waylineRedisService.setRunningWaylineJob(dockSn, runningData));
--
Gitblit v1.9.3