From 08cc6d5cf7e93b75cfabe7dcc2aeaa9afa1117eb Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期二, 12 五月 2026 15:01:47 +0800
Subject: [PATCH] Merge branch '1.0' of http://120.76.84.145:10101/gitblit/r/java/Robotaxi into 1.1

---
 xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpMapController.java |  169 ++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 132 insertions(+), 37 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 c08b40a..dee2018 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,18 +1,21 @@
 package com.xiaopeng.map.controller;
 
 
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.xiaopeng.api.dto.WeatherDTO;
 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.feignClient.order.XpOrderClient;
-import com.xiaopeng.api.dto.WeatherDTO;
+import com.xiaopeng.api.model.map.XpGeoFencingPolygon;
+import com.xiaopeng.api.model.operation.XpElectronicFenceArea;
 import com.xiaopeng.api.vo.map.PointByIpVo;
 import com.xiaopeng.api.vo.operation.RouteVo;
 import com.xiaopeng.common.core.domain.R;
 import com.xiaopeng.common.redis.service.RedisService;
 import com.xiaopeng.map.mangodb.model.GeoPoint;
 import com.xiaopeng.map.mangodb.service.XpGeoFencingPolygonService;
+import com.xiaopeng.map.service.XpElectronicFenceAreaService;
 import com.xiaopeng.map.utils.AmapWalkingRouteUtil;
 import com.xiaopeng.map.utils.GDMapGeocodingUtil;
 import com.xiaopeng.unifiedverification.interceptor.XpClientCheck;
@@ -28,15 +31,23 @@
 import org.bson.Document;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.geo.Point;
 import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.geo.GeoJsonPolygon;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
 
 @Slf4j
 @RestController
@@ -50,6 +61,8 @@
     private final RedisService redisService;
     private final XpOrderClient xpOrderClient;
     private final MongoTemplate mongoTemplate;
+    @Resource
+    private XpElectronicFenceAreaService xpElectronicFenceAreaService;
 
     public XpMapController(GDMapGeocodingUtil gdMapGeocodingUtil, XpGeoFencingPolygonService xpGeoFencingPolygonService, RedisService redisService, XpOrderClient xpOrderClient, MongoTemplate mongoTemplate) {
         this.gdMapGeocodingUtil = gdMapGeocodingUtil;
@@ -60,8 +73,8 @@
     }
 
 
