From 907931c9db3d62af425a42decfafc4956a3ddea7 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期二, 24 二月 2026 18:07:48 +0800
Subject: [PATCH] 修改分表分库框架和XPU对接逻辑
---
xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/util/XPUUtil.java | 93 ++++++++++++++++++++++++++++++++--------------
1 files changed, 65 insertions(+), 28 deletions(-)
diff --git a/xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/util/XPUUtil.java b/xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/util/XPUUtil.java
index bf11d48..e718051 100644
--- a/xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/util/XPUUtil.java
+++ b/xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/util/XPUUtil.java
@@ -2,9 +2,6 @@
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
-import cn.hutool.http.HttpRequest;
-import cn.hutool.http.HttpResponse;
-import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.xiaopeng.api.dto.automaticPilot.MqttPublishDto;
@@ -14,7 +11,7 @@
import com.xiaopeng.api.vo.automaticPilot.proto.down.*;
import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudCreateOrder.RTTask;
import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudOrderOperation.OrderOperation;
-import com.xiaopeng.common.core.exception.ServiceException;
+import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudPushNavigation.RestoreNavigationData;
import com.xiaopeng.common.core.utils.StringUtils;
import com.xiaopeng.common.core.utils.uuid.UUID;
import lombok.extern.slf4j.Slf4j;
@@ -22,7 +19,6 @@
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -34,8 +30,8 @@
@Component
public class XPUUtil {
- @Value("${xpu.topic}")
- private String topic;
+ @Value("${xpu.topic.msg.prefix:Robotaxi/Msg/Xpu}")
+ private String topicPrefix;
@Resource
private XPUClient xpuClient;
@@ -48,14 +44,13 @@
// 查询车管 车辆xpuid信息返回字段,用于按需返回字段
public static final List<String> TYPE_LIST = Collections.singletonList("1");
-
-
/**
* Robotaxi创建订单推送给XPU
*
* @param task
* @return
*/
+ //TODO 处理feign调用的异常
public MqttPublishDto cloudCreateOrder(RTTask task, String vin, Long sequence) {
MsgContent msgContent = new MsgContent();
// 消息头
@@ -65,30 +60,28 @@
header.setCmd(RTCmdType.CLOUD_CREATE_ORDER);
header.setSequence(sequence);
header.setType(MessageType.MESSAGE_TYPE_RESPONSE);
+ header.setSource(SourceType.CLOUD);
msgContent.setHeader(header);
// 消息内容
JSONObject jsonObject = new JSONObject();
jsonObject.put("task", task);
msgContent.setContent_detail(jsonObject);
- log.info("云端-->XPU 创建订单:{}", msgContent);
- //根据车辆VIN查询XPUID
- String xpuId = getXpuIdByVin(vin);
- //组装请求消息体
MqttPublishVo vo = new MqttPublishVo();
- vo.setTopic(topic + "/" + xpuId);
+ vo.setTopic(buildTopicByVin(vin));
vo.setPayload(JSON.toJSONString(msgContent));
+
+ log.info("云端-->XPU 创建订单:{}", vo);
return xpuClient.publish(vo);
}
/**
- * 操作订单
- * 取消订单/修改途经点、终点/下发导航地址到车端
- *
+ * 取消订单、修改途经点、终点
* @param operation
* @return
*/
- public MqttPublishDto cloudOrderOperation(OrderOperation operation, String vin,Long sequence) {
+ //TODO 处理feign调用的异常
+ public MqttPublishDto cloudOrderOperation(OrderOperation operation, String vin, Long sequence) {
MsgContent msgContent = new MsgContent();
// 消息头
RtMsgHeader header = new RtMsgHeader();
@@ -97,18 +90,17 @@
header.setCmd(RTCmdType.CLOUD_ORDER_OPERATION);
header.setSequence(sequence);
header.setType(MessageType.MESSAGE_TYPE_REQUEST);
+ header.setSource(SourceType.CLOUD);
msgContent.setHeader(header);
// 消息内容
JSONObject jsonObject = new JSONObject();
jsonObject.put("operation", operation);
msgContent.setContent_detail(jsonObject);
- log.info("云端-->XPU 操作订单:{}", msgContent);
- //根据车辆VIN查询XPUID
- String xpuId = getXpuIdByVin(vin);
- //组装请求消息体
MqttPublishVo vo = new MqttPublishVo();
- vo.setTopic(topic + "/" + xpuId);
+ vo.setTopic(buildTopicByVin(vin));
vo.setPayload(JSON.toJSONString(msgContent));
+
+ log.info("云端-->XPU 修改订单:{}", vo);
return xpuClient.publish(vo);
}
@@ -131,22 +123,49 @@
Snowflake snowflake = IdUtil.getSnowflake(0, 0);
header.setSequence(snowflake.nextId());
header.setType(MessageType.MESSAGE_TYPE_RESPONSE);
+ header.setSource(SourceType.CLOUD);
msgContent.setHeader(header);
// 消息内容
JSONObject jsonObject = new JSONObject();
jsonObject.put("resposne", responseMessage);
msgContent.setContent_detail(jsonObject);
- log.info("云端-->XPU 响应消息:{}", msgContent);
- //根据车辆VIN查询XPUID
- String xpuId = getXpuIdByVin(vin);
- //组装请求消息体
MqttPublishVo vo = new MqttPublishVo();
- vo.setTopic(topic + "/" + xpuId);
+ vo.setTopic(buildTopicByVin(vin));
vo.setPayload(JSON.toJSONString(msgContent));
+
+ log.info("云端-->XPU 响应消息:{}", vo);
return xpuClient.publish(vo);
}
+ /**
+ * 下发导航地址到车端
+ *
+ * @param navigationData
+ * @return
+ */
+ //TODO 处理feign调用的异常
+ public MqttPublishDto cloudPushNavigation(RestoreNavigationData navigationData, String xpuId, Long sequence) {
+ MsgContent msgContent = new MsgContent();
+ // 消息头
+ RtMsgHeader header = new RtMsgHeader();
+ header.setMsg_id(UUID.randomUUID().toString());
+ header.setTimestamp(System.currentTimeMillis());
+ header.setCmd(RTCmdType.CLOUD_NAVIGATION_RESPONSE);
+ header.setSequence(sequence);
+ header.setType(MessageType.MESSAGE_TYPE_RESPONSE);
+ header.setSource(SourceType.CLOUD);
+ msgContent.setHeader(header);
+ // 消息内容
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("navigationData", navigationData);
+ msgContent.setContent_detail(jsonObject);
+ MqttPublishVo vo = new MqttPublishVo();
+ vo.setTopic(buildTopicByXpuId(xpuId));
+ vo.setPayload(JSON.toJSONString(msgContent));
+ log.info("云端-->XPU 下发导航信息:{}", vo);
+ return xpuClient.publish(vo);
+ }
/**
@@ -164,5 +183,23 @@
return xpuIdMapping.get(XPU_ID_TYPE);
}
+ private String buildTopicByVin(String vin) {
+ String xpuId = getXpuIdByVin(vin);
+ return this.buildTopicByXpuId(xpuId);
+ }
+
+ private String buildTopicByXpuId(String xpuId) {
+ String prefix = topicPrefix == null ? "" : topicPrefix;
+ if (!prefix.endsWith("/")) {
+ prefix = prefix + "/";
+ }
+ String value = xpuId;
+ if (xpuId.length() > 10) {
+ int start = 10;
+ int end = Math.min(24, xpuId.length());
+ value = xpuId.substring(start, end);
+ }
+ return prefix + value + "00000000";
+ }
}
--
Gitblit v1.7.1