Browse Source

delete

v1.1.0
sean.zhou 3 years ago
parent
commit
ea1df99ee3
  1. 95
      src/main/java/com/dji/sample/component/mqtt/config/InboundMessageRouter.java
  2. 29
      src/main/java/com/dji/sample/component/mqtt/model/TopicStateReceiver.java
  3. 107
      src/main/java/com/dji/sample/component/oss/model/AliyunOSSConfiguration.java
  4. 96
      src/main/java/com/dji/sample/component/oss/model/MinIOConfiguration.java
  5. 2
      src/main/java/com/dji/sample/component/oss/model/enums/OssTypeEnum.java
  6. 112
      src/main/java/com/dji/sample/component/websocket/model/WebSocketManager.java
  7. 12
      src/main/java/com/dji/sample/manage/dao/ICameraVideoMapper.java
  8. 12
      src/main/java/com/dji/sample/manage/dao/ICapacityCameraMapper.java
  9. 35
      src/main/java/com/dji/sample/manage/handler/AbstractStateTopicHandler.java
  10. 25
      src/main/java/com/dji/sample/manage/handler/StateDefaultHandler.java
  11. 34
      src/main/java/com/dji/sample/manage/handler/StateDeviceBasicHandler.java
  12. 39
      src/main/java/com/dji/sample/manage/handler/StateLiveCapacityHandler.java
  13. 55
      src/main/java/com/dji/sample/manage/handler/StatePayloadHandler.java
  14. 92
      src/main/java/com/dji/sample/manage/handler/StateRouter.java
  15. 59
      src/main/java/com/dji/sample/manage/handler/StateSplitter.java
  16. 70
      src/main/java/com/dji/sample/manage/handler/StatusRouter.java
  17. 45
      src/main/java/com/dji/sample/manage/model/Chan.java
  18. 20
      src/main/java/com/dji/sample/manage/model/DeviceStatusManager.java
  19. 37
      src/main/java/com/dji/sample/manage/model/entity/CameraVideoEntity.java
  20. 46
      src/main/java/com/dji/sample/manage/model/entity/CapacityCameraEntity.java
  21. 27
      src/main/java/com/dji/sample/manage/model/enums/LiveMethodEnum.java
  22. 26
      src/main/java/com/dji/sample/manage/model/enums/StateDataEnum.java
  23. 28
      src/main/java/com/dji/sample/manage/model/receiver/RTKStateReceiver.java
  24. 18
      src/main/java/com/dji/sample/manage/model/receiver/ServiceReplyReceiver.java
  25. 32
      src/main/java/com/dji/sample/storage/service/impl/AliyunStorageServiceImpl.java
  26. 34
      src/main/java/com/dji/sample/storage/service/impl/MinIOStorageServiceImpl.java
  27. 41
      src/main/java/com/dji/sample/wayline/model/WaylineFileDTO.java
  28. 57
      src/main/java/com/dji/sample/wayline/model/WaylineFileEntity.java
  29. 18
      src/main/java/com/dji/sample/wayline/model/WaylineFileUploadDTO.java
  30. 30
      src/main/java/com/dji/sample/wayline/model/WaylineQueryParam.java

95
src/main/java/com/dji/sample/component/mqtt/config/InboundMessageRouter.java

@ -1,95 +0,0 @@ @@ -1,95 +0,0 @@
package com.dji.sample.component.mqtt.config;
import com.dji.sample.component.mqtt.model.ChannelName;
import lombok.extern.slf4j.Slf4j;
import org.springframework.integration.annotation.Router;
import org.springframework.integration.mqtt.support.MqttHeaders;
import org.springframework.integration.router.AbstractMessageRouter;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHeaders;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.regex.Pattern;
import static com.dji.sample.component.mqtt.model.TopicConst.*;
/**
*
* @author sean.zhou
* @date 2021/11/10
* @version 0.1
*/
@Component
@Slf4j
public class InboundMessageRouter extends AbstractMessageRouter {
@Resource(name = ChannelName.INBOUND)
private MessageChannel inboundChannel;
@Resource(name = ChannelName.INBOUND_STATUS)
private MessageChannel statusChannel;
@Resource(name = ChannelName.INBOUND_STATE)
private MessageChannel stateChannel;
@Resource(name = ChannelName.DEFAULT)
private MessageChannel defaultChannel;
@Resource(name = ChannelName.INBOUND_SERVICE_REPLY)
private MessageChannel serviceReplyChannel;
@Resource(name = ChannelName.INBOUND_OSD)
private MessageChannel osdChannel;
private static final Pattern PATTERN_TOPIC_STATUS =
Pattern.compile("^" + BASIC_PRE + PRODUCT + REGEX_SN + STATUS_SUF + "$");
private static final Pattern PATTERN_TOPIC_STATE =
Pattern.compile("^" + THING_MODEL_PRE + PRODUCT + REGEX_SN + STATE_SUF + "$");
private static final Pattern PATTERN_TOPIC_SERVICE_REPLY =
Pattern.compile("^" + THING_MODEL_PRE + PRODUCT + REGEX_SN + SERVICES_SUF + _REPLY_SUF + "$");
private static final Pattern PATTERN_TOPIC_OSD =
Pattern.compile("^" + THING_MODEL_PRE + PRODUCT + REGEX_SN + OSD_SUF);
/**
* All mqtt broker messages will arrive here before distributing them to different channels.
* @param message message from mqtt broker
* @return channel
*/
@Override
@Router(inputChannel = ChannelName.INBOUND)
protected Collection<MessageChannel> determineTargetChannels(Message<?> message) {
MessageHeaders headers = message.getHeaders();
String topic = headers.get(MqttHeaders.RECEIVED_TOPIC).toString();
byte[] payload = (byte[])message.getPayload();
// osd
if (PATTERN_TOPIC_OSD.matcher(topic).matches()) {
return Collections.singleton(osdChannel);
}
log.debug("received topic :{} \t payload :{}", topic, new String(payload));
// status
if (PATTERN_TOPIC_STATUS.matcher(topic).matches()) {
return Collections.singleton(statusChannel);
}
// state
if (PATTERN_TOPIC_STATE.matcher(topic).matches()) {
return Collections.singleton(stateChannel);
}
// services_reply
if (PATTERN_TOPIC_SERVICE_REPLY.matcher(topic).matches()) {
return Collections.singleton(serviceReplyChannel);
}
return Collections.singleton(defaultChannel);
}
}

