puzhibing
2026-03-03 1e16fb98c0dd2db59429e7b40f42841ea01bdb2e
xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpMapController.java
@@ -21,7 +21,6 @@
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.*;
@@ -42,14 +41,12 @@
    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, MongoTemplate mongoTemplate) {
    public XpMapController(GDMapGeocodingUtil gdMapGeocodingUtil, XpGeoFencingPolygonService xpGeoFencingPolygonService, RedisService redisService, XpOrderClient xpOrderClient) {
        this.gdMapGeocodingUtil = gdMapGeocodingUtil;
        this.xpGeoFencingPolygonService = xpGeoFencingPolygonService;
        this.redisService = redisService;
        this.xpOrderClient = xpOrderClient;
        this.mongoTemplate = mongoTemplate;
    }
@@ -60,36 +57,22 @@
        List<String> operatingArea = xpGeoFencingPolygonService.findFencesContainingPoint(startPoint, "operating_area", "points");
        String fenceId = operatingArea.get(0);
        List<Document> pointsInFence = xpGeoFencingPolygonService.findPointsByParentId(fenceId, "fenceId", "prohibited_area");
        List<Document> pointsInFence = xpGeoFencingPolygonService.findPointsByParentId(fenceId, "parentId", "prohibited_area");
        // 避让区域
        ArrayList<String> pointStrParam = new ArrayList<>();
        try {
            for (Document document : pointsInFence) {
                // 获取points字段(它是GeoJSON对象)
                Document geoJsonDoc = document.get("points", Document.class);
                if (geoJsonDoc != null && "Polygon".equals(geoJsonDoc.getString("type"))) {
                    // 获取coordinates数组
                    List<List<List<Double>>> coordinates = (List<List<List<Double>>>) geoJsonDoc.get("coordinates");
                    if (coordinates != null && !coordinates.isEmpty()) {
                        // 获取第一个多边形环(通常只有一个)
                        List<List<Double>> polygonPoints = coordinates.get(0);
                        // 转换为经纬度字符串
                        ArrayList<String> pointStr = new ArrayList<>();
                        for (List<Double> point : polygonPoints) {
                            if (point.size() >= 2) {
                                pointStr.add(point.get(0) + "," + point.get(1));
                            }
                        }
                        if (!pointStr.isEmpty()) {
                            pointStrParam.add(String.join(";", pointStr));
                        }
                    }
                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){
@@ -117,11 +100,14 @@
        GeoPoint startPoint = new GeoPoint(dto.getOrigin().getLongitude(),dto.getOrigin().getLatitude());
        List<String> operatingArea = xpGeoFencingPolygonService.findFencesContainingPoint(startPoint, "operating_area", "points");
        // 避让区域
        ArrayList<String> pointStrParam = new ArrayList<>();
        ArrayList<String> pointStrParam = null;
        String fenceId = null;
        if(!operatingArea.isEmpty()){
            fenceId = operatingArea.get(0);
            List<Document> pointsInFence = xpGeoFencingPolygonService.findPointsByParentId(fenceId, "parentId", "prohibited_area");
            if(!pointsInFence.isEmpty()){
                pointStrParam = new ArrayList<>();
            }
            for (Document document : pointsInFence) {
                List<GeoPoint> points = document.getList("points", GeoPoint.class);
                // 一个区域的点位