diff --git a/pom.xml b/pom.xml
index 9bc22a3..249aa19 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,85 +1,86 @@
- 4.0.0
-
- org.springframework.boot
- spring-boot-starter-parent
- 2.4.11
-
-
-
- com.dji
- cloud-api-sample
- 1.5.0
- cloud-api-sample
-
-
- 11
- 3.4.2
- 1.2.6
- 3.12.1
- 5.5.5
- 8.3.7
- 4.9.1
- 3.1.0
- 3.12.0
- 1.1.1
- 2.3.3
- 2.15.0
- 2.3.0
-
-
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
-
- mysql
- mysql-connector-java
-
-
-
- org.projectlombok
- lombok
- true
-
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
-
-
- com.baomidou
- mybatis-plus-boot-starter
- ${mybatis-plus.version}
-
-
-
- com.alibaba
- druid-spring-boot-starter
- ${druid.version}
-
-
-
- com.auth0
- java-jwt
- ${jwt.version}
-
-
-
- org.springframework.integration
- spring-integration-mqtt
- ${mqtt.version}
-
-
-
- org.springframework.boot
- spring-boot-starter-websocket
-
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.7.12
+
+
+
+ com.dji
+ cloud-api-sample
+ 1.7.0
+ cloud-api-sample
+
+
+ 11
+ 3.4.2
+ 1.2.6
+ 3.12.1
+ 5.5.5
+ 8.3.7
+ 4.9.1
+ 3.1.0
+ 3.12.0
+ 1.1.1
+ 2.3.3
+ 2.15.0
+ 2.3.0
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ mysql
+ mysql-connector-java
+ 8.0.31
+
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+ com.baomidou
+ mybatis-plus-boot-starter
+ ${mybatis-plus.version}
+
+
+
+ com.alibaba
+ druid-spring-boot-starter
+ ${druid.version}
+
+
+
+ com.auth0
+ java-jwt
+ ${jwt.version}
+
+
+
+ org.springframework.integration
+ spring-integration-mqtt
+ ${mqtt.version}
+
+
+
+ org.springframework.boot
+ spring-boot-starter-websocket
+
org.jetbrains
annotations
@@ -87,115 +88,121 @@
compile
-
- io.minio
- minio
- ${minio.version}
-
-
-
- com.squareup.okhttp3
- okhttp
- ${okhttp3.version}
-
-
-
- com.aliyun
- aliyun-java-sdk-sts
- ${aliyun-sdk-sts.version}
-
-
-
- com.aliyun.oss
- aliyun-sdk-oss
- ${aliyun-oss.version}
-
-
-
- javax.xml.bind
- jaxb-api
-
-
- javax.activation
- activation
- ${javax-activation.version}
-
-
-
- org.glassfish.jaxb
- jaxb-runtime
- ${glassfish-jaxb.version}
-
-
-
- org.springframework.boot
- spring-boot-starter-data-redis
-
-
- org.apache.commons
- commons-pool2
-
-
-
- com.amazonaws
- aws-java-sdk-s3
- 1.12.261
-
-
- com.amazonaws
- aws-java-sdk-sts
- 1.12.261
-
-
-
- com.fasterxml.jackson.datatype
- jackson-datatype-jsr310
-
-
-
- org.springframework.boot
- spring-boot-starter-aop
-
-
-
- org.dom4j
- dom4j
- 2.1.3
-
-
-
- jaxen
- jaxen
-
-
-
- org.bouncycastle
- bcpkix-jdk15on
- 1.69
-
-
-
- org.springframework.boot
- spring-boot-starter-validation
-
-
-
-
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
- org.projectlombok
- lombok
-
-
-
-
-
-
+
+ io.minio
+ minio
+ ${minio.version}
+
+
+
+ com.squareup.okhttp3
+ okhttp
+ ${okhttp3.version}
+
+
+
+ com.aliyun
+ aliyun-java-sdk-sts
+ ${aliyun-sdk-sts.version}
+
+
+
+ com.aliyun.oss
+ aliyun-sdk-oss
+ ${aliyun-oss.version}
+
+
+
+ javax.xml.bind
+ jaxb-api
+
+
+ javax.activation
+ activation
+ ${javax-activation.version}
+
+
+
+ org.glassfish.jaxb
+ jaxb-runtime
+ ${glassfish-jaxb.version}
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-redis
+
+
+ org.apache.commons
+ commons-pool2
+
+
+
+ com.amazonaws
+ aws-java-sdk-s3
+ 1.12.261
+
+
+ com.amazonaws
+ aws-java-sdk-sts
+ 1.12.261
+
+
+
+ com.fasterxml.jackson.datatype
+ jackson-datatype-jsr310
+
+
+
+ org.springframework.boot
+ spring-boot-starter-aop
+
+
+
+ org.dom4j
+ dom4j
+ 2.1.3
+
+
+
+ jaxen
+ jaxen
+
+
+
+ org.bouncycastle
+ bcpkix-jdk15on
+ 1.69
+
+
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
+
+
+
+ org.springdoc
+ springdoc-openapi-ui
+ 1.7.0
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+
+
diff --git a/sql/cloud_sample.sql b/sql/cloud_sample.sql
index ef864d9..18b9c78 100644
--- a/sql/cloud_sample.sql
+++ b/sql/cloud_sample.sql
@@ -21,7 +21,7 @@ CREATE TABLE `logs_file` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`file_id` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'uuid',
`name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'The name of the file in the bucket.',
- `size` int NOT NULL DEFAULT '0' COMMENT 'file size',
+ `size` bigint NOT NULL DEFAULT '0' COMMENT 'file size',
`logs_id` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'The logs_id in the manage_device_logs table.',
`device_sn` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'The sn of the device.',
`fingerprint` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'file fingerprint',
@@ -152,7 +152,7 @@ CREATE TABLE `manage_device_firmware` (
`file_name` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'undefined' COMMENT 'The file name of the firmware package, including the file suffix',
`firmware_version` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'It needs to be formatted according to the official firmware version. 00.00.0000',
`object_key` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'The object key of the firmware package in the bucket.',
- `file_size` int NOT NULL COMMENT 'The size of the firmware package.',
+ `file_size` bigint NOT NULL COMMENT 'The size of the firmware package.',
`file_md5` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'The md5 of the firmware package.',
`workspace_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`release_note` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'The release note of the firmware package.',
@@ -393,7 +393,7 @@ CREATE TABLE `media_file` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`file_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'uuid',
`file_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'The original name of the file.',
- `file_path` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'The path of the file.',
+ `file_path` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'The path of the file.',
`workspace_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'The workspace to which the file belongs.',
`fingerprint` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT '' COMMENT 'The fingerprint of the file. This property exists only for media files uploaded by Pilot.',
`tinny_fingerprint` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT '' COMMENT 'The tiny fingerprint of the file. This property exists only for media files uploaded by Pilot.',
diff --git a/src/main/java/com/dji/sample/CloudApiSampleApplication.java b/src/main/java/com/dji/sample/CloudApiSampleApplication.java
index a3619ab..b36e909 100644
--- a/src/main/java/com/dji/sample/CloudApiSampleApplication.java
+++ b/src/main/java/com/dji/sample/CloudApiSampleApplication.java
@@ -3,12 +3,13 @@ package com.dji.sample;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
@MapperScan("com.dji.sample.*.dao")
@SpringBootApplication
@EnableScheduling
-//@EnableConfigurationProperties(OssConfiguration.class)
+@ComponentScan("com.dji")
public class CloudApiSampleApplication {
public static void main(String[] args) {
diff --git a/src/main/java/com/dji/sample/common/error/CommonErrorEnum.java b/src/main/java/com/dji/sample/common/error/CommonErrorEnum.java
index 1ab3b32..73043a6 100644
--- a/src/main/java/com/dji/sample/common/error/CommonErrorEnum.java
+++ b/src/main/java/com/dji/sample/common/error/CommonErrorEnum.java
@@ -1,5 +1,7 @@
package com.dji.sample.common.error;
+import com.dji.sdk.common.IErrorInfo;
+
/**
* @author sean.zhou
* @version 0.1
@@ -43,12 +45,13 @@ public enum CommonErrorEnum implements IErrorInfo {
}
@Override
- public String getErrorMsg() {
+ public String getMessage() {
return this.msg;
}
@Override
- public Integer getErrorCode() {
+ public Integer getCode() {
return this.code;
}
+
}
diff --git a/src/main/java/com/dji/sample/common/error/LiveErrorEnum.java b/src/main/java/com/dji/sample/common/error/LiveErrorEnum.java
deleted file mode 100644
index 6ba3f95..0000000
--- a/src/main/java/com/dji/sample/common/error/LiveErrorEnum.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package com.dji.sample.common.error;
-
-/**
- * Live streaming related error codes. When on-demand via mqtt,
- * it can be matched with the error code information replied by the pilot.
- * @author sean.zhou
- * @version 0.1
- * @date 2021/11/25
- */
-public enum LiveErrorEnum implements IErrorInfo {
-
- NO_AIRCRAFT(613001, "No aircraft."),
-
- NO_CAMERA(613002, "No camera."),
-
- LIVE_STREAM_ALREADY_STARTED(613003, "The camera has started live streaming."),
-
- FUNCTION_NOT_SUPPORT(613004, "The function is not supported."),
-
- STRATEGY_NOT_SUPPORT(613005, "The strategy is not supported."),
-
- NOT_IN_CAMERA_INTERFACE(613006, "The current app is not in the camera interface."),
-
- NO_FLIGHT_CONTROL(613007, "The remote control has no flight control rights and cannot respond to control commands"),
-
- NO_STREAM_DATA(613008, "The current app has no stream data."),
-
- TOO_FREQUENT(613009, "The operation is too frequent."),
-
- ENABLE_FAILED(613010, "Please check whether the live stream service is normal."),
-
- NO_LIVE_STREAM(613011, "There are no live stream currently."),
-
- SWITCH_NOT_SUPPORT(613012, "There is already another camera in the live stream. It's not support to switch the stream directly."),
-
- URL_TYPE_NOT_SUPPORTED(613013, "This url type is not supported."),
-
- ERROR_PARAMETERS(613014, "The live stream parameters are abnormal or incomplete."),
-
- NO_REPLY(613098, "No live reply received."),
-
- UNKNOWN(613099, "UNKNOWN");
-
-
- private String msg;
-
- private int code;
-
- LiveErrorEnum(int code, String msg) {
- this.code = code;
- this.msg = msg;
- }
-
- @Override
- public String getErrorMsg() {
- return this.msg;
- }
-
- @Override
- public Integer getErrorCode() {
- return this.code;
- }
-
- /**
- * Get the corresponding enumeration object based on the error code.
- * @param code error code
- * @return enumeration object
- */
- public static LiveErrorEnum find(int code) {
- final int MOD = 100_000;
- for (LiveErrorEnum errorEnum : LiveErrorEnum.class.getEnumConstants()) {
- if (errorEnum.code % MOD == code % MOD) {
- return errorEnum;
- }
- }
- return UNKNOWN;
- }
-}
diff --git a/src/main/java/com/dji/sample/common/model/Pagination.java b/src/main/java/com/dji/sample/common/model/Pagination.java
deleted file mode 100644
index 74d1e8a..0000000
--- a/src/main/java/com/dji/sample/common/model/Pagination.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.dji.sample.common.model;
-
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import lombok.Data;
-
-/**
- * Used for paging display in the wayline. These field names cannot be changed.
- * Because they need to be the same as the pilot.
- * @author sean
- * @version 0.3
- * @date 2021/12/22
- */
-@Data
-public class Pagination {
-
- /**
- * The current page number.
- */
- private long page;
-
- /**
- * The amount of data displayed per page.
- */
- private long pageSize;
-
- /**
- * The total amount of all data.
- */
- private long total;
-
- public Pagination(Page page) {
- this.page = page.getCurrent();
- this.pageSize = page.getSize();
- this.total = page.getTotal();
- }
-}
diff --git a/src/main/java/com/dji/sample/common/model/PaginationData.java b/src/main/java/com/dji/sample/common/model/PaginationData.java
deleted file mode 100644
index 95e2442..0000000
--- a/src/main/java/com/dji/sample/common/model/PaginationData.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.dji.sample.common.model;
-
-import lombok.Data;
-
-import java.util.List;
-
-/**
- * The format of the data response when a paginated display is required.
- * @author sean
- * @version 0.3
- * @date 2021/12/22
- */
-@Data
-public class PaginationData {
-
- /**
- * The collection in which the data list is stored.
- */
- private List list;
-
- private Pagination pagination;
-
- public PaginationData(List list, Pagination pagination) {
- this.list = list;
- this.pagination = pagination;
- }
-}
diff --git a/src/main/java/com/dji/sample/common/model/ResponseResult.java b/src/main/java/com/dji/sample/common/model/ResponseResult.java
deleted file mode 100644
index 8ad8e1b..0000000
--- a/src/main/java/com/dji/sample/common/model/ResponseResult.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package com.dji.sample.common.model;
-
-import com.dji.sample.common.error.IErrorInfo;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import org.springframework.http.HttpStatus;
-
-@Data
-@AllArgsConstructor
-@NoArgsConstructor
-@Builder
-@JsonInclude
-public class ResponseResult {
-
- public static final int CODE_SUCCESS = 0;
- public static final String MESSAGE_SUCCESS = "success";
-
- private int code;
-
- private String message;
-
- private T data;
-
- public static ResponseResult success(T data) {
- return ResponseResult.builder()
- .code(CODE_SUCCESS)
- .message(MESSAGE_SUCCESS)
- .data(data)
- .build();
- }
-
- public static ResponseResult success() {
- return ResponseResult.builder()
- .code(0)
- .message(MESSAGE_SUCCESS)
- .build();
- }
-
- public static ResponseResult error() {
- return ResponseResult.builder()
- .code(HttpStatus.INTERNAL_SERVER_ERROR.value())
- .message(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
- .build();
- }
-
- public static ResponseResult error(String message) {
- return ResponseResult.builder()
- .code(HttpStatus.INTERNAL_SERVER_ERROR.value())
- .message(message)
- .build();
- }
-
- public static ResponseResult error(int code, String message) {
- return ResponseResult.builder()
- .code(code)
- .message(message)
- .build();
- }
-
- public static ResponseResult error(IErrorInfo errorInfo) {
- return ResponseResult.builder()
- .code(errorInfo.getErrorCode())
- .message(errorInfo.getErrorMsg())
- .build();
- }
-}
diff --git a/src/main/java/com/dji/sample/common/util/JwtUtil.java b/src/main/java/com/dji/sample/common/util/JwtUtil.java
index c04168e..d1e9c03 100644
--- a/src/main/java/com/dji/sample/common/util/JwtUtil.java
+++ b/src/main/java/com/dji/sample/common/util/JwtUtil.java
@@ -105,7 +105,7 @@ public class JwtUtil {
}
if (Objects.nonNull(age)) {
- builder.withExpiresAt(new Date(now.getTime() + age * 1000));
+ builder.withExpiresAt(new Date(now.getTime() + age));
}
String token = builder
diff --git a/src/main/java/com/dji/sample/common/util/SpringBeanUtilsTest.java b/src/main/java/com/dji/sample/common/util/SpringBeanUtilsTest.java
new file mode 100644
index 0000000..cbe4ab1
--- /dev/null
+++ b/src/main/java/com/dji/sample/common/util/SpringBeanUtilsTest.java
@@ -0,0 +1,30 @@
+package com.dji.sample.common.util;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author sean
+ * @version 1.3
+ * @date 2022/11/10
+ */
+@Component
+public class SpringBeanUtilsTest implements ApplicationContextAware {
+
+ private static ApplicationContext applicationContext;
+
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+ SpringBeanUtilsTest.applicationContext = applicationContext;
+ }
+
+ public static T getBean(Class clazz) {
+ return applicationContext.getBean(clazz);
+ }
+
+ public static Object getBean(String beanName) {
+ return applicationContext.getBean(beanName);
+ }
+}
diff --git a/src/main/java/com/dji/sample/component/ApplicationBootInitial.java b/src/main/java/com/dji/sample/component/ApplicationBootInitial.java
index d99f58d..16a691c 100644
--- a/src/main/java/com/dji/sample/component/ApplicationBootInitial.java
+++ b/src/main/java/com/dji/sample/component/ApplicationBootInitial.java
@@ -2,11 +2,17 @@ package com.dji.sample.component;
import com.dji.sample.component.redis.RedisConst;
import com.dji.sample.component.redis.RedisOpsUtils;
+import com.dji.sample.manage.model.dto.DeviceDTO;
+import com.dji.sample.manage.service.IDeviceRedisService;
import com.dji.sample.manage.service.IDeviceService;
+import com.dji.sdk.cloudapi.device.DeviceDomainEnum;
+import com.dji.sdk.common.SDKManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
+import java.util.Optional;
+
/**
* @author sean.zhou
* @date 2021/11/24
@@ -18,6 +24,9 @@ public class ApplicationBootInitial implements CommandLineRunner {
@Autowired
private IDeviceService deviceService;
+ @Autowired
+ private IDeviceRedisService deviceRedisService;
+
/**
* Subscribe to the devices that exist in the redis when the program starts,
* to prevent the data from being different from the pilot side due to program interruptions.
@@ -29,7 +38,15 @@ public class ApplicationBootInitial implements CommandLineRunner {
int start = RedisConst.DEVICE_ONLINE_PREFIX.length();
RedisOpsUtils.getAllKeys(RedisConst.DEVICE_ONLINE_PREFIX + "*")
- .forEach(key -> deviceService.subscribeTopicOnline(key.substring(start)));
+ .stream()
+ .map(key -> key.substring(start))
+ .map(deviceRedisService::getDeviceOnline)
+ .map(Optional::get)
+ .filter(device -> DeviceDomainEnum.DRONE != device.getDomain())
+ .forEach(device -> deviceService.subDeviceOnlineSubscribeTopic(
+ SDKManager.registerDevice(device.getDeviceSn(), device.getChildDeviceSn(), device.getDomain(),
+ device.getType(), device.getSubType(), device.getThingVersion(),
+ deviceRedisService.getDeviceOnline(device.getChildDeviceSn()).map(DeviceDTO::getThingVersion).orElse(null))));
}
}
\ No newline at end of file
diff --git a/src/main/java/com/dji/sample/component/AuthInterceptor.java b/src/main/java/com/dji/sample/component/AuthInterceptor.java
index 0d3b8f7..9933466 100644
--- a/src/main/java/com/dji/sample/component/AuthInterceptor.java
+++ b/src/main/java/com/dji/sample/component/AuthInterceptor.java
@@ -26,7 +26,7 @@ public class AuthInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String uri = request.getRequestURI();
- log.debug("request uri: {}", uri);
+ log.debug("request uri: {}, IP: {}", uri, request.getRemoteAddr());
// The options method is passed directly.
if (HttpMethod.OPTIONS.matches(request.getMethod())) {
response.setStatus(HttpStatus.OK.value());
@@ -36,7 +36,7 @@ public class AuthInterceptor implements HandlerInterceptor {
// Check if the token exists.
if (!StringUtils.hasText(token)) {
response.setStatus(HttpStatus.UNAUTHORIZED.value());
- log.error(CommonErrorEnum.NO_TOKEN.getErrorMsg());
+ log.error(CommonErrorEnum.NO_TOKEN.getMessage());
return false;
}
diff --git a/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java b/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java
index 0b6b6b0..f7e79c2 100644
--- a/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java
+++ b/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java
@@ -1,6 +1,6 @@
package com.dji.sample.component;
-import com.dji.sample.common.model.ResponseResult;
+import com.dji.sdk.common.HttpResultResponse;
import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
@@ -22,21 +22,21 @@ public class GlobalExceptionHandler {
* @return
*/
@ExceptionHandler(Exception.class)
- public ResponseResult exceptionHandler(Exception e) {
+ public HttpResultResponse exceptionHandler(Exception e) {
e.printStackTrace();
- return ResponseResult.error(e.getLocalizedMessage());
+ return HttpResultResponse.error(e.getLocalizedMessage());
}
@ExceptionHandler(NullPointerException.class)
- public ResponseResult nullPointerExceptionHandler(NullPointerException e) {
+ public HttpResultResponse nullPointerExceptionHandler(NullPointerException e) {
e.printStackTrace();
- return ResponseResult.error("A null object appeared.");
+ return HttpResultResponse.error("A null object appeared.");
}
@ExceptionHandler({MethodArgumentNotValidException.class, BindException.class})
- public ResponseResult methodArgumentNotValidExceptionHandler(BindException e) {
+ public HttpResultResponse methodArgumentNotValidExceptionHandler(BindException e) {
e.printStackTrace();
- return ResponseResult.error(e.getFieldError().getField() + e.getFieldError().getDefaultMessage());
+ return HttpResultResponse.error(e.getFieldError().getField() + e.getFieldError().getDefaultMessage());
}
}
diff --git a/src/main/java/com/dji/sample/component/GlobalScheduleService.java b/src/main/java/com/dji/sample/component/GlobalScheduleService.java
index 7e77a34..fe4dfd2 100644
--- a/src/main/java/com/dji/sample/component/GlobalScheduleService.java
+++ b/src/main/java/com/dji/sample/component/GlobalScheduleService.java
@@ -1,12 +1,11 @@
package com.dji.sample.component;
-import com.dji.sample.component.mqtt.service.IMqttTopicService;
import com.dji.sample.component.redis.RedisConst;
import com.dji.sample.component.redis.RedisOpsUtils;
import com.dji.sample.manage.model.dto.DeviceDTO;
-import com.dji.sample.manage.model.enums.DeviceDomainEnum;
import com.dji.sample.manage.service.IDeviceService;
-import com.dji.sample.wayline.service.IWaylineJobService;
+import com.dji.sdk.cloudapi.device.DeviceDomainEnum;
+import com.dji.sdk.mqtt.IMqttTopicService;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -31,8 +30,6 @@ public class GlobalScheduleService {
@Autowired
private IMqttTopicService topicService;
- @Autowired
- private IWaylineJobService waylineJobService;
@Autowired
private ObjectMapper mapper;
/**
@@ -46,14 +43,13 @@ public class GlobalScheduleService {
long expire = RedisOpsUtils.getExpire(key);
if (expire <= 30) {
DeviceDTO device = (DeviceDTO) RedisOpsUtils.get(key);
- if (DeviceDomainEnum.SUB_DEVICE.getVal() == device.getDomain()) {
+ if (null == device) {
+ return;
+ }
+ if (DeviceDomainEnum.DRONE == device.getDomain()) {
deviceService.subDeviceOffline(key.substring(start));
} else {
- deviceService.unsubscribeTopicOffline(key.substring(start));
- deviceService.pushDeviceOfflineTopo(device.getWorkspaceId(), device.getDeviceSn());
- RedisOpsUtils.hashDel(RedisConst.LIVE_CAPACITY, new String[]{device.getDeviceSn()});
- RedisOpsUtils.del(RedisConst.HMS_PREFIX + device.getDeviceSn());
- RedisOpsUtils.del(RedisConst.OSD_PREFIX + device.getDeviceSn());
+ deviceService.gatewayOffline(key.substring(start));
}
RedisOpsUtils.del(key);
}
diff --git a/src/main/java/com/dji/sample/component/mqtt/config/MqttMessageChannel.java b/src/main/java/com/dji/sample/component/mqtt/config/MqttMessageChannel.java
index 8ff8629..aba87cb 100644
--- a/src/main/java/com/dji/sample/component/mqtt/config/MqttMessageChannel.java
+++ b/src/main/java/com/dji/sample/component/mqtt/config/MqttMessageChannel.java
@@ -1,6 +1,6 @@
package com.dji.sample.component.mqtt.config;
-import com.dji.sample.component.mqtt.model.ChannelName;
+import com.dji.sdk.mqtt.ChannelName;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -27,18 +27,13 @@ public class MqttMessageChannel {
return new ExecutorChannel(threadPool);
}
- @Bean(name = ChannelName.INBOUND_STATUS)
- public MessageChannel statusChannel() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_STATUS_ONLINE)
- public MessageChannel statusOnlineChannel() {
+ @Bean(name = ChannelName.DEFAULT)
+ public MessageChannel defaultChannel() {
return new DirectChannel();
}
- @Bean(name = ChannelName.INBOUND_STATUS_OFFLINE)
- public MessageChannel statusOffChannel() {
+ @Bean(name = ChannelName.INBOUND_STATUS)
+ public MessageChannel statusChannel() {
return new DirectChannel();
}
@@ -47,158 +42,34 @@ public class MqttMessageChannel {
return new DirectChannel();
}
- @Bean(name = ChannelName.INBOUND_STATE_BASIC)
- public MessageChannel stateBasicChannel() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_STATE_PAYLOAD)
- public MessageChannel statePayloadChannel() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_SERVICE_REPLY)
+ @Bean(name = ChannelName.INBOUND_SERVICES_REPLY)
public MessageChannel serviceReplyChannel() {
return new DirectChannel();
}
- @Bean(name = ChannelName.INBOUND_STATE_CAPACITY)
- public MessageChannel stateCapacityChannel() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_STATE_PAYLOAD_UPDATE)
- public MessageChannel statePayloadUpdateChannel() {
- return new DirectChannel();
- }
-
@Bean(name = ChannelName.INBOUND_OSD)
public MessageChannel osdChannel() {
return new ExecutorChannel(threadPool);
}
- @Bean(name = ChannelName.DEFAULT)
- public MessageChannel defaultChannel() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.OUTBOUND)
- public MessageChannel outboundChannel() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_STATE_FIRMWARE_VERSION)
- public MessageChannel stateFirmwareVersionChannel() {
- return new DirectChannel();
- }
-
@Bean(name = ChannelName.INBOUND_REQUESTS)
public MessageChannel requestsChannel() {
return new DirectChannel();
}
- @Bean(name = ChannelName.INBOUND_REQUESTS_STORAGE_CONFIG_GET)
- public MessageChannel requestsConfigGetChannel() {
- return new DirectChannel();
- }
-
@Bean(name = ChannelName.INBOUND_EVENTS)
public MessageChannel eventsChannel() {
return new DirectChannel();
}
- @Bean(name = ChannelName.OUTBOUND_EVENTS)
- public MessageChannel eventsOutboundChannel() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_EVENTS_FLIGHT_TASK_PROGRESS)
- public MessageChannel eventsFlightTaskProgressChannel() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_EVENTS_FILE_UPLOAD_CALLBACK)
- public MessageChannel eventsFileUploadCallbackChannel() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_REQUESTS_AIRPORT_BIND_STATUS)
- public MessageChannel requestsAirportBindStatusChannel() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_REQUESTS_AIRPORT_ORGANIZATION_GET)
- public MessageChannel requestsAirportOrganizationGetChannel() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_REQUESTS_AIRPORT_ORGANIZATION_BIND)
- public MessageChannel requestsAirportOrganizationBindChannel() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_EVENTS_HMS)
- public MessageChannel eventsHms() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_EVENTS_CONTROL_PROGRESS)
- public MessageChannel eventsControlProgress() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_EVENTS_OTA_PROGRESS)
- public MessageChannel eventsOtaProgress() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_EVENTS_FILE_UPLOAD_PROGRESS)
- public MessageChannel eventsFileUploadProgress() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_REQUESTS_FLIGHT_TASK_RESOURCE_GET)
- public MessageChannel requestsFlightTaskResourceGet() {
- return new DirectChannel();
- }
-
@Bean(name = ChannelName.INBOUND_PROPERTY_SET_REPLY)
public MessageChannel propertySetReply() {
return new DirectChannel();
}
- @Bean(name = ChannelName.INBOUND_REQUESTS_CONFIG)
- public MessageChannel requestsConfig() {
+ @Bean(name = ChannelName.INBOUND_DRC_UP)
+ public MessageChannel drcUp() {
return new DirectChannel();
}
- @Bean(name = ChannelName.INBOUND_EVENTS_HIGHEST_PRIORITY_UPLOAD_FLIGHT_TASK_MEDIA)
- public MessageChannel eventsHighestPriorityUploadFlightTaskMedia() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_EVENTS_FLIGHT_TASK_READY)
- public MessageChannel eventsEventsFlightTaskReady() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_EVENTS_FLY_TO_POINT_PROGRESS)
- public MessageChannel eventsFlyToPointProgress() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_EVENTS_TAKE_OFF_TO_POINT_PROGRESS)
- public MessageChannel eventsTakeoffToPointProgress() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_EVENTS_DRC_STATUS_NOTIFY)
- public MessageChannel eventsDrcStatusNotify() {
- return new DirectChannel();
- }
-
- @Bean(name = ChannelName.INBOUND_EVENTS_DRC_MODE_EXIT_NOTIFY)
- public MessageChannel eventsDrcModeExitNotify() {
- return new DirectChannel();
- }
}
diff --git a/src/main/java/com/dji/sample/component/mqtt/config/MqttOutboundConfiguration.java b/src/main/java/com/dji/sample/component/mqtt/config/MqttOutboundConfiguration.java
deleted file mode 100644
index a376093..0000000
--- a/src/main/java/com/dji/sample/component/mqtt/config/MqttOutboundConfiguration.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.dji.sample.component.mqtt.config;
-
-import com.dji.sample.component.mqtt.model.ChannelName;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.integration.annotation.ServiceActivator;
-import org.springframework.integration.mqtt.core.MqttPahoClientFactory;
-import org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler;
-import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter;
-import org.springframework.messaging.MessageHandler;
-
-/**
- * Client configuration for outbound messages.
- * @author sean.zhou
- * @date 2021/11/10
- * @version 0.1
- */
-@Configuration
-public class MqttOutboundConfiguration {
-
- @Autowired
- private MqttConfiguration mqttConfiguration;
-
- @Autowired
- private MqttPahoClientFactory mqttClientFactory;
-
- /**
- * Clients of outbound message channels.
- * @return
- */
- @Bean
- @ServiceActivator(inputChannel = ChannelName.OUTBOUND)
- public MessageHandler mqttOutbound() {
- MqttPahoMessageHandler messageHandler = new MqttPahoMessageHandler(
- MqttConfiguration.getBasicClientOptions().getClientId() + "_producer_" + System.currentTimeMillis(),
- mqttClientFactory);
- DefaultPahoMessageConverter converter = new DefaultPahoMessageConverter();
- // use byte types uniformly
- converter.setPayloadAsBytes(true);
-
- messageHandler.setAsync(true);
- messageHandler.setDefaultQos(0);
- messageHandler.setConverter(converter);
- return messageHandler;
- }
-}
diff --git a/src/main/java/com/dji/sample/component/mqtt/config/MqttConfiguration.java b/src/main/java/com/dji/sample/component/mqtt/config/MqttPropertyConfiguration.java
similarity index 86%
rename from src/main/java/com/dji/sample/component/mqtt/config/MqttConfiguration.java
rename to src/main/java/com/dji/sample/component/mqtt/config/MqttPropertyConfiguration.java
index ba8d939..2f7dd86 100644
--- a/src/main/java/com/dji/sample/component/mqtt/config/MqttConfiguration.java
+++ b/src/main/java/com/dji/sample/component/mqtt/config/MqttPropertyConfiguration.java
@@ -5,7 +5,7 @@ import com.dji.sample.common.util.JwtUtil;
import com.dji.sample.component.mqtt.model.MqttClientOptions;
import com.dji.sample.component.mqtt.model.MqttProtocolEnum;
import com.dji.sample.component.mqtt.model.MqttUseEnum;
-import com.dji.sample.control.model.dto.MqttBrokerDTO;
+import com.dji.sdk.cloudapi.control.DrcModeMqttBroker;
import lombok.Data;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -26,12 +26,12 @@ import java.util.Map;
@Configuration
@Data
@ConfigurationProperties
-public class MqttConfiguration {
+public class MqttPropertyConfiguration {
private static Map mqtt;
public void setMqtt(Map mqtt) {
- MqttConfiguration.mqtt = mqtt;
+ MqttPropertyConfiguration.mqtt = mqtt;
}
/**
@@ -79,7 +79,7 @@ public class MqttConfiguration {
* @param map Custom data added in token.
* @return
*/
- public static MqttBrokerDTO getMqttBrokerWithDrc(String clientId, String username, Long age, Map map) {
+ public static DrcModeMqttBroker getMqttBrokerWithDrc(String clientId, String username, Long age, Map map) {
if (!mqtt.containsKey(MqttUseEnum.DRC)) {
throw new RuntimeException("Please configure the drc link parameters of mqtt in the backend configuration file first.");
}
@@ -87,13 +87,13 @@ public class MqttConfiguration {
String token = JwtUtil.createToken(map, age, algorithm, null, null);
- return MqttBrokerDTO.builder()
- .address(getMqttAddress(mqtt.get(MqttUseEnum.DRC)))
- .username(username)
- .clientId(clientId)
- .expireTime(System.currentTimeMillis() / 1000 + age)
- .password(token)
- .build();
+ return new DrcModeMqttBroker()
+ .setAddress(getMqttAddress(mqtt.get(MqttUseEnum.DRC)))
+ .setUsername(username)
+ .setClientId(clientId)
+ .setExpireTime(System.currentTimeMillis() / 1000 + age)
+ .setPassword(token)
+ .setEnableTls(false);
}
diff --git a/src/main/java/com/dji/sample/component/mqtt/handler/AbstractStateTopicHandler.java b/src/main/java/com/dji/sample/component/mqtt/handler/AbstractStateTopicHandler.java
deleted file mode 100644
index c3969f3..0000000
--- a/src/main/java/com/dji/sample/component/mqtt/handler/AbstractStateTopicHandler.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.dji.sample.component.mqtt.handler;
-
-import com.dji.sample.component.mqtt.model.CommonTopicReceiver;
-import com.dji.sample.component.redis.RedisOpsUtils;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import java.util.Map;
-
-/**
- * @author sean
- * @version 0.3
- * @date 2022/2/21
- */
-public abstract class AbstractStateTopicHandler {
-
- protected AbstractStateTopicHandler handler;
-
- @Autowired
- protected ObjectMapper mapper;
-
- @Autowired
- protected RedisOpsUtils redisOps;
-
- protected AbstractStateTopicHandler(AbstractStateTopicHandler handler) {
- this.handler = handler;
- }
-
- /**
- * Passing dataNode data, using different processing methods depending on the data selection.
- * @param dataNode
- * @param stateReceiver
- * @param sn
- * @return
- * @throws JsonProcessingException
- */
- public abstract CommonTopicReceiver handleState(Map dataNode, CommonTopicReceiver stateReceiver, String sn) throws JsonProcessingException;
-}
diff --git a/src/main/java/com/dji/sample/component/mqtt/handler/EventsRouter.java b/src/main/java/com/dji/sample/component/mqtt/handler/EventsRouter.java
deleted file mode 100644
index 152ae81..0000000
--- a/src/main/java/com/dji/sample/component/mqtt/handler/EventsRouter.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package com.dji.sample.component.mqtt.handler;
-
-import com.dji.sample.component.mqtt.model.*;
-import com.dji.sample.component.mqtt.service.IMessageSenderService;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.integration.annotation.ServiceActivator;
-import org.springframework.integration.dsl.IntegrationFlow;
-import org.springframework.integration.dsl.IntegrationFlows;
-import org.springframework.integration.mqtt.support.MqttHeaders;
-import org.springframework.messaging.MessageHeaders;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Optional;
-
-/**
- * @author sean
- * @version 1.1
- * @date 2022/6/1
- */
-@Configuration
-public class EventsRouter {
-
- @Autowired
- private ObjectMapper mapper;
-
- @Autowired
- private IMessageSenderService messageSenderService;
-
- @Bean
- public IntegrationFlow eventsMethodRouterFlow() {
- return IntegrationFlows
- .from(ChannelName.INBOUND_EVENTS)
- .transform(payload -> {
- try {
- return mapper.readValue(payload, CommonTopicReceiver.class);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return new CommonTopicReceiver();
- })
- .route(
- receiver -> EventsMethodEnum.find(receiver.getMethod()),
- mapping -> Arrays.stream(EventsMethodEnum.values()).forEach(
- methodEnum -> mapping.channelMapping(methodEnum, methodEnum.getChannelName())))
- .get();
- }
-
- @ServiceActivator(inputChannel = ChannelName.OUTBOUND_EVENTS, outputChannel = ChannelName.OUTBOUND)
- public void replyEventsOutbound(CommonTopicReceiver receiver, MessageHeaders headers) {
- if (Optional.ofNullable(receiver).map(CommonTopicReceiver::getNeedReply).flatMap(val -> Optional.of(1 != val)).orElse(true)) {
- return;
- }
- messageSenderService.publish(headers.get(MqttHeaders.RECEIVED_TOPIC) + TopicConst._REPLY_SUF,
- CommonTopicResponse.builder()
- .tid(receiver.getTid())
- .bid(receiver.getBid())
- .method(receiver.getMethod())
- .timestamp(System.currentTimeMillis())
- .data(RequestsReply.success())
- .build());
-
- }
-
-}
diff --git a/src/main/java/com/dji/sample/component/mqtt/handler/PropertySetReplyHandler.java b/src/main/java/com/dji/sample/component/mqtt/handler/PropertySetReplyHandler.java
deleted file mode 100644
index 9b503eb..0000000
--- a/src/main/java/com/dji/sample/component/mqtt/handler/PropertySetReplyHandler.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.dji.sample.component.mqtt.handler;
-
-import com.dji.sample.component.mqtt.model.Chan;
-import com.dji.sample.component.mqtt.model.ChannelName;
-import com.dji.sample.component.mqtt.model.CommonTopicReceiver;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.integration.annotation.ServiceActivator;
-import org.springframework.messaging.Message;
-import org.springframework.stereotype.Component;
-
-import java.io.IOException;
-
-/**
- * @author sean
- * @version 1.2
- * @date 2022/9/9
- */
-@Component
-public class PropertySetReplyHandler {
-
- @Autowired
- private ObjectMapper mapper;
-
- /**
- * Handle the reply message from the pilot side to the on-demand video.
- * @param message reply message
- * @throws IOException
- */
- @ServiceActivator(inputChannel = ChannelName.INBOUND_PROPERTY_SET_REPLY)
- public void serviceReply(Message> message) throws IOException {
- byte[] payload = (byte[])message.getPayload();
-
- CommonTopicReceiver receiver = mapper.readValue(payload, new TypeReference() {});
- Chan> chan = Chan.getInstance();
- // Put the message to the chan object.
- chan.put(receiver);
- }
-}
diff --git a/src/main/java/com/dji/sample/component/mqtt/handler/RequestsRouter.java b/src/main/java/com/dji/sample/component/mqtt/handler/RequestsRouter.java
deleted file mode 100644
index 95e0f7d..0000000
--- a/src/main/java/com/dji/sample/component/mqtt/handler/RequestsRouter.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.dji.sample.component.mqtt.handler;
-
-import com.dji.sample.component.mqtt.model.ChannelName;
-import com.dji.sample.component.mqtt.model.CommonTopicReceiver;
-import com.dji.sample.component.mqtt.model.RequestsMethodEnum;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.integration.dsl.IntegrationFlow;
-import org.springframework.integration.dsl.IntegrationFlows;
-
-import java.io.IOException;
-import java.util.Arrays;
-
-/**
- * @author sean
- * @version 1.0
- * @date 2022/5/25
- */
-@Configuration
-public class RequestsRouter {
-
- @Autowired
- private ObjectMapper mapper;
-
- @Bean
- public IntegrationFlow requestsMethodRouterFlow() {
- return IntegrationFlows
- .from(ChannelName.INBOUND_REQUESTS)
- .transform(payload -> {
- try {
- return mapper.readValue(payload, CommonTopicReceiver.class);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return new CommonTopicReceiver();
- })
- .route(
- receiver -> RequestsMethodEnum.find(receiver.getMethod()),
- mapping -> Arrays.stream(RequestsMethodEnum.values()).forEach(
- methodEnum -> mapping.channelMapping(methodEnum, methodEnum.getChannelName())))
- .get();
- }
-}
diff --git a/src/main/java/com/dji/sample/component/mqtt/handler/ServicesReplyHandler.java b/src/main/java/com/dji/sample/component/mqtt/handler/ServicesReplyHandler.java
deleted file mode 100644
index 8d8030d..0000000
--- a/src/main/java/com/dji/sample/component/mqtt/handler/ServicesReplyHandler.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.dji.sample.component.mqtt.handler;
-
-import com.dji.sample.component.mqtt.model.Chan;
-import com.dji.sample.component.mqtt.model.ChannelName;
-import com.dji.sample.component.mqtt.model.CommonTopicReceiver;
-import com.dji.sample.component.mqtt.model.ServiceReply;
-import com.dji.sample.manage.model.enums.LogsFileMethodEnum;
-import com.dji.sample.manage.model.receiver.LogsFileUploadList;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.integration.annotation.ServiceActivator;
-import org.springframework.messaging.Message;
-import org.springframework.stereotype.Component;
-
-import java.io.IOException;
-
-/**
- * @author sean
- * @version 1.2
- * @date 2022/9/9
- */
-@Component
-public class ServicesReplyHandler {
-
- @Autowired
- private ObjectMapper mapper;
-
- /**
- * Handle the reply message from the pilot side to the on-demand video.
- * @param message reply message
- * @throws IOException
- */
- @ServiceActivator(inputChannel = ChannelName.INBOUND_SERVICE_REPLY)
- public void serviceReply(Message> message) throws IOException {
- byte[] payload = (byte[])message.getPayload();
-
- CommonTopicReceiver receiver = mapper.readValue(payload, new TypeReference() {});
- ServiceReply reply;
- if (LogsFileMethodEnum.FILE_UPLOAD_LIST.getMethod().equals(receiver.getMethod())) {
- LogsFileUploadList list = mapper.convertValue(receiver.getData(), new TypeReference() {});
- reply = new ServiceReply();
- reply.setResult(list.getResult());
- reply.setOutput(list.getFiles());
- } else {
- reply = mapper.convertValue(receiver.getData(), new TypeReference() {});
- }
- receiver.setData(reply);
- Chan> chan = Chan.getInstance();
- // Put the message to the chan object.
- chan.put(receiver);
- }
-}
diff --git a/src/main/java/com/dji/sample/component/mqtt/handler/StateDefaultHandler.java b/src/main/java/com/dji/sample/component/mqtt/handler/StateDefaultHandler.java
deleted file mode 100644
index a1d2624..0000000
--- a/src/main/java/com/dji/sample/component/mqtt/handler/StateDefaultHandler.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.dji.sample.component.mqtt.handler;
-
-import com.dji.sample.component.mqtt.model.CommonTopicReceiver;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import org.springframework.stereotype.Service;
-
-import java.util.Map;
-
-/**
- * @author sean
- * @version 0.3
- * @date 2022/3/21
- */
-@Service
-public class StateDefaultHandler extends AbstractStateTopicHandler {
-
- protected StateDefaultHandler() {
- super(null);
- }
-
- @Override
- public CommonTopicReceiver handleState(Map dataNode, CommonTopicReceiver stateReceiver, String sn) throws JsonProcessingException {
- // If no suitable handler is found for the data, it is not processed.
- return stateReceiver;
- }
-}
diff --git a/src/main/java/com/dji/sample/component/mqtt/handler/StateDeviceBasicHandler.java b/src/main/java/com/dji/sample/component/mqtt/handler/StateDeviceBasicHandler.java
deleted file mode 100644
index b85ebca..0000000
--- a/src/main/java/com/dji/sample/component/mqtt/handler/StateDeviceBasicHandler.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.dji.sample.component.mqtt.handler;
-
-import com.dji.sample.component.mqtt.model.CommonTopicReceiver;
-import com.dji.sample.component.mqtt.model.StateDataEnum;
-import com.dji.sample.manage.model.receiver.DeviceBasicReceiver;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Service;
-
-import java.util.Map;
-
-/**
- * @author sean
- * @version 0.3
- * @date 2022/2/21
- */
-@Service
-public class StateDeviceBasicHandler extends AbstractStateTopicHandler {
-
- public StateDeviceBasicHandler(@Autowired @Qualifier("stateLiveCapacityHandler") AbstractStateTopicHandler handler) {
- super(handler);
- }
-
- @Override
- public CommonTopicReceiver handleState(Map dataNode, CommonTopicReceiver stateReceiver, String sn) throws JsonProcessingException {
- // handle device basic data
- if (dataNode.containsKey(StateDataEnum.PAYLOADS.getDesc())) {
- DeviceBasicReceiver data = mapper.convertValue(stateReceiver.getData(), DeviceBasicReceiver.class);
- data.setDeviceSn(sn);
- data.getPayloads().forEach(payload -> payload.setDeviceSn(sn));
-
- stateReceiver.setData(data);
- return stateReceiver;
- }
- return handler.handleState(dataNode, stateReceiver, sn);
- }
-}
diff --git a/src/main/java/com/dji/sample/component/mqtt/handler/StateFirmwareVersionHandler.java b/src/main/java/com/dji/sample/component/mqtt/handler/StateFirmwareVersionHandler.java
deleted file mode 100644
index aceeae4..0000000
--- a/src/main/java/com/dji/sample/component/mqtt/handler/StateFirmwareVersionHandler.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.dji.sample.component.mqtt.handler;
-
-import com.dji.sample.component.mqtt.model.CommonTopicReceiver;
-import com.dji.sample.component.mqtt.model.StateDataEnum;
-import com.dji.sample.manage.model.enums.DeviceDomainEnum;
-import com.dji.sample.manage.model.enums.PayloadModelEnum;
-import com.dji.sample.manage.model.receiver.FirmwareVersionReceiver;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author sean
- * @version 0.3
- * @date 2022/2/21
- */
-@Service
-public class StateFirmwareVersionHandler extends AbstractStateTopicHandler {
-
- protected StateFirmwareVersionHandler(@Autowired @Qualifier("stateDefaultHandler") AbstractStateTopicHandler handler) {
- super(handler);
- }
-
- @Override
- public CommonTopicReceiver handleState(Map dataNode, CommonTopicReceiver stateReceiver, String sn) throws JsonProcessingException {
- // Parse the firmware version of the device.
- if (dataNode.containsKey(StateDataEnum.FIRMWARE_VERSION.getDesc())) {
- FirmwareVersionReceiver firmware = mapper.convertValue(dataNode, FirmwareVersionReceiver.class);
- firmware.setSn(sn);
- firmware.setDomain(DeviceDomainEnum.SUB_DEVICE);
- stateReceiver.setData(firmware);
- return stateReceiver;
- }
-
- // Parse the firmware version of the payload.
- List payloads = PayloadModelEnum.getAllModel();
- long count = dataNode.keySet()
- .stream()
- .map(key -> {
- int end = key.indexOf("-");
- return end == -1 ? key : key.substring(0, end);
- })
- .filter(payloads::contains)
- .count();
- if (count > 0) {
- FirmwareVersionReceiver firmware = FirmwareVersionReceiver.builder()
- .firmwareVersion(((Map)(dataNode.values().iterator().next()))
- .get(StateDataEnum.FIRMWARE_VERSION.getDesc()))
- .sn(sn)
- .domain(DeviceDomainEnum.PAYLOAD)
- .build();
- stateReceiver.setData(firmware);
- return stateReceiver;
- }
-
- return handler.handleState(dataNode, stateReceiver, sn);
- }
-}
diff --git a/src/main/java/com/dji/sample/component/mqtt/handler/StateLiveCapacityHandler.java b/src/main/java/com/dji/sample/component/mqtt/handler/StateLiveCapacityHandler.java
deleted file mode 100644
index dc593ab..0000000
--- a/src/main/java/com/dji/sample/component/mqtt/handler/StateLiveCapacityHandler.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.dji.sample.component.mqtt.handler;
-
-import com.dji.sample.component.mqtt.model.CommonTopicReceiver;
-import com.dji.sample.component.mqtt.model.StateDataEnum;
-import com.dji.sample.manage.model.receiver.LiveCapacityReceiver;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Service;
-
-import java.util.Map;
-
-/**
- * @author sean
- * @version 0.3
- * @date 2022/2/21
- */
-@Service
-@Slf4j
-public class StateLiveCapacityHandler extends AbstractStateTopicHandler {
-
- protected StateLiveCapacityHandler(@Autowired @Qualifier("stateFirmwareVersionHandler") AbstractStateTopicHandler handler) {
- super(handler);
- }
-
- @Override
- public CommonTopicReceiver handleState(Map dataNode, CommonTopicReceiver stateReceiver, String sn) throws JsonProcessingException {
- // Determine if it is live capacity data based on name.
- if (dataNode.containsKey(StateDataEnum.LIVE_CAPACITY.getDesc())) {
- stateReceiver.setData(mapper.convertValue(
- dataNode.get(StateDataEnum.LIVE_CAPACITY.getDesc()),
- LiveCapacityReceiver.class));
- log.info("Analyze live stream capabilities.");
- return stateReceiver;
- }
- return handler.handleState(dataNode, stateReceiver, sn);
- }
-}
diff --git a/src/main/java/com/dji/sample/component/mqtt/handler/StateRouter.java b/src/main/java/com/dji/sample/component/mqtt/handler/StateRouter.java
deleted file mode 100644
index 4f0e1e5..0000000
--- a/src/main/java/com/dji/sample/component/mqtt/handler/StateRouter.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package com.dji.sample.component.mqtt.handler;
-
-import com.dji.sample.component.mqtt.model.ChannelName;
-import com.dji.sample.component.mqtt.model.CommonTopicReceiver;
-import com.dji.sample.manage.model.receiver.DeviceBasicReceiver;
-import com.dji.sample.manage.model.receiver.FirmwareVersionReceiver;
-import com.dji.sample.manage.model.receiver.LiveCapacityReceiver;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.integration.annotation.MessageEndpoint;
-import org.springframework.integration.annotation.Router;
-import org.springframework.integration.annotation.ServiceActivator;
-import org.springframework.integration.annotation.Splitter;
-import org.springframework.integration.mqtt.support.MqttHeaders;
-import org.springframework.integration.router.MessageRouter;
-import org.springframework.integration.router.PayloadTypeRouter;
-import org.springframework.messaging.Message;
-
-import javax.annotation.Resource;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Map;
-
-import static com.dji.sample.component.mqtt.model.TopicConst.*;
-
-/**
- *
- * @author sean.zhou
- * @date 2021/11/17
- * @version 0.1
- */
-@MessageEndpoint
-@Slf4j
-@Configuration
-public class StateRouter {
-
- @Resource(name = "stateDeviceBasicHandler")
- private AbstractStateTopicHandler handler;
-
- @Autowired
- private ObjectMapper mapper;
-
- /**
- * Handles the routing of state topic messages. Depending on the data, it is assigned to different channels for handling.
- * @param message
- * @return
- * @throws IOException
- */
- @ServiceActivator(inputChannel = ChannelName.INBOUND_STATE, outputChannel = ChannelName.INBOUND_STATE_SPLITTER)
- public CommonTopicReceiver> resolveStateData(Message> message) throws IOException {
- byte[] payload = (byte[])message.getPayload();
- String topic = message.getHeaders().get(MqttHeaders.RECEIVED_TOPIC).toString();
-
- CommonTopicReceiver stateReceiver = mapper.readValue(payload, CommonTopicReceiver.class);
- // Get the sn of the topic source.
- String from = topic.substring((THING_MODEL_PRE + PRODUCT).length(),
- topic.indexOf(STATE_SUF));
-
- try {
- Map data = (Map) (stateReceiver.getData());
-
- return handler.handleState(data, stateReceiver, from);
-
- } catch (UnrecognizedPropertyException e) {
- log.info("The {} data is not processed.", e.getPropertyName());
- }
- return stateReceiver;
- }
-
- /**
- * Split the state message data to different channels for handling according to their different types.
- * @param receiver state message
- * @return
- */
- @Splitter(inputChannel = ChannelName.INBOUND_STATE_SPLITTER, outputChannel = ChannelName.INBOUND_STATE_ROUTER)
- public Collection