29
src/main/java/com/dji/sample/component/mqtt/model/TopicStateReceiver.java

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
package com.dji.sample.component.mqtt.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
/**
* The data format of the state topic.
* @author sean.zhou
* @date 2021/11/17
* @version 0.1
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class TopicStateReceiver<T> {
private String tid;
private String bid;
private Long timestamp;
/**
* The sn of the gateway device.
*/
private String gateway;
private T data;
}

107
src/main/java/com/dji/sample/component/oss/model/AliyunOSSConfiguration.java

@ -1,107 +0,0 @@ @@ -1,107 +0,0 @@
package com.dji.sample.component.oss.model;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
/**
* @author sean
* @version 0.2
* @date 2021/12/9
*/
@Configuration
public class AliyunOSSConfiguration {
/**
* default
*/
public static final String PROVIDER = "ali";
/**
* Whether to use the current storage service.
*/
public static boolean enable;
/**
* The protocol needs to be included at the beginning of the address.
*/
public static String endpoint;
public static String accessKey;
public static String secretKey;
public static String region;
public static Long expire;
public static String roleSessionName;
public static String roleArn;
public static String bucket;
public static String objectDirPrefix;
@Value("${aliyun.oss.endpoint}")
private void setEndpoint(String endpoint) {
AliyunOSSConfiguration.endpoint = endpoint;
}
@Value("${aliyun.oss.access-key}")
private void setAccessKey(String accessKey) {
AliyunOSSConfiguration.accessKey = accessKey;
}
@Value("${aliyun.oss.secret-key}")
private void setSecretKey(String secretKey) {
AliyunOSSConfiguration.secretKey = secretKey;
}
@Value("${aliyun.oss.region}")
private void setRegion(String region) {
AliyunOSSConfiguration.region = region;
}
@Value("${aliyun.oss.expire: 3600}")
private void setExpire(Long expire) {
AliyunOSSConfiguration.expire = expire;
}
@Value("${aliyun.oss.enable: false}")
private void setEnable(boolean enable) {
AliyunOSSConfiguration.enable = enable;
}
@Value("${aliyun.oss.role-session-name}")
private void setRoleSessionName(String roleSessionName) {
AliyunOSSConfiguration.roleSessionName = roleSessionName;
}
@Value("${aliyun.oss.role-arn}")
private void setRoleArn(String roleArn) {
AliyunOSSConfiguration.roleArn = roleArn;
}
@Value("${aliyun.oss.bucket}")
private void setBucket(String bucket) {
AliyunOSSConfiguration.bucket = bucket;
}
@Value("${aliyun.oss.object-dir-prefix: wayline}")
private void setObjectDir(String objectDirPrefix) {
AliyunOSSConfiguration.objectDirPrefix = objectDirPrefix;
}
@Bean
@Lazy
public OSS ossClient() {
if (!enable) {
return null;
}
return new OSSClientBuilder().build(endpoint, accessKey, secretKey);
}
}

96
src/main/java/com/dji/sample/component/oss/model/MinIOConfiguration.java

