From 5205d55b6088b579a2ecf08d8aa98e260b9b975c Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期五, 13 二月 2026 18:55:57 +0800
Subject: [PATCH] feat(pricing): 优化地理查询实体服务并更新订单处理流程

---
 xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/service/impl/XpPricingServiceImpl.java |   37 +++++++++++++++++++++++++++++++++----
 1 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/service/impl/XpPricingServiceImpl.java b/xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/service/impl/XpPricingServiceImpl.java
index 52c4bab..0ba7ff6 100644
--- a/xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/service/impl/XpPricingServiceImpl.java
+++ b/xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/service/impl/XpPricingServiceImpl.java
@@ -20,6 +20,7 @@
 import com.xiaopeng.api.vo.operation.FareVo;
 import com.xiaopeng.api.vo.operation.RouteAndFareVo;
 import com.xiaopeng.api.vo.operation.RouteVo;
+import com.xiaopeng.api.vo.order.XpPricingCardVo;
 import com.xiaopeng.common.core.constant.CacheConstants;
 import com.xiaopeng.common.core.domain.R;
 import com.xiaopeng.common.core.exception.ServiceException;
@@ -35,12 +36,13 @@
 import com.xiaopeng.operation.utils.XpPricingUtil;
 import com.xiaopeng.operation.utils.holiday.HolidayUtil;
 import com.xiaopeng.operation.utils.map.FastDistanceCalculator;
-import com.xiaopeng.operation.vo.XpPricingCardVo;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.PreDestroy;
 import javax.annotation.Resource;
+import java.time.Duration;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.concurrent.*;
@@ -89,8 +91,6 @@
     @Resource
     private XpElectronicFenceAreaMapper xpElectronicFenceAreaMapper;
 
-    @Resource
-    private XpVehicleClient xpVehicleClient;
 
     @Resource
     private XpPointMapper xpPointMapper;
@@ -206,6 +206,8 @@
 //        );
         XpPricingCardVo xpPricingCardVo = new XpPricingCardVo();
 
+
+
         // 3. 并行执行远程服务调用 判断是否同一经营区域
         CompletableFuture<R<Boolean>> diagnosisAreaFuture = CompletableFuture.supplyAsync(
                 () -> xpMapClient.diagnosisArea(routeAndFareDto),
@@ -274,6 +276,9 @@
         RouteAndFareVo routeAndFareVo = new RouteAndFareVo();
 //        routeAndFareVo.setRoute(routeVo);
 
+
+        routeAndFareVo.setXpPricingCard(xpPricingCardVo);
+
         FareVo fareVo = new FareVo();
 //        fareVo.setEstimatedDistanceKm(routeVo.getDistance().doubleValue() / 1000);
 //        fareVo.setEstimatedDurationMin(routeVo.getDuration() / 60);
@@ -333,7 +338,7 @@
             return 1;
         } else {
             // 已完成接单的数据
-            List<XpGeoQueryEntity> validEntities = entities.stream().filter(e -> e.getStatus() > 1).collect(Collectors.toList());
+            List<XpGeoQueryEntity> validEntities = entities.stream().filter(e -> e.getStatus() == 1).collect(Collectors.toList());
 
             // 计算平均等待时间
             OptionalDouble averageOptional = validEntities.stream().mapToDouble(XpGeoQueryEntity::getSeconds).average();
@@ -347,6 +352,8 @@
                     double waitMinutes = (average * count) / 60;
                     if (waitMinutes > 3) {
                         throw new ServiceException("当前区域正在等待中,请耐心等待", I18nKeyConstant.WAITING_TIME);
+                    }else if(waitMinutes==0){
+                        return 1;
                     }
                     return (int) waitMinutes;
                 }
@@ -517,6 +524,16 @@
                 xpOrder.setQueueName(s);
                 xpOrderClient.updateOrder(xpOrder);
 
+                // 存储mongodb 数据
+                XpGeoQueryEntity xpGeoQueryEntity = new XpGeoQueryEntity();
+                xpGeoQueryEntity.setOrderId(orderId.toString());
+                xpGeoQueryEntity.setLocation(new GeoJsonPoint(xpPoint.getPointLon(),xpPoint.getPointLat()));
+                // 计算2个时间的秒数
+                xpGeoQueryEntity.setTime(currentTimeSlot);
+                xpGeoQueryEntity.setStatus(0);
+                xpGeoQueryEntity.setTimestamp(System.currentTimeMillis());
+                geoQueryEntityService.save(xpGeoQueryEntity);
+
                 return orderId;
             }
         }
@@ -525,6 +542,18 @@
         redisService.setCacheList(key, Arrays.asList(orderId + "_" + xpPoint.getPointLon() + "," + xpPoint.getPointLat() + "_0" + "_" + uid + "_" + xpOrder.getOrderNumber() + "_" + distance + "_" + duration + "_" + routeAndFareDto.getRoutePlanRule()));
         xpOrder.setQueueName(key);
         xpOrderClient.updateOrder(xpOrder);
+
+
+        // 存储mongodb 数据
+        XpGeoQueryEntity xpGeoQueryEntity = new XpGeoQueryEntity();
+        xpGeoQueryEntity.setOrderId(orderId.toString());
+        xpGeoQueryEntity.setLocation(new GeoJsonPoint(xpPoint.getPointLon(),xpPoint.getPointLat()));
+        // 计算2个时间的秒数
+        xpGeoQueryEntity.setTime(currentTimeSlot);
+        xpGeoQueryEntity.setStatus(0);
+
+        geoQueryEntityService.save(xpGeoQueryEntity);
+
         return orderId;
 
 //

--
Gitblit v1.7.1