From 8aa9e121554b84735c8ec6139bd095ea3acb05e7 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Tue, 14 Oct 2025 16:10:49 +0800
Subject: [PATCH] 更改六合边缘服务器动态连接
---
ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java | 46 ++++++++++------------------------------------
1 files changed, 10 insertions(+), 36 deletions(-)
diff --git a/ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java b/ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java
index e54d009..d27d7ed 100644
--- a/ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java
+++ b/ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java
@@ -113,8 +113,7 @@
@Override
public BoxStreamUrlReceiver getBoxLiveUrl(String boxSn) {
ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
- String baseUrl="http://"+ardDroneInfo.getArdServerInfo().getHost()+":"+ardDroneInfo.getArdServerInfo().getHttpPort();
- TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(baseUrl,boxSn);
+ TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(ardDroneInfo.getServerInfoId(),boxSn);
return boxLiveUrl.getContent();
}
@@ -126,8 +125,8 @@
@Override
public List<BoxHistoryReceiver> getBoxHistory(BoxHistoryDTO boxHistoryDTO) {
ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxHistoryDTO.getBoxSn());
- String baseUrl="http://"+ardDroneInfo.getArdServerInfo().getHost()+":"+ardDroneInfo.getArdServerInfo().getHttpPort();
- TyHttpCommonReceiver<List<BoxHistoryReceiver>> boxHistory = tyClient.getBoxHistory(baseUrl,boxHistoryDTO);
+ TyHttpCommonReceiver<List<BoxHistoryReceiver>> boxHistory = tyClient.getBoxHistory(ardDroneInfo.getServerInfoId(),
+ boxHistoryDTO);
return boxHistory.getContent();
}
@@ -139,8 +138,7 @@
@Override
public List<BoxPhotosReceiver> getBoxPhotos(BoxPhotosDTO boxPhotosDTO) {
ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxPhotosDTO.getBoxSn());
- String baseUrl="http://"+ardDroneInfo.getArdServerInfo().getHost()+":"+ardDroneInfo.getArdServerInfo().getHttpPort();
- TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(baseUrl,boxPhotosDTO);
+ TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(ardDroneInfo.getServerInfoId(),boxPhotosDTO);
return boxPhotos.getContent();
}
@@ -150,8 +148,7 @@
@Override
public Boolean updateBoxSettings(BoxSettingsDTO boxSettingsDTO) {
ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSettingsDTO.getBoxSn());
- String baseUrl="http://"+ardDroneInfo.getArdServerInfo().getHost()+":"+ardDroneInfo.getArdServerInfo().getHttpPort();
- TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(baseUrl,boxSettingsDTO);
+ TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(ardDroneInfo.getServerInfoId(),boxSettingsDTO);
return result.getState() == 1;
}
@@ -845,14 +842,12 @@
*/
@Override
public List<BoxInfoReceiver> getBoxSnToList(String id) {
- ArdServerInfo ardServerInfos = ardServerService.selectArdServerManagementById(id);
- String baseUrl = "http://" + ardServerInfos.getHost() + ":" + ardServerInfos.getHttpPort();
List<BoxInfoReceiver> lisbox = new ArrayList<>();
try {
- lisbox = tyClient.getBoxList(baseUrl).getContent();
+ lisbox = tyClient.getBoxList(id).getContent();
return lisbox;
} catch (Exception e) {
- log.error("获取云盒列表失败: {}", baseUrl, e);
+ log.error("获取云盒列表失败: {}", id, e);
return lisbox;
}
}
@@ -860,12 +855,12 @@
private List<BoxInfoReceiver> getBoxList(List<ArdServerInfo> ls) {
return ls.stream()
.flatMap(ardServerInfo -> {
- String baseUrl = "http://" + ardServerInfo.getHost() + ":" + ardServerInfo.getHttpPort();
+
try {
- List<BoxInfoReceiver> boxes = tyClient.getBoxList(baseUrl).getContent();
+ List<BoxInfoReceiver> boxes = tyClient.getBoxList(ardServerInfo.getId()).getContent();
return Optional.ofNullable(boxes).orElse(Collections.emptyList()).stream();
} catch (Exception e) {
- log.error("获取云盒列表失败: {}", baseUrl, e);
+ log.error("获取云盒列表失败: {}", ardServerInfo.getId(), e);
return Stream.empty();
}
})
@@ -887,27 +882,6 @@
}
- /**
- * 定时向所有已连接的六合服务器发送心跳
- */
- @Scheduled(fixedRate = 5000) // 每5秒执行一次
- public void sendHeartBeat() {
- long timestamp = System.currentTimeMillis();
-
- for (TcpClientSession session : channels.values()) {
- ChannelFuture future = session.getChannelFuture();
- if (future == null || !future.channel().isActive()) {
- log.warn("边缘服务器 [{}] 连接未激活,跳过心跳发送", session.getServerId());
- continue;
- }
-
- HeartbeatCmd heartbeat = new HeartbeatCmd(timestamp);
- future.channel().writeAndFlush(heartbeat);
-
- log.info("→ 向边缘服务器 [{}] ({}:{}) 发送心跳,时间戳={}",
- session.getServerId(), session.getHost(), session.getPort(), timestamp);
- }
- }
/**
* 发送消息
*/
--
Gitblit v1.9.3