@ -1,96 +0,0 @@ @@ -1,96 +0,0 @@
package com.dji.sample.component.oss.model;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.util.StringUtils;
/**
* @author sean
* @version 0.2
* @date 2021/12/7
*/
@Configuration
public class MinIOConfiguration {
/**
* default
*/
public static final String PROVIDER = "aws";
/**
* Whether to use the current storage service.
*/
public static boolean enable;
public static String endpoint;
public static String accessKey;
public static String secretKey;
public static String region;
public static String bucket;
public static Integer expire;
public static String objectDirPrefix;
@Value("${minio.endpoint: http://localhost:9000/}")
private void setEndpoint(String endpoint) {
MinIOConfiguration.endpoint = endpoint;
}
@Value("${minio.access-key: minioadmin}")
private void setAccessKey(String accessKey) {
MinIOConfiguration.accessKey = accessKey;
}
@Value("${minio.secret-key: minioadmin}")
private void setSecretKey(String secretKey) {
MinIOConfiguration.secretKey = secretKey;
}
@Value("${minio.region: }")
private void setRegion(String region) {
MinIOConfiguration.region = region;
}
@Value("${minio.bucket: test}")
private void setBucket(String bucket) {
MinIOConfiguration.bucket = bucket;
}
@Value("${minio.expire: 3600}")
private void setExpire(Integer expire) {
MinIOConfiguration.expire = expire;
}
@Value("${minio.enable: false}")
private void setEnable(boolean enable) {
MinIOConfiguration.enable = enable;
}
@Value("${minio.object-dir-prefix: wayline}")
private void setObjectDir(String objectDirPrefix) {
MinIOConfiguration.objectDirPrefix = objectDirPrefix;
}
@Bean
@Lazy
public MinioClient minioClient() {
if (!enable) {
return null;
}
MinioClient.Builder builder = MinioClient.builder()
.endpoint(endpoint)
.credentials(accessKey, secretKey);
if (StringUtils.hasText(region)) {
builder.region(MinIOConfiguration.region);
}
return builder.build();
}
}

2
src/main/java/com/dji/sample/component/oss/model/enums/OssTypeEnum.java

