puzhibing
2026-04-11 b6f3de8451867d85242b2bd706fcfa4a65df4ff7
xp-robotaxi-order-boot/src/main/java/com/xiaopeng/order/service/impl/XpOrderServiceImpl.java
@@ -59,6 +59,7 @@
import com.xiaopeng.common.core.constant.Constants;
import com.xiaopeng.common.core.constant.HttpStatus;
import com.xiaopeng.common.core.domain.R;
import com.xiaopeng.common.core.enums.CancelOrderSceneEnum;
import com.xiaopeng.common.core.enums.OrderStatusEnum;
import com.xiaopeng.common.core.enums.PushMessageTypeEnum;
import com.xiaopeng.common.core.exception.ServiceException;
@@ -135,6 +136,9 @@
@Service
@RequiredArgsConstructor(onConstructor_ = @Lazy)
public class XpOrderServiceImpl extends ServiceImpl<XpOrderMapper, XpOrder> implements IXpOrderService {
    private static final String REASSIGN_CANCEL_CONTEXT_PREFIX = "REASSIGN_CANCEL_CONTEXT:";
    private static final long REASSIGN_CANCEL_CONTEXT_TTL_MINUTES = 5L;
    private final UserResourcesClient userResourcesClient;
    private final XpPointClient xpPointClient;
@@ -590,6 +594,8 @@
        vo.setEndAddress(order.getEndAddress());
        vo.setOrderMoney(order.getOrderMoney());
        vo.setStatus(order.getStatus());
        vo.setStartPointName(order.getStartPointName());
        vo.setEndPointName(order.getEndPointName());
        // 用户信息
        if (Objects.nonNull(order.getAppUserId()) && userInfoMap != null && userInfoMap.containsKey(order.getAppUserId().toString())) {
@@ -962,11 +968,16 @@
                    // 6.1.1 取消原订单指令
                    PushOrderDto cancelDto = new PushOrderDto();
                    cancelDto.setTaskId(IdUtil.getSnowflakeNextIdStr());
                    cancelDto.setOrderId(order.getId().toString());
                    cancelDto.setVin(oldVehicle.getVehicleVin());
                    cancelDto.setOperation_type(OrderOperationType.CLOUD_CANCEL_ORDER);
                    cancelDto.setCancelScene(CancelOrderSceneEnum.REASSIGN_OLD_VEHICLE.getCode());
                    orderMissionClient.cancelOrder(cancelDto);
                    log.info("已取消原车辆订单指令,订单ID: {}, VIN: {}", orderId, oldVehicle.getVehicleVin());
                    cacheReassignCancelContext(orderId, oldVehicleId, newVehicleId,
                            oldVehicle.getVehicleVin(), currentStatus);
                    log.info("已取消原车辆订单指令,订单ID: {}, VIN: {}, taskId: {}, cancelScene: {}",
                            orderId, oldVehicle.getVehicleVin(), cancelDto.getTaskId(), cancelDto.getCancelScene());
                    // 6.1.2 解绑乘客与原车辆关系
                    if (Objects.nonNull(order.getAppUserId())) {
@@ -1109,6 +1120,22 @@
    }
    private void cacheReassignCancelContext(Long orderId, Long oldVehicleId, Long newVehicleId,
                                            String oldVehicleVin, Integer preReassignStatus) {
        JSONObject context = new JSONObject();
        context.put("orderId", orderId);
        context.put("oldVehicleId", oldVehicleId);
        context.put("newVehicleId", newVehicleId);
        context.put("oldVehicleVin", oldVehicleVin);
        context.put("cancelScene", CancelOrderSceneEnum.REASSIGN_OLD_VEHICLE.getCode());
        context.put("operationTime", System.currentTimeMillis());
        context.put("preReassignStatus", preReassignStatus);
        redisService.setCacheObject(REASSIGN_CANCEL_CONTEXT_PREFIX + orderId, context.toJSONString(),
                REASSIGN_CANCEL_CONTEXT_TTL_MINUTES, TimeUnit.MINUTES);
        log.info("记录改派取消上下文成功,orderId: {}, oldVehicleId: {}, newVehicleId: {}, preReassignStatus: {}",
                orderId, oldVehicleId, newVehicleId, preReassignStatus);
    }
    /**
     * 为原车辆创建返程巡游订单
     * <p>