diff --git a/src/main/java/club/joylink/rtss/controller/runplan/RunPlanUserDataController.java b/src/main/java/club/joylink/rtss/controller/runplan/RunPlanUserDataController.java index 5360f1373..cb6584e93 100644 --- a/src/main/java/club/joylink/rtss/controller/runplan/RunPlanUserDataController.java +++ b/src/main/java/club/joylink/rtss/controller/runplan/RunPlanUserDataController.java @@ -37,13 +37,13 @@ public class RunPlanUserDataController { @PostMapping(path = "/routing") public void createUserRouting(@RequestBody @Validated RunPlanRoutingVO routingVO, @RequestAttribute UserVO user) { routingVO.setUserId(user.getId()); - iRunPlanRoutingService.createUserRouting(routingVO); + iRunPlanRoutingService.createUserRouting(routingVO); } @ApiOperation(value = "生成通用交路区段数据") @PostMapping(path = "/routing/path/generate") public RunPlanRoutingVO generateUserRoutingPath(@RequestBody @Validated RunPlanRoutingVO routingVO) { - return iRunPlanRoutingService.generateUserRoutingSections(routingVO); + return iRunPlanRoutingService.generateUserRoutingData(routingVO); } @ApiOperation(value = "分页获取用户交路") diff --git a/src/main/java/club/joylink/rtss/services/runplan/IRunPlanRoutingService.java b/src/main/java/club/joylink/rtss/services/runplan/IRunPlanRoutingService.java index a61958d61..c1a7a2b7c 100644 --- a/src/main/java/club/joylink/rtss/services/runplan/IRunPlanRoutingService.java +++ b/src/main/java/club/joylink/rtss/services/runplan/IRunPlanRoutingService.java @@ -38,5 +38,5 @@ public interface IRunPlanRoutingService { @Transactional void pullDefaultRoutings(Long userId, Long mapId, List defaultRoutingIds); - RunPlanRoutingVO generateUserRoutingSections(RunPlanRoutingVO routingVO); + RunPlanRoutingVO generateUserRoutingData(RunPlanRoutingVO routingVO); } diff --git a/src/main/java/club/joylink/rtss/services/runplan/RunPlanRoutingService.java b/src/main/java/club/joylink/rtss/services/runplan/RunPlanRoutingService.java index 5591b937a..911278edb 100644 --- a/src/main/java/club/joylink/rtss/services/runplan/RunPlanRoutingService.java +++ b/src/main/java/club/joylink/rtss/services/runplan/RunPlanRoutingService.java @@ -5,6 +5,7 @@ import club.joylink.rtss.dao.RunPlanRoutingDAO; import club.joylink.rtss.entity.RunPlanDraft; import club.joylink.rtss.entity.RunPlanRouting; import club.joylink.rtss.entity.RunPlanRoutingExample; +import club.joylink.rtss.exception.BaseException; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.services.IMapService; import club.joylink.rtss.simulation.cbtc.build.SimulationBuilder; @@ -65,6 +66,13 @@ public class RunPlanRoutingService implements IRunPlanRoutingService { RunPlanRouting routing = routingVO.convert2Entity(); runPlanRoutingDAO.insert(routing); createRoutingRefData(deviceMap, routingVO); + if (Objects.equals(RunPlanRoutingVO.UserRoutingType.LOOP, routingVO.getRoutingType())) { + RunPlanRoutingVO routingDataLoop = routingVO.getRoutingDataLoop(); + generateUserRoutingSections(routingDataLoop, deviceMap); + if (routingDataExist(routingDataLoop)) return; + runPlanRoutingDAO.insert(routingDataLoop.convert2Entity()); + createRoutingRefData(deviceMap, routingDataLoop); + } } @Override @@ -73,7 +81,7 @@ public class RunPlanRoutingService implements IRunPlanRoutingService { if (CollectionUtils.isEmpty(defaultRoutings)) return; MapVO map = this.iMapService.getMapDetail(defaultRoutings.get(0).getMapId()); SimulationBuilder.SimulationDeviceBuildResult buildResult = SimulationBuilder.checkAndBuildMapDeviceData(map); - BusinessExceptionAssertEnum.DATA_ERROR.assertCollectionEmpty(buildResult.getErrMsgList(),"地图基础数据校验不通过"); + BusinessExceptionAssertEnum.DATA_ERROR.assertCollectionEmpty(buildResult.getErrMsgList(), "地图基础数据校验不通过"); Map deviceMap = buildResult.getDeviceMap(); defaultRoutings.forEach(routingVO -> { routingVO.setUserId(null); @@ -111,23 +119,27 @@ public class RunPlanRoutingService implements IRunPlanRoutingService { } @Override - public RunPlanRoutingVO generateUserRoutingSections(RunPlanRoutingVO routingVO) { + public RunPlanRoutingVO generateUserRoutingData(RunPlanRoutingVO routingVO) { MapVO map = this.iMapService.getMapDetail(routingVO.getMapId()); SimulationBuilder.SimulationDeviceBuildResult buildResult = SimulationBuilder.checkAndBuildMapDeviceData(map); BusinessExceptionAssertEnum.DATA_ERROR.assertCollectionEmpty(buildResult.getErrMsgList(), "地图基础数据校验不通过"); Map deviceMap = buildResult.getDeviceMap(); + generateUserRoutingSections(routingVO, deviceMap); + return routingVO; + } + + private void generateUserRoutingSections(RunPlanRoutingVO routingVO, Map deviceMap) { Section startSection = (Section) deviceMap.get(routingVO.getStartSectionCode()); Section endSection = (Section) deviceMap.get(routingVO.getEndSectionCode()); //中间经停所有站台轨 List
passingStandTrack = CalculateService.findPassingStandTrack(startSection, endSection, routingVO.getRight()); BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotNull(passingStandTrack, - "没有找到对应方向的中间经停区段,是否需要更换方向/手动添加/直接保存交路"); + String.format("没有找到线路方向[%s]的中间经停区段,是否需要更换方向/手动添加/直接保存交路", routingVO.getRight() ? "右向" : "左向")); LinkedList parkSectionCodeList = passingStandTrack.stream().map(section -> new RunPlanRoutingSection(section.getStation().getCode(), section.getCode())).collect(Collectors.toCollection(LinkedList::new)); parkSectionCodeList.addFirst(new RunPlanRoutingSection(routingVO.getStartStationCode(), routingVO.getStartSectionCode())); parkSectionCodeList.addLast(new RunPlanRoutingSection(routingVO.getEndStationCode(), routingVO.getEndSectionCode())); routingVO.setParkSectionCodeList(parkSectionCodeList); - return routingVO; } @Override @@ -139,7 +151,6 @@ public class RunPlanRoutingService implements IRunPlanRoutingService { @Transactional @Override public void updateUserRouting(Long routingId, RunPlanRoutingVO routingVO) { -// BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(routingDataExist(routingVO),"交路数据重复"); MapVO map = this.iMapService.getMapDetail(routingVO.getMapId()); SimulationBuilder.SimulationDeviceBuildResult buildResult = SimulationBuilder.checkAndBuildMapDeviceData(map); BusinessExceptionAssertEnum.DATA_ERROR.assertCollectionEmpty(buildResult.getErrMsgList(), @@ -175,8 +186,7 @@ public class RunPlanRoutingService implements IRunPlanRoutingService { private void generateUserParktimes(RunPlanRoutingVO routingVO, Map deviceMap) { List parkingTimeVOS = RunPlanParkingTimeVO.parkingTimeFromRouting(routingVO); parkingTimeVOS.forEach(p -> { -// if (!((Section) deviceMap.get(p.getSectionCode())).isTransferTrack() && !planParktimeService.isExisted(p)) { - if (((Section) deviceMap.get(p.getSectionCode())).isStandTrack()) { + if (((Section) deviceMap.get(p.getSectionCode())).isStandTrack() && !planParktimeService.isExisted(p)) { planParktimeService.createUserParktime(p); } }); @@ -185,28 +195,30 @@ public class RunPlanRoutingService implements IRunPlanRoutingService { private void generateUserRunlevels(RunPlanRoutingVO routingVO, Map deviceMap) { List levels = RunPlanRunlevelVO.runLevelsFromRouting(routingVO); 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 ((startSection.isStandTrack() && endSection.isTransferTrack()) || (endSection.isStandTrack() && startSection.isTransferTrack())) { - Float distance; - try { - distance = CalculateService.calculateDistance(startSection, endSection, l.getRight()); - } catch (SimulationException e) { - distance = CalculateService.calculateDistance(startSection, endSection, !l.getRight()); + if (!planRunlevelService.isExisted(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 ((startSection.isStandTrack() && endSection.isTransferTrack()) || (endSection.isStandTrack() && startSection.isTransferTrack())) { + Float distance; + try { + distance = CalculateService.calculateDistance(startSection, endSection, l.getRight()); + } catch (SimulationException e) { + distance = CalculateService.calculateDistance(startSection, endSection, !l.getRight()); + } + l.setDistance(distance); + l.generateDefaultRunLevel(); + planRunlevelService.createUserRunlevel(l); + return; + } + Float distance = CalculateService.calculateDistance(startSection, endSection, l.getRight()); l.setDistance(distance); l.generateDefaultRunLevel(); planRunlevelService.createUserRunlevel(l); - return; } - Float distance = CalculateService.calculateDistance(startSection, endSection, l.getRight()); - l.setDistance(distance); - l.generateDefaultRunLevel(); - planRunlevelService.createUserRunlevel(l); }); } diff --git a/src/main/java/club/joylink/rtss/vo/client/runplan/user/RunPlanRoutingVO.java b/src/main/java/club/joylink/rtss/vo/client/runplan/user/RunPlanRoutingVO.java index 2e93113b6..b92abf362 100644 --- a/src/main/java/club/joylink/rtss/vo/client/runplan/user/RunPlanRoutingVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/runplan/user/RunPlanRoutingVO.java @@ -201,7 +201,25 @@ public class RunPlanRoutingVO { startTbFront = startReentrySection.isReentryTrack() && startReentrySection.isStandTrack(); } } - public enum UserRoutingType{ + private final static String LOOP_MARK = "-LOOP"; + + @JsonIgnore + public RunPlanRoutingVO getRoutingDataLoop() { + RunPlanRoutingVO routing = new RunPlanRoutingVO(); + routing.setMapId(mapId); + routing.setUserId(userId); + routing.setName(name + LOOP_MARK); + routing.setCode(code + LOOP_MARK); + routing.setStartStationCode(endStationCode); + routing.setStartSectionCode(endSectionCode); + routing.setEndStationCode(startStationCode); + routing.setEndSectionCode(startSectionCode); + routing.setRight(!right); + routing.setRemarks(remarks + LOOP_MARK); + return routing; + } + + public enum UserRoutingType { OUTBOUND, INBOUND, LOOP,