“mitao”
2026-03-10 eb290fd6e70b6523ea0889936dba4d9f2d5c4b53
xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/utils/TaskOrderUtil.java
@@ -253,6 +253,9 @@
            return true;
        }
        XpOrder xpOrder = xpOrderR.getData();
        if (xpOrder.getStatus() == 0) {
            redisService.removeByPattern(quoteName, xpOrder.getOrderNumber());
        }
        // 找出围栏id
        Long xpElectronicFenceAreaId = xpOrder.getXpElectronicFenceAreaId();
@@ -262,7 +265,6 @@
        for (int i = 0; i < count; i++) {
            //等到sleepTime秒钟
            Thread.sleep(sleepTime * 1000);
//            log.info("进入找车环节 单号 {} 第{}轮", orderNo, count++);
            // 根据距离找车
            // 车多则根据配置找具体车数量 根据距离最近
            // 更改 暂不限制数量
@@ -272,7 +274,7 @@
            if (positionList.isEmpty()) {
                continue;
            }
            List<String> vinList = positionList.stream().map(VehiclePosition::getVin).collect(Collectors.toList());
            Set<String> vinList = positionList.stream().map(VehiclePosition::getVin).collect(Collectors.toSet());
            // 获取车辆的信息 筛选出可用车辆
            R<List<String>> vehiclePositionVos = xpVehicleClient.queryVehiclePositionByVin(new VehiclePositionByVinDto(xpElectronicFence.getId(), vinList, xpTradingStrategy.getSimultaneouslyOrderCount()));
@@ -302,6 +304,7 @@
                    // 时间价值
                    Integer tendencyTime = xpTradingStrategy.getTendencyTime();
                    try {
                    // 电量价值
                    Integer tendencyElectricity = xpTradingStrategy.getTendencyElectricity();
@@ -335,7 +338,9 @@
                                lonLatDto1.setLongitude(Double.valueOf(split[0]));
                                lonLatDto1.setLatitude(Double.valueOf(split[1]));
                                routeAndFareDto.setDestination(lonLatDto1);
                                    if(planRule!=null&& !"null".equals(planRule)){
                                routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule));
                                    }
                                R<RouteVo> distanceAndDuration = xpMapClient.getDistanceAndDuration(routeAndFareDto);
                                if (distanceAndDuration.getCode() == 200) {
                                    // 送驾- 接驾
@@ -356,7 +361,9 @@
                                lonLatDto1.setLongitude(Double.valueOf(split[0]));
                                lonLatDto1.setLatitude(Double.valueOf(split[1]));
                                routeAndFareDto.setDestination(lonLatDto1);
                                    if(planRule!=null&& !"null".equals(planRule)){
                                routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule));
                                    }
                                R<RouteVo> distanceAndDuration = xpMapClient.getDistanceAndDuration(routeAndFareDto);
                                if (distanceAndDuration.getCode() == 200) {
                                    // 送驾- 接驾
@@ -377,8 +384,9 @@
                                LonLatDto lonLatDto1 = new LonLatDto();
                                lonLatDto1.setLongitude(Double.parseDouble(split[0]));
                                lonLatDto1.setLatitude(Double.parseDouble(split[1]));
                                    if(planRule!=null&& !"null".equals(planRule)){
                                routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule));
                                    }
                                routeAndFareDto.setDestination(lonLatDto1);
                                //  调用地图 获取时间
                                R<RouteVo> r = xpMapClient.getDistanceAndDuration(routeAndFareDto);
@@ -400,8 +408,9 @@
                                LonLatDto lonLatDto1 = new LonLatDto();
                                lonLatDto1.setLongitude(Double.parseDouble(split[0]));
                                lonLatDto1.setLatitude(Double.parseDouble(split[1]));
                                    if(planRule!=null&& !"null".equals(planRule)){
                                routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule));
                                    }
                                routeAndFareDto.setDestination(lonLatDto1);
                                //  调用地图 获取时间
                                R<RouteVo> r = xpMapClient.getDistanceAndDuration(routeAndFareDto);
