diff --git a/pom.xml b/pom.xml
index 4f0fea6..9bc22a3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
com.dji
cloud-api-sample
- 1.4.0
+ 1.5.0
cloud-api-sample
diff --git a/sql/cloud_sample.sql b/sql/cloud_sample.sql
index 74fe68c..ef864d9 100644
--- a/sql/cloud_sample.sql
+++ b/sql/cloud_sample.sql
@@ -134,7 +134,8 @@ VALUES
(22,1,67,0,'Mavic 3T Camera',NULL),
(23,2,144,0,'DJI RC Pro','Remote control for Mavic 3E/T and Mavic 3M'),
(24,0,77,2,'Mavic 3M',NULL),
- (25,1,68,0,'Mavic 3M Camera',NULL);
+ (25,1,68,0,'Mavic 3M Camera',NULL),
+ (26,0,89,0,'Matrice 350 RTK',NULL);
/*!40000 ALTER TABLE `manage_device_dictionary` ENABLE KEYS */;
UNLOCK TABLES;
diff --git a/src/main/java/com/dji/sample/component/redis/RedisConst.java b/src/main/java/com/dji/sample/component/redis/RedisConst.java
index cb0ca7a..574ae62 100644
--- a/src/main/java/com/dji/sample/component/redis/RedisConst.java
+++ b/src/main/java/com/dji/sample/component/redis/RedisConst.java
@@ -37,11 +37,9 @@ public final class RedisConst {
public static final String LOGS_FILE_PREFIX = "logs_file" + DELIMITER;
- public static final String WAYLINE_JOB_TIMED_EXECUTE = "wayline_job_timed_execute";
+ public static final String WAYLINE_JOB_PREPARED = "wayline_job_prepared";
- public static final String WAYLINE_JOB_CONDITION_PREPARE = "wayline_job_condition_prepare";
-
- public static final String WAYLINE_JOB_CONDITION_PREFIX = WAYLINE_JOB_CONDITION_PREPARE + DELIMITER;
+ public static final String WAYLINE_JOB_CONDITION_PREFIX = "wayline_job_condition" + DELIMITER;
public static final String WAYLINE_JOB_BLOCK_PREFIX = "wayline_job_block" + DELIMITER;
diff --git a/src/main/java/com/dji/sample/component/websocket/service/impl/WebSocketManageServiceImpl.java b/src/main/java/com/dji/sample/component/websocket/service/impl/WebSocketManageServiceImpl.java
index 61e37e1..a0070d4 100644
--- a/src/main/java/com/dji/sample/component/websocket/service/impl/WebSocketManageServiceImpl.java
+++ b/src/main/java/com/dji/sample/component/websocket/service/impl/WebSocketManageServiceImpl.java
@@ -75,7 +75,7 @@ public class WebSocketManageServiceImpl implements IWebSocketManageService {
return RedisOpsUtils.hashKeys(key)
.stream()
.map(SESSIONS::get)
- .filter(Objects::nonNull)
+ .filter(this.getValueWithWorkspace(workspaceId)::contains)
.collect(Collectors.toSet());
}
diff --git a/src/main/java/com/dji/sample/manage/service/impl/DeviceServiceImpl.java b/src/main/java/com/dji/sample/manage/service/impl/DeviceServiceImpl.java
index 809fd7f..40b5314 100644
--- a/src/main/java/com/dji/sample/manage/service/impl/DeviceServiceImpl.java
+++ b/src/main/java/com/dji/sample/manage/service/impl/DeviceServiceImpl.java
@@ -518,11 +518,39 @@ public class DeviceServiceImpl implements IDeviceService {
}
entity.setId(deviceEntity.getId());
mapper.updateById(entity);
- return Optional.of(deviceEntity);
+ fillNullField(entity, deviceEntity);
+ return Optional.of(entity);
}
return mapper.insert(entity) > 0 ? Optional.of(entity) : Optional.empty();
}
+ private void fillNullField(DeviceEntity entity, DeviceEntity oldEntity) {
+ if (Objects.isNull(entity) || Objects.isNull(oldEntity)) {
+ return;
+ }
+ if (Objects.isNull(entity.getWorkspaceId())) {
+ entity.setWorkspaceId(oldEntity.getWorkspaceId());
+ }
+ if (Objects.isNull(entity.getUserId())) {
+ entity.setUserId(oldEntity.getUserId());
+ }
+ if (Objects.isNull(entity.getChildSn())) {
+ entity.setChildSn(oldEntity.getChildSn());
+ }
+ if (Objects.isNull(entity.getBoundStatus())) {
+ entity.setBoundStatus(oldEntity.getBoundStatus());
+ }
+ if (Objects.isNull(entity.getBoundTime())) {
+ entity.setBoundTime(oldEntity.getBoundTime());
+ }
+ if (Objects.isNull(entity.getFirmwareVersion())) {
+ entity.setFirmwareVersion(oldEntity.getFirmwareVersion());
+ }
+ if (Objects.isNull(entity.getDeviceIndex())) {
+ entity.setDeviceIndex(oldEntity.getDeviceIndex());
+ }
+ }
+
/**
* Convert the received gateway device object into a database entity object.
* @param gateway
@@ -650,7 +678,7 @@ public class DeviceServiceImpl implements IDeviceService {
return;
}
if (entity.getFirmwareVersion().equals(firmwareReleaseNoteOpt.get().getProductVersion())) {
- deviceDTO.setFirmwareStatus(entity.getCompatibleStatus() ?
+ deviceDTO.setFirmwareStatus(Objects.requireNonNullElse(entity.getCompatibleStatus(), true) ?
DeviceFirmwareStatusEnum.NOT_UPGRADE.getVal() :
DeviceFirmwareStatusEnum.CONSISTENT_UPGRADE.getVal());
return;
diff --git a/src/main/java/com/dji/sample/wayline/model/dto/WaylineJobDTO.java b/src/main/java/com/dji/sample/wayline/model/dto/WaylineJobDTO.java
index 718923b..4f36608 100644
--- a/src/main/java/com/dji/sample/wayline/model/dto/WaylineJobDTO.java
+++ b/src/main/java/com/dji/sample/wayline/model/dto/WaylineJobDTO.java
@@ -1,5 +1,7 @@
package com.dji.sample.wayline.model.dto;
+import com.dji.sample.wayline.model.enums.WaylineTaskTypeEnum;
+import com.dji.sample.wayline.model.enums.WaylineTemplateTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@@ -32,9 +34,9 @@ public class WaylineJobDTO {
private String workspaceId;
- private Integer waylineType;
+ private WaylineTemplateTypeEnum waylineType;
- private Integer taskType;
+ private WaylineTaskTypeEnum taskType;
private LocalDateTime executeTime;
diff --git a/src/main/java/com/dji/sample/wayline/model/dto/ConditionalWaylineJobKey.java b/src/main/java/com/dji/sample/wayline/model/dto/WaylineJobKey.java
similarity index 55%
rename from src/main/java/com/dji/sample/wayline/model/dto/ConditionalWaylineJobKey.java
rename to src/main/java/com/dji/sample/wayline/model/dto/WaylineJobKey.java
index 2dd1ca2..f19ed93 100644
--- a/src/main/java/com/dji/sample/wayline/model/dto/ConditionalWaylineJobKey.java
+++ b/src/main/java/com/dji/sample/wayline/model/dto/WaylineJobKey.java
@@ -3,15 +3,13 @@ package com.dji.sample.wayline.model.dto;
import com.dji.sample.component.redis.RedisConst;
import lombok.Data;
-import java.util.Objects;
-
/**
* @author sean
* @version 1.4
* @date 2023/3/28
*/
@Data
-public class ConditionalWaylineJobKey {
+public class WaylineJobKey {
private String workspaceId;
@@ -19,18 +17,17 @@ public class ConditionalWaylineJobKey {
private String jobId;
- public ConditionalWaylineJobKey(String workspaceId, String dockSn, String jobId) {
+ public WaylineJobKey(String workspaceId, String dockSn, String jobId) {
this.workspaceId = workspaceId;
this.dockSn = dockSn;
this.jobId = jobId;
}
+ private WaylineJobKey(String[] keyArr) {
+ this(keyArr[0], keyArr[1], keyArr[2]);
+ }
- public ConditionalWaylineJobKey(String key) {
- if (Objects.isNull(key)) {
- return;
- }
- String[] keyArr = key.split(RedisConst.DELIMITER);
- new ConditionalWaylineJobKey(keyArr[0], keyArr[1], keyArr[2]);
+ public WaylineJobKey(String key) {
+ this(key.split(RedisConst.DELIMITER));
}
public String getKey() {
diff --git a/src/main/java/com/dji/sample/wayline/model/dto/WaylineTaskCreateDTO.java b/src/main/java/com/dji/sample/wayline/model/dto/WaylineTaskCreateDTO.java
index 3297a08..04cde89 100644
--- a/src/main/java/com/dji/sample/wayline/model/dto/WaylineTaskCreateDTO.java
+++ b/src/main/java/com/dji/sample/wayline/model/dto/WaylineTaskCreateDTO.java
@@ -1,5 +1,7 @@
package com.dji.sample.wayline.model.dto;
+import com.dji.sample.wayline.model.enums.WaylineTaskTypeEnum;
+import com.dji.sample.wayline.model.enums.WaylineTemplateTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@@ -18,9 +20,9 @@ public class WaylineTaskCreateDTO {
private String flightId;
- private Integer taskType;
+ private WaylineTaskTypeEnum taskType;
- private Integer waylineType;
+ private WaylineTemplateTypeEnum waylineType;
private Long executeTime;
diff --git a/src/main/java/com/dji/sample/wayline/service/IWaylineRedisService.java b/src/main/java/com/dji/sample/wayline/service/IWaylineRedisService.java
index fa2b99b..0f8408c 100644
--- a/src/main/java/com/dji/sample/wayline/service/IWaylineRedisService.java
+++ b/src/main/java/com/dji/sample/wayline/service/IWaylineRedisService.java
@@ -1,8 +1,8 @@
package com.dji.sample.wayline.service;
import com.dji.sample.component.mqtt.model.EventsReceiver;
-import com.dji.sample.wayline.model.dto.ConditionalWaylineJobKey;
import com.dji.sample.wayline.model.dto.WaylineJobDTO;
+import com.dji.sample.wayline.model.dto.WaylineJobKey;
import com.dji.sample.wayline.model.dto.WaylineTaskProgressReceiver;
import java.util.Optional;
@@ -70,6 +70,13 @@ public interface IWaylineRedisService {
*/
String getBlockedWaylineJobId(String dockSn);
+ /**
+ * Delete the wayline job id blocked by the dock in redis.
+ * @param dockSn
+ * @return
+ */
+ Boolean delBlockedWaylineJobId(String dockSn);
+
/**
* Save the conditional wayline job by the dock to redis.
* @param waylineJob
@@ -90,11 +97,30 @@ public interface IWaylineRedisService {
*/
Boolean delConditionalWaylineJob(String jobId);
- Boolean addPrepareConditionalWaylineJob(WaylineJobDTO waylineJob);
+ /**
+ * Add the wayline job that needs to be issued.
+ * @param waylineJob
+ * @return
+ */
+ Boolean addPreparedWaylineJob(WaylineJobDTO waylineJob);
- Optional getNearestConditionalWaylineJob();
+ /**
+ * Get the latest wayline job that needs to be issued.
+ * @return
+ */
+ Optional getNearestPreparedWaylineJob();
- Double getConditionalWaylineJobTime(ConditionalWaylineJobKey jobKey);
+ /**
+ * Get the time when the wayline job is issued.
+ * @param jobKey
+ * @return
+ */
+ Double getPreparedWaylineJobTime(WaylineJobKey jobKey);
- Boolean removePrepareConditionalWaylineJob(ConditionalWaylineJobKey jobKey);
+ /**
+ * Delete the wayline job that needs to be issued in redis.
+ * @param jobKey
+ * @return
+ */
+ Boolean removePreparedWaylineJob(WaylineJobKey jobKey);
}
diff --git a/src/main/java/com/dji/sample/wayline/service/impl/FlightTaskServiceImpl.java b/src/main/java/com/dji/sample/wayline/service/impl/FlightTaskServiceImpl.java
index 9418b94..893b0bc 100644
--- a/src/main/java/com/dji/sample/wayline/service/impl/FlightTaskServiceImpl.java
+++ b/src/main/java/com/dji/sample/wayline/service/impl/FlightTaskServiceImpl.java
@@ -12,10 +12,11 @@ import com.dji.sample.manage.model.dto.DeviceDTO;
import com.dji.sample.manage.model.enums.UserTypeEnum;
import com.dji.sample.manage.service.IDeviceRedisService;
import com.dji.sample.media.model.MediaFileCountDTO;
-import com.dji.sample.wayline.model.dto.ConditionalWaylineJobKey;
import com.dji.sample.wayline.model.dto.WaylineJobDTO;
+import com.dji.sample.wayline.model.dto.WaylineJobKey;
import com.dji.sample.wayline.model.dto.WaylineTaskProgressReceiver;
import com.dji.sample.wayline.model.enums.WaylineJobStatusEnum;
+import com.dji.sample.wayline.model.enums.WaylineTaskTypeEnum;
import com.dji.sample.wayline.service.IFlightTaskService;
import com.dji.sample.wayline.service.IWaylineJobService;
import com.dji.sample.wayline.service.IWaylineRedisService;
@@ -25,7 +26,6 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.annotation.ServiceActivator;
-import org.springframework.integration.mqtt.support.MqttHeaders;
import org.springframework.messaging.MessageHeaders;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@@ -70,9 +70,6 @@ public class FlightTaskServiceImpl implements IFlightTaskService {
*/
@ServiceActivator(inputChannel = ChannelName.INBOUND_EVENTS_FLIGHT_TASK_PROGRESS, outputChannel = ChannelName.OUTBOUND_EVENTS)
public CommonTopicReceiver handleProgress(CommonTopicReceiver receiver, MessageHeaders headers) {
- String receivedTopic = String.valueOf(headers.get(MqttHeaders.RECEIVED_TOPIC));
- String dockSn = receivedTopic.substring((TopicConst.THING_MODEL_PRE + TopicConst.PRODUCT).length(),
- receivedTopic.indexOf(TopicConst.EVENTS_SUF));
EventsReceiver eventsReceiver = mapper.convertValue(receiver.getData(),
new TypeReference>(){});
eventsReceiver.setBid(receiver.getBid());
@@ -87,42 +84,52 @@ public class FlightTaskServiceImpl implements IFlightTaskService {
}
EventsResultStatusEnum statusEnum = EventsResultStatusEnum.find(output.getStatus());
- waylineRedisService.setRunningWaylineJob(dockSn, eventsReceiver);
-
- if (statusEnum.getEnd()) {
- WaylineJobDTO job = WaylineJobDTO.builder()
- .jobId(receiver.getBid())
- .status(WaylineJobStatusEnum.SUCCESS.getVal())
- .completedTime(LocalDateTime.now())
- .mediaCount(output.getExt().getMediaCount())
- .build();
-
- // record the update of the media count.
- if (Objects.nonNull(job.getMediaCount()) && job.getMediaCount() != 0) {
- RedisOpsUtils.hashSet(RedisConst.MEDIA_FILE_PREFIX + receiver.getGateway(), job.getJobId(),
- MediaFileCountDTO.builder().jobId(receiver.getBid()).mediaCount(job.getMediaCount()).uploadedCount(0).build());
- }
-
- if (EventsResultStatusEnum.OK != statusEnum) {
- job.setCode(eventsReceiver.getResult());
- job.setStatus(WaylineJobStatusEnum.FAILED.getVal());
- }
-
- waylineJobService.updateJob(job);
- waylineRedisService.delRunningWaylineJob(dockSn);
- waylineRedisService.delPausedWaylineJob(receiver.getBid());
- }
+ waylineRedisService.setRunningWaylineJob(receiver.getGateway(), eventsReceiver);
Optional deviceOpt = deviceRedisService.getDeviceOnline(receiver.getGateway());
if (deviceOpt.isEmpty()) {
return null;
}
+
+ if (statusEnum.getEnd()) {
+ handleEndStatus(receiver, statusEnum, output.getExt().getMediaCount(), eventsReceiver.getResult(), deviceOpt.get());
+ }
+
websocketMessageService.sendBatch(deviceOpt.get().getWorkspaceId(), UserTypeEnum.WEB.getVal(),
BizCodeEnum.FLIGHT_TASK_PROGRESS.getCode(), eventsReceiver);
return receiver;
}
+ private void handleEndStatus(CommonTopicReceiver receiver, EventsResultStatusEnum statusEnum, int mediaCount, int code, DeviceDTO dock) {
+
+ WaylineJobDTO job = WaylineJobDTO.builder()
+ .jobId(receiver.getBid())
+ .status(WaylineJobStatusEnum.SUCCESS.getVal())
+ .completedTime(LocalDateTime.now())
+ .mediaCount(mediaCount)
+ .build();
+
+ // record the update of the media count.
+ if (Objects.nonNull(job.getMediaCount()) && job.getMediaCount() != 0) {
+ RedisOpsUtils.hashSet(RedisConst.MEDIA_FILE_PREFIX + receiver.getGateway(), job.getJobId(),
+ MediaFileCountDTO.builder().jobId(receiver.getBid()).mediaCount(job.getMediaCount()).uploadedCount(0).build());
+ }
+
+ if (EventsResultStatusEnum.OK != statusEnum) {
+ job.setCode(code);
+ job.setStatus(WaylineJobStatusEnum.FAILED.getVal());
+ }
+
+ waylineRedisService.getConditionalWaylineJob(receiver.getBid()).ifPresent(waylineJob ->
+ retryPrepareConditionJob(new WaylineJobKey(dock.getWorkspaceId(), dock.getDeviceSn(), receiver.getBid()), waylineJob));
+ waylineJobService.updateJob(job);
+ waylineRedisService.delRunningWaylineJob(receiver.getGateway());
+ waylineRedisService.delPausedWaylineJob(receiver.getBid());
+ waylineRedisService.delBlockedWaylineJobId(receiver.getGateway());
+
+ }
+
/**
* Notifications will be received through this interface when tasks are ready on the device.
* @param receiver
@@ -130,106 +137,65 @@ public class FlightTaskServiceImpl implements IFlightTaskService {
*/
@ServiceActivator(inputChannel = ChannelName.INBOUND_EVENTS_FLIGHT_TASK_READY, outputChannel = ChannelName.OUTBOUND_EVENTS)
public CommonTopicReceiver handleTaskNotifications(CommonTopicReceiver receiver, MessageHeaders headers) {
- String receivedTopic = String.valueOf(headers.get(MqttHeaders.RECEIVED_TOPIC));
- String dockSn = receivedTopic.substring((TopicConst.THING_MODEL_PRE + TopicConst.PRODUCT).length(),
- receivedTopic.indexOf(TopicConst.EVENTS_SUF));
- List flightIds = mapper.convertValue(receiver.getData(),
- new TypeReference