From ba78f764042ca15bf3f3be62e7a3fc699df56d67 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期六, 07 三月 2026 20:59:53 +0800
Subject: [PATCH] 提交管理后台新接口,修改XPU报文相关功能,增加测试小程序状态流转接口
---
xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/util/XPUUtil.java | 145 +++++++++++++++++++++++++-----------------------
1 files changed, 75 insertions(+), 70 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 7187e2f..603e7ab 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,16 +2,12 @@
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
-import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.xiaopeng.api.dto.automaticPilot.MqttPublishDto;
import com.xiaopeng.api.feignClient.automaticPilot.VmpOpenServiceClient;
import com.xiaopeng.api.feignClient.automaticPilot.XPUClient;
import com.xiaopeng.api.vo.automaticPilot.MqttPublishVo;
-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.api.vo.automaticPilot.proto.down.cloudPushNavigation.RestoreNavigationData;
+import com.xiaopeng.api.vo.automaticPilot.protobuf.*;
import com.xiaopeng.common.core.utils.StringUtils;
import com.xiaopeng.common.core.utils.uuid.UUID;
import lombok.extern.slf4j.Slf4j;
@@ -44,32 +40,36 @@
// 查询车管 车辆xpuid信息返回字段,用于按需返回字段
public static final List<String> TYPE_LIST = Collections.singletonList("1");
+ private static final com.google.protobuf.util.JsonFormat.Printer jsonPrinter = com.google.protobuf.util.JsonFormat.printer().printingEnumsAsInts();
+
/**
* Robotaxi创建订单推送给XPU
*
- * @param task
+ * @param taskList
* @return
*/
//TODO 处理feign调用的异常
- public MqttPublishDto cloudCreateOrder(RTTask task, String vin, Long sequence) {
- MsgContent msgContent = new MsgContent();
- // 消息头
- RtMsgHeader header = new RtMsgHeader();
- header.setMsg_id(UUID.randomUUID().toString());
- header.setTimestamp(System.currentTimeMillis());
- header.setCmd(RTCmdType.CLOUD_CREATE_ORDER);
- header.setSequence(sequence);
- header.setType(MessageType.MESSAGE_TYPE_REQUEST);
- header.setSource(SourceType.CLOUD);
- msgContent.setHeader(header);
- // 消息内容
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("task", task);
- msgContent.setContent_detail(jsonObject);
+ public MqttPublishDto cloudCreateOrder(RtTaskList taskList, String vin, Long sequence) {
+ MsgContent.Builder msgContentBuilder = MsgContent.newBuilder();
+ MsgHeader.Builder headerBuilder = MsgHeader.newBuilder();
+ headerBuilder.setMsgId(UUID.randomUUID().toString());
+ headerBuilder.setTimestamp(System.currentTimeMillis());
+ headerBuilder.setCmd(RTCmdType.CLOUD_CREATE_ORDER.getValue());
+ headerBuilder.setSequence(sequence);
+ headerBuilder.setType(MessageType.MESSAGE_TYPE_REQUEST);
+ headerBuilder.setSource(SourceType.CLOUD);
+ msgContentBuilder.setHeader(headerBuilder.build());
+
+ msgContentBuilder.setRtTaskList(taskList);
+
MqttPublishVo vo = new MqttPublishVo();
vo.setTopic(buildTopicByVin(vin));
- vo.setPayload(JSON.toJSONString(msgContent));
-
+ try {
+ vo.setPayload(jsonPrinter.print(msgContentBuilder.build()));
+ } catch (Exception e) {
+ log.error("Protobuf转JSON失败", e);
+ throw new RuntimeException("Protobuf转JSON失败", e);
+ }
log.info("云端-->XPU 创建订单:{}", vo);
return xpuClient.publish(vo);
}
@@ -82,24 +82,26 @@
*/
//TODO 处理feign调用的异常
public MqttPublishDto cloudOrderOperation(OrderOperation operation, String vin, Long sequence) {
- MsgContent msgContent = new MsgContent();
- // 消息头
- RtMsgHeader header = new RtMsgHeader();
- header.setMsg_id(UUID.randomUUID().toString());
- header.setTimestamp(System.currentTimeMillis());
- 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);
+ MsgContent.Builder msgContentBuilder = MsgContent.newBuilder();
+ MsgHeader.Builder headerBuilder = MsgHeader.newBuilder();
+ headerBuilder.setMsgId(UUID.randomUUID().toString());
+ headerBuilder.setTimestamp(System.currentTimeMillis());
+ headerBuilder.setCmd(RTCmdType.CLOUD_ORDER_OPERATION.getValue());
+ headerBuilder.setSequence(sequence);
+ headerBuilder.setType(MessageType.MESSAGE_TYPE_REQUEST);
+ headerBuilder.setSource(SourceType.CLOUD);
+ msgContentBuilder.setHeader(headerBuilder.build());
+
+ msgContentBuilder.setOrderOperation(operation);
+
MqttPublishVo vo = new MqttPublishVo();
vo.setTopic(buildTopicByVin(vin));
- vo.setPayload(JSON.toJSONString(msgContent));
-
+ try {
+ vo.setPayload(jsonPrinter.print(msgContentBuilder.build()));
+ } catch (Exception e) {
+ log.error("Protobuf转JSON失败", e);
+ throw new RuntimeException("Protobuf转JSON失败", e);
+ }
log.info("云端-->XPU 修改订单:{}", vo);
return xpuClient.publish(vo);
}
@@ -114,25 +116,25 @@
* @return
*/
public MqttPublishDto responseMessage(ResponseMessage responseMessage, String vin) {
- MsgContent msgContent = new MsgContent();
- // 消息头
- RtMsgHeader header = new RtMsgHeader();
- header.setMsg_id(UUID.randomUUID().toString());
- header.setTimestamp(System.currentTimeMillis());
- header.setCmd(RTCmdType.CLOUD_TASK_CONTROL);
+ MsgContent.Builder msgContentBuilder = MsgContent.newBuilder();
+ MsgHeader.Builder headerBuilder = MsgHeader.newBuilder();
+ headerBuilder.setMsgId(UUID.randomUUID().toString());
+ headerBuilder.setTimestamp(System.currentTimeMillis());
+ headerBuilder.setCmd(RTCmdType.CLOUD_TASK_CONTROL.getValue());
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);
+ headerBuilder.setSequence(snowflake.nextId());
+ headerBuilder.setType(MessageType.MESSAGE_TYPE_RESPONSE);
+ headerBuilder.setSource(SourceType.CLOUD);
+ msgContentBuilder.setHeader(headerBuilder.build());
+ msgContentBuilder.setResponse(responseMessage);
MqttPublishVo vo = new MqttPublishVo();
vo.setTopic(buildTopicByVin(vin));
- vo.setPayload(JSON.toJSONString(msgContent));
-
+ try {
+ vo.setPayload(jsonPrinter.print(msgContentBuilder.build()));
+ } catch (Exception e) {
+ log.error("Protobuf转JSON失败", e);
+ throw new RuntimeException("Protobuf转JSON失败", e);
+ }
log.info("云端-->XPU 响应消息:{}", vo);
return xpuClient.publish(vo);
}
@@ -145,23 +147,26 @@
*/
//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);
+ MsgContent.Builder msgContentBuilder = MsgContent.newBuilder();
+ MsgHeader.Builder headerBuilder = MsgHeader.newBuilder();
+ headerBuilder.setMsgId(UUID.randomUUID().toString());
+ headerBuilder.setTimestamp(System.currentTimeMillis());
+ headerBuilder.setCmd(RTCmdType.CLOUD_NAVIGATION_RESPONSE.getValue());
+ headerBuilder.setSequence(sequence);
+ headerBuilder.setType(MessageType.MESSAGE_TYPE_RESPONSE);
+ headerBuilder.setSource(SourceType.CLOUD);
+ msgContentBuilder.setHeader(headerBuilder.build());
+
+ msgContentBuilder.setRestoreNavigationData(navigationData);
MqttPublishVo vo = new MqttPublishVo();
vo.setTopic(buildTopicByXpuId(xpuId));
- vo.setPayload(JSON.toJSONString(msgContent));
+ try {
+ vo.setPayload(jsonPrinter.print(msgContentBuilder.build()));
+ } catch (Exception e) {
+ log.error("Protobuf转JSON失败", e);
+ throw new RuntimeException("Protobuf转JSON失败", e);
+ }
+
log.info("云端-->XPU 下发导航信息:{}", vo);
return xpuClient.publish(vo);
--
Gitblit v1.7.1