@@ -430,7 +439,7 @@
                        // 算出总分 再来排序计算
                        for (VehiclePositionVo vehiclePositionVo : availableVehiclesNearby) {
                            vehiclePositionVo.setOrderValueTotal(vehiclePositionVo.getCurrentElectricityScore() + vehiclePositionVo.getDistanceScore() + vehiclePositionVo.getTimeScore() + vehiclePositionVo.getDistanceDifference() + vehiclePositionVo.getTimeDifference());
                                vehiclePositionVo.setOrderValueTotal(vehiclePositionVo.getCurrentElectricityScore() + vehiclePositionVo.getDistanceScore() + vehiclePositionVo.getTimeScore() + vehiclePositionVo.getDistanceDifference() + vehiclePositionVo.getTimeDifference()+vehiclePositionVo.getSecond()+vehiclePositionVo.getDistance().intValue());
                        }
                        availableVehiclesNearby = availableVehiclesNearby.stream().sorted(Comparator.comparing(VehiclePositionVo::getOrderValueTotal).reversed()).collect(Collectors.toList());
@@ -460,7 +469,9 @@
                            lonLatDto1.setLongitude(Double.parseDouble(split[0]));
                            lonLatDto1.setLatitude(Double.parseDouble(split[1]));
                                if(planRule!=null&& !"null".equals(planRule)){
                            routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule));
                                }
                            routeAndFareDto.setDestination(lonLatDto1);
                            //  调用地图 获取时间
                            R<RouteVo> r = xpMapClient.getDistanceAndDuration(routeAndFareDto);
@@ -495,7 +506,9 @@
                            lonLatDto1.setLongitude(Double.parseDouble(split[0]));
                            lonLatDto1.setLatitude(Double.parseDouble(split[1]));
                                if(planRule!=null&& !"null".equals(planRule)){
                            routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule));
                                }
                            routeAndFareDto.setDestination(lonLatDto1);
                            //  调用地图 获取时间
                            R<RouteVo> r = xpMapClient.getDistanceAndDuration(routeAndFareDto);
@@ -558,8 +571,9 @@
                                    LonLatDto lonLatDto1 = new LonLatDto();
                                    lonLatDto1.setLongitude(Double.parseDouble(split[0]));
                                    lonLatDto1.setLatitude(Double.parseDouble(split[1]));
                                        if(planRule!=null&& !"null".equals(planRule)){
                                    routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule));
                                        }
                                    routeAndFareDto.setDestination(lonLatDto1);
                                    //  调用地图 获取时间
                                    R<RouteVo> r = xpMapClient.getDistanceAndDuration(routeAndFareDto);
@@ -593,7 +607,9 @@
                                    lonLatDto1.setLongitude(Double.parseDouble(split[0]));
                                    lonLatDto1.setLatitude(Double.parseDouble(split[1]));
                                        if(planRule!=null&& !"null".equals(planRule)){
                                    routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule));
                                        }
                                    routeAndFareDto.setDestination(lonLatDto1);
                                    //  调用地图 获取时间
                                    R<RouteVo> r = xpMapClient.getDistanceAndDuration(routeAndFareDto);
@@ -645,7 +661,9 @@
                                        lonLatDto1.setLongitude(Double.valueOf(split[0]));
                                        lonLatDto1.setLatitude(Double.valueOf(split[1]));
                                        routeAndFareDto.setDestination(lonLatDto1);
                                            if(planRule!=null&& !"null".equals(planRule)){
                                        routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule));
                                            }
                                        R<RouteVo> distanceAndDuration = xpMapClient.getDistanceAndDuration(routeAndFareDto);
                                        if (distanceAndDuration.getCode() == 200) {
                                            // 送驾- 接驾
@@ -666,7 +684,9 @@
                                        lonLatDto1.setLongitude(Double.valueOf(split[0]));
                                        lonLatDto1.setLatitude(Double.valueOf(split[1]));
                                        routeAndFareDto.setDestination(lonLatDto1);
                                            if(planRule!=null&& !"null".equals(planRule)){
                                        routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule));
                                            }
                                        R<RouteVo> distanceAndDuration = xpMapClient.getDistanceAndDuration(routeAndFareDto);
                                        if (distanceAndDuration.getCode() == 200) {
                                            // 送驾- 接驾
@@ -687,8 +707,9 @@
                                        LonLatDto lonLatDto1 = new LonLatDto();
                                        lonLatDto1.setLongitude(Double.parseDouble(split[0]));
                                        lonLatDto1.setLatitude(Double.parseDouble(split[1]));
                                            if(planRule!=null&& !"null".equals(planRule)){
                                        routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule));
                                            }
                                        routeAndFareDto.setDestination(lonLatDto1);
                                        //  调用地图 获取时间
                                        R<RouteVo> r = xpMapClient.getDistanceAndDuration(routeAndFareDto);
