From 4f7fd9e879d9de211b255eb21535a034893ffbff Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期四, 14 五月 2026 16:20:48 +0800
Subject: [PATCH] 合并代码
---
xp-robotaxi-push-message-boot/src/main/java/com/xiaopeng/pushMessage/webSocket/controller/WebSocketController.java | 65 ++++++++++++++++++++++++--------
1 files changed, 49 insertions(+), 16 deletions(-)
diff --git a/xp-robotaxi-push-message-boot/src/main/java/com/xiaopeng/pushMessage/webSocket/controller/WebSocketController.java b/xp-robotaxi-push-message-boot/src/main/java/com/xiaopeng/pushMessage/webSocket/controller/WebSocketController.java
index c5cb1b8..d347d99 100644
--- a/xp-robotaxi-push-message-boot/src/main/java/com/xiaopeng/pushMessage/webSocket/controller/WebSocketController.java
+++ b/xp-robotaxi-push-message-boot/src/main/java/com/xiaopeng/pushMessage/webSocket/controller/WebSocketController.java
@@ -1,13 +1,13 @@
package com.xiaopeng.pushMessage.webSocket.controller;
import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.xiaopeng.api.dto.pushMessage.SendMessageDTO;
-import com.xiaopeng.api.vo.TaskVO;
+import com.xiaopeng.api.vo.XpTaskVO;
+import com.xiaopeng.api.vo.pushMessage.UpdateEndAddStatusVo;
import com.xiaopeng.common.core.domain.R;
import com.xiaopeng.common.core.web.controller.BaseController;
+import com.xiaopeng.common.redis.service.RedisService;
import com.xiaopeng.pushMessage.webSocket.service.WebSocketUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -15,10 +15,12 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
-import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.TimeUnit;
/**
* WebSocket控制器
@@ -34,15 +36,11 @@
@Autowired
private WebSocketUserService webSocketUserService;
+ @Autowired
private ObjectMapper om;
- @PostConstruct
- void setupObjectMapper() {
- // 允许对象忽略json中不存在的属性
- om = new ObjectMapper();
- om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- om.registerModule(new JavaTimeModule());
- }
+ @Resource
+ private RedisService redisService;
// ==================== 基于XpAppUser的WebSocket接口 ====================
@@ -56,7 +54,7 @@
* @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();
@@ -78,6 +76,8 @@
return R.fail("发送消息失败: " + e.getMessage());
}
}
+
+
@PostMapping("/base/websocket/order/sendStatusTest")
public R<String> sendStatusTest(@RequestBody SendMessageDTO dto) {
@@ -114,7 +114,7 @@
* @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();
@@ -377,12 +377,45 @@
* 运维工单app推送
*/
@PostMapping("/inner/websocket/push/task")
- public R<?> pushTask(@RequestBody TaskVO vo) throws JsonProcessingException {
+ public R<?> pushTask(@RequestBody XpTaskVO vo) throws JsonProcessingException {
String handleUserId = vo.getHandleUserId();
- String msg = om.writeValueAsString(vo);
- webSocketUserService.sendMessageToUser(handleUserId, msg);
+ Map<String, Object> msg = new HashMap<>();
+ msg.put("type", "task");
+ msg.put("data", vo);
+ webSocketUserService.sendMessageToUser(handleUserId, om.writeValueAsString(msg));
return R.ok();
}
+
+
+ /**
+ * 推送订单修改目的地状态消息
+ * @param vo
+ * @return
+ */
+ @PostMapping("/logan/inner/websocket/order/sendUpdateEndAddStatus")
+ public R<?> sendUpdateEndAddStatus(@RequestBody UpdateEndAddStatusVo vo){
+ try {
+ String message = vo.getMessage();
+ if (message.trim().isEmpty()) {
+ return R.fail("消息内容不能为空");
+ }
+ String appUserId = vo.getAppUserId().toString();
+ if (appUserId.trim().isEmpty()) {
+ return R.fail("用户id不能为空");
+ }
+ redisService.setCacheObject("UPDATE_END_ADDRESS_STATUS_MSG:" + vo, System.currentTimeMillis(), 5L, TimeUnit.SECONDS);
+ 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());
+ }
+ }
+
}
\ No newline at end of file
--
Gitblit v1.7.1