From 06006887e9625a5d8b2f348ce9aca65ee296c768 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期三, 25 二月 2026 18:49:59 +0800
Subject: [PATCH] 修改推送导航数据逻辑
---
xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/service/KafkaConsumerService.java | 116 +++++++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 86 insertions(+), 30 deletions(-)
diff --git a/xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/service/KafkaConsumerService.java b/xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/service/KafkaConsumerService.java
index d58558d..e14d760 100644
--- a/xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/service/KafkaConsumerService.java
+++ b/xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/service/KafkaConsumerService.java
@@ -4,7 +4,6 @@
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
-import com.xiaopeng.api.dto.automaticPilot.MqttPublishDto;
import com.xiaopeng.api.dto.map.OrderRouteAndFareDto;
import com.xiaopeng.api.dto.operation.LonLatDto;
import com.xiaopeng.api.dto.operation.ReassignOrderDTO;
@@ -21,6 +20,8 @@
import com.xiaopeng.api.model.order.XpCruiseOrder;
import com.xiaopeng.api.model.order.XpOrder;
import com.xiaopeng.api.model.vehicleConvoy.XpVehicle;
+import com.xiaopeng.api.vo.OrderType;
+import com.xiaopeng.api.vo.SystemEventType;
import com.xiaopeng.api.vo.automaticPilot.VehiclePosition;
import com.xiaopeng.api.vo.automaticPilot.proto.down.GeoPoint;
import com.xiaopeng.api.vo.automaticPilot.proto.down.ResponseMessage;
@@ -208,11 +209,17 @@
if(code == com.xiaopeng.api.vo.automaticPilot.proto.up.StatusCode.OK){
Object sequence = redisTemplate.opsForValue().get(requestSeq);
if(sequence!=null){
- String[] split = sequence.toString().split("_");
- if(split[0].equals("pushOrder")){
+ JSONObject jsonObject = JSON.parseObject(sequence.toString());
+ String event = jsonObject.getString("event");
+ //推送导航的响应消息
+ if(SystemEventType.PUSH_NAVIGATION.equals(event)){
+ String orderId = jsonObject.getString("orderId");
+ String vin = jsonObject.getString("vin");
+ String orderType = jsonObject.getString("orderType");
PopOrderDto dto = new PopOrderDto();
- dto.setOrderId(Long.valueOf(split[1]));
- dto.setXpVehicleVin(split[2]);
+ dto.setOrderId(Long.valueOf(orderId));
+ dto.setXpVehicleVin(vin);
+ dto.setOrderType(orderType);
xpOrderClient.popOrder(dto);
}
}
@@ -403,6 +410,10 @@
//开始处理消息对应的业务逻辑
NavigationDeviationEvent deviationEvent = msgContent.getContent_detail().getObject("deviationEvent", NavigationDeviationEvent.class);
String requestId = deviationEvent.getRequest_id();
+ //导航id
+ String routeID = "";
+ Long vehicleId = null;
+ String orderType = "";
//偏航事件类型 1:请求导航,2:取消导航
if (deviationEvent.getEvent_type().equals(RtEventType.RT_EVENT_TYPE_REQUEST)) {
NavigationDeviationMessage navigationDeviationMessage = deviationEvent.getNavigation_deviation_message();
@@ -414,15 +425,31 @@
LonLatDto destination = new LonLatDto();
LonLatDto origin = new LonLatDto();
if (orderId.contains("XU")) {
+ orderType = OrderType.CRUISE_ORDER;
// todo 下发巡游单的导航数据
- //巡游单
- origin.setLongitude(longitude);
- origin.setLatitude(latitude);
+ //先响应消息
+ responseMessage(sequence, "");
+ //构建导航数据给到车端
+ origin.setLongitude(116.40528);
+ origin.setLatitude(39.90498);
destination.setLongitude(116.40528);
destination.setLatitude(39.90498);
- //响应消息
- responseMessage(sequence, "");
+
+ OrderRouteAndFareDto dto = new OrderRouteAndFareDto();
+ dto.setOrderId(Long.parseLong(orderId));
+ dto.setOrigin(origin);
+ dto.setDestination(destination);
+ R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto);
+ if (200 != routeVoR.getCode()) {
+ throw new RuntimeException("获取订单线路和运费失败");
+ }
+ RouteVo routeVo = routeVoR.getData();
+ routeID = routeVo.getRouteID();
+
+
+// vehicleId = xpOrder.getVehicleId();
} else {
+ orderType = OrderType.USER_ORDER;
//正常单
R<XpOrder> xpOrderR = xpOrderClient.queryOrderById(Long.parseLong(orderId));
if (200 != xpOrderR.getCode()) {
@@ -439,31 +466,50 @@
origin.setLatitude(latitude);
destination.setLongitude(xpOrder.getStartLon());
destination.setLatitude(xpOrder.getStartLat());
+
+ OrderRouteAndFareDto dto = new OrderRouteAndFareDto();
+ dto.setOrderId(Long.parseLong(orderId));
+ dto.setOrigin(origin);
+ dto.setDestination(destination);
+ R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto);
+ if (200 != routeVoR.getCode()) {
+ throw new RuntimeException("获取订单线路和运费失败");
+ }
+ RouteVo routeVo = routeVoR.getData();
+ routeID = routeVo.getRouteID();
+ //缓存数据,用于后续推给乘客导航线路
+ redisService.setCacheObject("ORDER_NAVIGATION_START_DATA:" + xpOrder.getAppUserId(), com.alibaba.fastjson.JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS);
}
//驶往下车点的行程
if (Arrays.asList(6).contains(xpOrder.getStatus())) {
- //查询起点到终点的线路
origin.setLongitude(longitude);
origin.setLatitude(latitude);
destination.setLongitude(xpOrder.getEndLon());
destination.setLatitude(xpOrder.getEndLat());
+
+ OrderRouteAndFareDto dto = new OrderRouteAndFareDto();
+ dto.setOrderId(Long.parseLong(orderId));
+ dto.setOrigin(origin);
+ dto.setDestination(destination);
+ R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto);
+ if (200 != routeVoR.getCode()) {
+ throw new RuntimeException("获取订单线路和运费失败");
+ }
+ RouteVo routeVo = routeVoR.getData();
+ routeID = routeVo.getRouteID();
+ //缓存导航数据,用于后面的逻辑中给乘客端推送导航数据
+ redisService.setCacheObject("ORDER_NAVIGATION_END_DATA:" + xpOrder.getAppUserId(), com.alibaba.fastjson.JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS);
}
- OrderRouteAndFareDto dto = new OrderRouteAndFareDto();
- dto.setOrderId(Long.parseLong(orderId));
- dto.setOrigin(origin);
- dto.setDestination(destination);
- R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto);
- if (200 != routeVoR.getCode()) {
- throw new RuntimeException("获取订单线路和运费失败");
- }
- RouteVo routeVo = routeVoR.getData();
- R<String> stringR = xpMapClient.queryRouted(routeVo.getRouteID());
+ }
+
+ if(StringUtils.isNotEmpty(routeID)){
+ XpVehicle xpVehicle = xpVehicleClient.queryById(vehicleId).getData();
+ R<String> stringR = xpMapClient.queryRouted(routeID);
if (200 != stringR.getCode()) {
throw new RuntimeException("根据导航ID获取车端需要的导航数据失败");
}
-
//构建导航下发请求对象
- cloudPushNavigationInfo(requestId, routeVo.getRouteID(), stringR.getData(), orderId, xpVehicle.getVehicleVin(), xpVehicle.getXpuId());
+ cloudPushNavigationInfo(requestId, routeID, stringR.getData(), orderType, orderId, xpVehicle.getVehicleVin(), xpVehicle.getXpuId());
}
}
}
@@ -482,8 +528,10 @@
//导航id
String routeID = "";
Long vehicleId = null;
+ String orderType = "";
if (orderId.contains("XU")) {
// todo 下发巡游单的导航数据
+ orderType = OrderType.CRUISE_ORDER;
//巡游单
if (orderPhase.equals(OrderPhase.ROUTE_TO_CRUISE)) {
//先响应消息
@@ -509,17 +557,18 @@
// vehicleId = xpOrder.getVehicleId();
}
} else {
+ orderType = OrderType.USER_ORDER;
//正常单
R<XpOrder> xpOrderR = xpOrderClient.queryOrderById(Long.parseLong(orderId));
if (200 != xpOrderR.getCode()) {
throw new RuntimeException("订单不存在");
}
XpOrder xpOrder = xpOrderR.getData();
+ XpVehicle xpVehicle = xpVehicleClient.queryById(xpOrder.getVehicleId()).getData();
+ //先响应消息
+ responseMessage(sequence, xpVehicle.getVehicleVin());
//驶往上车点的行程
if (orderPhase.equals(OrderPhase.ROUTE_TO_PICKUP)) {
- XpVehicle xpVehicle = xpVehicleClient.queryById(xpOrder.getVehicleId()).getData();
- //先响应消息
- responseMessage(sequence, xpVehicle.getVehicleVin());
//查询车辆位置
VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(xpVehicle.getVehicleVin())), VehiclePosition.class);
if (Objects.isNull(vehiclePosition)) {
@@ -541,6 +590,8 @@
}
RouteVo routeVo = routeVoR.getData();
routeID = routeVo.getRouteID();
+ //缓存数据,用于后续推给乘客导航线路
+ redisService.setCacheObject("ORDER_NAVIGATION_START_DATA:" + xpOrder.getAppUserId(), com.alibaba.fastjson.JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS);
}
//驶往下车点的行程
if (orderPhase.equals(OrderPhase.ROUTE_TO_DESTINATION)) {
@@ -564,7 +615,7 @@
RouteVo routeVo = routeVoR.getData();
routeID = routeVo.getRouteID();
//缓存导航数据,用于后面的逻辑中给乘客端推送导航数据
- redisService.setCacheObject("ORDER_NAVIGATION_DATA:" + xpOrder.getAppUserId(), com.alibaba.fastjson.JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS);
+ redisService.setCacheObject("ORDER_NAVIGATION_END_DATA:" + xpOrder.getAppUserId(), com.alibaba.fastjson.JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS);
}else{
RouteVo routeVo = JSON.parseObject(cacheObject.toString(), RouteVo.class);
routeID = routeVo.getRouteID();
@@ -580,7 +631,7 @@
throw new RuntimeException("根据导航ID获取车端需要的导航数据失败");
}
//构建导航下发请求对象
- cloudPushNavigationInfo(requestId, routeID, stringR.getData(), orderId, xpVehicle.getVehicleVin(), xpVehicle.getXpuId());
+ cloudPushNavigationInfo(requestId, routeID, stringR.getData(), orderType, orderId, xpVehicle.getVehicleVin(), xpVehicle.getXpuId());
}
}
@@ -832,7 +883,7 @@
* @param vin 车辆VIN
* @param xpuId XPU设备id
*/
- public void cloudPushNavigationInfo(String requestId, String routeId, String routeDataContent, String orderId, String vin, String xpuId) {
+ public void cloudPushNavigationInfo(String requestId, String routeId, String routeDataContent, String orderType, String orderId, String vin, String xpuId) {
//组装报文,将routeDateContent信息推送到XPU
RestoreNavigationData navigationData = new RestoreNavigationData();
navigationData.setRoute_id(routeId);
@@ -841,7 +892,12 @@
navigationData.setTimestamp(System.currentTimeMillis());
long sequence = snowflake.nextId();
// 处理数据
- redisTemplate.opsForValue().set(sequence,"pushOrder_"+orderId+"_"+vin,30, TimeUnit.MINUTES);
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("event", SystemEventType.PUSH_NAVIGATION);
+ jsonObject.put("orderType", orderType);
+ jsonObject.put("orderId", orderId);
+ jsonObject.put("vin", vin);
+ redisTemplate.opsForValue().set(sequence, jsonObject.toJSONString(),30, TimeUnit.MINUTES);
xpuUtil.cloudPushNavigation(navigationData, xpuId, sequence);
}
--
Gitblit v1.7.1