Junjie
9 天以前 cd448f774cfd4837a969d01ebea03530608c6839
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.*;
@@ -369,4 +371,40 @@
            return R.error("重启失败: " + e.getMessage());
        }
    }
    /**
     * 查询电视机WebSocket连接状态
     */
    @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);
    }
}