报错消除(未完)

This commit is contained in:
joylink_zhangsai 2020-11-19 17:56:12 +08:00
parent bcc570afe9
commit 413a2c2b94

View File

@ -1619,9 +1619,7 @@ public class DraftMapService implements IDraftMapService {
@Override
public void createRouting(MapRoutingVO routingVO) {
if (ifRoutingExist(routingVO, null)) {
throw new DBException(ExceptionMapping.DATA_EXISTS);
}
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(ifRoutingExist(routingVO, null));
DraftMapRouting routing = routingVO.convert2Draft();
draftMapRoutingDAO.insert(routing);
}
@ -1632,18 +1630,15 @@ public class DraftMapService implements IDraftMapService {
@Override
@Transactional
public void createRoutingData(MapRoutingDataVO routingVO) {
if (ifRoutingDataExist(routingVO, null)) {
throw new DBException(ExceptionMapping.DATA_EXISTS);
}
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(ifRoutingDataExist(routingVO, null));
DraftMapRouting routing = routingVO.convert2Draft();
draftMapRoutingDAO.insert(routing);
//同时生成回路
// routingVO.setWithLoop(true);//测试用
if (Objects.nonNull(routingVO.getWithLoop()) && routingVO.getWithLoop()) {
MapRoutingDataVO loopRoutingData = generateRoutingLoopData(routingVO);
if (ifRoutingDataExist(loopRoutingData, null)) {
throw new DBException(ExceptionMapping.DATA_EXISTS, "对应回路已存在");
}
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(ifRoutingDataExist(loopRoutingData, null),
"对应回路已经存在");
draftMapRoutingDAO.insert(loopRoutingData.convert2Draft());
}
}
@ -1653,33 +1648,30 @@ public class DraftMapService implements IDraftMapService {
*/
@Override
public MapRoutingDataVO generateRoutingData(MapRoutingDataVO routingVO) {
if (ifRoutingDataExist(routingVO, null)) {
throw new DBException(ExceptionMapping.DATA_EXISTS);
}
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(ifRoutingDataExist(routingVO, null),
"对应回路已经存在");
MapDataVO mapData = this.iDraftMapService.getMapData(routingVO.getMapId());
if (mapData.isDrawWay()) {
MapVO map = new MapVO();
map.setDrawWay(mapData.isDrawWay());
map.setMapData(mapData);
SimulationBuilder.SimulationDeviceBuildResult buildResult = SimulationBuilder.checkAndBuildMapDeviceData(map);
if (!CollectionUtils.isEmpty(buildResult.getErrMsgList())) {
throw new BusinessException(ExceptionMapping.OPERATION_EXCEPTION, String.format("地图基础数据校验不通过,不能生成"));
}
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(CollectionUtils.isEmpty(buildResult.getErrMsgList()),
"地图基础数据校验不通过,不能生成");
Section startSection = (Section) buildResult.getDeviceMap().get(routingVO.getStartSectionCode());
Section endSection = (Section) buildResult.getDeviceMap().get(routingVO.getEndSectionCode());
if (Objects.isNull(startSection) || Objects.isNull(endSection)) {
throw new BusinessException(ExceptionMapping.ARGUMENT_ILLEGAL, String.format("站间从区段code[%s]——至区段code[%s],两个区段中某个区段不存在", routingVO.getStartSectionCode(), routingVO.getEndSectionCode()));
}
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue(Objects.isNull(startSection) || Objects.isNull(endSection),
String.format("站间从区段code[%s]——至区段code[%s],两个区段中某个区段不存在", routingVO.getStartSectionCode(), routingVO.getEndSectionCode()));
//中间经停所有站台轨
List<Section> passingStandTrack = CalculateService.findPassingStandTrack(startSection, endSection, routingVO.getRight());
if (Objects.isNull(passingStandTrack))
throw new BusinessException(ExceptionMapping.OPERATION_EXCEPTION, "没有找到对应方向的中间经停区段,是否可手动添加或者直接保存交路");
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotNull(passingStandTrack,
"没有找到对应方向的中间经停区段,是否可手动添加或者直接保存交路");
LinkedList<MapRoutingSectionNewVO> parkSectionCodeList = passingStandTrack.stream().map(section -> new MapRoutingSectionNewVO(section.getStation().getCode(), section.getCode())).collect(Collectors.toCollection(LinkedList::new));
parkSectionCodeList.addFirst(new MapRoutingSectionNewVO(routingVO.getStartStationCode(), routingVO.getStartSectionCode()));
parkSectionCodeList.addLast(new MapRoutingSectionNewVO(routingVO.getEndStationCode(), routingVO.getEndSectionCode()));
routingVO.setParkSectionCodeList(parkSectionCodeList);
} else {
throw new BusinessException(ExceptionMapping.OPERATION_EXCEPTION, String.format("旧地图数据不支持此功能"));
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("意外的旧地图");
}
return routingVO;
}
@ -1689,53 +1681,42 @@ public class DraftMapService implements IDraftMapService {
*/
private MapRoutingDataVO generateRoutingLoopData(MapRoutingDataVO routingDataVO) {
MapRoutingDataVO routingVO = routingDataVO.generateLoopRoutingBasicData();
if (ifRoutingDataExist(routingVO, null)) {
throw new DBException(ExceptionMapping.DATA_EXISTS);
}
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(ifRoutingDataExist(routingVO, null));
MapDataVO mapData = this.iDraftMapService.getMapData(routingVO.getMapId());
if (mapData.isDrawWay()) {
MapVO map = new MapVO();
map.setDrawWay(mapData.isDrawWay());
map.setMapData(mapData);
SimulationBuilder.SimulationDeviceBuildResult buildResult = SimulationBuilder.checkAndBuildMapDeviceData(map);
if (!CollectionUtils.isEmpty(buildResult.getErrMsgList())) {
throw new BusinessException(ExceptionMapping.OPERATION_EXCEPTION, String.format("地图基础数据校验不通过,不能生成"));
}
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(CollectionUtils.isEmpty(buildResult.getErrMsgList()),
"地图基础数据校验不通过,不能生成");
Section startSection = (Section) buildResult.getDeviceMap().get(routingVO.getStartSectionCode());
Section endSection = (Section) buildResult.getDeviceMap().get(routingVO.getEndSectionCode());
routingVO.setDestinationCode(endSection.getDestinationCode());
if (Objects.isNull(startSection) || Objects.isNull(endSection)) {
throw new BusinessException(ExceptionMapping.ARGUMENT_ILLEGAL, String.format("回路生成站间从区段code[%s]——至区段code[%s],两个区段中某个区段不存在", routingVO.getStartSectionCode(), routingVO.getEndSectionCode()));
}
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue(Objects.isNull(startSection) || Objects.isNull(endSection),
"回路生成站间从区段code[%s]——至区段code[%s],两个区段中某个区段不存在");
//中间经停所有站台轨
List<Section> passingStandTrack = CalculateService.findPassingStandTrack(startSection, endSection, routingVO.getRight());
if (Objects.isNull(passingStandTrack))
throw new BusinessException(ExceptionMapping.OPERATION_EXCEPTION, "没有对应的回路");
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotNull(Objects.isNull(passingStandTrack), "没有对应的回路");
LinkedList<MapRoutingSectionNewVO> parkSectionCodeList = passingStandTrack.stream().map(section -> new MapRoutingSectionNewVO(section.getStation().getCode(), section.getCode())).collect(Collectors.toCollection(LinkedList::new));
parkSectionCodeList.addFirst(new MapRoutingSectionNewVO(routingVO.getStartStationCode(), routingVO.getStartSectionCode()));
parkSectionCodeList.addLast(new MapRoutingSectionNewVO(routingVO.getEndStationCode(), routingVO.getEndSectionCode()));
routingVO.setParkSectionCodeList(parkSectionCodeList);
} else {
throw new BusinessException(ExceptionMapping.OPERATION_EXCEPTION, String.format("旧地图数据不支持此功能"));
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("意外的旧地图");
}
return routingVO;
}
@Override
public MapRoutingVO getRouting(Long routingId) {
DraftMapRouting routing = draftMapRoutingDAO.selectByPrimaryKey(routingId);
if (Objects.isNull(routing)) {
throw new DBException(ExceptionMapping.DATA_NOT_EXIST);
}
DraftMapRouting routing = getDraftMapRoutingEntity(routingId);
return MapRoutingVO.convert2VO(routing);
}
@Override
public MapRoutingDataVO getRoutingData(Long routingId) {
DraftMapRouting routing = draftMapRoutingDAO.selectByPrimaryKey(routingId);
if (Objects.isNull(routing)) {
throw new DBException(ExceptionMapping.DATA_NOT_EXIST);
}
DraftMapRouting routing = getDraftMapRoutingEntity(routingId);
return MapRoutingDataVO.convert2VO(routing);
}
@ -1745,24 +1726,15 @@ public class DraftMapService implements IDraftMapService {
DraftMapRoutingExample.Criteria criteria = routingExample.createCriteria();
criteria.andMapIdEqualTo(mapId);
List<DraftMapRouting> routings = draftMapRoutingDAO.selectByExampleWithBLOBs(routingExample);
if (CollectionUtils.isEmpty(routings)) {
throw new DBException(ExceptionMapping.DATA_NOT_EXIST, "没有交路数据");
}
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(!CollectionUtils.isEmpty(routings), "没有交路数据");
List<MapRoutingDataVO> routingVOList = routings.stream().map(MapRoutingDataVO::convert2VO).collect(Collectors.toList());
return routingVOList;
}
@Override
public void updateRouting(Long routingId, MapRoutingVO routingVO) {
DraftMapRouting routing = draftMapRoutingDAO.selectByPrimaryKey(routingId);
if (Objects.isNull(routing)) {
throw new DBException(ExceptionMapping.DATA_NOT_EXIST);
}
if (ifRoutingExist(routingVO, routingId)) {
throw new DBException(ExceptionMapping.DATA_EXISTS);
}
DraftMapRouting routing = getDraftMapRoutingEntity(routingId);
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(ifRoutingExist(routingVO, routingId));
// 更新
DraftMapRouting newRouting = routingVO.convert2Draft();
newRouting.setId(routingId);
@ -1771,13 +1743,8 @@ public class DraftMapService implements IDraftMapService {
@Override
public void updateRoutingData(Long routingId, MapRoutingDataVO routingVO) {
DraftMapRouting routing = draftMapRoutingDAO.selectByPrimaryKey(routingId);
if (Objects.isNull(routing)) {
throw new DBException(ExceptionMapping.DATA_NOT_EXIST);
}
if (ifRoutingDataExist(routingVO, routingId)) {
throw new DBException(ExceptionMapping.DATA_EXISTS);
}
DraftMapRouting routing = getDraftMapRoutingEntity(routingId);
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(ifRoutingDataExist(routingVO, routingId));
// 更新
DraftMapRouting newRouting = routingVO.convert2Draft();
newRouting.setId(routingId);
@ -1850,10 +1817,7 @@ public class DraftMapService implements IDraftMapService {
@Override
public void update3dMapData(Long map3dId, Map3dDataVO mapData3D) {
DraftMap3dDataWithBLOBs data = draftMap3dDataDAO.selectByPrimaryKey(map3dId);
if (Objects.isNull(data)) {
throw new DBException(ExceptionMapping.DATA_NOT_EXIST);
}
DraftMap3dDataWithBLOBs data = getDraftMap3dDataEntity(map3dId);
data.setAssets(mapData3D.getAssets());
data.setSections(mapData3D.getSections());
data.setSwitchs(mapData3D.getSwitchs());
@ -1889,9 +1853,8 @@ public class DraftMapService implements IDraftMapService {
example.createCriteria()
.andMapIdEqualTo(parkingTimeVO.getMapId())
.andStationCodeEqualTo(parkingTimeVO.getStationCode());
if (this.draftMapParkingTimeDAO.countByExample(example) > 0) {
throw new DBException(ExceptionMapping.DATA_EXISTS, "车站(" + parkingTimeVO.getStationCode() + ")停站时间数据已存在");
}
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertTrue(this.draftMapParkingTimeDAO.countByExample(example) == 0,
"车站(" + parkingTimeVO.getStationCode() + ")停站时间数据已存在");
DraftMapParkingTime draftMapParkingTime = parkingTimeVO.convert2Draft();
this.draftMapParkingTimeDAO.insert(draftMapParkingTime);
}
@ -1913,21 +1876,13 @@ public class DraftMapService implements IDraftMapService {
@Override
public MapStationParkingTimeVO getStationParkTime(Long id) {
DraftMapParkingTime draftMapParkingTime = this.draftMapParkingTimeDAO.selectByPrimaryKey(id);
if (Objects.isNull(draftMapParkingTime)) {
throw new DBException(ExceptionMapping.DATA_NOT_EXIST,
String.format("id为[%s]的草稿车站停站时间数据不存在", id));
}
DraftMapParkingTime draftMapParkingTime = getDraftMapParkingTimeEntity(id);
return MapStationParkingTimeVO.convert2VO(draftMapParkingTime);
}
@Override
public void updateStationParkTime(Long id, MapStationParkingTimeVO parkingTimeVO) {
DraftMapParkingTime draftMapParkingTime = this.draftMapParkingTimeDAO.selectByPrimaryKey(id);
if (Objects.isNull(draftMapParkingTime)) {
throw new DBException(ExceptionMapping.DATA_NOT_EXIST,
String.format("id为[%s]的草稿车站停站时间数据不存在", id));
}
DraftMapParkingTime draftMapParkingTime = getDraftMapParkingTimeEntity(id);
draftMapParkingTime.setSectionParkingTime(JsonUtils.writeValueAsString(parkingTimeVO.getParkingTimeVOList()));
this.draftMapParkingTimeDAO.updateByPrimaryKeyWithBLOBs(draftMapParkingTime);
}
@ -1943,7 +1898,7 @@ public class DraftMapService implements IDraftMapService {
DraftMapWithBLOBs entity = getEntity(mapId);
String logicData = entity.getLogicData();
List<MapDestinationCodeDefinitionVO> list;
if (StringUtils.isBlank(logicData)) {
if (logicData.isBlank()) {
list = new ArrayList<>();
} else {
list = JsonUtils.read(logicData, JsonUtils.getCollectionType(ArrayList.class, MapDestinationCodeDefinitionVO.class));
@ -1968,7 +1923,7 @@ public class DraftMapService implements IDraftMapService {
public PageVO<MapDestinationCodeDefinitionVO> pagedQueryOperationDefinitions(Long mapId, MapDestinationCodeDefinitionQueryVO queryVO) {
DraftMapWithBLOBs entity = getEntity(mapId);
String logicData = entity.getLogicData();
if (StringUtils.isBlank(logicData)) {
if (logicData.isBlank()) {
return new PageVO<>(queryVO.getPageNum(), queryVO.getPageSize(), 0, new ArrayList<>());
}
List<MapDestinationCodeDefinitionVO> vos = JsonUtils.read(logicData, JsonUtils.getCollectionType(ArrayList.class, MapDestinationCodeDefinitionVO.class));
@ -2021,7 +1976,13 @@ public class DraftMapService implements IDraftMapService {
return entity;
}
private DraftMapAutoSignal getDraftMapAutoSignalEntity(Long autoSignalId){
private DraftMapParkingTime getDraftMapParkingTimeEntity(Long id) {
DraftMapParkingTime draftMapParkingTime = this.draftMapParkingTimeDAO.selectByPrimaryKey(id);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(draftMapParkingTime, String.format("id为[%s]的草稿车站停站时间数据不存在", id));
return draftMapParkingTime;
}
private DraftMapAutoSignal getDraftMapAutoSignalEntity(Long autoSignalId) {
DraftMapAutoSignal autoSignal = findDraftMapAutoSignalEntity(autoSignalId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(autoSignal, String.format("id为[%s]的自动信号不存在", autoSignalId));
return autoSignal;
@ -2076,4 +2037,16 @@ public class DraftMapService implements IDraftMapService {
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(draftMapAutoReentry);
return draftMapAutoReentry;
}
private DraftMapRouting getDraftMapRoutingEntity(Long routingId) {
DraftMapRouting routing = draftMapRoutingDAO.selectByPrimaryKey(routingId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(routing);
return routing;
}
private DraftMap3dDataWithBLOBs getDraftMap3dDataEntity(Long map3dId) {
DraftMap3dDataWithBLOBs data = draftMap3dDataDAO.selectByPrimaryKey(map3dId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(data);
return data;
}
}