@@ -710,8 +731,9 @@
                                        LonLatDto lonLatDto1 = new LonLatDto();
                                        lonLatDto1.setLongitude(Double.parseDouble(split[0]));
                                        lonLatDto1.setLatitude(Double.parseDouble(split[1]));
                                            if(planRule!=null&& !"null".equals(planRule)){
                                        routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule));
                                            }
                                        routeAndFareDto.setDestination(lonLatDto1);
                                        //  调用地图 获取时间
                                        R<RouteVo> r = xpMapClient.getDistanceAndDuration(routeAndFareDto);
@@ -736,11 +758,11 @@
                                        }
                                    }
                                }
                                }
                                // 算出总分 再来排序计算
                                for (VehiclePositionVo vehiclePositionVo : availableVehiclesNearby) {
                                    vehiclePositionVo.setOrderValueTotal(vehiclePositionVo.getCurrentElectricityScore() + vehiclePositionVo.getDistanceScore() + vehiclePositionVo.getTimeScore() + vehiclePositionVo.getDistanceDifference() + vehiclePositionVo.getTimeDifference());
                                    vehiclePositionVo.setOrderValueTotal(vehiclePositionVo.getCurrentElectricityScore() + vehiclePositionVo.getDistanceScore() + vehiclePositionVo.getTimeScore() + vehiclePositionVo.getDistanceDifference() + vehiclePositionVo.getTimeDifference()+vehiclePositionVo.getSecond()+vehiclePositionVo.getDistance().intValue());
                                }
                                availableVehiclesNearby = availableVehiclesNearby.stream().sorted(Comparator.comparing(VehiclePositionVo::getOrderValueTotal).reversed()).collect(Collectors.toList());
@@ -759,6 +781,8 @@
                        }
                    } catch (Exception e) {
                        log.error("异常", e);
                    }
                    // 判断总分来计算
@@ -783,7 +807,7 @@
                        XpVehicle vehiclePosition = vehiclePositionR.getData();
                        log.info("符合条件的车辆 {} ,直接推单XPU。单号 {}", vehiclePosition.getPlateNumber(), orderNo);
                        log.info("当前车辆状态 {} 单号 {}", vehiclePosition.getStatus(), orderNo);
                        if (vehiclePosition.getStatus() != 1 || vehiclePosition.getState() != 0 || vehiclePosition.getVehicleType()==1) {
                        if (vehiclePosition.getOperatingStatus() != 1 || vehiclePosition.getState() != 0 || vehiclePosition.getVehicleType() == 1) {
                            continue;
                        }
                        //  关闭巡游单子
@@ -807,7 +831,7 @@
                        orderMissionClient.pushOrder(pushOrderDto);
                        log.info("开始推送 {} 订单到XPU。单号 {}", xpOrder.getOrderNumber(), orderNo);
                        redisService.popFirstElement(quoteName);
                        redisService.removeByPattern(quoteName,xpOrder.getOrderNumber());
                        log.info("将订单 {} 从队列 {} 弹出去", orderNo, quoteName);
                        return true;
                    } catch (Exception e) {
@@ -818,7 +842,7 @@
                } else {
                    // 直接派单  定义一个锁来锁定车辆
                    VehiclePosition vehiclePosition = positionList.get(0);
                    VehiclePositionVo vehiclePosition = availableVehiclesNearby.get(0);
                    String vehicleVin = vehiclePosition.getVin();
                    RLock lock = redissonClient.getLock("FIND_CAR_" + vehiclePosition.getVin());
@@ -856,17 +880,6 @@
                        log.info("开始推送 {} 订单到XPU", xpOrder.getOrderNumber());
                        redisService.popFirstElement(quoteName);
                        log.info("将订单 {} 从队列 {} 弹出去", orderNo, quoteName);
                        //判断还原车辆状态
                        Object cacheObject = redisService.getCacheObject("CREATE_ORDER:" + xpOrder.getId().toString());
                        if(null != cacheObject){
                            JSONObject jsonObject = JSON.parseObject(cacheObject.toString());
                            String vin = jsonObject.getString("vin");
                            XpVehicle vehicle = xpVehicleClient.findByVehicleVin(vin).getData();
                            if(null != vehicle && 0 != vehicle.getState()){
                                vehicle.setState(0);
                                xpVehicleClient.updateVehicleById(vehicle);
                            }
                        }
                        return true;
                    } catch (Exception e) {
                        e.printStackTrace();