-    @PostMapping("/base/v1/map/getDistanceAndDuration")
-    public R<RouteVo> getDistanceAndDuration(@RequestBody RouteAndFareDto dto){
+    @PostMapping("/base/v1/map/getDistanceAndDurationList")
+    public R<List<RouteVo>> getDistanceAndDurationList(@RequestBody RouteAndFareDto dto){
         // 获取电子围栏的禁行区域点位
         GeoPoint startPoint = new GeoPoint(dto.getOrigin().getLongitude(),dto.getOrigin().getLatitude());
         List<String> operatingArea = xpGeoFencingPolygonService.findFencesContainingPoint(startPoint, "operating_area", "points");
@@ -70,7 +83,7 @@
         List<Document> pointsInFence = xpGeoFencingPolygonService.findPointsByParentId(fenceId, "fenceId", "prohibited_area");
 
         // 避让区域
-        ArrayList<String> pointStrParam = new ArrayList<>();
+        ArrayList<JSONObject> pointStrParam = new ArrayList<>();
         try {
             for (Document document : pointsInFence) {
                 // 获取points字段(它是GeoJSON对象)
@@ -83,25 +96,96 @@
                     if (coordinates != null && !coordinates.isEmpty()) {
                         // 获取第一个多边形环(通常只有一个)
                         List<List<Double>> polygonPoints = coordinates.get(0);
-
+                        List<String> coordinatesList = new ArrayList<>();
                         // 转换为经纬度字符串
                         for (List<Double> point : polygonPoints) {
                             if (point.size() >= 2) {
-                                pointStrParam.add(point.get(0) + "," + point.get(1));
+                                coordinatesList.add(point.get(0) + "," + point.get(1));
                             }
                         }
+                        JSONObject jsonObject = new JSONObject();
+                        jsonObject.put("coordinates", coordinatesList);
+                        pointStrParam.add(jsonObject);
                     }
                 }
             }
 
             List<HistoryPointDto> history = new ArrayList<>();
             if(null != dto.getVehicleId()){
-                history = redisService.getCacheList("VEHICLE_HISTORY_POINT_LIST:" + dto.getVehicleId());
+//                history = redisService.getCacheList("VEHICLE_HISTORY_POINT_LIST:" + dto.getVehicleId());
+//                if(history.size() > 10){
+//                    history = history.subList(history.size() - 10, history.size());
+//                }
+//                history.forEach(s->{
+//                    s.setDirection(new BigDecimal(s.getDirection()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
+//                });
+//                redisService.setCacheList("VEHICLE_HISTORY_POINT_LIST:" + dto.getVehicleId(), history);
             }
-            if(history.size() > 10){
-                history = history.subList(history.size() - 10, history.size());
+            List<RouteVo> routeVo = gdMapGeocodingUtil.getDistanceAndTimeList(dto.getOrigin(), dto.getDestination(), pointStrParam, fenceId,dto.getRoutePlanRule(), history);
+            if(routeVo==null || routeVo.isEmpty()){
+                return R.fail("没有找到路线");
             }
-            redisService.setCacheList("VEHICLE_HISTORY_POINT_LIST:" + dto.getVehicleId(), history);
+
+            return R.ok(routeVo);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return R.fail("没有找到路线");
+
+
+    }
+
+
+
+
+    @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, "fenceId", "prohibited_area");
+
+        // 避让区域
+        ArrayList<JSONObject> 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);
+                        List<String> coordinatesList = new ArrayList<>();
+                        // 转换为经纬度字符串
+                        for (List<Double> point : polygonPoints) {
+                            if (point.size() >= 2) {
+                                coordinatesList.add(point.get(0) + "," + point.get(1));
+                            }
+                        }
+                        JSONObject jsonObject = new JSONObject();
+                        jsonObject.put("coordinates", coordinatesList);
+                        pointStrParam.add(jsonObject);
+                    }
+                }
+            }
+
+            List<HistoryPointDto> history = new ArrayList<>();
+            if(null != dto.getVehicleId()){
+//                history = redisService.getCacheList("VEHICLE_HISTORY_POINT_LIST:" + dto.getVehicleId());
+//                if(history.size() > 10){
+//                    history = history.subList(history.size() - 10, history.size());
+//                }
+//                history.forEach(s->{
+//                    s.setDirection(new BigDecimal(s.getDirection()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
+//                });
+//                redisService.setCacheList("VEHICLE_HISTORY_POINT_LIST:" + dto.getVehicleId(), history);
+            }
             RouteVo routeVo = gdMapGeocodingUtil.getDistanceAndTime(dto.getOrigin(), dto.getDestination(), pointStrParam, fenceId,dto.getRoutePlanRule(), history);
             if(routeVo==null){
                 return R.fail("没有找到路线");
@@ -125,30 +209,37 @@
     @PostMapping("/base/v1/map/getOrderDistanceAndDuration")
     public R<RouteVo> getOrderDistanceAndDuration(@Validated @RequestBody OrderRouteAndFareDto dto){
         // 获取电子围栏的禁行区域点位
-        GeoPoint startPoint = new GeoPoint(dto.getOrigin().getLongitude(),dto.getOrigin().getLatitude());
+        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<JSONObject> pointStrParam = new ArrayList<>();
         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);
-                // 一个区域的点位
-                for (GeoPoint point : points) {
-                    pointStrParam.add(point.getLongitude()+","+point.getLatitude());
+            List<XpElectronicFenceArea> list = xpElectronicFenceAreaService.list(new QueryWrapper<XpElectronicFenceArea>().eq("electronic_id", fenceId).eq("is_deleted", 0).eq("area_type", 2));
+            for (XpElectronicFenceArea xpElectronicFenceArea : list) {
+                String fencePoints = xpElectronicFenceArea.getFencePoints();
+                List<String> coordinatesList = new ArrayList<>();
+                for (String s : fencePoints.split(",")) {
+                    coordinatesList.add(s.replace("_", ","));
                 }
+
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("coordinates", coordinatesList);
+                pointStrParam.add(jsonObject);
             }
         }
         List<HistoryPointDto> history = new ArrayList<>();
         if(null != dto.getVehicleId()){
-            history = redisService.getCacheList("VEHICLE_HISTORY_POINT_LIST:" + dto.getVehicleId());
+//            history = redisService.getCacheList("VEHICLE_HISTORY_POINT_LIST:" + dto.getVehicleId());
+//            if(history.size() > 10){
+//                history = history.subList(history.size() - 10, history.size());
+//            }
+//            history.forEach(s->{
+//                s.setDirection(new BigDecimal(s.getDirection()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
+//            });
+//            redisService.setCacheList("VEHICLE_HISTORY_POINT_LIST:" + dto.getVehicleId(), history);
         }
-        if(history.size() > 10){
-            history = history.subList(history.size() - 10, history.size());
-        }
-        redisService.setCacheList("VEHICLE_HISTORY_POINT_LIST:" + dto.getVehicleId(), history);
         RouteVo routeVo = gdMapGeocodingUtil.getDistanceAndTime(dto.getOrigin(), dto.getDestination(), pointStrParam, fenceId,dto.getRoutePlanRule(), history);
         if(routeVo==null){
             return R.fail("没有找到路线");
@@ -180,6 +271,7 @@
     }
 
 
+
     @Value("${map.urls.weather:https://restapi.amap.com/v3/weather/weatherInfo?key=%s&city=%s}")
     String WEATHER_URL;
 
@@ -190,21 +282,24 @@
     String key;
 
     @ApiOperation(value = "获取天气信息", tags = {"内部-调价"})
-    @GetMapping("/logan/inner/weatherInfo")
-    public R<WeatherDTO> weather(@RequestParam String city) throws IOException {
-
-        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
-            HttpGet httpGet = new HttpGet(String.format(WEATHER_URL, key, city));
-            try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
-                HttpEntity entity = response.getEntity();
-                if (entity != null) {
-                    String resp = EntityUtils.toString(entity, StandardCharsets.UTF_8);
-                    System.out.println(resp);
-                    return R.ok(om.readValue(resp, WeatherDTO.class));
-                }
-                return R.fail("获取天气信息失败");
+    @PostMapping("/logan/inner/weatherInfo")
+    public R<WeatherDTO> wether(@RequestParam("cityCode") String cityCode) {
+        try{
+            CloseableHttpClient httpClient = HttpClients.createDefault();
+            HttpGet httpGet = new HttpGet(String.format(WEATHER_URL, key, cityCode));
+            CloseableHttpResponse response = httpClient.execute(httpGet);
+            HttpEntity entity = response.getEntity();
+            if (entity != null) {
+                String resp = EntityUtils.toString(entity, StandardCharsets.UTF_8);
+                log.info("天气预报查询结果:{}", resp);
+                return R.ok(om.readValue(resp, WeatherDTO.class));
             }
+            return R.fail("获取天气信息失败");
+        }catch (Exception e){
+            e.printStackTrace();
         }
+        return R.fail("获取天气信息失败");
     }
 
+
 }

--
Gitblit v1.7.1