From 320e7cd68a368a666986019e29c4af0fc9ddaa48 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期日, 12 四月 2026 20:13:21 +0800
Subject: [PATCH] 处理冲突
---
xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/service/KafkaConsumerService.java | 102 +++++++++++++++++++++++++++++++++-----------------
1 files changed, 67 insertions(+), 35 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 33b5f45..5f7f1c3 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
@@ -73,7 +73,7 @@
@Slf4j
@Service
public class KafkaConsumerService {
- private static final String CANCEL_ORDER_CONTEXT_PREFIX = "CANCEL_ORDER_CONTEXT:";
+ private static final String REASSIGN_CANCEL_CONTEXT_PREFIX = "REASSIGN_CANCEL_CONTEXT:";
@Resource
@@ -375,16 +375,9 @@
//保存车辆实时信息到mongodb
if(0 != longitude && 0 != latitude){
//缓存车辆历史定位,用户辅助获取导航抓路用
- List<Object> cacheList = redisService.getCacheList("VEHICLE_HISTORY_POINT_LIST:" + xpVehicle.getId());
- List<HistoryPointDto> history = new ArrayList<>();
- if(cacheList!=null && !cacheList.isEmpty()){
- for (Object cache : cacheList) {
- HistoryPointDto historyPointDto = JSON.parseObject(cache.toString(), HistoryPointDto.class);
- history.add(historyPointDto);
- }
- }
+ List<HistoryPointDto> history = redisService.getCacheList("VEHICLE_HISTORY_POINT_LIST:" + xpVehicle.getId());
if(history.size() >= 10){
- history.subList(history.size() - 10, history.size());
+ history = new ArrayList<>(history.subList(history.size() - 9, history.size()));
}
HistoryPointDto historyPointDto = new HistoryPointDto();
historyPointDto.setLocation(longitude + "," + latitude);
@@ -392,6 +385,7 @@
historyPointDto.setAccuracy(naviPose.getPosAcc());
historyPointDto.setDirection(course);
historyPointDto.setSpeed(dynamicStatus.getSpeed());
+ historyPointDto.setHeight(naviPose.getAlt());
history.add(historyPointDto);
redisService.setCacheList("VEHICLE_HISTORY_POINT_LIST:" + xpVehicle.getId(), history);
@@ -782,11 +776,12 @@
dto.setLongitude(longitude);
dto.setLatitude(latitude);
if (null != routeVo) {
- dto.setDuration(routeVo.getDuration().doubleValue());
- dto.setDistance(routeVo.getDistance().doubleValue());
- dto.setDirection(routeVo.getDirection().intValue());
+ dto.setDuration(null == routeVo.getDuration() ? 0 : routeVo.getDuration().doubleValue());
+ dto.setDistance(null == routeVo.getDistance() ? 0 : routeVo.getDistance().doubleValue());
+ dto.setDirection(null == routeVo.getDirection() ? 0 : routeVo.getDirection().intValue());
}
xpPushMessageClient.pushOrderRoute(dto);
+ log.info("完成小程序下发导航偏离后的新轨迹:" + orderId);
}
XpVehicle xpVehicle = xpVehicleClient.queryById(vehicleId).getData();
@@ -794,8 +789,10 @@
if (200 != stringR.getCode()) {
throw new RuntimeException("根据导航ID获取车端需要的导航数据失败");
}
+ log.info("开始下发XPU导航偏离后新的导航数据:" + orderId);
//构建响应导航数据给车端
cloudPushNavigationInfo(requestId, routeID, stringR.getData(), orderType, orderId, xpVehicle.getVehicleVin(), xpVehicle.getXpuId(), taskId);
+ log.info("完成下发XPU导航偏离后新的导航数据:" + orderId);
}
}
@@ -1239,12 +1236,18 @@
//已取消
if(!orderId.contains("XU")){
String taskId = orderStatusInfo.getTaskId();
- JSONObject cancelContext = getCancelOrderContext(taskId);
- if (shouldSkipCancelForReassign(cancelContext)) {
+ JSONObject reassignCancelContext = resolveReassignCancelContext(orderId, orderStatusInfo);
+ if (Objects.nonNull(reassignCancelContext)) {
log.info("改派旧车取消回调,跳过订单取消处理,orderId: {}, taskId: {}, cancelScene: {}, context: {}",
- orderId, taskId, cancelContext.getString("cancelScene"), cancelContext);
+ orderId, taskId, reassignCancelContext.getString("cancelScene"), reassignCancelContext);
//响应消息
- responseMessage(cmd, sequence, cancelContext.getString("vin"));
+ String responseVin = resolveReassignCancelResponseVin(reassignCancelContext);
+ if (StringUtils.isNotEmpty(responseVin)) {
+ responseMessage(cmd, sequence, responseVin);
+ } else {
+ log.warn("改派旧车取消回调未找到响应VIN,orderId: {}, taskId: {}, context: {}",
+ orderId, taskId, reassignCancelContext);
+ }
return;
}
if(orderId.contains("TEST")){
@@ -1454,33 +1457,62 @@
}
}
- /**
- * 根据taskId获取订单取消的上下文信息
- * @param taskId
- * @return
- */
- private JSONObject getCancelOrderContext(String taskId) {
- if (StringUtils.isEmpty(taskId)) {
+ private JSONObject getReassignCancelContext(String orderId) {
+ if (StringUtils.isEmpty(orderId)) {
return null;
}
- Object cacheObject = redisService.getCacheObject(CANCEL_ORDER_CONTEXT_PREFIX + taskId);
+ Object cacheObject = redisService.getCacheObject(REASSIGN_CANCEL_CONTEXT_PREFIX + orderId);
if (cacheObject == null) {
return null;
}
return JSON.parseObject(cacheObject.toString());
}
- /**
- * 判断是否是改派旧车取消回调,是则跳过订单取消处理
- * @param cancelContext
- * @return
- */
- private boolean shouldSkipCancelForReassign(JSONObject cancelContext) {
- if (cancelContext == null) {
- return false;
+ private JSONObject resolveReassignCancelContext(String orderId, OrderStatusInfo orderStatusInfo) {
+ if (OrderStateChangeSource.ORDER_STATE_CHANGE_SOURCE_VEHICLE != orderStatusInfo.getChangeSource()) {
+ return null;
}
- return CancelOrderSceneEnum.REASSIGN_OLD_VEHICLE == CancelOrderSceneEnum.fromCode(
- cancelContext.getString("cancelScene"));
+ JSONObject cancelContext = getReassignCancelContext(orderId);
+ if (cancelContext == null) {
+ return null;
+ }
+ if (CancelOrderSceneEnum.REASSIGN_OLD_VEHICLE != CancelOrderSceneEnum.fromCode(
+ cancelContext.getString("cancelScene"))) {
+ return null;
+ }
+ R<XpOrder> orderResult = xpOrderClient.queryOrderById(Long.parseLong(orderId));
+ XpOrder xpOrder = orderResult == null ? null : orderResult.getData();
+ if (xpOrder == null) {
+ log.warn("改派取消回调识别失败,订单不存在,orderId: {}, context: {}", orderId, cancelContext);
+ return null;
+ }
+ Long newVehicleId = cancelContext.getLong("newVehicleId");
+ Integer currentStatus = xpOrder.getStatus();
+ boolean vehicleMatched = Objects.nonNull(newVehicleId) && Objects.equals(newVehicleId, xpOrder.getVehicleId());
+ boolean statusMatched = Objects.nonNull(currentStatus) && currentStatus > 0 && currentStatus < 8;
+ if (vehicleMatched && statusMatched) {
+ return cancelContext;
+ }
+ log.info("改派取消回调未命中专用上下文,orderId: {}, currentVehicleId: {}, newVehicleId: {}, currentStatus: {}",
+ orderId, xpOrder.getVehicleId(), newVehicleId, currentStatus);
+ return null;
+ }
+
+ private String resolveReassignCancelResponseVin(JSONObject cancelContext) {
+ if (cancelContext == null) {
+ return null;
+ }
+ String oldVehicleVin = cancelContext.getString("oldVehicleVin");
+ if (StringUtils.isNotEmpty(oldVehicleVin)) {
+ return oldVehicleVin;
+ }
+ Long oldVehicleId = cancelContext.getLong("oldVehicleId");
+ if (Objects.isNull(oldVehicleId)) {
+ return null;
+ }
+ R<XpVehicle> vehicleResult = xpVehicleClient.queryById(oldVehicleId);
+ XpVehicle xpVehicle = vehicleResult == null ? null : vehicleResult.getData();
+ return xpVehicle == null ? null : xpVehicle.getVehicleVin();
}
/**
--
Gitblit v1.7.1