Commit f45fa8dd authored by hanbing's avatar hanbing

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

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