From 3e64bca8c8133298f242224f52b3d5f1278f68a6 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期三, 04 三月 2026 16:00:04 +0800
Subject: [PATCH] 修改围栏查询及其他mongodb查询

---
 xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpMapController.java |   31 +++++++++++++++++++------------
 1 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpMapController.java b/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpMapController.java
index af9283e..1365c3b 100644
--- a/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpMapController.java
+++ b/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpMapController.java
@@ -21,6 +21,7 @@
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.bson.Document;
+import org.springframework.data.mongodb.core.MongoTemplate;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
@@ -41,12 +42,14 @@
     private final XpGeoFencingPolygonService xpGeoFencingPolygonService;
     private final RedisService redisService;
     private final XpOrderClient xpOrderClient;
+    private final MongoTemplate mongoTemplate;
 
-    public XpMapController(GDMapGeocodingUtil gdMapGeocodingUtil, XpGeoFencingPolygonService xpGeoFencingPolygonService, RedisService redisService, XpOrderClient xpOrderClient) {
+    public XpMapController(GDMapGeocodingUtil gdMapGeocodingUtil, XpGeoFencingPolygonService xpGeoFencingPolygonService, RedisService redisService, XpOrderClient xpOrderClient, MongoTemplate mongoTemplate) {
         this.gdMapGeocodingUtil = gdMapGeocodingUtil;
         this.xpGeoFencingPolygonService = xpGeoFencingPolygonService;
         this.redisService = redisService;
         this.xpOrderClient = xpOrderClient;
+        this.mongoTemplate = mongoTemplate;
     }
 
 
@@ -99,21 +102,25 @@
         // 获取电子围栏的禁行区域点位
         GeoPoint startPoint = new GeoPoint(dto.getOrigin().getLongitude(),dto.getOrigin().getLatitude());
         List<String> operatingArea = xpGeoFencingPolygonService.findFencesContainingPoint(startPoint, "operating_area", "points");
-        String fenceId = operatingArea.get(0);
-        List<Document> pointsInFence = xpGeoFencingPolygonService.findPointsByParentId(fenceId, "parentId", "prohibited_area");
         // 避让区域
         ArrayList<String> pointStrParam = new ArrayList<>();
-        for (Document document : pointsInFence) {
-            List<GeoPoint> points = document.getList("points", GeoPoint.class);
-            // 一个区域的点位
-            ArrayList<String> pointStr = new ArrayList<>();
-            for (GeoPoint point : points) {
-                pointStr.add( point.getLongitude()+","+point.getLatitude());
-            }
-            if(!pointStr.isEmpty()){
-                pointStrParam.add(String.join(";", pointStr));
+        String fenceId = null;
+        if(!operatingArea.isEmpty()){
+            fenceId = operatingArea.get(0);
+            List<Document> pointsInFence = xpGeoFencingPolygonService.findPointsByParentId(fenceId, "parentId", "prohibited_area");
+            for (Document document : pointsInFence) {
+                List<GeoPoint> points = document.getList("points", GeoPoint.class);
+                // 一个区域的点位
+                ArrayList<String> pointStr = new ArrayList<>();
+                for (GeoPoint point : points) {
+                    pointStr.add( point.getLongitude()+","+point.getLatitude());
+                }
+                if(!pointStr.isEmpty()){
+                    pointStrParam.add(String.join(";", pointStr));
+                }
             }
         }
+
         RouteVo routeVo = gdMapGeocodingUtil.getDistanceAndTime(dto.getOrigin(), dto.getDestination(), String.join("|", pointStrParam), fenceId,dto.getRoutePlanRule());
         if(routeVo==null){
             return R.fail("没有找到路线");

--
Gitblit v1.7.1