大铁线路进路数据构建bug修改,添加删除时更新敌对关系逻辑

This commit is contained in:
walker-sheng 2021-04-28 14:51:26 +08:00
parent d9226d47b6
commit 035f9fffdf
7 changed files with 112 additions and 8 deletions

View File

@ -37,4 +37,14 @@ public class DraftMapDataHandleController {
public void calculateSectionLen(@PathVariable Long mapId) {
this.draftMapDataHandleService.calculateSectionLen(mapId);
}
@PutMapping("/{mapId}/routeConflict")
public void handleRouteConflictRelation(@PathVariable Long mapId) {
this.draftMapDataHandleService.handleRouteConflictRelation(mapId);
}
@PutMapping("/{mapId}/doublePath")
public void handleDoublePathRoute(@PathVariable Long mapId) {
this.draftMapDataHandleService.handleDoublePathRoute(mapId);
}
}

View File

@ -8,4 +8,8 @@ public interface DraftMapDataHandleService {
void handleSectionRelStation(Long mapId);
void calculateSectionLen(Long mapId);
void handleRouteConflictRelation(Long mapId);
void handleDoublePathRoute(Long mapId);
}

View File

@ -6,8 +6,11 @@ import club.joylink.rtss.dao.DraftMapRouteDAO;
import club.joylink.rtss.dao.DraftMapRouteFlankProtectionDAO;
import club.joylink.rtss.entity.*;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.IDraftMapService;
import club.joylink.rtss.simulation.cbtc.build.SimulationBuilder;
import club.joylink.rtss.simulation.cbtc.data.map.*;
import club.joylink.rtss.simulation.rt.repo.CommonRepository;
import club.joylink.rtss.simulation.rt.repo.CommonRepositoryBuilder;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.Point;
import club.joylink.rtss.vo.client.map.MapSwitchVO;
@ -35,7 +38,10 @@ public class DraftMapDataHandleServiceImpl implements DraftMapDataHandleService
@Autowired
private DraftMapOverlapDAO draftMapOverlapDAO;
@Autowired
private RailwayRouteGenerator railwayRouteGenerator;
@Autowired
private IDraftMapService iDraftMapService;
@Autowired
private DraftMapRouteFlankProtectionDAO draftMapRouteFlankProtectionDAO;
@ -133,6 +139,55 @@ public class DraftMapDataHandleServiceImpl implements DraftMapDataHandleService
this.draftMapDAO.updateByPrimaryKeyWithBLOBs(draftMapWithBLOBs);
}
@Override
public void handleRouteConflictRelation(Long mapId) {
DraftMapRouteExample example = new DraftMapRouteExample();
example.createCriteria()
.andMapIdEqualTo(mapId);
List<DraftMapRoute> routeList = this.draftMapRouteDAO.selectByExampleWithBLOBs(example);
Map<String, MapRouteNewVO> routeVOMap = routeList.stream()
.map(draftMapRoute -> {
MapRouteNewVO vo = MapRouteNewVO.convert2VO(draftMapRoute);
vo.setConflictRouteList(new ArrayList<>());
return vo;
})
.collect(Collectors.toMap(MapRouteNewVO::getCode, Function.identity()));
// 构建敌对进路关系
Set<MapRouteNewVO> updateSet = new HashSet<>();
for (DraftMapRoute route : routeList) {
List<MapRouteNewVO> updateVOList = this.railwayRouteGenerator
.buildConflict(MapRouteNewVO.convert2VO(route), routeVOMap);
updateSet.addAll(updateVOList);
}
for (MapRouteNewVO routeVO : updateSet) {
DraftMapRoute route = routeVO.convert2Draft();
this.draftMapRouteDAO.updateByPrimaryKeyWithBLOBs(route);
}
}
@Override
public void handleDoublePathRoute(Long mapId) {
DraftMapRouteExample example = new DraftMapRouteExample();
example.createCriteria()
.andMapIdEqualTo(mapId);
List<DraftMapRoute> routeList = this.draftMapRouteDAO.selectByExampleWithBLOBs(example);
MapGraphDataNewVO mapShapeData = this.iDraftMapService.getMapShapeData(mapId);
CommonRepository commonRepository = CommonRepositoryBuilder.buildFrom(mapShapeData);
for (DraftMapRoute route : routeList) {
MapRouteNewVO routeNewVO = MapRouteNewVO.convert2VO(route);
if (routeNewVO.isMultiRoute()) {
continue;
}
int size = routeNewVO.getRouteSectionList().size();
MapRouteNewVO routeVO = this.railwayRouteGenerator.generateRoute(commonRepository, routeNewVO);
if (routeVO.getRouteSectionList().size() != size) {
// update
DraftMapRoute db = routeVO.convert2Draft();
this.draftMapRouteDAO.updateByPrimaryKeyWithBLOBs(db);
}
}
}
private void calculateSectionLengthThroughStationKmPostVal(MapVO mapVO) {
SimulationBuilder.SimulationDeviceBuildResult buildResult = SimulationBuilder.checkAndBuildBasicMapData(mapVO);
for (String errMsg : buildResult.getErrMsgList()) {

View File

@ -5,12 +5,16 @@ import club.joylink.rtss.entity.DraftMapRoute;
import club.joylink.rtss.entity.DraftMapRouteExample;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.IDraftMapService;
import club.joylink.rtss.simulation.rt.repo.CommonRepository;
import club.joylink.rtss.simulation.rt.repo.CommonRepositoryBuilder;
import club.joylink.rtss.vo.client.map.newmap.MapGraphDataNewVO;
import club.joylink.rtss.vo.client.map.newmap.MapRouteNewVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
@ -42,7 +46,8 @@ public class DraftMapRouteServiceImpl implements DraftMapRouteService {
routeNewVO.setMapId(id);
if (!routeNewVO.isMultiRoute()) {
MapGraphDataNewVO mapShapeData = this.iDraftMapService.getMapShapeData(id);
routeNewVO = this.railwayRouteGenerator.generateRoute(mapShapeData, routeNewVO);
CommonRepository commonRepository = CommonRepositoryBuilder.buildFrom(mapShapeData);
routeNewVO = this.railwayRouteGenerator.generateRoute(commonRepository, routeNewVO);
// 构建敌对进路关系
List<MapRouteNewVO> updateVOList = this.railwayRouteGenerator.buildConflict(routeNewVO, routeVOMap);
if (!CollectionUtils.isEmpty(updateVOList)) {
@ -66,14 +71,32 @@ public class DraftMapRouteServiceImpl implements DraftMapRouteService {
return MapRouteNewVO.convertDraft2VOList(routeList);
}
@Transactional
@Override
public void deleteRoute(Long id, String code) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertHasText(code,
String.format("code不能为空"));
DraftMapRouteExample example = new DraftMapRouteExample();
example.createCriteria()
.andMapIdEqualTo(id);
List<DraftMapRoute> routeList = this.draftMapRouteDAO.selectByExampleWithBLOBs(example);
Map<String, MapRouteNewVO> routeVOMap = routeList.stream()
.map(draftMapRoute -> MapRouteNewVO.convert2VO(draftMapRoute))
.collect(Collectors.toMap(MapRouteNewVO::getCode, Function.identity()));
List<MapRouteNewVO> updateList = new ArrayList<>();
for (MapRouteNewVO vo : routeVOMap.values()) {
if (vo.removeConflictRoute(code)) {
updateList.add(vo);
}
}
DraftMapRouteExample deleteExample = new DraftMapRouteExample();
example.createCriteria()
.andMapIdEqualTo(id)
.andCodeEqualTo(code);
this.draftMapRouteDAO.deleteByExample(example);
this.draftMapRouteDAO.deleteByExample(deleteExample);
for (MapRouteNewVO routeVO : updateList) {
DraftMapRoute route = routeVO.convert2Draft();
this.draftMapRouteDAO.updateByPrimaryKeyWithBLOBs(route);
}
}
}

View File

@ -3,7 +3,6 @@ package club.joylink.rtss.services.draftData;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.rt.repo.*;
import club.joylink.rtss.vo.client.map.newmap.MapCISwitchVO;
import club.joylink.rtss.vo.client.map.newmap.MapGraphDataNewVO;
import club.joylink.rtss.vo.client.map.newmap.MapRouteNewVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@ -23,16 +22,15 @@ public class RailwayRouteGenerator {
/**
* 半自动化生成
*
* @param graphDataVO
* @param commonRepository
* @param routeVO
* @return
*/
public MapRouteNewVO generateRoute(MapGraphDataNewVO graphDataVO, MapRouteNewVO routeVO) {
public MapRouteNewVO generateRoute(CommonRepository commonRepository, MapRouteNewVO routeVO) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertHasText(routeVO.getCode());
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertHasText(routeVO.getStartSignalCode());
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertHasText(routeVO.getStartSignalCode());
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertHasText(routeVO.getEndSectionCode());
CommonRepository commonRepository = CommonRepositoryBuilder.buildFrom(graphDataVO);
CommonSignal startSignal = commonRepository.getSignalById(routeVO.getStartSignalCode());
BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(startSignal.getStation(),
String.format("信号机[%s]所属车站未设置", startSignal.getId()));
@ -148,6 +146,9 @@ public class RailwayRouteGenerator {
public List<MapRouteNewVO> buildConflict(MapRouteNewVO routeNewVO, Map<String, MapRouteNewVO> routeVOMap) {
List<MapRouteNewVO> updateList = new ArrayList<>();
for (MapRouteNewVO routeVO : routeVOMap.values()) {
if (routeVO.isMultiRoute()) {
continue;
}
if (routeVO.getStartSignalCode().equals(routeNewVO.getStartSignalCode())) { // 同信号机
continue;
}

View File

@ -70,7 +70,7 @@ public class TrackWay implements Debug {
return true;
}
}
return normal;
return false;
}
public List<CommonSection> getAllSectionList() {

View File

@ -268,6 +268,13 @@ public class MapRouteNewVO {
}
public boolean containSameSection(List<String> routeSectionList) {
if (this.routeSectionList != null && routeSectionList != null) {
for (String s : routeSectionList) {
if (this.routeSectionList.contains(s)) {
return true;
}
}
}
return false;
}
@ -281,4 +288,8 @@ public class MapRouteNewVO {
}
this.conflictRouteList.add(code);
}
public boolean removeConflictRoute(String code) {
return this.conflictRouteList != null && this.conflictRouteList.remove(code);
}
}