From 7b1903b3135ffc3040be8f7cd9ed566b24a86260 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期六, 07 三月 2026 20:56:19 +0800
Subject: [PATCH] 合并代码
---
xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpMapController.java | 117 ++++++++++++++++------------------------------------------
1 files changed, 33 insertions(+), 84 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 baa9153..34eec00 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,9 +4,6 @@
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;
import com.xiaopeng.common.core.constant.CacheConstants;
@@ -14,19 +11,17 @@
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.utils.AmapWalkingRouteUtil;
import com.xiaopeng.map.utils.GDMapGeocodingUtil;
import com.xiaopeng.map.utils.mangoUtils.MongoGeoFenceUtil;
import io.swagger.annotations.Api;
-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.*;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
-import javax.servlet.http.HttpServletRequest;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@@ -41,15 +36,11 @@
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, XpOrderClient xpOrderClient, MongoTemplate mongoTemplate) {
+ public XpMapController(GDMapGeocodingUtil gdMapGeocodingUtil, XpGeoFencingPolygonService xpGeoFencingPolygonService, RedisService redisService) {
this.gdMapGeocodingUtil = gdMapGeocodingUtil;
this.xpGeoFencingPolygonService = xpGeoFencingPolygonService;
this.redisService = redisService;
- this.xpOrderClient = xpOrderClient;
- this.mongoTemplate = mongoTemplate;
}
@@ -60,47 +51,28 @@
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));
- }
- }
- }
+ 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());
}
- RouteVo routeVo = gdMapGeocodingUtil.getDistanceAndTime(dto.getOrigin(), dto.getDestination(), String.join("|", pointStrParam), fenceId,dto.getRoutePlanRule());
- if(routeVo==null){
- return R.fail("没有找到路线");
+ if(!pointStr.isEmpty()){
+ pointStrParam.add(String.join(";", pointStr));
}
- return R.ok(routeVo);
- }catch (Exception e){
- e.printStackTrace();
}
- return R.fail("没有找到路线");
+ RouteVo routeVo = gdMapGeocodingUtil.getDistanceAndTime(dto.getOrigin(), dto.getDestination(), String.join("|", pointStrParam), fenceId,dto.getRoutePlanRule());
+ if(routeVo==null){
+ return R.fail("没有找到路线");
+ }
+
+ return R.ok(routeVo);
}
@@ -116,25 +88,21 @@
// 获取电子围栏的禁行区域点位
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<>();
- 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));
- }
+ 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("没有找到路线");
@@ -142,32 +110,13 @@
// 存储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);
}
- /**
- * 根据导航ID获取车端需要的导航数据
- * @param routedID
- * @return
- */
- @PostMapping("/map/queryRouted")
- public R<String> getOrderDistanceAndDuration(@RequestParam("routedID") String routedID){
- return R.ok(gdMapGeocodingUtil.routed(routedID));
- }
-
- /**
- * 根据ip获取点位
- */
- @ApiOperation(value = "根据ip获取点位", tags = {"小程序-站点导航"})
- @GetMapping("/point/getPointByIp")
- public R<PointByIpVo> getPointByIp(HttpServletRequest request) throws IOException {
- String ip = request.getRemoteAddr();
- PointByIpVo pointByIpVo = AmapWalkingRouteUtil.ipLocation(ip);
- return R.ok(pointByIpVo);
- }
}
--
Gitblit v1.7.1