From 4c81bf56309588672a166511d451aa20ce21c604 Mon Sep 17 00:00:00 2001
From: zhaowenyu <35589726@qq.com>
Date: Tue, 06 Jan 2026 10:04:21 +0800
Subject: [PATCH] 2026-01-06 zwy 优化飞行轨迹数据存储时,对json数据转对象的代码。
---
ard-sample/src/main/java/com/ard/sample/manage/service/impl/DeviceOSDServiceImpl.java | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 46 insertions(+), 1 deletions(-)
diff --git a/ard-sample/src/main/java/com/ard/sample/manage/service/impl/DeviceOSDServiceImpl.java b/ard-sample/src/main/java/com/ard/sample/manage/service/impl/DeviceOSDServiceImpl.java
index 6e62f09..0dafd41 100644
--- a/ard-sample/src/main/java/com/ard/sample/manage/service/impl/DeviceOSDServiceImpl.java
+++ b/ard-sample/src/main/java/com/ard/sample/manage/service/impl/DeviceOSDServiceImpl.java
@@ -5,6 +5,8 @@
import com.ard.sample.component.mqtt.model.CommonTopicReceiver;
import com.ard.sample.component.websocket.config.ConcurrentWebSocketSession;
+import com.ard.sample.component.websocket.enums.MessageType;
+import com.ard.sample.component.websocket.handler.DockWebSocketHandler;
import com.ard.sample.component.websocket.model.BizCodeEnum;
import com.ard.sample.component.websocket.model.CustomWebSocketMessage;
import com.ard.sample.manage.model.dto.DeviceDTO;
@@ -14,6 +16,11 @@
import com.ard.sample.manage.model.enums.DeviceDomainEnum;
import com.ard.sample.manage.model.receiver.OsdPayloadReceiver;
import com.ard.sample.manage.model.receiver.OsdSubDeviceReceiver;
+import com.ard.sample.manage.service.IDeviceService;
+import com.ard.sample.manage.service.IWaylineTrajectoryService;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -32,6 +39,15 @@
@Service
@Slf4j
public class DeviceOSDServiceImpl extends AbstractTSAService {
+
+ @Autowired
+ private IDeviceService _deviceService;
+
+ @Autowired
+ private IWaylineTrajectoryService _waylineTrajectoryService;
+
+ @Autowired
+ private DockWebSocketHandler _dockWebSocketHandler;
protected DeviceOSDServiceImpl(@Autowired @Qualifier("dockOSDServiceImpl") AbstractTSAService tsaService) {
super(tsaService);
@@ -65,7 +81,30 @@
OsdSubDeviceReceiver data = mapper.convertValue(receiver.getData(), OsdSubDeviceReceiver.class);
List<DevicePayloadDTO> payloadsList = device.getPayloadsList();
+ //data.setChildDeviceSn(device.getDeviceSn());
+ String dockOsd = "";
+ receiver.setType(MessageType.STATUS.getType()+"-aircraft");
+// receiver.setData(data);
try {
+ dockOsd=mapper.writeValueAsString(receiver);
+ JsonNode jsonNode = mapper.readTree(dockOsd);
+ //在JSON的data下插入childDeviceSn,飞行器的sn
+ if(jsonNode.get("data") instanceof ObjectNode){
+ ObjectNode objectNode = (ObjectNode) jsonNode.get("data");
+ objectNode.put("childDeviceSn", device.getDeviceSn());
+ }
+ if(jsonNode.has("data")){
+
+ if(jsonNode.get("data").has("mode_code")) {
+ Long code = jsonNode.get("data").get("mode_code").asLong();
+ if ("0,1,2,3,4,5,8,9,10,11,13,14".contains(code.toString())) {
+ _deviceService.updateWorkType(device.getDeviceSn(), code);
+ RedisOpsUtils.set(RedisConst.OSD_STATUS_PREFIX + device.getDeviceSn(), code);
+ }
+ }
+ }
+ dockOsd=mapper.writeValueAsString(jsonNode);
+
Map<String, Object> receiverData = (Map<String, Object>) receiver.getData();
data.setPayloads(payloadsList.stream()
.map(payload -> mapper.convertValue(
@@ -73,13 +112,19 @@
OsdPayloadReceiver.class))
.collect(Collectors.toList()));
- } catch (NullPointerException e) {
+ } catch (NullPointerException | JsonProcessingException e) {
log.warn("Please remount the payload, or restart the drone. Otherwise the data of the payload will not be received.");
}
RedisOpsUtils.setWithExpire(RedisConst.OSD_PREFIX + device.getDeviceSn(), data, RedisConst.DEVICE_ALIVE_SECOND);
wsMessage.getData().setHost(data);
+ // 发送给websocket客户端
+ _dockWebSocketHandler.sendMessageToSubscribers(device.getDeviceSn(), MessageType.STATUS.getType(), dockOsd, "");
+
+ // 将飞行器的OSD数据dockOsd入库;
+ _waylineTrajectoryService.setList(device.getDeviceSn(),"0", dockOsd);
+
sendMessageService.sendBatch(webSessions, wsMessage);
this.pushTelemetryData(data, device.getDeviceSn());
}
--
Gitblit v1.9.3