| | |
| | | } |
| | | |
| | | /** |
| | | * 发送是否开启倒计时 |
| | | * { |
| | | * "appUserId":"-1", |
| | | * {"type":"OPEN_TRUNK","content":"{\"orderId\":\"1983875114637811713\",\"isOpen\":1}","timestamp":"176569945845456"} |
| | | * } |
| | | * |
| | | * @param dto 消息实体 |
| | | * @return 操作结果 |
| | | */ |
| | | @ApiOperation(value = "发送是否开启倒计时") |
| | | @PostMapping("/inner/websocket/order/sendOpenTrunk") |
| | | public R<String> sendOpenTrunk(@RequestBody SendMessageDTO dto) { |
| | | try { |
| | | String message = dto.getMessage(); |
| | | if (message.trim().isEmpty()) { |
| | | return R.fail("消息内容不能为空"); |
| | | } |
| | | String appUserId = dto.getAppUserId(); |
| | | if (appUserId.trim().isEmpty()) { |
| | | return R.fail("用户id不能为空"); |
| | | } |
| | | int deviceCount = webSocketUserService.sendMessageToUser(appUserId, message); |
| | | if (deviceCount > 0) { |
| | | return R.ok("消息发送成功,发送到 " + deviceCount + " 个设备"); |
| | | } else { |
| | | return R.fail("用户不在线或发送失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("向用户发送消息失败", e); |
| | | return R.fail("发送消息失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 向指定用户发送JSON格式消息 |
| | | * @param appUserId 用户ID |
| | | * @param request 请求参数 |