From 7271e84699c2abd048d5e7f0ae9c15eaf5fcb73e Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期五, 27 三月 2026 12:26:10 +0800
Subject: [PATCH] 修改bug
---
xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/service/KafkaConsumerService.java | 106 +++++++++++++++++++++++++++++------------------------
1 files changed, 58 insertions(+), 48 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 c4f8ba8..73ad12f 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
@@ -602,7 +602,6 @@
XpVehicle xpVehicle = xpVehicleClient.queryById(xpOrder.getVehicleId()).getData();
//驶往上车点的行程
if (3 == xpOrder.getStatus()) {
- redisService.deleteObject("ORDER_NAVIGATION_START_DATA:" + xpOrder.getAppUserId());
//查询司机当前位置到起点的线路
origin.setLongitude(longitude);
origin.setLatitude(latitude);
@@ -712,30 +711,36 @@
XpVehicle xpVehicle = xpVehicleClient.queryById(xpOrder.getVehicleId()).getData();
//驶往上车点的行程
if (orderPhase.equals(OrderPhase.ROUTE_TO_PICKUP)) {
- //查询车辆位置
- VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(xpVehicle.getVehicleVin())), VehiclePosition.class);
- if (Objects.isNull(vehiclePosition)) {
- throw new RuntimeException("车辆位置信息不存在");
+ //直接取缓存中的导航数据推送给车端和乘客
+ Object cacheObject = redisService.getCacheObject("TEST_ORDER_NAVIGATION_START_DATA:" + xpOrder.getVehicleId());
+ if(null == cacheObject){
+ //没有缓存数据,重新规划线路
+ //查询车辆位置
+ VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(xpVehicle.getVehicleVin())), VehiclePosition.class);
+ if (Objects.isNull(vehiclePosition)) {
+ throw new RuntimeException("车辆位置信息不存在");
+ }
+ origin.setLongitude(vehiclePosition.getPoint().getX());
+ origin.setLatitude(vehiclePosition.getPoint().getY());
+ destination.setLongitude(xpOrder.getStartLon());
+ destination.setLatitude(xpOrder.getStartLat());
+ OrderRouteAndFareDto dto = new OrderRouteAndFareDto();
+ dto.setOrderId(Long.parseLong(orderId));
+ dto.setOrigin(origin);
+ dto.setDestination(destination);
+ dto.setRouteType(2);
+ R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto);
+ if (200 != routeVoR.getCode()) {
+ throw new RuntimeException("获取订单线路和运费失败");
+ }
+ RouteVo routeVo = routeVoR.getData();
+ routeID = routeVo.getRouteID();
+ //缓存导航数据,用于后面的逻辑中给乘客端推送导航数据
+ redisService.setCacheObject("TEST_ORDER_NAVIGATION_START_DATA:" + xpOrder.getVehicleId(), JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS);
+ }else{
+ RouteVo routeVo = JSON.parseObject(cacheObject.toString(), RouteVo.class);
+ routeID = routeVo.getRouteID();
}
- //查询司机当前位置到起点的线路
- origin.setLongitude(vehiclePosition.getPoint().getX());
- origin.setLatitude(vehiclePosition.getPoint().getY());
- destination.setLongitude(xpOrder.getStartLon());
- destination.setLatitude(xpOrder.getStartLat());
-
- OrderRouteAndFareDto dto = new OrderRouteAndFareDto();
- dto.setOrderId(Long.parseLong(orderId));
- dto.setOrigin(origin);
- dto.setDestination(destination);
- dto.setRouteType(1);
- R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto);
- if (200 != routeVoR.getCode()) {
- throw new RuntimeException("获取订单线路和运费失败");
- }
- RouteVo routeVo = routeVoR.getData();
- routeID = routeVo.getRouteID();
- //缓存数据,用于后续推给乘客导航线路
- redisService.setCacheObject("TEST_ORDER_NAVIGATION_START_DATA:" + xpOrder.getVehicleId(), JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS);
}
//驶往下车点的行程
if (orderPhase.equals(OrderPhase.ROUTE_TO_DESTINATION)) {
@@ -778,31 +783,36 @@
XpVehicle xpVehicle = xpVehicleClient.queryById(xpOrder.getVehicleId()).getData();
//驶往上车点的行程
if (orderPhase.equals(OrderPhase.ROUTE_TO_PICKUP)) {
- //查询车辆位置
- VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(xpVehicle.getVehicleVin())), VehiclePosition.class);
- if (Objects.isNull(vehiclePosition)) {
- throw new RuntimeException("车辆位置信息不存在");
- }
- redisService.deleteObject("ORDER_NAVIGATION_START_DATA:" + xpOrder.getAppUserId());
- //查询司机当前位置到起点的线路
- origin.setLongitude(vehiclePosition.getPoint().getX());
- origin.setLatitude(vehiclePosition.getPoint().getY());
- destination.setLongitude(xpOrder.getStartLon());
- destination.setLatitude(xpOrder.getStartLat());
+ Object cacheObject = redisService.getCacheObject("ORDER_NAVIGATION_START_DATA:" + xpOrder.getAppUserId());
+ if(null == cacheObject){
+ //查询车辆位置
+ VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(xpVehicle.getVehicleVin())), VehiclePosition.class);
+ if (Objects.isNull(vehiclePosition)) {
+ throw new RuntimeException("车辆位置信息不存在");
+ }
+ //查询司机当前位置到起点的线路
+ origin.setLongitude(vehiclePosition.getPoint().getX());
+ origin.setLatitude(vehiclePosition.getPoint().getY());
+ destination.setLongitude(xpOrder.getStartLon());
+ destination.setLatitude(xpOrder.getStartLat());
- OrderRouteAndFareDto dto = new OrderRouteAndFareDto();
- dto.setOrderId(Long.parseLong(orderId));
- dto.setOrigin(origin);
- dto.setDestination(destination);
- dto.setRouteType(1);
- 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(), JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS);
+ OrderRouteAndFareDto dto = new OrderRouteAndFareDto();
+ dto.setOrderId(Long.parseLong(orderId));
+ dto.setOrigin(origin);
+ dto.setDestination(destination);
+ dto.setRouteType(1);
+ 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(), JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS);
+ }else{
+ RouteVo routeVo = JSON.parseObject(cacheObject.toString(), RouteVo.class);
+ routeID = routeVo.getRouteID();
+ };
}
//驶往下车点的行程
if (orderPhase.equals(OrderPhase.ROUTE_TO_DESTINATION)) {
--
Gitblit v1.7.1