From 57b2a831bb61ac6008a0e350f00efb7e8b723fd5 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期三, 08 四月 2026 20:51:17 +0800
Subject: [PATCH] 修改获取轨迹的参数

---
 xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpMapController.java |  112 ++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 68 insertions(+), 44 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 05dee01..e6d1501 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
@@ -1,6 +1,8 @@
 package com.xiaopeng.map.controller;
 
 
+import com.alibaba.fastjson2.JSON;
+import com.xiaopeng.api.dto.map.HistoryPointDto;
 import com.xiaopeng.api.dto.map.OrderRouteAndFareDto;
 import com.xiaopeng.api.dto.map.RouteAndFareDto;
 import com.xiaopeng.api.dto.operation.LonLatDto;
@@ -21,6 +23,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.*;
 
@@ -32,7 +35,7 @@
 
 @Slf4j
 @RestController
-@RequestMapping("/base/v1/mini-program")
+@RequestMapping("")
 @Api(tags = "地图调用服务")
 public class XpMapController {
 
@@ -41,40 +44,65 @@
     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;
     }
 
 
-    @PostMapping("/map/getDistanceAndDuration")
+    @PostMapping("/base/v1/map/getDistanceAndDuration")
     public R<RouteVo> getDistanceAndDuration(@RequestBody RouteAndFareDto dto){
         // 获取电子围栏的禁行区域点位
         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");
+        List<Document> pointsInFence = xpGeoFencingPolygonService.findPointsByParentId(fenceId, "fenceId", "prohibited_area");
 
         // 避让区域
         ArrayList<String> pointStrParam = new ArrayList<>();
         try {
             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));
-                }
+                // 获取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));
+                        }
+                    }
+                }
             }
-            RouteVo routeVo = gdMapGeocodingUtil.getDistanceAndTime(dto.getOrigin(), dto.getDestination(), String.join("|", pointStrParam), fenceId,dto.getRoutePlanRule());
+
+            List<Object> cacheList = redisService.getCacheList("VEHICLE_HISTORY_POINT_LIST:" + dto.getVin());
+            List<HistoryPointDto> history = new ArrayList<>();
+            if(cacheList!=null && !cacheList.isEmpty()){
+                for (Object cache : cacheList) {
+                    HistoryPointDto historyPointDto = JSON.parseObject(cache.toString(), HistoryPointDto.class);
+                    history.add(historyPointDto);
+                }
+            }
+            RouteVo routeVo = gdMapGeocodingUtil.getDistanceAndTime(dto.getOrigin(), dto.getDestination(), String.join("|", pointStrParam), fenceId,dto.getRoutePlanRule(), history);
             if(routeVo==null){
                 return R.fail("没有找到路线");
             }
@@ -94,45 +122,41 @@
      * @param dto
      * @return
      */
-    @PostMapping("/map/getOrderDistanceAndDuration")
+    @PostMapping("/base/v1/map/getOrderDistanceAndDuration")
     public R<RouteVo> getOrderDistanceAndDuration(@Validated @RequestBody OrderRouteAndFareDto dto){
         // 获取电子围栏的禁行区域点位
         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());
+        List<Object> cacheList = redisService.getCacheList("VEHICLE_HISTORY_POINT_LIST:" + dto.getVin());
+        List<HistoryPointDto> history = new ArrayList<>();
+        if(cacheList!=null && !cacheList.isEmpty()){
+            for (Object cache : cacheList) {
+                HistoryPointDto historyPointDto = JSON.parseObject(cache.toString(), HistoryPointDto.class);
+                history.add(historyPointDto);
+            }
+        }
+        RouteVo routeVo = gdMapGeocodingUtil.getDistanceAndTime(dto.getOrigin(), dto.getDestination(), String.join("|", pointStrParam), fenceId,dto.getRoutePlanRule(), history);
         if(routeVo==null){
             return R.fail("没有找到路线");
         }
-
-        // 存储redis
-        redisService.setCacheObject(CacheConstants.ORDER_ROUTE + "_" + dto.getOrderId() + "_" +dto.getRouteType(), routeVo);
-        // 查询订单信息
-        XpOrder xpOrder = xpOrderClient.queryOrderById(dto.getOrderId()).getData();
-        // 封装消息内容
-        Integer routeType = dto.getRouteType();
-        if(routeType == 2){
-            routeType = 3;
-        }else {
-            routeType = xpOrder.getStatus() == 4 ? 1 : 2;
-        }
-        // 存储路线偏离缓存,后续进行轨迹截取
-        redisService.setCacheObject(CacheConstants.ORDER_ROUTE_CAPTURE + "_" + dto.getOrderId() + "_" +routeType, routeVo);
-
         return R.ok(routeVo);
     }
 
@@ -141,7 +165,7 @@
      * @param routedID
      * @return
      */
-    @PostMapping("/map/queryRouted")
+    @PostMapping("/base/v1/map/queryRouted")
     public R<String> getOrderDistanceAndDuration(@RequestParam("routedID") String routedID){
         return R.ok(gdMapGeocodingUtil.routed(routedID));
     }
@@ -151,7 +175,7 @@
      * 根据ip获取点位
      */
     @ApiOperation(value = "根据ip获取点位", tags = {"小程序-站点导航"})
-    @GetMapping("/point/getPointByIp")
+    @GetMapping("/base/v1/mini-program/point/getPointByIp")
     public R<PointByIpVo> getPointByIp(HttpServletRequest request) throws IOException {
         String ip = request.getRemoteAddr();
         PointByIpVo pointByIpVo = AmapWalkingRouteUtil.ipLocation(ip);

--
Gitblit v1.7.1