| | |
| | | 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.*; |
| | |
| | | @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<>(); |
| | | |
| | |
| | | @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文件"); |
| | |
| | | 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); |
| | | } |
| | | } |