From cd448f774cfd4837a969d01ebea03530608c6839 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 07 四月 2026 16:55:55 +0800
Subject: [PATCH] #websocket连接管理页面
---
src/main/java/com/zy/asrs/controller/TvDeviceController.java | 44 +++++++++++++++++++++++++++++++++++++++++---
1 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/src/main/java/com/zy/asrs/controller/TvDeviceController.java b/src/main/java/com/zy/asrs/controller/TvDeviceController.java
index 65aae3d..a3ed5ec 100644
--- a/src/main/java/com/zy/asrs/controller/TvDeviceController.java
+++ b/src/main/java/com/zy/asrs/controller/TvDeviceController.java
@@ -11,6 +11,8 @@
import com.zy.asrs.entity.TvDevice;
import com.zy.asrs.service.ApkBuildTaskService;
import com.zy.asrs.service.TvDeviceService;
+import com.zy.asrs.websocket.TvWebSocketServer;
+import jakarta.websocket.Session;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -50,8 +52,8 @@
@RequestMapping(value = "/tvDevice/list/auth")
@ManagerAuth
public R list(@RequestParam(defaultValue = "1") Integer curr,
- @RequestParam(defaultValue = "10") Integer limit,
- @RequestParam Map<String, Object> param) {
+ @RequestParam(defaultValue = "10") Integer limit,
+ @RequestParam Map<String, Object> param) {
excludeTrash(param);
QueryWrapper<TvDevice> wrapper = new QueryWrapper<>();
@@ -230,7 +232,7 @@
@RequestMapping(value = "/tvDevice/uploadAndInstall/auth", method = RequestMethod.POST)
@ManagerAuth
public R uploadAndInstall(@RequestParam("file") MultipartFile file,
- @RequestParam("deviceIds") String deviceIdsStr) {
+ @RequestParam("deviceIds") String deviceIdsStr) {
try {
if (file.isEmpty()) {
return R.error("璇烽�夋嫨APK鏂囦欢");
@@ -369,4 +371,40 @@
return R.error("閲嶅惎澶辫触: " + e.getMessage());
}
}
+
+ /**
+ * 鏌ヨ鐢佃鏈篧ebSocket杩炴帴鐘舵��
+ */
+ @RequestMapping(value = "/tvDevice/tvWebSocket/status/auth")
+ @ManagerAuth
+ public R tvWebSocketStatus() {
+ Map<String, Session> sessions = TvWebSocketServer.getSessions();
+
+ // 鏌ヨ鎵�鏈夎澶囦俊鎭紝鐢ㄤ簬鍖归厤IP瀵瑰簲鐨勮澶囧悕绉�
+ List<TvDevice> allDevices = tvDeviceService.list();
+ Map<String, String> ipToDeviceName = new HashMap<>();
+ for (TvDevice device : allDevices) {
+ if (device.getIp() != null) {
+ ipToDeviceName.put(device.getIp(), device.getName());
+ }
+ }
+
+ List<Map<String, Object>> connections = new ArrayList<>();
+ for (Map.Entry<String, Session> entry : sessions.entrySet()) {
+ Map<String, Object> info = new HashMap<>();
+ String ip = entry.getKey();
+ Session session = entry.getValue();
+
+ info.put("ip", ip);
+ info.put("deviceName", ipToDeviceName.getOrDefault(ip, "-"));
+ info.put("sessionId", session.getId());
+ info.put("open", session.isOpen());
+ connections.add(info);
+ }
+
+ Map<String, Object> result = new HashMap<>();
+ result.put("total", sessions.size());
+ result.put("connections", connections);
+ return R.ok(result);
+ }
}
--
Gitblit v1.9.1