Junjie
8 天以前 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.*;
@@ -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());
        }
    }
    /**
     * 查询电视机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);
    }
}