From a6f0b69caf5c1913b6fec8b94d2454b33d15d649 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期六, 07 三月 2026 21:00:56 +0800
Subject: [PATCH] 修改mongodb查询
---
xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpMapController.java | 71 +++++++++++++++++++++--------------
1 files changed, 43 insertions(+), 28 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 93bc0e9..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
@@ -4,6 +4,8 @@
import com.xiaopeng.api.dto.map.OrderRouteAndFareDto;
import com.xiaopeng.api.dto.map.RouteAndFareDto;
import com.xiaopeng.api.dto.operation.LonLatDto;
+import com.xiaopeng.api.feignClient.order.XpOrderClient;
+import com.xiaopeng.api.model.order.XpOrder;
import com.xiaopeng.api.vo.map.PointByIpVo;
import com.xiaopeng.api.vo.map.XpDistanceAndDurationVo;
import com.xiaopeng.api.vo.operation.RouteVo;
@@ -19,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.*;
@@ -38,11 +41,15 @@
private final GDMapGeocodingUtil gdMapGeocodingUtil;
private final XpGeoFencingPolygonService xpGeoFencingPolygonService;
private final RedisService redisService;
+ private final XpOrderClient xpOrderClient;
+ private final MongoTemplate mongoTemplate;
- public XpMapController(GDMapGeocodingUtil gdMapGeocodingUtil, XpGeoFencingPolygonService xpGeoFencingPolygonService, RedisService redisService) {
+ 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;
}
@@ -57,24 +64,29 @@
// 避让区域
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());
+ 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));
+ }
+
}
- 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("没有找到路线");
}
+ return R.ok(routeVo);
+ }catch (Exception e){
+ e.printStackTrace();
}
- RouteVo routeVo = gdMapGeocodingUtil.getDistanceAndTime(dto.getOrigin(), dto.getDestination(), String.join("|", pointStrParam), fenceId,dto.getRoutePlanRule());
- if(routeVo==null){
- return R.fail("没有找到路线");
- }
-
- return R.ok(routeVo);
+ return R.fail("没有找到路线");
}
@@ -90,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("没有找到路线");
@@ -112,9 +128,8 @@
// 存储redis
redisService.setCacheObject(CacheConstants.ORDER_ROUTE + "_" + dto.getOrderId() + "_" +dto.getRouteType(), routeVo);
-
// 存储路线偏离缓存,后续进行轨迹截取
- redisService.setCacheObject(CacheConstants.ORDER_ROUTE_CAPTURE + "_" + dto.getOrderId() + "_" +dto.getRouteType(), routeVo);
+// redisService.setCacheObject(CacheConstants.ORDER_ROUTE_CAPTURE + "_" + dto.getOrderId() + "_" +dto.getRouteType(), routeVo);
return R.ok(routeVo);
}
--
Gitblit v1.7.1