@ -11,7 +11,7 @@ public enum OssTypeEnum { @@ -11,7 +11,7 @@ public enum OssTypeEnum {
AWS("aws"),
/*
/*
* MinIO is temporarily unavailable.
*/
MINIO("minio");

112
src/main/java/com/dji/sample/component/websocket/model/WebSocketManager.java

@ -1,112 +0,0 @@ @@ -1,112 +0,0 @@
package com.dji.sample.component.websocket.model;
import com.dji.sample.component.websocket.config.ConcurrentWebSocketSession;
import com.dji.sample.manage.model.enums.UserTypeEnum;
import lombok.extern.slf4j.Slf4j;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
* Manage all WebSocket connection objects.
* @author sean.zhou
* @date 2021/11/16
* @version 0.1
*/
@Slf4j
public class WebSocketManager {
private static final ConcurrentHashMap<String,
ConcurrentHashMap<String,
ConcurrentHashMap<String, ConcurrentWebSocketSession>>> MANAGER = new ConcurrentHashMap<>(16);
/**
* WebSocket connection from the pilot.
*/
private static final Set<ConcurrentWebSocketSession> PILOT_SESSION = ConcurrentHashMap.newKeySet(16);
/**
* WebSocket connection from the web.
*/
private static final Set<ConcurrentWebSocketSession> WEB_SESSION = ConcurrentHashMap.newKeySet(16);
public static void put(String key, ConcurrentWebSocketSession val) {
String[] name = key.split("/");
if (name.length != 3) {
log.debug("The key is out of format. [{workspaceId}/{userType}/{userId}]");
return;
}
ConcurrentHashMap<String, ConcurrentHashMap<String, ConcurrentWebSocketSession>> workspaceSessions =
MANAGER.getOrDefault(name[0], new ConcurrentHashMap<>(16));
ConcurrentHashMap<String, ConcurrentWebSocketSession> userSessions = workspaceSessions.getOrDefault(
name[2], new ConcurrentHashMap<>(16));
userSessions.put(val.getId(), val);
workspaceSessions.put(name[2], userSessions);
MANAGER.put(name[0], workspaceSessions);
getSetByUserType(Integer.valueOf(name[1])).add(val);
}
public static void remove(String key, String sessionId) {
String[] name = key.split("/");
if (name.length != 3) {
log.debug("The key is out of format. [{workspaceId}/{userType}/{userId}]");
return;
}
ConcurrentHashMap<String, ConcurrentWebSocketSession> userSession = MANAGER.get(name[0]).get(name[2]);
Set<ConcurrentWebSocketSession> typeSession = getSetByUserType(Integer.valueOf(name[1]));
ConcurrentWebSocketSession session = userSession.get(sessionId);
typeSession.remove(session);
userSession.remove(sessionId);
}
public static int getConnectedCount() {
return PILOT_SESSION.size() + WEB_SESSION.size();
}
public static Collection<ConcurrentWebSocketSession> getValueWithWorkspace(String workspaceId) {
Set<ConcurrentWebSocketSession> sessions = ConcurrentHashMap.newKeySet();
MANAGER.get(workspaceId)
.forEach((userId, userSessions) -> {
sessions.addAll(userSessions.values());
});
return sessions;
}
public static Collection<ConcurrentWebSocketSession> getValueWithWorkspaceAndUserType(String workspaceId, Integer userType) {
Set<ConcurrentWebSocketSession> sessions = ConcurrentHashMap.newKeySet();
Set<ConcurrentWebSocketSession> typeSessions = getSetByUserType(userType);
MANAGER.getOrDefault(workspaceId, new ConcurrentHashMap<>())
.forEach((userId, userSessions) -> {
Collection<ConcurrentWebSocketSession> sessionList = userSessions.values();
if (!sessionList.isEmpty()) {
ConcurrentWebSocketSession session = sessionList.iterator().next();
if (typeSessions.contains(session)) {
sessions.addAll(sessionList);
}
}
});
return sessions;
}
private static Set<ConcurrentWebSocketSession> getSetByUserType(Integer userType) {
if (UserTypeEnum.PILOT.getVal() == userType) {
return PILOT_SESSION;
}
if (UserTypeEnum.WEB.getVal() == userType) {
return WEB_SESSION;
}
return new HashSet<>();
}
}

12
src/main/java/com/dji/sample/manage/dao/ICameraVideoMapper.java

@ -1,12 +0,0 @@ @@ -1,12 +0,0 @@
package com.dji.sample.manage.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dji.sample.manage.model.entity.CameraVideoEntity;
/**
* @author sean.zhou
* @version 0.1
* @date 2021/11/19
*/
public interface ICameraVideoMapper extends BaseMapper<CameraVideoEntity> {
}

12
src/main/java/com/dji/sample/manage/dao/ICapacityCameraMapper.java

@ -1,12 +0,0 @@ @@ -1,12 +0,0 @@
package com.dji.sample.manage.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dji.sample.manage.model.entity.CapacityCameraEntity;
/**
* @author sean.zhou
* @date 2021/11/19
* @version 0.1
*/
public interface ICapacityCameraMapper extends BaseMapper<CapacityCameraEntity> {
}

35
src/main/java/com/dji/sample/manage/handler/AbstractStateTopicHandler.java

@ -1,35 +0,0 @@ @@ -1,35 +0,0 @@
package com.dji.sample.manage.handler;
import com.dji.sample.component.mqtt.model.TopicStateReceiver;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
/**
* @author sean
* @version 0.3
* @date 2022/2/21
*/
public abstract class AbstractStateTopicHandler {
protected AbstractStateTopicHandler handler;
protected static ObjectMapper mapper = new ObjectMapper();;
protected AbstractStateTopicHandler(AbstractStateTopicHandler handler){
this.handler = handler;
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
/**
* Passing dataNode data, using different processing methods depending on the data selection.
* @param dataNode
* @param stateReceiver
* @param sn
* @return
* @throws JsonProcessingException
*/
public abstract TopicStateReceiver handleState(JsonNode dataNode, TopicStateReceiver stateReceiver, String sn) throws JsonProcessingException;
}

25
src/main/java/com/dji/sample/manage/handler/StateDefaultHandler.java

@ -1,25 +0,0 @@ @@ -1,25 +0,0 @@
package com.dji.sample.manage.handler;
import com.dji.sample.component.mqtt.model.TopicStateReceiver;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.stereotype.Service;
/**
* @author sean
* @version 0.3
* @date 2022/3/21
*/
@Service
public class StateDefaultHandler extends AbstractStateTopicHandler {
protected StateDefaultHandler() {
super(null);
}
@Override
public TopicStateReceiver handleState(JsonNode dataNode, TopicStateReceiver stateReceiver, String sn) throws JsonProcessingException {
// If no suitable handler is found for the data, it is not processed.
return stateReceiver;
}
}

34
src/main/java/com/dji/sample/manage/handler/StateDeviceBasicHandler.java

@ -1,34 +0,0 @@ @@ -1,34 +0,0 @@
package com.dji.sample.manage.handler;
import com.dji.sample.component.mqtt.model.TopicStateReceiver;
import com.dji.sample.manage.model.receiver.DeviceBasicReceiver;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
/**
* @author sean
* @version 0.3
* @date 2022/2/21
*/
@Service
public class StateDeviceBasicHandler extends AbstractStateTopicHandler {
public StateDeviceBasicHandler(@Autowired @Qualifier("statePayloadHandler") AbstractStateTopicHandler handler) {
super(handler);
}
@Override
public TopicStateReceiver handleState(JsonNode dataNode, TopicStateReceiver stateReceiver, String sn) throws JsonProcessingException {
// handle device basic data
if (dataNode.size() != 1) {
DeviceBasicReceiver data = mapper.treeToValue(dataNode, DeviceBasicReceiver.class);
data.setDeviceSn(sn);
stateReceiver.setData(data);
return stateReceiver;
}
return handler.handleState(dataNode, stateReceiver, sn);
}
}

39
src/main/java/com/dji/sample/manage/handler/StateLiveCapacityHandler.java

@ -1,39 +0,0 @@ @@ -1,39 +0,0 @@
package com.dji.sample.manage.handler;
import com.dji.sample.component.mqtt.model.TopicStateReceiver;
import com.dji.sample.manage.model.enums.StateDataEnum;
import com.dji.sample.manage.model.receiver.CapacityDeviceReceiver;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
/**
* @author sean
* @version 0.3
* @date 2022/2/21
*/
@Service
public class StateLiveCapacityHandler extends AbstractStateTopicHandler {
private static final String DEVICE_LIST = "device_list";
protected StateLiveCapacityHandler(@Autowired @Qualifier("stateDefaultHandler") AbstractStateTopicHandler handler) {
super(handler);
}
@Override
public TopicStateReceiver handleState(JsonNode dataNode, TopicStateReceiver stateReceiver, String sn) throws JsonProcessingException {
String name = dataNode.fieldNames().next();
JsonNode childNode = dataNode.findPath(name);
// Determine if it is live capacity data based on name.
if (name.equals(StateDataEnum.LIVE_CAPACITY.getDesc())) {
JsonNode deviceNode = childNode.findPath(DEVICE_LIST);
stateReceiver.setData(
mapper.treeToValue(deviceNode.get(0), CapacityDeviceReceiver.class));
return stateReceiver;
}
return handler.handleState(dataNode, stateReceiver, sn);
}
}

55
src/main/java/com/dji/sample/manage/handler/StatePayloadHandler.java

@ -1,55 +0,0 @@ @@ -1,55 +0,0 @@
package com.dji.sample.manage.handler;
import com.dji.sample.component.mqtt.model.TopicStateReceiver;
import com.dji.sample.manage.model.enums.StateDataEnum;
import com.dji.sample.manage.model.receiver.DevicePayloadReceiver;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* @author sean
* @version 0.3
* @date 2022/2/21
*/
@Service
public class StatePayloadHandler extends AbstractStateTopicHandler {
protected StatePayloadHandler(@Autowired @Qualifier("stateLiveCapacityHandler") AbstractStateTopicHandler handler) {
super(handler);
}
@Override
public TopicStateReceiver handleState(JsonNode dataNode, TopicStateReceiver stateReceiver, String sn) throws JsonProcessingException {
String name = dataNode.fieldNames().next();
JsonNode childNode = dataNode.findPath(name);
// Determine if it is payload data based on name.
if (name.equals(StateDataEnum.PAYLOADS.getDesc())) {
List<DevicePayloadReceiver> payloadsList = new ArrayList<>();
Iterator<JsonNode> payloadsNode = childNode.elements();
while (payloadsNode.hasNext()) {
DevicePayloadReceiver payloadReceiver = mapper.treeToValue(
payloadsNode.next(), DevicePayloadReceiver.class);
payloadReceiver.setDeviceSn(sn);
payloadsList.add(payloadReceiver);
}
if (payloadsList.isEmpty()) {
DevicePayloadReceiver payloadReceiver = new DevicePayloadReceiver();
payloadReceiver.setDeviceSn(sn);
payloadsList.add(payloadReceiver);
}
stateReceiver.setData(payloadsList);
return stateReceiver;
}
return handler.handleState(dataNode, stateReceiver, sn);
}
}

92
src/main/java/com/dji/sample/manage/handler/StateRouter.java

@ -1,92 +0,0 @@ @@ -1,92 +0,0 @@
package com.dji.sample.manage.handler;
import com.dji.sample.component.mqtt.model.ChannelName;
import com.dji.sample.component.mqtt.model.TopicStateReceiver;
import com.dji.sample.manage.model.receiver.CapacityDeviceReceiver;
import com.dji.sample.manage.model.receiver.DeviceBasicReceiver;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import lombok.extern.slf4j.Slf4j;
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.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.List;
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;
/**
* 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 TopicStateReceiver<?> resolveStateData(Message<?> message) throws IOException {
byte[] payload = (byte[])message.getPayload();
String topic = message.getHeaders().get(MqttHeaders.RECEIVED_TOPIC).toString();
ObjectMapper mapper = new ObjectMapper();
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
TopicStateReceiver stateReceiver = mapper.readValue(payload, TopicStateReceiver.class);
// Get the sn of the topic source.
String from = topic.substring((THING_MODEL_PRE + PRODUCT).length(),
topic.indexOf(STATE_SUF));
try {
JsonNode dataNode = mapper.readTree(payload).findPath("data");
return handler.handleState(dataNode, stateReceiver, from);
} catch (UnrecognizedPropertyException e) {
log.info("The {} data is not processed.", e.getPropertyName());
}
return stateReceiver;
}
@Bean
@Router(inputChannel = ChannelName.INBOUND_STATE_ROUTER)
public MessageRouter resolveStateRouter() {
PayloadTypeRouter router = new PayloadTypeRouter();
// // Channel mapping for basic data.
router.setChannelMapping(DeviceBasicReceiver.class.getName(),
ChannelName.INBOUND_STATE_BASIC);
// Channel mapping for live streaming capabilities.
router.setChannelMapping(CapacityDeviceReceiver.class.getName(),
ChannelName.INBOUND_STATE_CAPACITY);
// Channel mapping for payload data.
router.setChannelMapping(List.class.getName(),
ChannelName.INBOUND_STATE_PAYLOAD);
router.setChannelMapping(Map.class.getName(),
ChannelName.DEFAULT);
return router;
}
}

59
src/main/java/com/dji/sample/manage/handler/StateSplitter.java

@ -1,59 +0,0 @@ @@ -1,59 +0,0 @@
package com.dji.sample.manage.handler;
import com.dji.sample.component.mqtt.model.ChannelName;
import com.dji.sample.component.mqtt.model.TopicStateReceiver;
import com.dji.sample.manage.model.receiver.DevicePayloadReceiver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.Splitter;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import java.util.ArrayList;
import java.util.Collection;
/**
*
* @author sean.zhou
* @date 2021/11/17
* @version 0.1
*/
@MessageEndpoint
@Configuration
public class StateSplitter {
/**
* 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<Object> splitState(TopicStateReceiver receiver) {
ArrayList<Object> type = new ArrayList<>();
type.add(receiver.getData());
return type;
}
/**
* Split according to the different types in the list.
* @return
*/
@Bean
public IntegrationFlow splitList() {
return IntegrationFlows
.from(ChannelName.INBOUND_STATE_LIST)
.split()
.<Object, String> route(dataType -> {
Class<?> clazz = dataType.getClass();
if (DevicePayloadReceiver.class.isAssignableFrom(clazz)) {
return ChannelName.INBOUND_STATE_PAYLOAD;
}
return null;
}, mapping -> {
mapping.channelMapping(ChannelName.INBOUND_STATE_PAYLOAD,
ChannelName.INBOUND_STATE_PAYLOAD);
})
.get();
}
}

70
src/main/java/com/dji/sample/manage/handler/StatusRouter.java

@ -1,70 +0,0 @@ @@ -1,70 +0,0 @@
package com.dji.sample.manage.handler;
import com.dji.sample.component.mqtt.model.ChannelName;
import com.dji.sample.component.mqtt.model.CommonTopicReceiver;
import com.dji.sample.manage.model.enums.DeviceDomainEnum;
import com.dji.sample.manage.model.receiver.StatusGatewayReceiver;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.Router;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.mqtt.support.MqttHeaders;
import org.springframework.messaging.Message;
import org.springframework.util.CollectionUtils;
import static com.dji.sample.component.mqtt.model.TopicConst.*;
/**
*
* @author sean.zhou
* @date 2021/11/12
* @version 0.1
*/
@MessageEndpoint
public class StatusRouter {
/**
* Converts the status data sent by the gateway device into an object.
* @param message
* @return
*/
@ServiceActivator(inputChannel = ChannelName.INBOUND_STATUS, outputChannel = ChannelName.INBOUND_STATUS_ROUTER)
public CommonTopicReceiver<StatusGatewayReceiver> resolveStatus(Message<?> message) {
CommonTopicReceiver<StatusGatewayReceiver> statusReceiver = new CommonTopicReceiver<>();
ObjectMapper mapper = new ObjectMapper();
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
try {
statusReceiver = mapper.readValue(
(byte[])message.getPayload(),
new TypeReference<CommonTopicReceiver<StatusGatewayReceiver>>() {});
String topic = message.getHeaders().get(MqttHeaders.RECEIVED_TOPIC).toString();
// set gateway's domain
statusReceiver.getData().setDomain(DeviceDomainEnum.GATEWAY.getVal());
// set gateway's sn
statusReceiver.getData().setSn(
topic.substring((BASIC_PRE + PRODUCT).length(),
topic.indexOf(STATUS_SUF)));
} catch (Exception e) {
e.printStackTrace();
}
return statusReceiver;
}
/**
* Handles the routing of status topic messages. Depending on the data, it is assigned to different channels for handling.
* @param receiver
* @return
*/
@Router(inputChannel = ChannelName.INBOUND_STATUS_ROUTER)
public String resolveStatusRouter(CommonTopicReceiver<StatusGatewayReceiver> receiver) {
// Determine whether the drone is online or offline according to whether the data of the sub-device is empty.
return CollectionUtils.isEmpty(receiver.getData().getSubDevices()) ?
ChannelName.INBOUND_STATUS_OFFLINE : ChannelName.INBOUND_STATUS_ONLINE;
}
}

45
src/main/java/com/dji/sample/manage/model/Chan.java

@ -1,45 +0,0 @@ @@ -1,45 +0,0 @@
package com.dji.sample.manage.model;
import java.util.concurrent.locks.LockSupport;
/**
* The demo is only for functional closure, which is not recommended.
* @author sean.zhou
* @date 2021/11/22
* @version 0.1
*/
public class Chan<T> {
private static final long THREAD_WAIT_TIME = 1000_000 * 500;
private volatile T data;
private volatile Thread t;
private Chan () {
}
public static Chan getInstance() {
return ChanSingleton.INSTANCE;
}
public T get(Object blocker) {
this.t = Thread.currentThread();
LockSupport.parkNanos(blocker, THREAD_WAIT_TIME);
this.t = null;
return data;
}
public void put(T data) {
this.data = data;
if (t == null) {
return;
}
LockSupport.unpark(t);
}
private static class ChanSingleton {
private static final Chan<?> INSTANCE = new Chan<>();
}
}

20
src/main/java/com/dji/sample/manage/model/DeviceStatusManager.java

@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
package com.dji.sample.manage.model;
import java.time.LocalDateTime;
import java.util.concurrent.ConcurrentHashMap;
/**
* The demo is only for functional closure, which is not recommended,
* and it is recommended to use caching for handling.
* @author sean.zhou
* @version 0.1
* @date 2021/11/25
*/
public class DeviceStatusManager {
public static final ConcurrentHashMap<String, LocalDateTime> STATUS_MANAGER =
new ConcurrentHashMap<>(16);
public static final Integer DEFAULT_ALIVE_SECOND = 30;
}

37
src/main/java/com/dji/sample/manage/model/entity/CameraVideoEntity.java

@ -1,37 +0,0 @@ @@ -1,37 +0,0 @@
package com.dji.sample.manage.model.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author sean.zhou
* @date 2021/11/19
* @version 0.1
*/
@TableName(value = "manage_camera_video")
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CameraVideoEntity implements Serializable {
@TableId(type = IdType.AUTO)
private Integer id;
@TableField(value = "camera_id")
private Integer cameraId;
@TableField(value = "video_index")
private String videoIndex;
@TableField(value = "video_type")
private String videoType;
}

46
src/main/java/com/dji/sample/manage/model/entity/CapacityCameraEntity.java

@ -1,46 +0,0 @@ @@ -1,46 +0,0 @@
package com.dji.sample.manage.model.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author sean.zhou
* @date 2021/11/19
* @version 0.1
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "manage_capacity_camera")
public class CapacityCameraEntity implements Serializable {
@TableId(type = IdType.AUTO)
private Integer id;
@TableField(value = "device_sn")
private String deviceSn;
@TableField(value = "name")
private String name;
@TableField(value = "description")
private String description;
@TableField(value = "camera_index")
private String cameraIndex;
@TableField(value = "coexist_video_number_max")
private Integer coexistVideoNumberMax;
@TableField(value = "available_video_number")
private Integer availableVideoNumber;
}

27
src/main/java/com/dji/sample/manage/model/enums/LiveMethodEnum.java

@ -1,27 +0,0 @@ @@ -1,27 +0,0 @@
package com.dji.sample.manage.model.enums;
/**
* @author sean.zhou
* @date 2021/11/22
* @version 0.1
*/
public enum LiveMethodEnum {
LIVE_START_PUSH("live_start_push"),
LIVE_STOP_PUSH("live_stop_push"),
LIVE_SET_QUALITY("live_set_quality"),
UNKNOWN("unknown");
private String method;
LiveMethodEnum(String method) {
this.method = method;
}
public String getMethod() {
return method;
}
}

26
src/main/java/com/dji/sample/manage/model/enums/StateDataEnum.java

@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
package com.dji.sample.manage.model.enums;
/**
*
* @author sean.zhou
* @date 2021/11/18
* @version 0.1
*/
public enum StateDataEnum {
BATTERIES("batteries"),
LIVE_CAPACITY("live_capacity"),
PAYLOADS("payloads");
private String desc;
StateDataEnum(String desc) {
this.desc = desc;
}
public String getDesc() {
return this.desc;
}
}

28
src/main/java/com/dji/sample/manage/model/receiver/RTKStateReceiver.java

@ -1,28 +0,0 @@ @@ -1,28 +0,0 @@
package com.dji.sample.manage.model.receiver;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Data;
/**
* @author sean.zhou
* @version 0.1
* @date 2021/11/24
*/
@Data
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class RTKStateReceiver {
private Integer bdsNumber;
private Integer galNumber;
private Integer gloNumber;
private Integer gpsNumber;
private Boolean isFixed;
private Integer quality;
}

18
src/main/java/com/dji/sample/manage/model/receiver/ServiceReplyReceiver.java

@ -1,18 +0,0 @@ @@ -1,18 +0,0 @@
package com.dji.sample.manage.model.receiver;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
/**
* @author sean.zhou
* @version 0.1
* @date 2021/11/22
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class ServiceReplyReceiver<T> {
private Integer result;
private String info;
}

32
src/main/java/com/dji/sample/storage/service/impl/AliyunStorageServiceImpl.java

@ -1,32 +0,0 @@ @@ -1,32 +0,0 @@
package com.dji.sample.storage.service.impl;
import com.dji.sample.component.oss.model.AliyunOSSConfiguration;
import com.dji.sample.component.oss.service.impl.AliyunOssServiceImpl;
import com.dji.sample.media.model.StsCredentialsDTO;
import com.dji.sample.storage.service.IStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author sean
* @version 0.3
* @date 2022/3/9
*/
@Service
public class AliyunStorageServiceImpl implements IStorageService {
@Autowired
private AliyunOssServiceImpl ossService;
@Override
public StsCredentialsDTO getSTSCredentials() {
return StsCredentialsDTO.builder()
.endpoint(AliyunOSSConfiguration.endpoint)
.bucket(AliyunOSSConfiguration.bucket)
.credentials(ossService.getCredentials())
.provider(AliyunOSSConfiguration.PROVIDER)
.objectKeyPrefix(AliyunOSSConfiguration.objectDirPrefix)
.region(AliyunOSSConfiguration.region)
.build();
}
}

34
src/main/java/com/dji/sample/storage/service/impl/MinIOStorageServiceImpl.java

@ -1,34 +0,0 @@ @@ -1,34 +0,0 @@
package com.dji.sample.storage.service.impl;
import com.dji.sample.component.oss.model.MinIOConfiguration;
import com.dji.sample.component.oss.service.impl.MinIOServiceImpl;
import com.dji.sample.media.model.StsCredentialsDTO;
import com.dji.sample.storage.service.IStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author sean
* @version 0.3
* @date 2021/12/31
*/
@Service
public class MinIOStorageServiceImpl implements IStorageService {
@Autowired
private MinIOServiceImpl ossService;
@Override
public StsCredentialsDTO getSTSCredentials() {
return StsCredentialsDTO.builder()
.endpoint(MinIOConfiguration.endpoint)
.bucket(MinIOConfiguration.bucket)
.credentials(ossService.getCredentials())
.provider(MinIOConfiguration.PROVIDER)
.objectKeyPrefix(MinIOConfiguration.objectDirPrefix)
.region(MinIOConfiguration.region)
.build();
}
}

41
src/main/java/com/dji/sample/wayline/model/WaylineFileDTO.java

@ -1,41 +0,0 @@ @@ -1,41 +0,0 @@
package com.dji.sample.wayline.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author sean
* @version 0.3
* @date 2021/12/22
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class WaylineFileDTO {
private String name;
@JsonProperty("id")
private String waylineId;
private String droneModelKey;
private List<String> payloadModelKeys;
private Boolean favorited;
private List<Integer> templateTypes;
private String objectKey;
@JsonProperty("user_name")
private String username;
private Long updateTime;
}

57
src/main/java/com/dji/sample/wayline/model/WaylineFileEntity.java

@ -1,57 +0,0 @@ @@ -1,57 +0,0 @@
package com.dji.sample.wayline.model;
import com.baomidou.mybatisplus.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author sean
* @version 0.3
* @date 2021/12/22
*/
@Data
@TableName("wayline_file")
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class WaylineFileEntity {
@TableId(type = IdType.AUTO)
private Integer id;
@TableField("name")
private String name;
@TableField("wayline_id")
private String waylineId;
@TableField("drone_model_key")
private String droneModelKey;
@TableField("payload_model_keys")
private String payloadModelKeys;
@TableField("workspace_id")
private String workspaceId;
@TableField("favorited")
private Boolean favorited;
@TableField("template_types")
private String templateTypes;
@TableField("object_key")
private String objectKey;
@TableField("user_name")
private String username;
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Long createTime;
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private Long updateTime;
}

18
src/main/java/com/dji/sample/wayline/model/WaylineFileUploadDTO.java

@ -1,18 +0,0 @@ @@ -1,18 +0,0 @@
package com.dji.sample.wayline.model;
import lombok.Data;
/**
* @author sean
* @version 0.3
* @date 2021/12/23
*/
@Data
public class WaylineFileUploadDTO {
private String objectKey;
private String name;
private WaylineFileDTO metadata;
}

30
src/main/java/com/dji/sample/wayline/model/WaylineQueryParam.java

@ -1,30 +0,0 @@ @@ -1,30 +0,0 @@
package com.dji.sample.wayline.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author sean
* @version 0.3
* @date 2021/12/22
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class WaylineQueryParam {
private boolean favorited;
@Builder.Default
private int page = 1;
@Builder.Default
private int pageSize = 10;
private String orderBy;
private Integer[] templateType;
}
Loading…
Cancel
Save