运行图交路定义修改,增加车站折返时间配置

This commit is contained in:
DU 2021-03-08 11:39:55 +08:00
parent 15ec7c7b3b
commit bfd278017a
13 changed files with 224 additions and 621 deletions

View File

@ -43,7 +43,7 @@ public class RunPlanUserDataController {
@ApiOperation(value = "生成通用交路区段数据") @ApiOperation(value = "生成通用交路区段数据")
@PostMapping(path = "/routing/path/generate") @PostMapping(path = "/routing/path/generate")
public RunPlanRoutingVO generateUserRoutingPath(@RequestBody @Validated RunPlanRoutingVO routingVO) { public RunPlanRoutingVO generateUserRoutingPath(@RequestBody @Validated RunPlanRoutingVO routingVO) {
return iRunPlanRoutingService.generateUserRouting(routingVO); return iRunPlanRoutingService.generateUserRoutingSections(routingVO);
} }
@ApiOperation(value = "分页获取用户交路") @ApiOperation(value = "分页获取用户交路")

View File

@ -21,7 +21,6 @@ import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.UserVO;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.map.MapRoutingVO;
import club.joylink.rtss.vo.client.map.MapVO; import club.joylink.rtss.vo.client.map.MapVO;
import club.joylink.rtss.vo.client.map.RealLineConfigVO; import club.joylink.rtss.vo.client.map.RealLineConfigVO;
import club.joylink.rtss.vo.client.map.newmap.*; import club.joylink.rtss.vo.client.map.newmap.*;
@ -199,8 +198,6 @@ public class RunPlanDraftService implements IRunPlanDraftService {
checkNameRepeat(null, name, mapId, userVO); checkNameRepeat(null, name, mapId, userVO);
// 查询车站数据车站 --- 站台 --- 站台轨 // 查询车站数据车站 --- 站台 --- 站台轨
MapVO mapVO = this.iMapService.getMapDetail(mapId); MapVO mapVO = this.iMapService.getMapDetail(mapId);
List<RunPlanTripVO> tripVOList;
List<MapStationNewVO> stationList = this.prepareStationDataNew(mapVO); List<MapStationNewVO> stationList = this.prepareStationDataNew(mapVO);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertCollectionNotEmpty(stationList); BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertCollectionNotEmpty(stationList);
// 查询目的地码-区段code关系 // 查询目的地码-区段code关系
@ -226,7 +223,7 @@ public class RunPlanDraftService implements IRunPlanDraftService {
IRunPlanStrategyNew runPlanStrategy =RunPlanImportStrategyEnum.matchImportStrategy(mapVO.getLineCode()); IRunPlanStrategyNew runPlanStrategy =RunPlanImportStrategyEnum.matchImportStrategy(mapVO.getLineCode());
runPlanStrategy.importDataCheckAndPreHandle(runPlanImportList, stationList, upDirection); runPlanStrategy.importDataCheckAndPreHandle(runPlanImportList, stationList, upDirection);
// 生成到站计划数据 // 生成到站计划数据
tripVOList = runPlanStrategy.parseRunPlanImport(runPlanImportList, sectionMap, upDirection); List<RunPlanTripVO> tripVOList = runPlanStrategy.parseRunPlanImport(runPlanImportList, sectionMap, upDirection);
// 生成计划对象 // 生成计划对象
RunPlanDraft plan = new RunPlanDraft(); RunPlanDraft plan = new RunPlanDraft();
plan.setMapId(mapId); plan.setMapId(mapId);
@ -393,56 +390,54 @@ public class RunPlanDraftService implements IRunPlanDraftService {
List<RunPlanTripVO> newTripList = new ArrayList<>(); List<RunPlanTripVO> newTripList = new ArrayList<>();
RunPlanUserConfigVO config = runPlanUserConfigService.getConfig(userVO.getId(), mapVO.getId()); RunPlanUserConfigVO config = runPlanUserConfigService.getConfig(userVO.getId(), mapVO.getId());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(config) && config.hasReentryData(), "运行图-用户缺少配置或没有配置车站折返数据"); BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(config) && config.hasReentryData(), "运行图-用户缺少配置或没有配置车站折返数据");
Map<String, String> userReentryData = config.getConfig().getRunPlanUserReentryData(); Map<String, RunPlanUserConfigVO.ReentryTime> userReentryData = config.getConfig().getReentryData();
List<RunPlanRoutingVO> userRoutings = runPlanRoutingService.getUserRoutingBy(userVO.getId(), mapVO.getId()); List<RunPlanRoutingVO> userRoutings = runPlanRoutingService.getUserRoutingBy(userVO.getId(), mapVO.getId());
Map<String, RunPlanRoutingVO> userRoutingMap = userRoutings.stream().collect(Collectors.toMap(RunPlanRoutingVO::getCode, Function.identity())); Map<String, RunPlanRoutingVO> userRoutingMap = userRoutings.stream().collect(Collectors.toMap(RunPlanRoutingVO::getCode, Function.identity()));
for (RunPlanTripConfigVO tripConfigVO : serviceConfig.getTripConfigList()) { for (RunPlanTripConfigVO tripConfigVO : serviceConfig.getTripConfigList()) {
// 查询交路 // 查询交路
// MapRoutingDataVO routingData = mapVO.findRoutingDataByCode(tripConfigVO.getRoutingCode());
RunPlanRoutingVO routingData = userRoutingMap.get(tripConfigVO.getRoutingCode()); RunPlanRoutingVO routingData = userRoutingMap.get(tripConfigVO.getRoutingCode());
String endSectionCode = routingData.getEndSectionCode(); // String endSectionCode = routingData.getEndSectionCode();
String startSectionCode = routingData.getStartSectionCode(); // String startSectionCode = routingData.getStartSectionCode();
MapSectionNewVO endSection = mapVO.findSectionNew(endSectionCode); // MapSectionNewVO endSection = mapVO.findSectionNew(endSectionCode);
MapSectionNewVO endReentrySection = null; //// MapSectionNewVO endReentrySection = null;
if (endSection.isStandTrack()) { // if (endSection.isStandTrack()) {
String endReentrySectionCode = userReentryData.get(routingData.getEndStationCode()); // RunPlanUserConfigVO.ReentryTime endReentryTime = userReentryData.get(routingData.getEndStationCode());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(endReentrySectionCode, "车站" + routingData.getEndStationCode() + "折返轨未设置"); // BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(endReentryTime, "车站未设置折返数据");
endReentrySection = mapVO.findSectionNew(endReentrySectionCode); //// endReentrySection = mapVO.findSectionNew(endReentrySectionCode);
} // }
MapSectionNewVO startSection = mapVO.findSectionNew(startSectionCode); // MapSectionNewVO startSection = mapVO.findSectionNew(startSectionCode);
MapSectionNewVO startReentrySection = null; //// MapSectionNewVO startReentrySection = null;
if (startSection.isStandTrack()) { // if (startSection.isStandTrack()) {
String startReentrySectionCode = userReentryData.get(routingData.getStartStationCode()); // RunPlanUserConfigVO.ReentryTime startReentryTime = userReentryData.get(routingData.getStartStationCode());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(startReentrySectionCode, "车站" + routingData.getStartStationCode() + "折返轨未设置"); // BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(startReentryTime, "车站未设置折返数据");
startReentrySection = mapVO.findSectionNew(startReentrySectionCode); //// startReentrySection = mapVO.findSectionNew(startReentrySectionCode);
} // }
RunPlanTripVO tripVO = new RunPlanTripVO(routingData);
RunPlanTripVO tripVO = new RunPlanTripVO(tripConfigVO, routingData, startReentrySection, endReentrySection); setDirectionCode(mapVO.getConfigVO().getUpRight(), tripVO);
if (mapVO.getConfigVO().getUpRight()) { // if (mapVO.getConfigVO().getUpRight()) {
if (routingData.getRight()) { // if (routingData.getRight()) {
tripVO.setDirectionCode(DirectionType.Type02); // tripVO.setDirectionCode(DirectionType.Type02);
} else { // } else {
tripVO.setDirectionCode(DirectionType.Type01); // tripVO.setDirectionCode(DirectionType.Type01);
} // }
} else { // } else {
if (routingData.getRight()) { // if (routingData.getRight()) {
tripVO.setDirectionCode(DirectionType.Type01); // tripVO.setDirectionCode(DirectionType.Type01);
} else { // } else {
tripVO.setDirectionCode(DirectionType.Type02); // tripVO.setDirectionCode(DirectionType.Type02);
} // }
} // }
// 构建类车到站数据 // 构建类车到站数据
tripVO.setServiceNumber(serviceConfig.getServiceNumber()); tripVO.setServiceNumber(serviceConfig.getServiceNumber());
//增加方向码 //增加方向码
List<RunPlanArriveConfigVO> arriveConfigList = tripConfigVO.getArriveConfigList(); List<RunPlanArriveConfigVO> arriveConfigList = tripConfigVO.getArriveConfigList();
arriveConfigList.stream().map(RunPlanTripTimeVO::new).forEach(timeVO -> tripVO.getTimeList().add(timeVO)); arriveConfigList.stream().map(RunPlanTripTimeVO::new).forEach(timeVO -> tripVO.addTime(timeVO));
if (Objects.equals(tripVO.getEndSectionCode(), (new LinkedList<>(tripVO.getTimeList())).getLast().getSectionCode())) { // if (Objects.equals(tripVO.getEndSectionCode(), (new LinkedList<>(tripVO.getTimeList())).getLast().getSectionCode())) {
tripVO.setEndTime(tripConfigVO.getEndTime().minusHours(SimulationConstants.RUN_DIAGRAM_TRANS_TIME)); tripVO.setEndTime(tripConfigVO.getEndTime().minusHours(SimulationConstants.RUN_DIAGRAM_TRANS_TIME));
} // }
if (Objects.equals(tripVO.getStartSectionCode(), (new LinkedList<>(tripVO.getTimeList())).getFirst().getSectionCode())) { // if (Objects.equals(tripVO.getStartSectionCode(), (new LinkedList<>(tripVO.getTimeList())).getFirst().getSectionCode())) {
tripVO.setStartTime(tripConfigVO.getStartTime().minusHours(SimulationConstants.RUN_DIAGRAM_TRANS_TIME)); tripVO.setStartTime(tripConfigVO.getStartTime().minusHours(SimulationConstants.RUN_DIAGRAM_TRANS_TIME));
} // }
newTripList.add(tripVO); newTripList.add(tripVO);
} }
// 添加数据 // 添加数据
@ -688,44 +683,44 @@ public class RunPlanDraftService implements IRunPlanDraftService {
MapVO mapVO = this.iMapService.getMapDetail(runPlanVO.getMapId()); MapVO mapVO = this.iMapService.getMapDetail(runPlanVO.getMapId());
RunPlanUserConfigVO config = runPlanUserConfigService.getConfig(userVO.getId(), mapVO.getId()); RunPlanUserConfigVO config = runPlanUserConfigService.getConfig(userVO.getId(), mapVO.getId());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(config) && config.hasReentryData(), "运行图-用户缺少配置或没有配置车站折返数据"); BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(config) && config.hasReentryData(), "运行图-用户缺少配置或没有配置车站折返数据");
Map<String, String> userReentryData = config.getConfig().getRunPlanUserReentryData(); Map<String, RunPlanUserConfigVO.ReentryTime> userReentryData = config.getConfig().getReentryData();
List<RunPlanRoutingVO> userRoutings = runPlanRoutingService.getUserRoutingBy(userVO.getId(), mapVO.getId()); List<RunPlanRoutingVO> userRoutings = runPlanRoutingService.getUserRoutingBy(userVO.getId(), mapVO.getId());
Map<String, RunPlanRoutingVO> userRoutingMap = userRoutings.stream().collect(Collectors.toMap(RunPlanRoutingVO::getCode, Function.identity())); Map<String, RunPlanRoutingVO> userRoutingMap = userRoutings.stream().collect(Collectors.toMap(RunPlanRoutingVO::getCode, Function.identity()));
String tripNumber = "000"; String tripNumber = "000";
RunPlanTripVO tripVO;
// 查询交路 // 查询交路
// MapRoutingDataVO routing = mapVO.findRoutingDataByCode(tripConfig.getRoutingCode()); // MapRoutingDataVO routing = mapVO.findRoutingDataByCode(tripConfig.getRoutingCode());
RunPlanRoutingVO routingData = userRoutingMap.get(tripConfig.getRoutingCode()); RunPlanRoutingVO routingData = userRoutingMap.get(tripConfig.getRoutingCode());
String endSectionCode = routingData.getEndSectionCode(); // String endSectionCode = routingData.getEndSectionCode();
String startSectionCode = routingData.getStartSectionCode(); // String startSectionCode = routingData.getStartSectionCode();
MapSectionNewVO endSection = mapVO.findSectionNew(endSectionCode); // MapSectionNewVO endSection = mapVO.findSectionNew(endSectionCode);
MapSectionNewVO endReentrySection = null; // MapSectionNewVO endReentrySection = null;
if (endSection.isStandTrack()) { // if (endSection.isStandTrack()) {
String endReentrySectionCode = userReentryData.get(routingData.getEndStationCode()); // String endReentrySectionCode = userReentryData.get(routingData.getEndStationCode());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(endReentrySectionCode, "车站" + routingData.getEndStationCode() + "折返轨未设置"); // BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(endReentrySectionCode, "车站" + routingData.getEndStationCode() + "折返轨未设置");
endReentrySection = mapVO.findSectionNew(endReentrySectionCode); // endReentrySection = mapVO.findSectionNew(endReentrySectionCode);
} // }
MapSectionNewVO startSection = mapVO.findSectionNew(startSectionCode); // MapSectionNewVO startSection = mapVO.findSectionNew(startSectionCode);
MapSectionNewVO startReentrySection = null; // MapSectionNewVO startReentrySection = null;
if (startSection.isStandTrack()) { // if (startSection.isStandTrack()) {
String startReentrySectionCode = userReentryData.get(routingData.getStartStationCode()); // String startReentrySectionCode = userReentryData.get(routingData.getStartStationCode());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(startReentrySectionCode, "车站" + routingData.getStartStationCode() + "折返轨未设置"); // BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(startReentrySectionCode, "车站" + routingData.getStartStationCode() + "折返轨未设置");
startReentrySection = mapVO.findSectionNew(startReentrySectionCode); // startReentrySection = mapVO.findSectionNew(startReentrySectionCode);
} // }
tripVO = new RunPlanTripVO(tripConfig, routingData, startReentrySection, endReentrySection); RunPlanTripVO tripVO = new RunPlanTripVO(routingData);
// 构建类车到站数据 // 构建类车到站数据
// tripVO = new RunPlanTripVO(tripConfig, routing); // tripVO = new RunPlanTripVO(tripConfig, routing);
setDirectionCode(mapVO.getConfigVO().getUpRight(), tripVO); setDirectionCode(mapVO.getConfigVO().getUpRight(), tripVO);
tripVO.setServiceNumber(serviceNumber); tripVO.setServiceNumber(serviceNumber);
tripVO.setTripNumber(tripVO.getDirectionCode() + tripNumber); tripVO.setTripNumber(tripVO.getDirectionCode() + tripNumber);
tripConfig.getArriveConfigList().stream().map(RunPlanTripTimeVO::new).sorted(Comparator.comparing(RunPlanTripTimeVO::getArrivalTime)).forEach(timeVO -> tripVO.getTimeList().add(timeVO)); tripConfig.getArriveConfigList().stream().map(RunPlanTripTimeVO::new).sorted(Comparator.comparing(RunPlanTripTimeVO::getArrivalTime)).forEach(timeVO -> tripVO.getTimeList().add(timeVO));
if (Objects.equals(tripVO.getEndSectionCode(), (new LinkedList<> (tripVO.getTimeList())).getLast().getSectionCode())) { // if (Objects.equals(tripVO.getEndSectionCode(), (new LinkedList<> (tripVO.getTimeList())).getLast().getSectionCode())) {
tripVO.setEndTime(tripConfig.getEndTime().minusHours(SimulationConstants.RUN_DIAGRAM_TRANS_TIME)); tripVO.setEndTime(tripConfig.getEndTime().minusHours(SimulationConstants.RUN_DIAGRAM_TRANS_TIME));
} // }
if (Objects.equals(tripVO.getStartSectionCode(), (new LinkedList<> (tripVO.getTimeList())).getFirst().getSectionCode())) { // if (Objects.equals(tripVO.getStartSectionCode(), (new LinkedList<> (tripVO.getTimeList())).getFirst().getSectionCode())) {
tripVO.setStartTime(tripConfig.getStartTime().minusHours(SimulationConstants.RUN_DIAGRAM_TRANS_TIME)); tripVO.setStartTime(tripConfig.getStartTime().minusHours(SimulationConstants.RUN_DIAGRAM_TRANS_TIME));
} // }
if (CollectionUtils.isEmpty(runPlanVO.getTripList())) { if (CollectionUtils.isEmpty(runPlanVO.getTripList())) {
runPlanVO.setTripList(new ArrayList<>()); runPlanVO.setTripList(new ArrayList<>());

View File

@ -30,5 +30,5 @@ public interface IRunPlanRoutingService {
List<RunPlanRoutingSection> getRoutingSectionDataBy(Long userId, Long planId, String routingCode); List<RunPlanRoutingSection> getRoutingSectionDataBy(Long userId, Long planId, String routingCode);
RunPlanRoutingVO generateUserRouting(RunPlanRoutingVO routingVO); RunPlanRoutingVO generateUserRoutingSections(RunPlanRoutingVO routingVO);
} }

View File

@ -1,474 +0,0 @@
package club.joylink.rtss.services.runplan;
import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.vo.client.map.MapVO;
import club.joylink.rtss.vo.client.map.newmap.MapSectionNewVO;
import club.joylink.rtss.vo.client.runplan.RunPlanTripTimeVO;
import club.joylink.rtss.vo.client.runplan.RunPlanTripVO;
import club.joylink.rtss.vo.client.runplan.user.*;
import club.joylink.rtss.vo.runplan.RunPlanInput;
import club.joylink.rtss.vo.runplan.RunPlanInputData;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.time.LocalTime;
import java.util.*;
import java.util.stream.Collectors;
/**
* 通用运行图生成
*/
@Component
public class RunPlanGenerator {
private static final int OFFSET_TIME_HOURS = 2; //时间偏移早两小时
@Autowired
private IRunPlanRoutingService runPlanRoutingService;
@Autowired
private IRunPlanRunlevelService runPlanRunlevelService;
@Autowired
private IRunPlanParktimeService runPlanParktimeService;
@Autowired
private IRunPlanUserConfigService runPlanUserConfigService;
public List<RunPlanTripVO> generatorTrips(Long userId, RunPlanInput runPlanInput, MapVO mapVO) {
//校验发车停运时间
BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(runPlanInput.getOverTime().isAfter(runPlanInput.getBeginTime()));
//校验车站
LocalTime beginTimeOffset = runPlanInput.getBeginTime().minusHours(OFFSET_TIME_HOURS);
//向前推两小时如果到前一天则时间不合理
BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(runPlanInput.getBeginTime().isAfter(beginTimeOffset), "发车时间过早,建议晚于上午两点");
runPlanInput.setBeginTime(beginTimeOffset);
runPlanInput.setOverTime(runPlanInput.getOverTime().minusHours(OFFSET_TIME_HOURS));
//检查环路
RunPlanRoutingVO running1Routing = runPlanRoutingService.queryUserRoutingByCode(userId, mapVO.getId(), runPlanInput.getRunningRouting1());
RunPlanRoutingVO running2Routing = runPlanRoutingService.queryUserRoutingByCode(userId, mapVO.getId(), runPlanInput.getRunningRouting2());
boolean isLoop = running1Routing.getParkSectionCodeList().get(0).getStationCode().equals(running2Routing.getParkSectionCodeList().get(running2Routing.getParkSectionCodeList().size() - 1).getStationCode())
&& running2Routing.getParkSectionCodeList().get(0).getStationCode().equals(running1Routing.getParkSectionCodeList().get(running1Routing.getParkSectionCodeList().size() - 1).getStationCode());
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(isLoop, "运行两交路无法构成环路数据");
//查站间运行等级
List<RunPlanRunlevelVO> levels = runPlanRunlevelService.queryUserRunLevels(userId, mapVO.getId());
Map<String, Integer> runLevelTime = levels.stream().collect(Collectors.toMap(runLevelVO -> String.format("%s-%s", runLevelVO.getStartSectionCode(), runLevelVO.getEndSectionCode()), runLevelVO -> runLevelVO.getLevelTime(runPlanInput.getRunLevel())));
//查停站时间
List<RunPlanParkingTimeVO> parkTimes = runPlanParktimeService.queryUserParktimes(userId, mapVO.getId());
Map<String, Integer> parkTime = parkTimes.stream().collect(Collectors.toMap(RunPlanParkingTimeVO::getSectionCode, RunPlanParkingTimeVO::getParkingTime));
//查折返
RunPlanUserConfigVO config = runPlanUserConfigService.getConfig(userId, mapVO.getId());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(config) && config.hasReentryData(), "运行图-用户缺少配置或没有配置车站折返数据");
Map<String, String> userReentryData = config.getConfig().getRunPlanUserReentryData();
// 检测折返轨配置
if (Objects.isNull(userReentryData.get(running1Routing.getParkSectionCodeList().get(0).getStationCode()))
|| Objects.isNull(userReentryData.get(running1Routing.getParkSectionCodeList().get(running1Routing.getParkSectionCodeList().size() - 1).getStationCode()))) {
throw BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.exception("折返轨未设置");
}
//生成车次
LinkedList<RunPlanTripVO> tripList = new LinkedList<>();
//是否同时相向发车
boolean opposite = Objects.isNull(runPlanInput.getRight());
if (opposite) {
//相向发车
int initialServiceNum = 1;
/*分别先发一辆车,计算控制左右发车服务号*/
//上个服务号发车时刻
//首班发车时间,首班车往返回来时间 来限定发车服务数量
ServiceTempResult tempResultLeft = new ServiceTempResult(runPlanInput.getBeginTime(), null);
serviceNumberDepart(mapVO, runPlanInput, running1Routing, running2Routing, initialServiceNum++, tripList, tempResultLeft, false, runLevelTime, parkTime, userReentryData);
//上个服务号发车时刻
//首班发车时间,首班车往返回来时间 来限定发车服务数量
ServiceTempResult tempResultRight = new ServiceTempResult(runPlanInput.getBeginTime(), null);
serviceNumberDepart(mapVO, runPlanInput, running1Routing, running2Routing, initialServiceNum++, tripList, tempResultRight, true, runLevelTime, parkTime, userReentryData);
LocalTime firstRoundTripTimeLeft = tempResultLeft.getFirstRoundTripTime();
LocalTime firstRoundTripTimeRight = tempResultRight.getFirstRoundTripTime();
tempResultRight.setFirstRoundTripTime(firstRoundTripTimeLeft);
tempResultLeft.setFirstRoundTripTime(firstRoundTripTimeRight);
//暂时先定义发完左行再发右行..
do {
tempResultLeft.setPreServiceDepartTime(tempResultLeft.getPreServiceDepartTime().plusSeconds(runPlanInput.getDepartureTimeInterval()));
serviceNumberDepart(mapVO, runPlanInput, running1Routing, running2Routing, initialServiceNum++, tripList, tempResultLeft, false, runLevelTime, parkTime, userReentryData);
} while (tempResultLeft.getPreServiceDepartTime().minusSeconds(runPlanInput.getReentryTime()).plusSeconds(runPlanInput.getDepartureTimeInterval() * 2).compareTo(tempResultLeft.getFirstRoundTripTime()) <= 0);
//发完左行再发右行
do {
tempResultRight.setPreServiceDepartTime(tempResultRight.getPreServiceDepartTime().plusSeconds(runPlanInput.getDepartureTimeInterval()));
serviceNumberDepart(mapVO, runPlanInput, running1Routing, running2Routing, initialServiceNum++, tripList, tempResultRight, true, runLevelTime, parkTime, userReentryData);
} while (tempResultRight.getPreServiceDepartTime().minusSeconds(runPlanInput.getReentryTime()).plusSeconds(runPlanInput.getDepartureTimeInterval() * 2).compareTo(tempResultRight.getFirstRoundTripTime()) <= 0);
} else {
//单向发车
allServiceNumberDepart(mapVO, runPlanInput, running1Routing, running2Routing, tripList, runLevelTime, parkTime, userReentryData);
}
return tripList;
}
/**
* 服务号发车
*/
private void serviceNumberDepart(MapVO mapVO, RunPlanInput runPlanInput, RunPlanRoutingVO running1Routing, RunPlanRoutingVO running2Routing, int initialServiceNum, LinkedList<RunPlanTripVO> tripList, ServiceTempResult tempResult, boolean isRight, Map<String, Integer> runLevelTime, Map<String, Integer> parkTime, Map<String, String> userReentryData) {
String serviceNumber = String.format("%03d", initialServiceNum);
//初始化车次号,右行偶数左行奇数
int initTripNumber = isRight ? 0 : 1;
LocalTime lastTripEndTime = null;//一个车次终点时间
LinkedList<RunPlanTripVO> tempTripList = new LinkedList<>();
//根据运行时间判断结束末班车次
do {
RunPlanRoutingVO routing = Objects.equals(running1Routing.getRight(), isRight) ? running1Routing : running2Routing;
String startReentrySectionCode = userReentryData.get(routing.getStartStationCode());
String endReentrySectionCode = userReentryData.get(routing.getEndStationCode());
MapSectionNewVO endReentrySection = null;
if (Objects.nonNull(endReentrySectionCode)) {
endReentrySection = mapVO.findSectionNew(endReentrySectionCode);
}
MapSectionNewVO startReentrySection = null;
if (Objects.nonNull(startReentrySectionCode)) {
startReentrySection = mapVO.findSectionNew(startReentrySectionCode);
}
RunPlanTripVO runPlanTripVO = new RunPlanTripVO(routing, startReentrySection, endReentrySection);
runPlanTripVO.setServiceNumber(serviceNumber);
setDirectionCode(mapVO, runPlanTripVO);
runPlanTripVO.setIsReentry(true);
//车次号
String tripNumber = String.format("%03d", initTripNumber++);
runPlanTripVO.setTripNumber(runPlanTripVO.getDirectionCode() + tripNumber);
//首班右行方向
LinkedList<RunPlanTripTimeVO> tripTimeList = new LinkedList<>();//车次时刻表
routing.getParkSectionCodeList().forEach(runPlanRoutingSection -> {
RunPlanTripTimeVO runPlanTripTimeVO = new RunPlanTripTimeVO();
runPlanTripTimeVO.setStationCode(runPlanRoutingSection.getStationCode());
runPlanTripTimeVO.setSectionCode(runPlanRoutingSection.getSectionCode());
runPlanTripTimeVO.setArrivalTime(CollectionUtils.isEmpty(tempTripList) && CollectionUtils.isEmpty(tripTimeList) ?
tempResult.getPreServiceDepartTime() :
(CollectionUtils.isEmpty(tripTimeList) ?
(Objects.equals(tempTripList.getLast().getEndSectionCode(), runPlanTripTimeVO.getSectionCode()) ?
tempTripList.getLast().getEndTime() : ((LinkedList<RunPlanTripTimeVO>) tempTripList.getLast().getTimeList()).getLast().getDepartureTime().plusSeconds(runPlanInput.getReentryTime())) : tripTimeList.getLast().getDepartureTime().plusSeconds(runLevelTime.get(tripTimeList.getLast().getSectionCode() + "-" + runPlanTripTimeVO.getSectionCode()))));
runPlanTripTimeVO.setDepartureTime(CollectionUtils.isEmpty(tempTripList) && CollectionUtils.isEmpty(tripTimeList) ? tempResult.getPreServiceDepartTime() : runPlanTripTimeVO.getArrivalTime().plusSeconds(parkTime.getOrDefault(runPlanTripTimeVO.getSectionCode(), 0)));
tripTimeList.add(runPlanTripTimeVO);
});
runPlanTripVO.setTimeList(tripTimeList);
setTripTerminalTime(runPlanTripVO, tripTimeList, runPlanInput.getReentryTime());
lastTripEndTime = runPlanTripVO.getEndTime();
if(CollectionUtils.isEmpty(tempTripList)){
runPlanTripVO.setIsOutbound(true);
}
tempTripList.add(runPlanTripVO);
if (tempTripList.size() > 50) { // 最快半小时跑一趟的一天车次数如果大于这个可能死循环此时停止发车
break;
}
isRight = !isRight;
} while (lastTripEndTime.isBefore(runPlanInput.getOverTime()));
//设置服务号末班车次入库
RunPlanTripVO lastrunPlanTrip = tempTripList.get(tempTripList.size() - 1);
lastrunPlanTrip.setIsInbound(true);
lastrunPlanTrip.setIsReentry(false);
LinkedList<RunPlanTripTimeVO> tripTimeList = (LinkedList<RunPlanTripTimeVO>) lastrunPlanTrip.getTimeList();
setTripEndTime(lastrunPlanTrip, tripTimeList, runPlanInput.getReentryTime());
tripList.addAll(tempTripList);
if (Objects.isNull(tempResult.getFirstRoundTripTime())) {
tempResult.setFirstRoundTripTime(((RunPlanTripTimeVO) (((LinkedList) (tempTripList.get(0).getTimeList())).getLast())).getDepartureTime());
}
tempResult.setPreServiceDepartTime(((RunPlanTripTimeVO) (((LinkedList) (tempTripList.get(0).getTimeList())).getFirst())).getArrivalTime());
}
/**
* 单向发车
*/
private void allServiceNumberDepart(MapVO mapVO, RunPlanInput runPlanInput, RunPlanRoutingVO running1Routing, RunPlanRoutingVO running2Routing, LinkedList<RunPlanTripVO> tripList, Map<String, Integer> runLevelTime, Map<String, Integer> parkTime, Map<String, String> userReentryData) {
//设置初始服务号
int initialServiceNum = 1;
//上个服务号发车时刻
//首班发车时间,首班车往返回来时间 来限定发车服务数量
ServiceTempResult tempResult = new ServiceTempResult(runPlanInput.getBeginTime(), null);
do {
if (initialServiceNum != 1) {
tempResult.setPreServiceDepartTime(tempResult.getPreServiceDepartTime().plusSeconds(runPlanInput.getDepartureTimeInterval()));
}
serviceNumberDepart(mapVO, runPlanInput, running1Routing, running2Routing, initialServiceNum++, tripList, tempResult, runPlanInput.getRight(), runLevelTime, parkTime, userReentryData);
} while (tempResult.getPreServiceDepartTime().minusSeconds(runPlanInput.getReentryTime()).plusSeconds(runPlanInput.getDepartureTimeInterval() * 2).compareTo(tempResult.getFirstRoundTripTime()) <= 0);
}
public List<RunPlanTripVO> generatorTrips(Long userId, RunPlanInputData inputData, MapVO mapVO) {
//校验时间
BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(inputData.getOverTime().isAfter(inputData.getBeginTime()),"输入参数错误:发车时间应早于结束时间");
LocalTime beginTimeOffset = inputData.getBeginTime().minusHours(OFFSET_TIME_HOURS);
//向前推两小时如果到前一天则时间不合理
BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(inputData.getBeginTime().isAfter(beginTimeOffset), "发车时间过早,建议晚于上午两点");
inputData.setBeginTime(beginTimeOffset);
inputData.setOverTime(inputData.getOverTime().minusHours(OFFSET_TIME_HOURS));
//查交路
RunPlanRoutingVO outboundRouting = null;
if (inputData.hasOutbound()) {
outboundRouting = runPlanRoutingService.queryUserRoutingByCode(userId, mapVO.getId(), inputData.getOutboundRouting());
}
RunPlanRoutingVO inboundRouting = null;
if (inputData.hasInbound()) {
inboundRouting = runPlanRoutingService.queryUserRoutingByCode(userId, mapVO.getId(), inputData.getInboundRouting());
}
RunPlanRoutingVO running1Routing = runPlanRoutingService.queryUserRoutingByCode(userId, mapVO.getId(), inputData.getRunningRouting1());
RunPlanRoutingVO running2Routing = runPlanRoutingService.queryUserRoutingByCode(userId, mapVO.getId(), inputData.getRunningRouting2());
//构建环路 出入库关系
//验证 出库和入库 一端折返轨 一段转换轨验证环路 两端折返轨 环路是否闭环 或出入库跟环路是否衔接
boolean isLoop = running1Routing.getParkSectionCodeList().get(0).getStationCode().equals(running2Routing.getParkSectionCodeList().get(running2Routing.getParkSectionCodeList().size() - 1).getStationCode())
&& running2Routing.getParkSectionCodeList().get(0).getStationCode().equals(running1Routing.getParkSectionCodeList().get(running1Routing.getParkSectionCodeList().size() - 1).getStationCode());
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(isLoop, "运行两交路无法构成环路数据");
boolean outToRun1 = outboundRouting.getParkSectionCodeList().get(outboundRouting.getParkSectionCodeList().size() - 1).getStationCode().equals(running1Routing.getParkSectionCodeList().get(0).getStationCode());
boolean outToRun2 = outboundRouting.getParkSectionCodeList().get(outboundRouting.getParkSectionCodeList().size() - 1).getStationCode().equals(running2Routing.getParkSectionCodeList().get(0).getStationCode());
boolean inToRun1 = inboundRouting.getParkSectionCodeList().get(0).getStationCode().equals(running1Routing.getParkSectionCodeList().get(running1Routing.getParkSectionCodeList().size() - 1).getStationCode());
boolean inToRun2 = inboundRouting.getParkSectionCodeList().get(0).getStationCode().equals(running2Routing.getParkSectionCodeList().get(running2Routing.getParkSectionCodeList().size() - 1).getStationCode());
//出库关联环路某交楼
RunPlanRoutingVO outRef = null;
//环路其它交路
RunPlanRoutingVO other = null;
boolean same = false;
if (outToRun1 && inToRun1) {
same = true;
outRef = running1Routing;
other = running2Routing;
} else if (outToRun2 && inToRun2) {
same = true;
outRef = running2Routing;
other = running1Routing;
} else if (outToRun1 && inToRun2) {
outRef = running1Routing;
other = running2Routing;
} else if (outToRun2 && inToRun1) {
outRef = running2Routing;
other = running1Routing;
} else {
throw BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.exception("出库交路 无法与环路交路相接");
}
//查站间运行等级
List<RunPlanRunlevelVO> levels = runPlanRunlevelService.queryUserRunLevels(userId, mapVO.getId());
Map<String, Integer> runLevelMap = levels.stream().collect(Collectors.toMap(runLevelVO -> String.format("%s-%s", runLevelVO.getStartSectionCode(), runLevelVO.getEndSectionCode()), runLevelVO -> runLevelVO.getLevelTime(inputData.getRunLevel())));
//查停站时间
List<RunPlanParkingTimeVO> parktimes = runPlanParktimeService.queryUserParktimes(userId, mapVO.getId());
Map<String, Integer> parkTimeMap = parktimes.stream().collect(Collectors.toMap(RunPlanParkingTimeVO::getSectionCode, RunPlanParkingTimeVO::getParkingTime));
//查折返
RunPlanUserConfigVO config = runPlanUserConfigService.getConfig(userId, mapVO.getId());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(config) && config.hasReentryData(), "运行图-用户缺少配置或没有配置车站折返数据");
Map<String, String> userReentryData = config.getConfig().getRunPlanUserReentryData();
// 检测折返轨配置
if (Objects.isNull(userReentryData.get(running1Routing.getParkSectionCodeList().get(0).getStationCode()))
|| Objects.isNull(userReentryData.get(running1Routing.getParkSectionCodeList().get(running1Routing.getParkSectionCodeList().size() - 1).getStationCode()))) {
throw BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.exception("折返轨未设置");
}
List<RunPlanTripVO> tripList = new ArrayList<>(100);
ServiceTempResult serviceResult = new ServiceTempResult();
//单个服务号还是多个
if (Objects.nonNull(inputData.getDepartureInterval())) {
do {
generateService(inputData, mapVO, outboundRouting, inboundRouting, outRef, same, other, runLevelMap, parkTimeMap, userReentryData, tripList, serviceResult);
inputData.setServiceNumber(String.format("%03d", Integer.parseInt(inputData.getServiceNumber()) + 1));
inputData.setBeginTime(inputData.getBeginTime().plusSeconds(inputData.getDepartureInterval()));
} while (serviceResult.preServiceDepartTime.plusSeconds(inputData.getDepartureInterval()).compareTo(serviceResult.firstRoundTripTime) <= 0);
} else {
generateService(inputData, mapVO, outboundRouting, inboundRouting, outRef, same, other, runLevelMap, parkTimeMap, userReentryData, tripList, serviceResult);
}
return tripList;
}
private void generateService(RunPlanInputData inputData, MapVO mapVO, RunPlanRoutingVO outboundRouting, RunPlanRoutingVO inboundRouting, RunPlanRoutingVO outRef, final boolean same, RunPlanRoutingVO other, Map<String, Integer> runLevelMap, Map<String, Integer> parkTimeMap, Map<String, String> userReentryData, List<RunPlanTripVO> tripList, ServiceTempResult serviceResult) {
LinkedList<RunPlanTripVO> serviceTripList = new LinkedList<>();
int initTripNumber = 1;
TripTempResult temp = new TripTempResult(initTripNumber, inputData.getBeginTime());
//构建出库车次
buildServiceTrips(inputData, mapVO, outboundRouting, true, runLevelMap, parkTimeMap, userReentryData, serviceTripList, temp);
//计算出库车次运行所需时间
int size = inboundRouting.getParkSectionCodeList().size();
int inboundTripRunTime = inputData.getReentryTime()/2;
for (int i = 0; i < size - 1; i++) {
RunPlanRoutingSection routingSection = inboundRouting.getParkSectionCodeList().get(i);
RunPlanRoutingSection nextRoutingSection = inboundRouting.getParkSectionCodeList().get(i + 1);
Integer parkTime = parkTimeMap.get(routingSection.getSectionCode() );
Integer runTime = runLevelMap.get(routingSection.getSectionCode() + "-" + nextRoutingSection.getSectionCode());
inboundTripRunTime = inboundTripRunTime + parkTime + runTime;
}
//计算出库对接环路运行所需时间
int oSize = outRef.getParkSectionCodeList().size();
int outRefTripRunTime = inputData.getReentryTime()+parkTimeMap.get(outRef.getParkSectionCodeList().get(oSize - 1).getSectionCode());
for (int i = 0; i < oSize - 1; i++) {
RunPlanRoutingSection routingSection = outRef.getParkSectionCodeList().get(i);
RunPlanRoutingSection nextRoutingSection = outRef.getParkSectionCodeList().get(i + 1);
Integer parkTime = parkTimeMap.get(routingSection.getSectionCode());
Integer runTime = runLevelMap.get(routingSection.getSectionCode() + "-" + nextRoutingSection.getSectionCode());
outRefTripRunTime = outRefTripRunTime + parkTime + runTime;
}
//计算另一环路运行所需时间
int iSize = other.getParkSectionCodeList().size();
int otherTripRunTime = inputData.getReentryTime()+parkTimeMap.get(other.getParkSectionCodeList().get(iSize - 1).getSectionCode());
for (int i = 0; i < iSize - 1; i++) {
RunPlanRoutingSection routingSection = other.getParkSectionCodeList().get(i);
RunPlanRoutingSection nextRoutingSection = other.getParkSectionCodeList().get(i + 1);
Integer parkTime = parkTimeMap.get(routingSection.getSectionCode());
Integer runTime = runLevelMap.get(routingSection.getSectionCode() + "-" + nextRoutingSection.getSectionCode());
otherTripRunTime = otherTripRunTime + parkTime + runTime;
}
if (same ? true :
(temp.getLastStationDepartTime().plusSeconds(inputData.getReentryTime()/2 + inboundTripRunTime).isBefore(inputData.getOverTime()) &&
(temp.getLastStationDepartTime().plusSeconds(inputData.getReentryTime()/2).getHour()<3
|| temp.getLastStationDepartTime().plusSeconds(inputData.getReentryTime()/2 + outRefTripRunTime + otherTripRunTime + inboundTripRunTime).getHour()>3))
) {
//构建环路车次
boolean loop = false;
do {
if (same) {
if (!loop) {
buildServiceTrips(inputData, mapVO, outRef, null, runLevelMap, parkTimeMap, userReentryData, serviceTripList, temp);
loop = true;
} else {
buildServiceTrips(inputData, mapVO, other, null, runLevelMap, parkTimeMap, userReentryData, serviceTripList, temp);
buildServiceTrips(inputData, mapVO, outRef, null, runLevelMap, parkTimeMap, userReentryData, serviceTripList, temp);
}
} else {
buildServiceTrips(inputData, mapVO, outRef, null, runLevelMap, parkTimeMap, userReentryData, serviceTripList, temp);
buildServiceTrips(inputData, mapVO, other, null, runLevelMap, parkTimeMap, userReentryData, serviceTripList, temp);
}
}
while (temp.getLastStationDepartTime().plusSeconds(inputData.getReentryTime()/2 + inboundTripRunTime).isBefore(inputData.getOverTime())
&&
(temp.getLastStationDepartTime().plusSeconds(inputData.getReentryTime()/2).getHour()<3||temp.getLastStationDepartTime().plusSeconds(inputData.getReentryTime()/2 + outRefTripRunTime + otherTripRunTime + inboundTripRunTime).getHour()>3));
}
//构建回库计划
buildServiceTrips(inputData, mapVO, inboundRouting, false, runLevelMap, parkTimeMap, userReentryData, serviceTripList, temp);
if (Objects.isNull(serviceResult.getFirstRoundTripTime())) {
serviceResult.setFirstRoundTripTime(serviceTripList.get(1).getEndTime());
}
serviceResult.setPreServiceDepartTime(serviceTripList.getFirst().getStartTime());
tripList.addAll(serviceTripList);
}
private void buildServiceTrips(RunPlanInputData inputData, MapVO mapVO, RunPlanRoutingVO routing, Boolean outbound,
Map<String, Integer> runLevelMap, Map<String, Integer> parkTimeMap, Map<String, String> userReentryData,
LinkedList<RunPlanTripVO> tripList, TripTempResult tempResult) {
String startReentrySectionCode = userReentryData.get(routing.getStartStationCode());
String endReentrySectionCode = userReentryData.get(routing.getEndStationCode());
MapSectionNewVO endReentrySection = null;
if (Objects.nonNull(endReentrySectionCode)) {
endReentrySection = mapVO.findSectionNew(endReentrySectionCode);
}
MapSectionNewVO startReentrySection = null;
if (Objects.nonNull(startReentrySectionCode)) {
startReentrySection = mapVO.findSectionNew(startReentrySectionCode);
}
RunPlanTripVO tripVO = new RunPlanTripVO(routing, startReentrySection, endReentrySection);
setDirectionCode(mapVO, tripVO);
tripVO.setServiceNumber(inputData.getServiceNumber());
tripVO.setTripNumber(tripVO.getDirectionCode() + String.format("%03d", tempResult.getTripNumber()));
tripVO.setIsReentry(true);
if (Objects.nonNull(outbound)) {
if (outbound) {
tripVO.setIsOutbound(true);
} else {
tripVO.setIsInbound(true);
tripVO.setIsReentry(false);
}
}
LinkedList<RunPlanTripTimeVO> tripTimeList = new LinkedList<>();
routing.getParkSectionCodeList().forEach(runPlanRoutingSection -> {
RunPlanTripTimeVO runPlanTripTimeVO = new RunPlanTripTimeVO();
runPlanTripTimeVO.setStationCode(runPlanRoutingSection.getStationCode());
runPlanTripTimeVO.setSectionCode(runPlanRoutingSection.getSectionCode());
runPlanTripTimeVO.setArrivalTime(CollectionUtils.isEmpty(tripList) && CollectionUtils.isEmpty(tripTimeList) ?
tempResult.getLastStationDepartTime() :
(CollectionUtils.isEmpty(tripTimeList) ?
(Objects.equals(tripList.getLast().getEndSectionCode(), runPlanTripTimeVO.getSectionCode()) ?
tripList.getLast().getEndTime() : tempResult.getLastStationDepartTime().plusSeconds(inputData.getReentryTime())) : tempResult.getLastStationDepartTime().plusSeconds(runLevelMap.get(tripTimeList.getLast().getSectionCode() + "-" + runPlanTripTimeVO.getSectionCode()))));
runPlanTripTimeVO.setDepartureTime(CollectionUtils.isEmpty(tripList) && CollectionUtils.isEmpty(tripTimeList) ? tempResult.getLastStationDepartTime() : runPlanTripTimeVO.getArrivalTime().plusSeconds(parkTimeMap.getOrDefault(runPlanTripTimeVO.getSectionCode(), 0)));
tempResult.setLastStationDepartTime(runPlanTripTimeVO.getDepartureTime());
tripTimeList.add(runPlanTripTimeVO);
});
tripVO.setTimeList(tripTimeList);
setTripTerminalTime(tripVO, tripTimeList, inputData.getReentryTime());
tripList.add(tripVO);
tempResult.incrementTripNumber();
}
private void setDirectionCode(MapVO mapVO, RunPlanTripVO tripVO) {
if (mapVO.getConfigVO().getUpRight()) {
if (tripVO.getRight()) {
tripVO.setDirectionCode(BusinessConsts.RunPlan.DirectionType.Type02);
} else {
tripVO.setDirectionCode(BusinessConsts.RunPlan.DirectionType.Type01);
}
} else {
if (tripVO.getRight()) {
tripVO.setDirectionCode(BusinessConsts.RunPlan.DirectionType.Type01);
} else {
tripVO.setDirectionCode(BusinessConsts.RunPlan.DirectionType.Type02);
}
}
}
public void setTripTerminalTime(RunPlanTripVO runPlanTripVO, LinkedList<RunPlanTripTimeVO> tripTimeList, int reentryTime) {
setTripStartTime(runPlanTripVO, tripTimeList, reentryTime);
setTripEndTime(runPlanTripVO, tripTimeList, reentryTime);
}
private void setTripEndTime(RunPlanTripVO lastRunPlanTrip, LinkedList<RunPlanTripTimeVO> tripTimeList, int reentryTime) {
if (Objects.equals(lastRunPlanTrip.getEndSectionCode(), tripTimeList.getLast().getSectionCode())) {
lastRunPlanTrip.setEndTime(tripTimeList.getLast().getDepartureTime());
} else {
lastRunPlanTrip.setEndTime(tripTimeList.getLast().getDepartureTime().plusSeconds(reentryTime / 2));
}
}
private void setTripStartTime(RunPlanTripVO runPlanTripVO, LinkedList<RunPlanTripTimeVO> tripTimeList, int reentryTime) {
if (Objects.equals(runPlanTripVO.getStartSectionCode(), tripTimeList.getFirst().getSectionCode())) {
runPlanTripVO.setStartTime(tripTimeList.getFirst().getArrivalTime());
} else {
runPlanTripVO.setStartTime(tripTimeList.getFirst().getArrivalTime().minusSeconds(reentryTime / 2));
}
}
@Getter
@Setter
@AllArgsConstructor
private class TripTempResult {
private int tripNumber;
private LocalTime lastStationDepartTime;
public void incrementTripNumber() {
tripNumber++;
}
}
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
private class ServiceTempResult {
private LocalTime preServiceDepartTime;
private LocalTime firstRoundTripTime;
}
}

