liujie
2026-06-09 c96fbe6b0aeb413a17c429133ee6d81d138144b9
xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpMapController.java
@@ -13,6 +13,7 @@
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.config.MapApiProperties;
import com.xiaopeng.map.mangodb.model.GeoPoint;
import com.xiaopeng.map.mangodb.service.XpGeoFencingPolygonService;
import com.xiaopeng.map.service.XpElectronicFenceAreaService;
@@ -30,7 +31,6 @@
import org.apache.http.util.EntityUtils;
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;
@@ -71,6 +71,71 @@
        this.xpOrderClient = xpOrderClient;
        this.mongoTemplate = mongoTemplate;
    }
    @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");
        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);
            }
            List<RouteVo> routeVo = gdMapGeocodingUtil.getDistanceAndTimeList(dto.getOrigin(), dto.getDestination(), pointStrParam, fenceId,dto.getRoutePlanRule(), history);
            if(routeVo==null || routeVo.isEmpty()){
                return R.fail("没有找到路线");
            }
            return R.ok(routeVo);
        }catch (Exception e){
            e.printStackTrace();
        }
        return R.fail("没有找到路线");
    }
    @PostMapping("/base/v1/map/getDistanceAndDuration")
@@ -206,21 +271,19 @@
    }
    @Value("${map.urls.weather:https://restapi.amap.com/v3/weather/weatherInfo?key=%s&city=%s}")
    String WEATHER_URL;
    @Autowired
    ObjectMapper om;
    @Value("${map.apikey:66ae577f63898dae3016d599fda57221}")
    String key;
    @Autowired
    private MapApiProperties mapApiProperties;
    @ApiOperation(value = "获取天气信息", tags = {"内部-调价"})
    @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));
            HttpGet httpGet = new HttpGet(String.format(mapApiProperties.getUrls().getWeather(), mapApiProperties.getApiKey(), cityCode));
            CloseableHttpResponse response = httpClient.execute(httpGet);
            HttpEntity entity = response.getEntity();
            if (entity != null) {
@@ -235,4 +298,5 @@
        return R.fail("获取天气信息失败");
    }
}