zhouhn
2026-02-25 0f5fc39356b6bff677984c33c296573bb9c8393e
xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/util/XPUUtil.java
@@ -12,6 +12,7 @@
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.RtTaskList;
import com.xiaopeng.common.core.utils.StringUtils;
import com.xiaopeng.common.core.utils.uuid.UUID;
import lombok.extern.slf4j.Slf4j;
@@ -51,24 +52,28 @@
     * @return
     */
    //TODO 处理feign调用的异常
    public MqttPublishDto cloudCreateOrder(RTTask task, String vin, Long sequence) {
        MsgContent msgContent = new MsgContent();
    public MqttPublishDto cloudCreateOrder(RtTaskList taskList, String vin, Long sequence) {
        com.xiaopeng.api.vo.automaticPilot.protobuf.MsgContent.Builder msgContentBuilder = com.xiaopeng.api.vo.automaticPilot.protobuf.MsgContent.newBuilder();
        // 消息头
        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);
        com.xiaopeng.api.vo.automaticPilot.protobuf.MsgHeader.Builder headerBuilder = com.xiaopeng.api.vo.automaticPilot.protobuf.MsgHeader.newBuilder();
        headerBuilder.setMsgId(UUID.randomUUID().toString());
        headerBuilder.setTimestamp(System.currentTimeMillis());
        headerBuilder.setCmd(RTCmdType.CLOUD_CREATE_ORDER.getValue());
        headerBuilder.setSequence(sequence);
        headerBuilder.setType(com.xiaopeng.api.vo.automaticPilot.protobuf.MessageType.MESSAGE_TYPE_REQUEST);
        headerBuilder.setSource(com.xiaopeng.api.vo.automaticPilot.protobuf.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(com.google.protobuf.util.JsonFormat.printer().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);
@@ -81,24 +86,28 @@
     * @return
     */
    //TODO 处理feign调用的异常
    public MqttPublishDto cloudOrderOperation(OrderOperation operation, String vin, Long sequence) {
        MsgContent msgContent = new MsgContent();
    public MqttPublishDto cloudOrderOperation(com.xiaopeng.api.vo.automaticPilot.protobuf.OrderOperation operation, String vin, Long sequence) {
        com.xiaopeng.api.vo.automaticPilot.protobuf.MsgContent.Builder msgContentBuilder = com.xiaopeng.api.vo.automaticPilot.protobuf.MsgContent.newBuilder();
        // 消息头
        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);
        com.xiaopeng.api.vo.automaticPilot.protobuf.MsgHeader.Builder headerBuilder = com.xiaopeng.api.vo.automaticPilot.protobuf.MsgHeader.newBuilder();
        headerBuilder.setMsgId(UUID.randomUUID().toString());
        headerBuilder.setTimestamp(System.currentTimeMillis());
        headerBuilder.setCmd(RTCmdType.CLOUD_ORDER_OPERATION.getValue());
        headerBuilder.setSequence(sequence);
        headerBuilder.setType(com.xiaopeng.api.vo.automaticPilot.protobuf.MessageType.MESSAGE_TYPE_REQUEST);
        headerBuilder.setSource(com.xiaopeng.api.vo.automaticPilot.protobuf.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(com.google.protobuf.util.JsonFormat.printer().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);
@@ -113,25 +122,29 @@
     * @param responseMessage
     * @return
     */
    public MqttPublishDto responseMessage(ResponseMessage responseMessage, String vin) {
        MsgContent msgContent = new MsgContent();
    public MqttPublishDto responseMessage(com.xiaopeng.api.vo.automaticPilot.protobuf.ResponseMessage responseMessage, String vin) {
        com.xiaopeng.api.vo.automaticPilot.protobuf.MsgContent.Builder msgContentBuilder = com.xiaopeng.api.vo.automaticPilot.protobuf.MsgContent.newBuilder();
        // 消息头
        RtMsgHeader header = new RtMsgHeader();
        header.setMsg_id(UUID.randomUUID().toString());
        header.setTimestamp(System.currentTimeMillis());
        header.setCmd(RTCmdType.CLOUD_TASK_CONTROL);
        com.xiaopeng.api.vo.automaticPilot.protobuf.MsgHeader.Builder headerBuilder = com.xiaopeng.api.vo.automaticPilot.protobuf.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(com.xiaopeng.api.vo.automaticPilot.protobuf.MessageType.MESSAGE_TYPE_RESPONSE);
        headerBuilder.setSource(com.xiaopeng.api.vo.automaticPilot.protobuf.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(com.google.protobuf.util.JsonFormat.printer().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);
@@ -144,24 +157,28 @@
     * @return
     */
    //TODO 处理feign调用的异常
    public MqttPublishDto cloudPushNavigation(RestoreNavigationData navigationData, String xpuId, Long sequence) {
        MsgContent msgContent = new MsgContent();
    public MqttPublishDto cloudPushNavigation(com.xiaopeng.api.vo.automaticPilot.protobuf.RestoreNavigationData navigationData, String xpuId, Long sequence) {
        com.xiaopeng.api.vo.automaticPilot.protobuf.MsgContent.Builder msgContentBuilder = com.xiaopeng.api.vo.automaticPilot.protobuf.MsgContent.newBuilder();
        // 消息头
        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);
        com.xiaopeng.api.vo.automaticPilot.protobuf.MsgHeader.Builder headerBuilder = com.xiaopeng.api.vo.automaticPilot.protobuf.MsgHeader.newBuilder();
        headerBuilder.setMsgId(UUID.randomUUID().toString());
        headerBuilder.setTimestamp(System.currentTimeMillis());
        headerBuilder.setCmd(RTCmdType.CLOUD_NAVIGATION_RESPONSE.getValue());
        headerBuilder.setSequence(sequence);
        headerBuilder.setType(com.xiaopeng.api.vo.automaticPilot.protobuf.MessageType.MESSAGE_TYPE_RESPONSE);
        headerBuilder.setSource(com.xiaopeng.api.vo.automaticPilot.protobuf.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(com.google.protobuf.util.JsonFormat.printer().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);