Commit f45fa8dd authored by hanbing's avatar hanbing

[add] 快速特勤,备选路线路网不连续异常处理

parent 423c806f
......@@ -402,7 +402,7 @@ public class SpecialServiceServiceImpl implements SpecialServiceService {
String location = baseCrossInfoPO.getLocation();
double[] lonLat = CrossUtil.getLonLat(location);
String ridPointLonLat = lonLat[0] + "," + lonLat[1];
double distance = gtsService.distance(startLonLat, ridPointLonLat);
double distance = gtsService.distance(endLonLat, ridPointLonLat);
endMinDistance = Math.min(endMinDistance, distance);
if (distance == endMinDistance) {
endCross = baseCrossInfoPO;
......@@ -430,9 +430,15 @@ public class SpecialServiceServiceImpl implements SpecialServiceService {
distanceList.add(distance);
}
Collections.sort(distanceList);
BaseCrossInfoPO secondStartCross = distanceMap.get(distanceList.get(1));
List<BaseCrossInfoPO> routeList2 = getRouteList(secondStartCross, endCross);
routeList2.add(0, startCross);
BaseCrossInfoPO secondStartCross = null;
try {
secondStartCross = distanceMap.get(distanceList.get(1));
} catch (IndexOutOfBoundsException e) {
throw new RuntimeException("路网数据不连续");
}
List<BaseCrossInfoPO> routeList2 = new ArrayList<>();
routeList2.add(startCross);
getSecondRouteList(secondStartCross, endCross, routeList2);
List<RouteElementVO> route2 = buildRoute(routeList2);
res.add(route1);
......@@ -442,6 +448,44 @@ public class SpecialServiceServiceImpl implements SpecialServiceService {
return null;
}
private void getSecondRouteList(BaseCrossInfoPO secondStartCross, BaseCrossInfoPO endCross,
List<BaseCrossInfoPO> routeList2) {
String endCrossLonLatStr = getCrossLonLatStr(endCross);
// 获取上游路口到终点距离最近的
BaseCrossInfoPO nextStartCross = secondStartCross;
while (ObjectUtil.notEqual(endCross.getId(), nextStartCross.getId())) {
String nextCrossId = nextStartCross.getId();
double minDistance = Double.MAX_VALUE;
List<RidInfoEntity> ridUpCrossList = ridInfoMapper.selectUpCross(nextStartCross.getId());
for (RidInfoEntity ridUpCross : ridUpCrossList) {
String upCrossId = ridUpCross.getStartCrossId();
BaseCrossInfoPO upCross = baseCrossInfoMapper.selectById(upCrossId);
String upCrossLonLatStr = getCrossLonLatStr(upCross);
double distance = gtsService.distance(endCrossLonLatStr, upCrossLonLatStr);
minDistance = Math.min(minDistance, distance);
if (minDistance == distance && !hasCross(routeList2, upCross)) { // 已选过的路口不可再选
nextStartCross = upCross;
}
}
if (ObjectUtil.equal(nextStartCross.getId(), nextCrossId)) {
throw new RuntimeException("路网数据不连续");
}
routeList2.add(nextStartCross);
}
routeList2.add(1, secondStartCross);
}
private boolean hasCross(List<BaseCrossInfoPO> routeList, BaseCrossInfoPO upCross) {
for (BaseCrossInfoPO baseCrossInfoPO : routeList) {
String id = baseCrossInfoPO.getId();
String upCrossId = upCross.getId();
if (ObjectUtil.equal(id, upCrossId)) {
return true;
}
}
return false;
}
@Override
public void isValidPoint(IsValidPointBO isValidPointBO) {
String lonLat = isValidPointBO.getLonLat();
......@@ -469,28 +513,29 @@ public class SpecialServiceServiceImpl implements SpecialServiceService {
@NotNull
private List<BaseCrossInfoPO> getRouteList(BaseCrossInfoPO startCross, BaseCrossInfoPO endCross) {
String endCrossLonLatStr = getCrossLonLatStr(endCross);
// 获取起点路口所有上游路口
String startCrossId = startCross.getId();
List<RidInfoEntity> ridUpCrossList = ridInfoMapper.selectUpCross(startCrossId);
// 获取上有路口到终点距离最近的
// 获取上游路口到终点距离最近的
BaseCrossInfoPO nextStartCross = startCross;
List<BaseCrossInfoPO> routeList = new ArrayList<>();
routeList.add(nextStartCross);
while (ObjectUtil.notEqual(endCross, nextStartCross)) {
while (ObjectUtil.notEqual(endCross.getId(), nextStartCross.getId())) {
String nextCrossId = nextStartCross.getId();
double minDistance = Double.MAX_VALUE;
List<RidInfoEntity> ridUpCrossList = ridInfoMapper.selectUpCross(nextStartCross.getId());
for (RidInfoEntity ridUpCross : ridUpCrossList) {
String upCrossId = ridUpCross.getStartCrossId();
BaseCrossInfoPO upCross = baseCrossInfoMapper.selectById(upCrossId);
String upCrossLonLatStr = getCrossLonLatStr(upCross);
double distance = gtsService.distance(endCrossLonLatStr, upCrossLonLatStr);
minDistance = Math.min(minDistance, distance);
if (minDistance == distance && !routeList.contains(nextStartCross)) { // 已选过的路口不可再选
if (minDistance == distance && !hasCross(routeList, upCross)) { // 已选过的路口不可再选
nextStartCross = upCross;
}
}
if (ObjectUtil.equal(nextStartCross.getId(), nextCrossId)) {
throw new RuntimeException("路网数据不连续");
}
routeList.add(nextStartCross);
}
routeList.add(endCross);
routeList.add(0, startCross);
return routeList;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment