TsbWebSocketController.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package com.ruoyi.web.controller.device;
  2. import com.ruoyi.common.core.controller.BaseController;
  3. import com.ruoyi.common.core.domain.AjaxResult;
  4. import com.ruoyi.common.core.domain.model.LoginUser;
  5. import com.ruoyi.common.utils.SecurityUtils;
  6. import com.ruoyi.device.domain.model.TsbUserDeviceBind;
  7. import com.ruoyi.device.websocket.TsbWebSocketService;
  8. import jakarta.annotation.Resource;
  9. import org.springframework.web.bind.annotation.GetMapping;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RequestParam;
  12. import org.springframework.web.bind.annotation.RestController;
  13. /**
  14. * 调试宝 WebSocket连接 辅助接口(连接前的检测接口)
  15. *
  16. * @author lwm
  17. */
  18. @RestController
  19. @RequestMapping("/tsb/ws")
  20. public class TsbWebSocketController extends BaseController
  21. {
  22. @Resource
  23. private TsbWebSocketService tsbWebSocketService;
  24. /**
  25. * WebSocket 连接预检(设备在线、操作权限、设备未被占用)
  26. */
  27. @GetMapping("/bindInfo")
  28. public AjaxResult bindInfo(@RequestParam Long deviceSn)
  29. {
  30. Long userId = SecurityUtils.getUserId();
  31. LoginUser loginUser = SecurityUtils.getLoginUser();
  32. String precheckMsg = tsbWebSocketService.precheckConnect(userId, deviceSn, loginUser);
  33. if (precheckMsg != null)
  34. {
  35. logger.warn("设备连接预检失败:{}, userId={}, deviceSn={}", precheckMsg, userId, deviceSn);
  36. return error(precheckMsg);
  37. }
  38. TsbUserDeviceBind bind = tsbWebSocketService.buildOperateBind(deviceSn, loginUser);
  39. return success(bind);
  40. }
  41. }