View File

@ -11,7 +11,6 @@ import club.joylink.rtss.simulation.cbtc.build.SimulationBuilder;
import club.joylink.rtss.simulation.cbtc.data.CalculateService; import club.joylink.rtss.simulation.cbtc.data.CalculateService;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement; import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.Section; import club.joylink.rtss.simulation.cbtc.data.map.Section;
import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition;
import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.util.JsonUtils; import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
@ -53,7 +52,7 @@ public class RunPlanRoutingService implements IRunPlanRoutingService {
@Transactional @Transactional
@Override @Override
public void createUserRouting(RunPlanRoutingVO routingVO) { public void createUserRouting(RunPlanRoutingVO routingVO) {
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(ifRoutingDataExist(routingVO),"存在相同经停轨道的交路"); BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(ifRoutingDataExist(routingVO), "存在相同经停轨道的交路");
MapVO map = this.iMapService.getMapDetail(routingVO.getMapId()); MapVO map = this.iMapService.getMapDetail(routingVO.getMapId());
SimulationBuilder.SimulationDeviceBuildResult buildResult = SimulationBuilder.checkAndBuildMapDeviceData(map); SimulationBuilder.SimulationDeviceBuildResult buildResult = SimulationBuilder.checkAndBuildMapDeviceData(map);
BusinessExceptionAssertEnum.DATA_ERROR.assertCollectionEmpty(buildResult.getErrMsgList(), BusinessExceptionAssertEnum.DATA_ERROR.assertCollectionEmpty(buildResult.getErrMsgList(),
@ -61,14 +60,14 @@ public class RunPlanRoutingService implements IRunPlanRoutingService {
Map<String, MapElement> deviceMap = buildResult.getDeviceMap(); Map<String, MapElement> deviceMap = buildResult.getDeviceMap();
Section startSection = (Section) deviceMap.get(routingVO.getStartSectionCode()); Section startSection = (Section) deviceMap.get(routingVO.getStartSectionCode());
Section endSection = (Section) deviceMap.get(routingVO.getEndSectionCode()); Section endSection = (Section) deviceMap.get(routingVO.getEndSectionCode());
if (startSection.isTransferTrack() && endSection.isTransferTrack()) { if (startSection.isTransferTrack() && endSection.isTurnBackTrack()) {
routingVO.setRoutingType(RunPlanRoutingVO.UserRoutingType.OTHER);
} else if (startSection.isTransferTrack()) {
routingVO.setRoutingType(RunPlanRoutingVO.UserRoutingType.OUTBOUND); routingVO.setRoutingType(RunPlanRoutingVO.UserRoutingType.OUTBOUND);
} else if (endSection.isTransferTrack()) { } else if (startSection.isTurnBackTrack() && endSection.isTransferTrack()) {
routingVO.setRoutingType(RunPlanRoutingVO.UserRoutingType.INBOUND); routingVO.setRoutingType(RunPlanRoutingVO.UserRoutingType.INBOUND);
} else { } else if (startSection.isTurnBackTrack() && endSection.isTurnBackTrack()) {
routingVO.setRoutingType(RunPlanRoutingVO.UserRoutingType.LOOP); routingVO.setRoutingType(RunPlanRoutingVO.UserRoutingType.LOOP);
} else {
routingVO.setRoutingType(RunPlanRoutingVO.UserRoutingType.OTHER);
} }
RunPlanRouting routing = routingVO.convert2Entity(); RunPlanRouting routing = routingVO.convert2Entity();
runPlanRoutingDAO.insert(routing); runPlanRoutingDAO.insert(routing);
@ -77,7 +76,7 @@ public class RunPlanRoutingService implements IRunPlanRoutingService {
} }
@Override @Override
public RunPlanRoutingVO generateUserRouting(RunPlanRoutingVO routingVO) { public RunPlanRoutingVO generateUserRoutingSections(RunPlanRoutingVO routingVO) {
MapVO map = this.iMapService.getMapDetail(routingVO.getMapId()); MapVO map = this.iMapService.getMapDetail(routingVO.getMapId());
SimulationBuilder.SimulationDeviceBuildResult buildResult = SimulationBuilder.checkAndBuildMapDeviceData(map); SimulationBuilder.SimulationDeviceBuildResult buildResult = SimulationBuilder.checkAndBuildMapDeviceData(map);
BusinessExceptionAssertEnum.DATA_ERROR.assertCollectionEmpty(buildResult.getErrMsgList(), BusinessExceptionAssertEnum.DATA_ERROR.assertCollectionEmpty(buildResult.getErrMsgList(),
@ -113,14 +112,14 @@ public class RunPlanRoutingService implements IRunPlanRoutingService {
Map<String, MapElement> deviceMap = buildResult.getDeviceMap(); Map<String, MapElement> deviceMap = buildResult.getDeviceMap();
Section startSection = (Section) deviceMap.get(routingVO.getStartSectionCode()); Section startSection = (Section) deviceMap.get(routingVO.getStartSectionCode());
Section endSection = (Section) deviceMap.get(routingVO.getEndSectionCode()); Section endSection = (Section) deviceMap.get(routingVO.getEndSectionCode());
if (startSection.isTransferTrack() && endSection.isTransferTrack()) { if (startSection.isTransferTrack() && endSection.isTurnBackTrack()) {
routingVO.setRoutingType(RunPlanRoutingVO.UserRoutingType.OTHER);
} else if (startSection.isTransferTrack()) {
routingVO.setRoutingType(RunPlanRoutingVO.UserRoutingType.OUTBOUND); routingVO.setRoutingType(RunPlanRoutingVO.UserRoutingType.OUTBOUND);
} else if (endSection.isTransferTrack()) { } else if (startSection.isTurnBackTrack() && endSection.isTransferTrack()) {
routingVO.setRoutingType(RunPlanRoutingVO.UserRoutingType.INBOUND); routingVO.setRoutingType(RunPlanRoutingVO.UserRoutingType.INBOUND);
} else { } else if (startSection.isTurnBackTrack() && endSection.isTurnBackTrack()) {
routingVO.setRoutingType(RunPlanRoutingVO.UserRoutingType.LOOP); routingVO.setRoutingType(RunPlanRoutingVO.UserRoutingType.LOOP);
} else {
routingVO.setRoutingType(RunPlanRoutingVO.UserRoutingType.OTHER);
} }
RunPlanRouting newRouting = routingVO.convert2Entity(); RunPlanRouting newRouting = routingVO.convert2Entity();
newRouting.setId(routingId); newRouting.setId(routingId);
@ -132,25 +131,29 @@ public class RunPlanRoutingService implements IRunPlanRoutingService {
private void generateUserParktimes(RunPlanRoutingVO routingVO, Map<String, MapElement> deviceMap) { private void generateUserParktimes(RunPlanRoutingVO routingVO, Map<String, MapElement> deviceMap) {
List<RunPlanParkingTimeVO> parkingTimeVOS = RunPlanParkingTimeVO.parkingTimeFromRouting(routingVO); List<RunPlanParkingTimeVO> parkingTimeVOS = RunPlanParkingTimeVO.parkingTimeFromRouting(routingVO);
parkingTimeVOS.forEach(p -> { parkingTimeVOS.forEach(p -> {
if (!((Section) deviceMap.get(p.getSectionCode())).isTransferTrack() && !planParktimeService.isExisted(p)) { // if (!((Section) deviceMap.get(p.getSectionCode())).isTransferTrack() && !planParktimeService.isExisted(p)) {
if (((Section) deviceMap.get(p.getSectionCode())).isStandTrack() && !planParktimeService.isExisted(p)) {
planParktimeService.createUserParktime(p); planParktimeService.createUserParktime(p);
} }
}); });
} }
private void generateUserRunlevels(RunPlanRoutingVO routingVO, Map<String, MapElement> deviceMap) { private void generateUserRunlevels(RunPlanRoutingVO routingVO, Map<String, MapElement> deviceMap) {
List<RunPlanRunlevelVO> levels = RunPlanRunlevelVO.runLevelsFromRouting(routingVO); List<RunPlanRunlevelVO> levels = RunPlanRunlevelVO.runLevelsFromRouting(routingVO);
levels.forEach(l -> { levels.forEach(l -> {
Section startSection = (Section) deviceMap.get(l.getStartSectionCode());
Section endSection = (Section) deviceMap.get(l.getEndSectionCode());
if ((startSection.isTurnBackTrack() && !startSection.isStandTrack())
|| (endSection.isTurnBackTrack() && !endSection.isStandTrack())) {
return;
}
if (!planRunlevelService.isExisted(l)) { if (!planRunlevelService.isExisted(l)) {
Section startSection = (Section) deviceMap.get(l.getStartSectionCode()); if ((startSection.isStandTrack() && endSection.isTransferTrack()) || (endSection.isStandTrack() && startSection.isTransferTrack())) {
Section endSection = (Section) deviceMap.get(l.getEndSectionCode());
if((startSection.isStandTrack() && endSection.isTransferTrack()) || (endSection.isStandTrack() && startSection.isTransferTrack())){
Float distance; Float distance;
try{ try {
distance = CalculateService.calculateDistance(startSection, endSection, l.getRight()); distance = CalculateService.calculateDistance(startSection, endSection, l.getRight());
}catch (SimulationException e){ } catch (SimulationException e) {
distance = CalculateService.calculateDistance(startSection, endSection, !l.getRight()); distance = CalculateService.calculateDistance(startSection, endSection, !l.getRight());
} }
l.setDistance(distance); l.setDistance(distance);
l.generateDefaultRunLevel(); l.generateDefaultRunLevel();
@ -199,7 +202,7 @@ public class RunPlanRoutingService implements IRunPlanRoutingService {
RunPlanRoutingExample example = new RunPlanRoutingExample(); RunPlanRoutingExample example = new RunPlanRoutingExample();
example.createCriteria().andMapIdEqualTo(mapId).andUserIdEqualTo(userId); example.createCriteria().andMapIdEqualTo(mapId).andUserIdEqualTo(userId);
List<RunPlanRouting> runPlanRoutings = runPlanRoutingDAO.selectByExampleWithBLOBs(example); List<RunPlanRouting> runPlanRoutings = runPlanRoutingDAO.selectByExampleWithBLOBs(example);
return RunPlanRoutingVO.convert2VOList(runPlanRoutings); return RunPlanRoutingVO.convert2VOList(runPlanRoutings,this.iMapService.getMapDetail(mapId));
} }
@Override @Override
@ -209,15 +212,11 @@ public class RunPlanRoutingService implements IRunPlanRoutingService {
.filter(tripVO -> tripVO.getSDTNumberNew().equals(SDTNumber)) .filter(tripVO -> tripVO.getSDTNumberNew().equals(SDTNumber))
.findFirst() .findFirst()
.orElseThrow(() -> BusinessExceptionAssertEnum.DATA_NOT_EXIST.exception()); .orElseThrow(() -> BusinessExceptionAssertEnum.DATA_NOT_EXIST.exception());
List<RunPlanRoutingSection> routingSections = trip.getTimeList().stream().map(rt -> { RunPlanRoutingExample example = new RunPlanRoutingExample();
RunPlanRoutingSection routingSection = new RunPlanRoutingSection(); example.createCriteria().andMapIdEqualTo(planVO.getMapId()).andUserIdEqualTo(userId).andStartSectionCodeEqualTo(trip.getStartSectionCode()).andEndSectionCodeEqualTo(trip.getEndSectionCode());
routingSection.setStationCode(rt.getStationCode()); List<RunPlanRouting> runPlanRoutings = runPlanRoutingDAO.selectByExampleWithBLOBs(example);
routingSection.setSectionCode(rt.getSectionCode()); if (CollectionUtils.isEmpty(runPlanRoutings)) return null;
return routingSection; return RunPlanRoutingVO.convert2VO(runPlanRoutings.get(0), this.iMapService.getMapDetail(planVO.getMapId()));
}).collect(Collectors.toList());
RunPlanRouting runPlanRouting = runPlanRoutingDAO.getUserRoutingBySectionData(userId,planVO.getMapId(),JsonUtils.writeValueAsString(routingSections));
if (Objects.isNull(runPlanRouting)) return null;
return RunPlanRoutingVO.convert2VO(runPlanRouting);
} }
@Override @Override
@ -232,12 +231,11 @@ public class RunPlanRoutingService implements IRunPlanRoutingService {
@Override @Override
public List<RunPlanRoutingSection> getRoutingSectionDataBy(Long userId, Long planId, String routingCode) { public List<RunPlanRoutingSection> getRoutingSectionDataBy(Long userId, Long planId, String routingCode) {
RunPlanDraft runPlanDraft = runPlanDraftDAO.selectByPrimaryKey(planId); RunPlanDraft runPlanDraft = runPlanDraftDAO.selectByPrimaryKey(planId);
RunPlanRoutingExample example = new RunPlanRoutingExample(); RunPlanRoutingExample example = new RunPlanRoutingExample();
example.createCriteria().andMapIdEqualTo(runPlanDraft.getMapId()).andUserIdEqualTo(userId).andCodeEqualTo(routingCode); example.createCriteria().andMapIdEqualTo(runPlanDraft.getMapId()).andUserIdEqualTo(userId).andCodeEqualTo(routingCode);
List<RunPlanRouting> runPlanRoutings = runPlanRoutingDAO.selectByExampleWithBLOBs(example); List<RunPlanRouting> list = runPlanRoutingDAO.selectByExampleWithBLOBs(example);
if (CollectionUtils.isEmpty(runPlanRoutings)) return Collections.emptyList(); if (CollectionUtils.isEmpty(list)) return Collections.emptyList();
return RunPlanRoutingVO.convert2VO(runPlanRoutings.get(0)).getParkSectionCodeList(); return RunPlanRoutingVO.convert2VO(list.get(0)).getParkSectionCodeList();
} }

View File

@ -151,7 +151,7 @@ public class MapVO {
} }
@JsonIgnore @JsonIgnore
public MapSectionNewVO findSectionNew(String code) { public MapSectionNewVO findSection(String code) {
MapGraphDataNewVO graphData = this.getGraphDataNew(); MapGraphDataNewVO graphData = this.getGraphDataNew();
if (Objects.nonNull(graphData)) { if (Objects.nonNull(graphData)) {
List<MapSectionNewVO> sectionList = graphData.getSectionList(); List<MapSectionNewVO> sectionList = graphData.getSectionList();
@ -163,6 +163,19 @@ public class MapVO {
return null; return null;
} }
@JsonIgnore
public MapStationNewVO findStation(String code) {
MapGraphDataNewVO graphData = this.getGraphDataNew();
if (Objects.nonNull(graphData)) {
List<MapStationNewVO> stationList = graphData.getStationList();
if (!CollectionUtils.isEmpty(stationList)) {
MapStationNewVO station = stationList.stream().filter(mapStationNewVO -> mapStationNewVO.getCode().equals(code)).findFirst().orElse(null);
return station;
}
}
return null;
}
@JsonIgnore @JsonIgnore
public List<MapStationNewVO> findSortedAllStationListNew() { public List<MapStationNewVO> findSortedAllStationListNew() {

View File

@ -1,13 +1,12 @@
package club.joylink.rtss.vo.client.runplan; package club.joylink.rtss.vo.client.runplan;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.vo.client.map.newmap.MapSectionNewVO;
import club.joylink.rtss.vo.client.runplan.user.RunPlanRoutingVO;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan; import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan;
import club.joylink.rtss.vo.client.map.MapRoutingVO; import club.joylink.rtss.vo.client.map.MapRoutingVO;
import club.joylink.rtss.vo.client.map.newmap.MapRoutingDataVO; import club.joylink.rtss.vo.client.map.newmap.MapRoutingDataVO;
import club.joylink.rtss.vo.client.runplan.user.RunPlanRoutingVO;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
@ -15,7 +14,6 @@ import lombok.Setter;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -140,23 +138,31 @@ public class RunPlanTripVO {
this.timeList = new ArrayList<>(); this.timeList = new ArrayList<>();
} }
public RunPlanTripVO(RunPlanTripConfigVO tripConfigVO, RunPlanRoutingVO routingVO , MapSectionNewVO startReentrySection, MapSectionNewVO endReentrySection) { public RunPlanTripVO(RunPlanRoutingVO routingVO) {
this.right = routingVO.getRight(); this.right = routingVO.getRight();
this.destinationCode = Objects.nonNull(endReentrySection) ? endReentrySection.getDestinationCode() : routingVO.getDestinationCode(); this.destinationCode = routingVO.getDestinationCode();
this.startSectionCode = Objects.nonNull(startReentrySection) ? startReentrySection.getCode() : routingVO.getStartSectionCode(); this.startSectionCode = routingVO.getStartSectionCode();
this.endSectionCode = Objects.nonNull(endReentrySection) ? endReentrySection.getCode() : routingVO.getEndSectionCode(); this.endSectionCode = routingVO.getEndSectionCode();
this.startTime = tripConfigVO.getStartTime().minusHours(SimulationConstants.RUN_DIAGRAM_TRANS_TIME).minusSeconds(40);
this.endTime = tripConfigVO.getEndTime().minusHours(SimulationConstants.RUN_DIAGRAM_TRANS_TIME).plusSeconds(40);
this.timeList = new ArrayList<>(); this.timeList = new ArrayList<>();
} }
public RunPlanTripVO(RunPlanRoutingVO routingVO , MapSectionNewVO startReentrySection, MapSectionNewVO endReentrySection) { // public RunPlanTripVO(RunPlanTripConfigVO tripConfigVO, RunPlanRoutingVO routingVO , MapSectionNewVO startReentrySection, MapSectionNewVO endReentrySection) {
this.right = routingVO.getRight(); // this.right = routingVO.getRight();
this.destinationCode = Objects.nonNull(endReentrySection) ? endReentrySection.getDestinationCode() : routingVO.getDestinationCode(); // this.destinationCode = Objects.nonNull(endReentrySection) ? endReentrySection.getDestinationCode() : routingVO.getDestinationCode();
this.startSectionCode = Objects.nonNull(startReentrySection) ? startReentrySection.getCode() : routingVO.getStartSectionCode(); // this.startSectionCode = Objects.nonNull(startReentrySection) ? startReentrySection.getCode() : routingVO.getStartSectionCode();
this.endSectionCode = Objects.nonNull(endReentrySection) ? endReentrySection.getCode() : routingVO.getEndSectionCode(); // this.endSectionCode = Objects.nonNull(endReentrySection) ? endReentrySection.getCode() : routingVO.getEndSectionCode();
this.timeList = new ArrayList<>(); // this.startTime = tripConfigVO.getStartTime().minusHours(SimulationConstants.RUN_DIAGRAM_TRANS_TIME).minusSeconds(40);
} // this.endTime = tripConfigVO.getEndTime().minusHours(SimulationConstants.RUN_DIAGRAM_TRANS_TIME).plusSeconds(40);
// this.timeList = new ArrayList<>();
// }
//
// public RunPlanTripVO(RunPlanRoutingVO routingVO , MapSectionNewVO startReentrySection, MapSectionNewVO endReentrySection) {
// this.right = routingVO.getRight();
// this.destinationCode = Objects.nonNull(endReentrySection) ? endReentrySection.getDestinationCode() : routingVO.getDestinationCode();
// this.startSectionCode = Objects.nonNull(startReentrySection) ? startReentrySection.getCode() : routingVO.getStartSectionCode();
// this.endSectionCode = Objects.nonNull(endReentrySection) ? endReentrySection.getCode() : routingVO.getEndSectionCode();
// this.timeList = new ArrayList<>();
// }
public RunPlanTripVO(TripPlan plan) { public RunPlanTripVO(TripPlan plan) {
this.serviceNumber = plan.getServiceNumber(); this.serviceNumber = plan.getServiceNumber();
@ -179,6 +185,9 @@ public class RunPlanTripVO {
} }
public void addTime(RunPlanTripTimeVO timeVO) { public void addTime(RunPlanTripTimeVO timeVO) {
if(Objects.isNull(timeList)){
timeList = new ArrayList<>();
}
this.timeList.add(timeVO); this.timeList.add(timeVO);
} }

View File

@ -1,17 +1,13 @@
package club.joylink.rtss.vo.client.runplan.user; package club.joylink.rtss.vo.client.runplan.user;
import club.joylink.rtss.simulation.cbtc.data.map.Section;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.springframework.util.CollectionUtils;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;
@ApiModel(value="交路经停区段草稿") @ApiModel(value="交路经停区段草稿")
@NoArgsConstructor @NoArgsConstructor
@ -28,13 +24,4 @@ public class RunPlanRoutingSection {
@NotBlank(message = "区段编号不能为空") @NotBlank(message = "区段编号不能为空")
private String sectionCode; private String sectionCode;
public static List<RunPlanRoutingSection> from(List<Section> viaSectionList) {
List<RunPlanRoutingSection> voList = new ArrayList<>();
if (!CollectionUtils.isEmpty(viaSectionList)) {
for (Section section : viaSectionList) {
voList.add(new RunPlanRoutingSection(section.getStation().getCode(), section.getCode()));
}
}
return voList;
}
} }

View File

@ -2,6 +2,9 @@ package club.joylink.rtss.vo.client.runplan.user;
import club.joylink.rtss.entity.RunPlanRouting; import club.joylink.rtss.entity.RunPlanRouting;
import club.joylink.rtss.util.JsonUtils; import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.map.MapVO;
import club.joylink.rtss.vo.client.map.newmap.MapSectionNewVO;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Getter; import lombok.Getter;
@ -12,7 +15,9 @@ import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ApiModel(value = "运行图用户交路对象") @ApiModel(value = "运行图用户交路对象")
@ -67,6 +72,11 @@ public class RunPlanRoutingVO {
@ApiModelProperty(value = "描述") @ApiModelProperty(value = "描述")
private String remarks; private String remarks;
/**起始车站是否站前折返站前折返站后折返null 不是折返*/
private Boolean startTbFront;
/**终到车站是否站前折返站前折返站后折返null 不是折返*/
private Boolean endTbFront;
public RunPlanRoutingVO() { public RunPlanRoutingVO() {
this.parkSectionCodeList = new ArrayList<>(); this.parkSectionCodeList = new ArrayList<>();
@ -91,6 +101,26 @@ public class RunPlanRoutingVO {
return routingVO; return routingVO;
} }
public static RunPlanRoutingVO convert2VO(RunPlanRouting runPlanRouting, MapVO mapVO ) {
RunPlanRoutingVO routingVO = new RunPlanRoutingVO();
routingVO.setId(runPlanRouting.getId());
routingVO.setMapId(runPlanRouting.getMapId());
routingVO.setUserId(runPlanRouting.getUserId());
routingVO.setName(runPlanRouting.getName());
routingVO.setCode(runPlanRouting.getCode());
routingVO.setRoutingType(UserRoutingType.valueOf(runPlanRouting.getType()));
routingVO.setStartStationCode(runPlanRouting.getStartStationCode());
routingVO.setStartSectionCode(runPlanRouting.getStartSectionCode());
routingVO.setEndStationCode(runPlanRouting.getEndStationCode());
routingVO.setEndSectionCode(runPlanRouting.getEndSectionCode());
routingVO.setRight(runPlanRouting.getRight());
routingVO.setDestinationCode(runPlanRouting.getDestinationCode());
routingVO.setRemarks(runPlanRouting.getRemarks());
routingVO.setParkSectionCodeList(JsonUtils.readCollection(runPlanRouting.getSectionData(), List.class, RunPlanRoutingSection.class));
routingVO.setReentryType(mapVO);
return routingVO;
}
public RunPlanRouting convert2Entity() { public RunPlanRouting convert2Entity() {
RunPlanRouting routing = new RunPlanRouting(); RunPlanRouting routing = new RunPlanRouting();
routing.setId(id); routing.setId(id);
@ -128,6 +158,34 @@ public class RunPlanRoutingVO {
return runPlanRoutings.stream().map(RunPlanRoutingVO::convert2VO).collect(Collectors.toList()); return runPlanRoutings.stream().map(RunPlanRoutingVO::convert2VO).collect(Collectors.toList());
} }
public static List<RunPlanRoutingVO> convert2VOList(List<RunPlanRouting> runPlanRoutings, MapVO mapVO) {
return runPlanRoutings.stream().map(r -> RunPlanRoutingVO.convert2VO(r, mapVO)).collect(Collectors.toList());
}
@JsonIgnore
public boolean isOutBoundRoute(){
return Objects.equals(UserRoutingType.OUTBOUND,routingType);
}
@JsonIgnore
public boolean isInBoundRoute(){
return Objects.equals(UserRoutingType.INBOUND,routingType);
}
@JsonIgnore
public boolean isLoopRoute(){
return Objects.equals(UserRoutingType.LOOP,routingType);
}
@JsonIgnore
private void setReentryType(MapVO mapVO){
if(isOutBoundRoute() || isLoopRoute()){
MapSectionNewVO endReentrySection = mapVO.findSection(endSectionCode);
endTbFront = endReentrySection.isReentryTrack() && endReentrySection.isStandTrack();
}
if(isInBoundRoute() || isLoopRoute()){
MapSectionNewVO startReentrySection = mapVO.findSection(startSectionCode);
startTbFront = startReentrySection.isReentryTrack() && startReentrySection.isStandTrack();
}
}
public enum UserRoutingType{ public enum UserRoutingType{
OUTBOUND, OUTBOUND,
INBOUND, INBOUND,

View File

@ -148,7 +148,8 @@ public class RunPlanRunlevelVO {
public static List<RunPlanRunlevelVO> runLevelsFromRouting(RunPlanRoutingVO routingVO) { public static List<RunPlanRunlevelVO> runLevelsFromRouting(RunPlanRoutingVO routingVO) {
List<RunPlanRoutingSection> parkSectionList = routingVO.getParkSectionCodeList(); List<RunPlanRoutingSection> parkSectionList = routingVO.getParkSectionCodeList();
List<RunPlanRunlevelVO> list = new ArrayList<>(); List<RunPlanRunlevelVO> list = new ArrayList<>();
for (int i = 0; i < parkSectionList.size()-1; i++) { int n = parkSectionList.size()- 1;
for (int i = 0; i < n; i++) {
RunPlanRunlevelVO runlevelVO = new RunPlanRunlevelVO(); RunPlanRunlevelVO runlevelVO = new RunPlanRunlevelVO();
runlevelVO.setMapId(routingVO.getMapId()); runlevelVO.setMapId(routingVO.getMapId());
runlevelVO.setUserId(routingVO.getUserId()); runlevelVO.setUserId(routingVO.getUserId());

View File

@ -9,8 +9,9 @@ import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.validation.constraints.NotEmpty; import javax.validation.Valid;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -33,6 +34,7 @@ public class RunPlanUserConfigVO {
@ApiModelProperty(value = "交路编号") @ApiModelProperty(value = "交路编号")
@NotNull(message = "交路编号不能为空") @NotNull(message = "交路编号不能为空")
@Valid
private Config config; private Config config;
public static RunPlanUserConfigVO convert2VO(RunPlanUserConfig runPlanUserConfig) { public static RunPlanUserConfigVO convert2VO(RunPlanUserConfig runPlanUserConfig) {
@ -58,7 +60,7 @@ public class RunPlanUserConfigVO {
} }
public boolean hasReentryData(){ public boolean hasReentryData(){
return Objects.nonNull(config) && !CollectionUtils.isEmpty(config.getRunPlanUserReentryData()); return Objects.nonNull(config) && !CollectionUtils.isEmpty(config.reentryData);
} }
@Getter @Getter
@ -68,6 +70,20 @@ public class RunPlanUserConfigVO {
/**运行车站折返配置数据:车站code->折返轨code*/ /**运行车站折返配置数据:车站code->折返轨code*/
@ApiModelProperty(value = "运行车站折返配置数据") @ApiModelProperty(value = "运行车站折返配置数据")
@NonNull @NonNull
private Map<String,String> runPlanUserReentryData; private Map<String,ReentryTime> reentryData=new HashMap<>();
// private Map<String,String> runPlanUserReentryData;
}
@Getter
@Setter
public static class ReentryTime{
/**站前折返s*/
private Integer tbFront;
/**站后折返s*/
private Integer tbBack;
/**从股道到折返s*/
private Integer tbFrom;
/**从折返到股道s*/
private Integer tbTo;
} }
} }

View File

@ -26,9 +26,9 @@ public class RunPlanInput {
@NotBlank(message= "环路不能为空") @NotBlank(message= "环路不能为空")
private String runningRouting2; private String runningRouting2;
/**折返时间*/ // /**折返时间*/
@ApiModelProperty(value = "折返时间") // @ApiModelProperty(value = "折返时间")
private int reentryTime; // private int reentryTime;
/**运行等级默认-站间运行时间*/ /**运行等级默认-站间运行时间*/
private int runLevel=3; private int runLevel=3;

View File

@ -52,9 +52,9 @@ public class RunPlanInputData {
@ApiModelProperty(value = "发车间隔,s") @ApiModelProperty(value = "发车间隔,s")
private Integer departureInterval ; private Integer departureInterval ;
/**折返时间*/ // /**折返时间*/
@ApiModelProperty(value = "折返时间") // @ApiModelProperty(value = "折返时间")
private int reentryTime = 80; // private int reentryTime = 80;
/**运行等级默认-站间运行时间*/ /**运行等级默认-站间运行时间*/
private int runLevel = 3; private int runLevel = 3;