| File was renamed from ruoyi-admin/src/main/java/com/ruoyi/web/utils/WebSocketUtil.java |
| | |
| | | package com.ruoyi.web.utils; |
| | | package com.ruoyi.web.controller.webSocket; |
| | | |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.web.webSocket.WebSocketUserService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | * 提供REST接口用于触发服务端主动发送消息 |
| | | * 支持基于AppUser的消息发送 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/open/websocket") |
| | | @Slf4j |
| | | @Component |
| | | public class WebSocketUtil { |
| | | public class WebSocketController extends BaseController { |
| | | |
| | | |
| | | @Autowired |
| | | private WebSocketUserService webSocketUserService; |
| | | |
| | | // ==================== 基于AppUser的WebSocket接口 ==================== |
| | | |
| | | /** |
| | |
| | | * @param request 请求参数 |
| | | * @return 操作结果 |
| | | */ |
| | | public R<String> sendMessageToUser(String appUserId,Map<String, String> request) { |
| | | @PostMapping("/user/send/{appUserId}") |
| | | public R<String> sendMessageToUser(@PathVariable String appUserId, @RequestBody Map<String, String> request) { |
| | | try { |
| | | String message = request.get("message"); |
| | | if (message == null || message.trim().isEmpty()) { |
| | |
| | | * @param request 请求参数 |
| | | * @return 操作结果 |
| | | */ |
| | | public R<String> sendJsonMessageToUser(String appUserId, Map<String, Object> request) { |
| | | @PostMapping("/user/send-json/{appUserId}") |
| | | public R<String> sendJsonMessageToUser(@PathVariable String appUserId, @RequestBody Map<String, Object> request) { |
| | | try { |
| | | String messageType = (String) request.get("messageType"); |
| | | Object data = request.get("data"); |
| | |
| | | * @param request 请求参数 |
| | | * @return 操作结果 |
| | | */ |
| | | public R<String> sendMessageToUsers( Map<String, Object> request) { |
| | | @PostMapping("/user/send-multiple") |
| | | public R<String> sendMessageToUsers(@RequestBody Map<String, Object> request) { |
| | | try { |
| | | @SuppressWarnings("unchecked") |
| | | List<String> appUserIds = (List<String>) request.get("appUserIds"); |
| | |
| | | * @param request 请求参数 |
| | | * @return 操作结果 |
| | | */ |
| | | public R<String> sendTaskAssignment(Map<String, String> request) { |
| | | @PostMapping("/user/task-assignment") |
| | | public R<String> sendTaskAssignment(@RequestBody Map<String, String> request) { |
| | | try { |
| | | String taskId = request.get("taskId"); |
| | | String taskName = request.get("taskName"); |
| | |
| | | * @param request 请求参数 |
| | | * @return 操作结果 |
| | | */ |
| | | public R<String> sendStatusUpdate(Map<String, String> request) { |
| | | @PostMapping("/user/status-update") |
| | | public R<String> sendStatusUpdate(@RequestBody Map<String, String> request) { |
| | | try { |
| | | String status = request.get("status"); |
| | | String details = request.get("details"); |
| | |
| | | * @param request 请求参数 |
| | | * @return 操作结果 |
| | | */ |
| | | public R<String> sendTaskStatusUpdate(Map<String, String> request) { |
| | | @PostMapping("/user/task-status-update") |
| | | public R<String> sendTaskStatusUpdate(@RequestBody Map<String, String> request) { |
| | | try { |
| | | String taskId = request.get("taskId"); |
| | | String taskStatus = request.get("taskStatus"); |
| | |
| | | * @param request 请求参数 |
| | | * @return 操作结果 |
| | | */ |
| | | public R<String> sendLocationUpdate(Map<String, String> request) { |
| | | @PostMapping("/user/location-update") |
| | | public R<String> sendLocationUpdate(@RequestBody Map<String, String> request) { |
| | | try { |
| | | String userId = request.get("userId"); |
| | | String longitude = request.get("longitude"); |
| | |
| | | * @param appUserId 用户ID |
| | | * @return 连接信息 |
| | | */ |
| | | public R getUserConnectionInfo(String appUserId) { |
| | | @GetMapping("/user/info/{appUserId}") |
| | | public R getUserConnectionInfo(@PathVariable String appUserId) { |
| | | try { |
| | | Map<String, Object> info = webSocketUserService.getUserConnectionInfo(appUserId); |
| | | return R.ok(info, "获取用户连接信息成功"); |
| | |
| | | * 获取所有连接统计信息 |
| | | * @return 统计信息 |
| | | */ |
| | | @GetMapping("/user/stats") |
| | | public R getConnectionStats() { |
| | | try { |
| | | Map<String, Object> stats = webSocketUserService.getConnectionStats(); |
| | |
| | | * @param appUserId 用户ID |
| | | * @return 检查结果 |
| | | */ |
| | | public R checkUserOnline(String appUserId) { |
| | | @GetMapping("/user/online/{appUserId}") |
| | | public R checkUserOnline(@PathVariable String appUserId) { |
| | | try { |
| | | boolean isOnline = webSocketUserService.isUserOnline(appUserId); |
| | | return R.ok(isOnline, "用户在线状态检查完成"); |
| | |
| | | * 获取在线用户列表 |
| | | * @return 在线用户列表 |
| | | */ |
| | | @GetMapping("/user/online-list") |
| | | public R getOnlineUserIds() { |
| | | try { |
| | | Set<String> onlineUserIds = webSocketUserService.getOnlineUserIds(); |