|
|
@@ -37,14 +37,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.cache.support.AbstractCacheManager;
|
|
|
import org.springframework.messaging.MessageHeaders;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -256,11 +254,11 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
.setVerticalSpeed(data.getVerticalSpeed()));
|
|
|
deviceService.pushOsdDataToWeb(device.getWorkspaceId(), BizCodeEnum.DEVICE_OSD, from, data);
|
|
|
//添加航点轨迹信息
|
|
|
- toAddFilghtPoint(device, data);
|
|
|
+ toAddFilghtPoint(from, device, data);
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void toAddFilghtPoint(DeviceDTO device,OsdRcDrone data) {
|
|
|
+ private void toAddFilghtPoint(String from, DeviceDTO device,OsdRcDrone data) {
|
|
|
|
|
|
switch (data.getModeCode()) {
|
|
|
case TAKEOFF_FINISHED:
|
|
|
@@ -275,6 +273,9 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
case LANDING_THREE_PROPELLER:
|
|
|
//添加飞行轨迹
|
|
|
addFlightPoint(device,data);
|
|
|
+ //推送实时轨迹信息
|
|
|
+ pushFlyTrackToWeb(from,device,data);
|
|
|
+
|
|
|
break;
|
|
|
case LANDING_AUTO:
|
|
|
case LANDING_FORCED:
|
|
|
@@ -282,17 +283,55 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
|
|
|
//添加飞行轨迹
|
|
|
FlightTaskDTO task = addFlightPoint(device,data);
|
|
|
+ //推送实时轨迹信息
|
|
|
+ pushFlyTrackToWeb(from,device,data);
|
|
|
+
|
|
|
//更新飞行任务
|
|
|
if(task != null) {
|
|
|
updateFlightTask(task);
|
|
|
}
|
|
|
//移除redis
|
|
|
deviceRedisService.delDroneFlightTask(device.getDeviceSn());
|
|
|
+ deviceRedisService.delDroneFlyTrack(device.getDeviceSn());
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void pushFlyTrackToWeb(String from, DeviceDTO device,OsdRcDrone data) {
|
|
|
+ //推送实时轨迹信息
|
|
|
+ List<FlightTrackDTO> trackList = getFlightLine(device,data);
|
|
|
+ if(!CollectionUtils.isEmpty(trackList)) {
|
|
|
+ deviceService.pushOsdDataToWeb(device.getWorkspaceId(), BizCodeEnum.DRONE_FLY_TRACK, from, data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<FlightTrackDTO> getFlightLine(DeviceDTO device,OsdRcDrone data) {
|
|
|
+ Optional<List<FlightTrackDTO>> optList = deviceRedisService.getDroneFlyTrack(device.getDeviceSn());
|
|
|
+ if(!optList.isPresent() || optList.get().isEmpty()) {
|
|
|
+ //获取飞行任务(轨迹)
|
|
|
+ FlightTaskDTO task = getFlightTask(device, data, false);
|
|
|
+ if(task == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<FlightTrackDTO> flightPoints = flightTaskService.getRTFlightTrackByTaskId(task.getId());
|
|
|
+ deviceRedisService.setDroneFlyTrack(device.getDeviceSn(),flightPoints);
|
|
|
+ return flightPoints;
|
|
|
+ } else {
|
|
|
+ return optList.get();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addRedisFlightPoint(String sn,FlightTrackDTO point) {
|
|
|
+ List<FlightTrackDTO> flightPoints = new ArrayList<FlightTrackDTO>();
|
|
|
+ Optional<List<FlightTrackDTO>> optList = deviceRedisService.getDroneFlyTrack(sn);
|
|
|
+ if(optList.isPresent()) {
|
|
|
+ flightPoints = optList.get();
|
|
|
+ }
|
|
|
+ flightPoints.add(point);
|
|
|
+ deviceRedisService.setDroneFlyTrack(sn,flightPoints);
|
|
|
+ }
|
|
|
+
|
|
|
private FlightTaskDTO addFlightPoint(DeviceDTO device,OsdRcDrone data) {
|
|
|
synchronized (device.getDeviceSn().intern()) {
|
|
|
Optional<FlightTrackEntity> lastPoint = deviceRedisService.getLastDroneTrack(device.getDeviceSn());
|
|
|
@@ -323,7 +362,7 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
}
|
|
|
if(isAdd) {
|
|
|
//获取飞行任务(轨迹)
|
|
|
- FlightTaskDTO task = getFlightTask(device, data);
|
|
|
+ FlightTaskDTO task = getFlightTask(device, data, true);
|
|
|
log.info("获取飞行轨迹任务:" + task.toString());
|
|
|
//添加Home信息
|
|
|
if(!lastPoint.isPresent()) {
|
|
|
@@ -337,6 +376,7 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
.type(FlightPointTypeEnum.HOME.getType())
|
|
|
.createTime(System.currentTimeMillis()).build();
|
|
|
flightTaskService.addHomePoint(flightTrackEntity);
|
|
|
+ addRedisFlightPoint(device.getDeviceSn(),flightTaskService.flightTrackEntityToDto(flightTrackEntity));
|
|
|
}
|
|
|
}
|
|
|
//添加轨迹信息
|
|
|
@@ -350,6 +390,7 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
.type(FlightPointTypeEnum.HAND.getType())
|
|
|
.createTime(System.currentTimeMillis()).build();
|
|
|
flightTaskService.addFlightPoint(flightTrackEntity);
|
|
|
+ addRedisFlightPoint(device.getDeviceSn(),flightTaskService.flightTrackEntityToDto(flightTrackEntity));
|
|
|
log.info("添加轨迹完成: task:" + task.getTaskName());
|
|
|
//记录添加时间
|
|
|
deviceRedisService.setLastDroneTrack(device.getDeviceSn(), flightTrackEntity);
|
|
|
@@ -381,7 +422,7 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- private FlightTaskDTO getFlightTask(DeviceDTO device,OsdRcDrone data) {
|
|
|
+ private FlightTaskDTO getFlightTask(DeviceDTO device,OsdRcDrone data,boolean isCreate) {
|
|
|
//获取任务名称
|
|
|
FlightTaskDTO flightTaskDTO = null;
|
|
|
Optional<FlightTaskDTO> opt = deviceRedisService.getDroneFlightTask(device.getDeviceSn());
|
|
|
@@ -391,7 +432,7 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
//查询当天未完成的任务
|
|
|
flightTaskDTO = flightTaskService.getCurrentFlightTask(device.getWorkspaceId(),device.getDeviceSn());
|
|
|
}
|
|
|
- if(flightTaskDTO == null) {
|
|
|
+ if(flightTaskDTO == null && isCreate) {
|
|
|
Date curTime = new Date();
|
|
|
String taskName = getTaskName(curTime, device.getDeviceSn());
|
|
|
flightTaskDTO = flightTaskService.createFlightTask(FlightTaskEntity.builder()
|