| | |
| | | package com.xiaopeng.pushMessage.webSocket.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.xiaopeng.api.dto.pushMessage.SendMessageDTO; |
| | | import com.xiaopeng.api.vo.XpTaskVO; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.web.controller.BaseController; |
| | | import com.xiaopeng.pushMessage.webSocket.service.WebSocketUserService; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | |
| | | @Autowired |
| | | private WebSocketUserService webSocketUserService; |
| | | |
| | | @Autowired ObjectMapper om; |
| | | |
| | | // ==================== 基于XpAppUser的WebSocket接口 ==================== |
| | | |
| | | // 消息格式 "{\"type\":\"mission_push\",\"content\":\"{\"missionId\":\"1983875114637811713\"}\",\"timestamp\":\"2025-10-27T09:22:45.681\"}"; |
| | |
| | | * @return 操作结果 |
| | | */ |
| | | @ApiOperation(value = "发送订单状态") |
| | | @PostMapping("/inner/websocket/order/sendStatus") |
| | | @PostMapping("/logan/inner/websocket/order/sendStatus") |
| | | public R<String> sendStatus(@RequestBody SendMessageDTO dto) { |
| | | try { |
| | | String message = dto.getMessage(); |
| | |
| | | * @return 操作结果 |
| | | */ |
| | | @ApiOperation(value = "发送车辆路线、时间") |
| | | @PostMapping("/inner/websocket/order/sendRoute") |
| | | @PostMapping("/logan/inner/websocket/order/sendRoute") |
| | | public R<String> sendRoute(@RequestBody SendMessageDTO dto) { |
| | | try { |
| | | String message = dto.getMessage(); |
| | |
| | | @ApiOperation(value = "发送车辆实时定位") |
| | | @PostMapping("/inner/websocket/order/sendVehicleLocation") |
| | | public R<String> sendVehicleLocation(@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()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 发送是否开启倒计时 |
| | | * { |
| | | * "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("获取在线用户列表失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 运维工单app推送 |
| | | */ |
| | | @PostMapping("/inner/websocket/push/task") |
| | | public R<?> pushTask(@RequestBody XpTaskVO vo) throws JsonProcessingException { |
| | | |
| | | String handleUserId = vo.getHandleUserId(); |
| | | Map<String, Object> msg = new HashMap<>(); |
| | | msg.put("type", "task"); |
| | | msg.put("data", vo); |
| | | webSocketUserService.sendMessageToUser(handleUserId, om.writeValueAsString(msg)); |
| | | return R.ok(); |
| | | |
| | | } |
| | | |
| | | } |