package com.xiaopeng.map.controller;
|
|
|
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.vo.map.XpDistanceAndDurationVo;
|
import com.xiaopeng.api.vo.operation.RouteVo;
|
import com.xiaopeng.common.core.constant.CacheConstants;
|
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.utils.GDMapGeocodingUtil;
|
import com.xiaopeng.map.utils.mangoUtils.MongoGeoFenceUtil;
|
import io.swagger.annotations.Api;
|
import lombok.extern.slf4j.Slf4j;
|
import org.bson.Document;
|
import org.springframework.validation.annotation.Validated;
|
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 java.util.ArrayList;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
@Slf4j
|
@RestController
|
@RequestMapping("/base/v1/mini-program")
|
@Api(tags = "地图调用服务")
|
public class XpMapController {
|
|
|
private final GDMapGeocodingUtil gdMapGeocodingUtil;
|
private final XpGeoFencingPolygonService xpGeoFencingPolygonService;
|
private final RedisService redisService;
|
|
public XpMapController(GDMapGeocodingUtil gdMapGeocodingUtil, XpGeoFencingPolygonService xpGeoFencingPolygonService, RedisService redisService) {
|
this.gdMapGeocodingUtil = gdMapGeocodingUtil;
|
this.xpGeoFencingPolygonService = xpGeoFencingPolygonService;
|
this.redisService = redisService;
|
}
|
|
|
@PostMapping("/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");
|
|
// 避让区域
|
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));
|
}
|
|
}
|
RouteVo routeVo = gdMapGeocodingUtil.getDistanceAndTime(dto.getOrigin(), dto.getDestination(), String.join("|", pointStrParam), fenceId,dto.getRoutePlanRule());
|
if(routeVo==null){
|
return R.fail("没有找到路线");
|
}
|
|
return R.ok(routeVo);
|
|
|
}
|
|
|
/**
|
* 获取订单距离和时长
|
* @param dto
|
* @return
|
*/
|
@PostMapping("/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));
|
}
|
}
|
RouteVo routeVo = gdMapGeocodingUtil.getDistanceAndTime(dto.getOrigin(), dto.getDestination(), String.join("|", pointStrParam), fenceId,dto.getRoutePlanRule());
|
if(routeVo==null){
|
return R.fail("没有找到路线");
|
}
|
|
// 存储redis
|
redisService.setCacheObject(CacheConstants.ORDER_ROUTE + "_" + dto.getOrderId() + "_" +dto.getRouteType(), routeVo);
|
|
// 存储路线偏离缓存,后续进行轨迹截取
|
redisService.setCacheObject(CacheConstants.ORDER_ROUTE_CAPTURE + "_" + dto.getOrderId() + "_" +dto.getRouteType(), routeVo);
|
|
return R.ok(routeVo);
|
}
|
|
|
|
}
|