报错消除(未完)
This commit is contained in:
parent
d761ef143b
commit
88e49ce5b0
@ -2,9 +2,6 @@ package club.joylink.rtss.services;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.joylink.base.exception.BusinessException;
|
||||
import com.joylink.base.exception.DBException;
|
||||
import com.joylink.base.exception.constant.ExceptionMapping;
|
||||
import club.joylink.rtss.simulation.cbtc.build.SimulationBuilder;
|
||||
import club.joylink.rtss.simulation.cbtc.data.CalculateService;
|
||||
import club.joylink.rtss.simulation.cbtc.data.map.Section;
|
||||
@ -14,7 +11,6 @@ import club.joylink.rtss.entity.*;
|
||||
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
|
||||
import club.joylink.rtss.services.draftData.DraftMapFlankProtectionService;
|
||||
import club.joylink.rtss.services.draftData.DraftMapRunLevelService;
|
||||
import club.joylink.rtss.util.ConvertUtil;
|
||||
import club.joylink.rtss.util.JsonUtils;
|
||||
import club.joylink.rtss.vo.UserVO;
|
||||
import club.joylink.rtss.vo.client.PageQueryVO;
|
||||
@ -158,9 +154,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
DraftMapWithBLOBs draftMap = draftMapVo.convert2Draft();
|
||||
draftMap.setAuthorId(userVO.getId());
|
||||
// 名称唯一性校验
|
||||
if (checkDraftMapNameExist(draftMap)) {
|
||||
throw new DBException(ExceptionMapping.NAME_REPEAT);
|
||||
}
|
||||
ensureDraftMapNameNotExist(draftMap);
|
||||
draftMap.setUpdateTime(LocalDateTime.now());
|
||||
if (draftMap.getDrawWay()) {
|
||||
MapGraphDataNewVO graphDataVO = new MapGraphDataNewVO();
|
||||
@ -172,23 +166,19 @@ public class DraftMapService implements IDraftMapService {
|
||||
draftMap.setGraphData(JsonUtils.writeValueAsString(graphDataVO));
|
||||
}
|
||||
draftMapDAO.insert(draftMap);
|
||||
return ConvertUtil.long2Str(draftMap.getId());
|
||||
return draftMap.getId().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Long id, DraftMapVO draftMapVO, UserVO userVO) {
|
||||
draftMapVO.setId(id);
|
||||
DraftMapWithBLOBs draftMap = draftMapDAO.selectByPrimaryKey(id);
|
||||
if (ObjectUtils.isEmpty(draftMap)) {
|
||||
throw new DBException(ExceptionMapping.DATA_NOT_EXIST);
|
||||
}
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(!ObjectUtils.isEmpty(draftMap));
|
||||
DraftMapWithBLOBs upMap = draftMapVO.convert2Draft();
|
||||
upMap.setAuthorId(userVO.getId());
|
||||
upMap.setUpdateTime(LocalDateTime.now());
|
||||
// 名称唯一性校验
|
||||
if (checkDraftMapNameExist(upMap)) {
|
||||
throw new DBException(ExceptionMapping.NAME_REPEAT);
|
||||
}
|
||||
ensureDraftMapNameNotExist(upMap);
|
||||
//更改线路的话重置皮肤数据
|
||||
String changedLineCode = draftMapVO.getLineCode();//传递的线路code
|
||||
if (StringUtils.hasText(changedLineCode) && !Objects.equals(draftMap.getLineCode(), changedLineCode)) {
|
||||
@ -214,9 +204,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
draftMap.setName(name);
|
||||
draftMap.setUpdateTime(LocalDateTime.now());
|
||||
// 名称唯一性校验
|
||||
if (checkDraftMapNameExist(draftMap)) {
|
||||
throw new DBException(ExceptionMapping.NAME_REPEAT);
|
||||
}
|
||||
ensureDraftMapNameNotExist(draftMap);
|
||||
// 插入新副本
|
||||
draftMapDAO.insert(draftMap);
|
||||
if (draftMap.getDrawWay()) {
|
||||
@ -245,7 +233,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
String shapeData = draftMap.getGraphData();
|
||||
if (draftMap.getDrawWay()) {
|
||||
MapGraphDataNewVO mapGraphDataNewVO;
|
||||
if (StringUtils.isBlank(shapeData)) {
|
||||
if (shapeData.isBlank()) {
|
||||
mapGraphDataNewVO = new MapGraphDataNewVO();
|
||||
} else {
|
||||
mapGraphDataNewVO = JsonUtils.read(shapeData, MapGraphDataNewVO.class);
|
||||
@ -253,7 +241,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
return mapGraphDataNewVO;
|
||||
}
|
||||
MapGraphDataVO mapGraphDataVO;
|
||||
if (StringUtils.isBlank(shapeData)) {
|
||||
if (shapeData.isBlank()) {
|
||||
mapGraphDataVO = new MapGraphDataVO();
|
||||
} else {
|
||||
mapGraphDataVO = JsonUtils.read(shapeData, MapGraphDataVO.class);
|
||||
@ -324,11 +312,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
|
||||
@Override
|
||||
public MapVO export(Long id) {
|
||||
DraftMapWithBLOBs draftMap = this.draftMapDAO.selectByPrimaryKey(id);
|
||||
if (Objects.isNull(draftMap)) {
|
||||
throw new BusinessException(ExceptionMapping.DATA_NOT_EXIST,
|
||||
String.format("id为[%s]的草稿地图不存在", id));
|
||||
}
|
||||
DraftMapWithBLOBs draftMap = getEntity(id);
|
||||
MapVO mapVO = new MapVO(draftMap);
|
||||
MapDataVO mapDataVO;
|
||||
if (draftMap.getDrawWay()) {
|
||||
@ -345,7 +329,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
String shapeData = draftMap.getGraphData();
|
||||
if (draftMap.getDrawWay()) {
|
||||
MapGraphDataNewVO mapGraphDataNewVO;
|
||||
if (StringUtils.isBlank(shapeData)) {
|
||||
if (shapeData.isBlank()) {
|
||||
mapGraphDataNewVO = new MapGraphDataNewVO();
|
||||
} else {
|
||||
mapGraphDataNewVO = JsonUtils.read(shapeData, MapGraphDataNewVO.class);
|
||||
@ -353,7 +337,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
return mapGraphDataNewVO;
|
||||
}
|
||||
MapGraphDataVO mapGraphDataVO;
|
||||
if (StringUtils.isBlank(shapeData)) {
|
||||
if (shapeData.isBlank()) {
|
||||
mapGraphDataVO = new MapGraphDataVO();
|
||||
} else {
|
||||
mapGraphDataVO = JsonUtils.read(shapeData, MapGraphDataVO.class);
|
||||
@ -381,9 +365,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
draftMap.setName(name);
|
||||
draftMap.setAuthorId(userVO.getId());
|
||||
// 名称唯一性校验
|
||||
if (checkDraftMapNameExist(draftMap)) {
|
||||
throw new DBException(ExceptionMapping.NAME_REPEAT);
|
||||
}
|
||||
ensureDraftMapNameNotExist(draftMap);
|
||||
draftMap.setLineCode(mapVO.getLineCode());
|
||||
draftMap.setDrawWay(mapVO.isDrawWay());
|
||||
draftMap.setUpdateTime(LocalDateTime.now());
|
||||
@ -510,7 +492,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
List<MapStationVO> stationList = mapDataVO.getShapeData().getStationList();
|
||||
Map<String, MapStationVO> stationVOMap = stationList.stream().collect(Collectors.toMap(MapStationVO::getCode, Function.identity()));
|
||||
stationList.forEach(station -> {
|
||||
if (StringUtils.isBlank(station.getConcentrateStationCode())) {
|
||||
if (station.getConcentrateStationCode().isBlank()) {
|
||||
exDataList.add(String.format("车站 %s(%s) 所属设备集中站为空", station.getName(), station.getCode()));
|
||||
} else if (!stationVOMap.containsKey(station.getConcentrateStationCode())) {
|
||||
exDataList.add(String.format("车站 %s(%s) 所属设备集中站不存在", station.getName(), station.getCode()));
|
||||
@ -570,13 +552,13 @@ public class DraftMapService implements IDraftMapService {
|
||||
section1.getName(), section1.getCode(), section2.getName(), section2.getCode()));
|
||||
}
|
||||
}
|
||||
if (StringUtils.isBlank(section1.getStationCode())) {
|
||||
if (section1.getStationCode().isBlank()) {
|
||||
exDataList.add(String.format("区段 %s(%s) 所属设备集中站为空", section1.getName(), section1.getCode()));
|
||||
} else if (!stationVOMap.containsKey(section1.getStationCode())) {
|
||||
exDataList.add(String.format("区段 %s(%s) 所属设备集中站不存在", section1.getName(), section1.getCode()));
|
||||
}
|
||||
if (section1.getIsStandTrack()) {
|
||||
if (StringUtils.isBlank(section1.getRelStandCode())) {
|
||||
if (section1.getRelStandCode().isBlank()) {
|
||||
exDataList.add(String.format("区段 %s(%s) 是站台轨,但没有关联站台", section1.getName(), section1.getCode()));
|
||||
} else if (!standVOMap.containsKey(section1.getRelStandCode())) {
|
||||
exDataList.add(String.format("区段 %s(%s) 关联的站台不存在", section1.getName(), section1.getCode()));
|
||||
@ -593,7 +575,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
List<MapSwitchVO> switchList = mapDataVO.getShapeData().getSwitchList();
|
||||
Map<String, MapSwitchVO> switchVOMap = switchList.stream().collect(Collectors.toMap(MapSwitchVO::getCode, Function.identity()));
|
||||
switchList.forEach(switchVO -> {
|
||||
if (StringUtils.isBlank(switchVO.getStationCode())) {
|
||||
if (switchVO.getStationCode().isBlank()) {
|
||||
exDataList.add(String.format("道岔 %s(%s) 所属设备集中站为空", switchVO.getName(), switchVO.getCode()));
|
||||
} else if (!stationVOMap.containsKey(switchVO.getStationCode())) {
|
||||
exDataList.add(String.format("道岔 %s(%s) 所属设备集中站不存在", switchVO.getName(), switchVO.getCode()));
|
||||
@ -629,7 +611,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
&& signalVO.getOffset().equals(linkVO.getLengthFact())) {
|
||||
exDataList.add(String.format("信号机 %s(%s) 偏移量不能为Link实际长度", signalVO.getName(), signalVO.getCode()));
|
||||
}
|
||||
if (StringUtils.isBlank(signalVO.getStationCode())) {
|
||||
if (signalVO.getStationCode().isBlank()) {
|
||||
exDataList.add(String.format("信号机 %s(%s) 所属设备集中站为空", signalVO.getName(), signalVO.getCode()));
|
||||
} else if (!stationVOMap.containsKey(signalVO.getStationCode())) {
|
||||
exDataList.add(String.format("信号机 %s(%s) 所属设备集中站不存在", signalVO.getName(), signalVO.getCode()));
|
||||
@ -682,7 +664,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
List<MapRouteVO> routeList = mapDataVO.getLogicData().getRouteList();
|
||||
Map<String, MapRouteVO> routeVOMap = routeList.stream().collect(Collectors.toMap(MapRouteVO::getCode, Function.identity()));
|
||||
routeList.forEach(routeVO -> {
|
||||
if (StringUtils.isBlank(routeVO.getStationCode())) {
|
||||
if (routeVO.getStationCode().isBlank()) {
|
||||
exDataList.add(String.format("进路 %s(%s) 所属设备集中站为空", routeVO.getName(), routeVO.getCode()));
|
||||
} else if (!stationVOMap.containsKey(routeVO.getStationCode())) {
|
||||
exDataList.add(String.format("进路 %s(%s) 所属设备集中站不存在", routeVO.getName(), routeVO.getCode()));
|
||||
@ -822,11 +804,12 @@ public class DraftMapService implements IDraftMapService {
|
||||
draftMapDAO.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
private void ensureDraftMapNameNotExist(DraftMap map) {
|
||||
BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertNotTrue(checkDraftMapNameExist(map));
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验地图名称是否已经存在
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
private boolean checkDraftMapNameExist(DraftMap map) {
|
||||
DraftMapExample example = new DraftMapExample();
|
||||
@ -1104,16 +1087,12 @@ public class DraftMapService implements IDraftMapService {
|
||||
//数据校验
|
||||
String switchACode = switchCoupledVO.getSwitchACode();
|
||||
String switchBCode = switchCoupledVO.getSwitchBCode();
|
||||
if (switchACode.equalsIgnoreCase(switchBCode)) {
|
||||
throw new DBException(ExceptionMapping.ILLEGAL_OPERATION);
|
||||
}
|
||||
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue(switchACode.equalsIgnoreCase(switchBCode));
|
||||
DraftMapSwitchCoupledExample example = new DraftMapSwitchCoupledExample();
|
||||
List<String> switchCodes = Arrays.asList(switchCoupledVO.getSwitchACode(), switchCoupledVO.getSwitchBCode());
|
||||
example.createCriteria().andMapIdEqualTo(switchCoupledVO.getMapId()).andSwitchaCodeIn(switchCodes).andSwitchbCodeIn(switchCodes);
|
||||
long size = draftMapSwitchCoupledDAO.countByExample(example);
|
||||
if (size > 0) {
|
||||
throw new DBException(ExceptionMapping.CODE_REPEAT);
|
||||
}
|
||||
BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertNotTrue(size > 0);
|
||||
//插入数据
|
||||
draftMapSwitchCoupledDAO.insert(switchCoupledVO.convert2VO());
|
||||
}
|
||||
@ -1158,9 +1137,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
.andMapIdEqualTo(approachSectionVO.getMapId())
|
||||
.andSignalCodeEqualTo(approachSectionVO.getSignalCode());
|
||||
List<DraftMapSignalApproachSection> list = this.draftMapSignalApproachSectionDAO.selectByExample(example);
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
throw new DBException(ExceptionMapping.DATA_EXISTS);
|
||||
}
|
||||
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertTrue(CollectionUtils.isEmpty(list));
|
||||
DraftMapSignalApproachSection approachSection = approachSectionVO.convert2Draft();
|
||||
this.draftMapSignalApproachSectionDAO.insert(approachSection);
|
||||
}
|
||||
@ -1185,9 +1162,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
public MapSignalApproachSectionVO getApproachSectionById(Long id) {
|
||||
Objects.requireNonNull(id);
|
||||
DraftMapSignalApproachSection approachSection = this.draftMapSignalApproachSectionDAO.selectByPrimaryKey(id);
|
||||
if (Objects.isNull(approachSection)) {
|
||||
throw new DBException(ExceptionMapping.DATA_NOT_EXIST);
|
||||
}
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(approachSection);
|
||||
return MapSignalApproachSectionVO.convert2VO(approachSection);
|
||||
}
|
||||
|
||||
@ -1208,18 +1183,14 @@ public class DraftMapService implements IDraftMapService {
|
||||
|
||||
@Override
|
||||
public void createAutoSignal(MapAutoSignalVO autoSignalVO) {
|
||||
if (ifAutoSignalExist(autoSignalVO, null)) {
|
||||
throw new DBException(ExceptionMapping.DATA_EXISTS);
|
||||
}
|
||||
ensureAutoSignalNotExist(autoSignalVO, null);
|
||||
DraftMapAutoSignal autoSignal = autoSignalVO.convert2Draft();
|
||||
draftMapAutoSignalDAO.insert(autoSignal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAutoSignal(MapAutoSignalNewVO autoSignalVO) {
|
||||
if (ifAutoSignalExist(autoSignalVO, null)) {
|
||||
throw new DBException(ExceptionMapping.DATA_EXISTS);
|
||||
}
|
||||
ensureAutoSignalNotExist(autoSignalVO, null);
|
||||
DraftMapAutoSignal autoSignal = autoSignalVO.convert2Draft();
|
||||
draftMapAutoSignalDAO.insert(autoSignal);
|
||||
}
|
||||
@ -1262,31 +1233,26 @@ public class DraftMapService implements IDraftMapService {
|
||||
|
||||
@Override
|
||||
public MapAutoSignalVO getAutoSignal(Long autoSignalId) {
|
||||
DraftMapAutoSignal autoSignal = draftMapAutoSignalDAO.selectByPrimaryKey(autoSignalId);
|
||||
if (Objects.isNull(autoSignal)) {
|
||||
throw new DBException(ExceptionMapping.DATA_NOT_EXIST);
|
||||
}
|
||||
DraftMapAutoSignal autoSignal = findDraftMapAutoSignalEntity(autoSignalId);
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(autoSignal);
|
||||
return MapAutoSignalVO.convert2VO(autoSignal);
|
||||
}
|
||||
|
||||
private DraftMapAutoSignal findDraftMapAutoSignalEntity(Long autoSignalId) {
|
||||
return draftMapAutoSignalDAO.selectByPrimaryKey(autoSignalId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapAutoSignalNewVO getAutoSignalNew(Long autoSignalId) {
|
||||
DraftMapAutoSignal autoSignal = draftMapAutoSignalDAO.selectByPrimaryKey(autoSignalId);
|
||||
if (Objects.isNull(autoSignal)) {
|
||||
throw new DBException(ExceptionMapping.DATA_NOT_EXIST);
|
||||
}
|
||||
DraftMapAutoSignal autoSignal = findDraftMapAutoSignalEntity(autoSignalId);
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(autoSignal);
|
||||
return MapAutoSignalNewVO.convert2VO(autoSignal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAutoSignal(Long autoSignalId, MapAutoSignalVO autoSignalVO) {
|
||||
DraftMapAutoSignal autoSignal = draftMapAutoSignalDAO.selectByPrimaryKey(autoSignalId);
|
||||
if (Objects.isNull(autoSignal)) {
|
||||
throw new DBException(ExceptionMapping.DATA_NOT_EXIST);
|
||||
}
|
||||
if (ifAutoSignalExist(autoSignalVO, autoSignalId)) {
|
||||
throw new DBException(ExceptionMapping.DATA_EXISTS);
|
||||
}
|
||||
getDraftMapAutoSignalEntity(autoSignalId);
|
||||
ensureAutoSignalNotExist(autoSignalVO, autoSignalId);
|
||||
DraftMapAutoSignal newAutoSignal = autoSignalVO.convert2Draft();
|
||||
newAutoSignal.setId(autoSignalId);
|
||||
draftMapAutoSignalDAO.updateByPrimaryKeyWithBLOBs(newAutoSignal);
|
||||
@ -1294,13 +1260,8 @@ public class DraftMapService implements IDraftMapService {
|
||||
|
||||
@Override
|
||||
public void updateAutoSignal(Long autoSignalId, MapAutoSignalNewVO autoSignalVO) {
|
||||
DraftMapAutoSignal autoSignal = draftMapAutoSignalDAO.selectByPrimaryKey(autoSignalId);
|
||||
if (Objects.isNull(autoSignal)) {
|
||||
throw new DBException(ExceptionMapping.DATA_NOT_EXIST);
|
||||
}
|
||||
if (ifAutoSignalExist(autoSignalVO, autoSignalId)) {
|
||||
throw new DBException(ExceptionMapping.DATA_EXISTS);
|
||||
}
|
||||
getDraftMapAutoSignalEntity(autoSignalId);
|
||||
ensureAutoSignalNotExist(autoSignalVO, autoSignalId);
|
||||
DraftMapAutoSignal newAutoSignal = autoSignalVO.convert2Draft();
|
||||
newAutoSignal.setId(autoSignalId);
|
||||
draftMapAutoSignalDAO.updateByPrimaryKeyWithBLOBs(newAutoSignal);
|
||||
@ -1331,6 +1292,10 @@ public class DraftMapService implements IDraftMapService {
|
||||
return !CollectionUtils.isEmpty(draftMapAutoSignals);
|
||||
}
|
||||
|
||||
private void ensureAutoSignalNotExist(MapAutoSignalVO mapAutoSignalVO, Long autoSignalId) {
|
||||
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(ifAutoSignalExist(mapAutoSignalVO, autoSignalId));
|
||||
}
|
||||
|
||||
private boolean ifAutoSignalExist(MapAutoSignalNewVO mapAutoSignalVO, Long autoSignalId) {
|
||||
DraftMapAutoSignalExample autoSignalExample = new DraftMapAutoSignalExample();
|
||||
DraftMapAutoSignalExample.Criteria criteria = autoSignalExample.createCriteria();
|
||||
@ -1342,6 +1307,10 @@ public class DraftMapService implements IDraftMapService {
|
||||
List<DraftMapAutoSignal> draftMapAutoSignals = draftMapAutoSignalDAO.selectByExample(autoSignalExample);
|
||||
return !CollectionUtils.isEmpty(draftMapAutoSignals);
|
||||
}
|
||||
|
||||
private void ensureAutoSignalNotExist(MapAutoSignalNewVO mapAutoSignalVO, Long autoSignalId) {
|
||||
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(ifAutoSignalExist(mapAutoSignalVO, autoSignalId));
|
||||
}
|
||||
/*------------ AutoSignal END ---------------------*/
|
||||
|
||||
|
||||
@ -1349,11 +1318,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
@Override
|
||||
public void createRoute(MapRouteVO routeVO) {
|
||||
// 编号唯一校验
|
||||
DraftMapRouteExample example = new DraftMapRouteExample();
|
||||
example.createCriteria().andMapIdEqualTo(routeVO.getMapId()).andCodeEqualTo(routeVO.getCode());
|
||||
if (draftMapRouteDAO.countByExample(example) > 0) {
|
||||
throw new DBException(ExceptionMapping.DATA_EXISTS);
|
||||
}
|
||||
ensureRouteNotExist(routeVO.getMapId(), routeVO.getCode());
|
||||
// 保存进路信息
|
||||
DraftMapRoute route = routeVO.convert2Draft();
|
||||
draftMapRouteDAO.insert(route);
|
||||
@ -1362,11 +1327,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
@Override
|
||||
public void createRoute(MapRouteNewVO routeVO) {
|
||||
// 编号唯一校验
|
||||
DraftMapRouteExample example = new DraftMapRouteExample();
|
||||
example.createCriteria().andMapIdEqualTo(routeVO.getMapId()).andCodeEqualTo(routeVO.getCode());
|
||||
if (draftMapRouteDAO.countByExample(example) > 0) {
|
||||
throw new DBException(ExceptionMapping.DATA_EXISTS);
|
||||
}
|
||||
ensureRouteNotExist(routeVO.getMapId(), routeVO.getCode());
|
||||
// 保存进路信息
|
||||
DraftMapRoute route = routeVO.convert2Draft();
|
||||
draftMapRouteDAO.insert(route);
|
||||
@ -1431,22 +1392,19 @@ public class DraftMapService implements IDraftMapService {
|
||||
|
||||
@Override
|
||||
public MapRouteVO getRouteDetail(Long routeId) {
|
||||
DraftMapRoute route = draftMapRouteDAO.selectByPrimaryKey(routeId);
|
||||
DraftMapRoute route = findDraftRouteEntity(routeId);
|
||||
return MapRouteVO.convert2VO(route);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapRouteNewVO getRouteDetailNew(Long routeId) {
|
||||
DraftMapRoute route = draftMapRouteDAO.selectByPrimaryKey(routeId);
|
||||
DraftMapRoute route = findDraftRouteEntity(routeId);
|
||||
return MapRouteNewVO.convert2VO(route);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRoute(Long routeId, MapRouteVO routeVO) {
|
||||
DraftMapRoute route = draftMapRouteDAO.selectByPrimaryKey(routeId);
|
||||
if (Objects.isNull(route)) {
|
||||
throw new DBException(ExceptionMapping.DATA_NOT_EXIST);
|
||||
}
|
||||
getDraftRouteEntity(routeId);
|
||||
DraftMapRoute newRoute = routeVO.convert2Draft();
|
||||
newRoute.setId(routeId);
|
||||
draftMapRouteDAO.updateByPrimaryKeyWithBLOBs(newRoute);
|
||||
@ -1454,10 +1412,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
|
||||
@Override
|
||||
public void updateRoute(Long routeId, MapRouteNewVO routeVO) {
|
||||
DraftMapRoute route = draftMapRouteDAO.selectByPrimaryKey(routeId);
|
||||
if (Objects.isNull(route)) {
|
||||
throw new DBException(ExceptionMapping.DATA_NOT_EXIST);
|
||||
}
|
||||
getDraftRouteEntity(routeId);
|
||||
DraftMapRoute newRoute = routeVO.convert2Draft();
|
||||
newRoute.setId(routeId);
|
||||
draftMapRouteDAO.updateByPrimaryKeyWithBLOBs(newRoute);
|
||||
@ -1474,15 +1429,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
@Override
|
||||
public void createOverlap(MapOverlapVO mapOverlapVO) {
|
||||
if (StringUtils.hasText(mapOverlapVO.getName())) {
|
||||
DraftMapOverlapExample example = new DraftMapOverlapExample();
|
||||
example.createCriteria()
|
||||
.andMapIdEqualTo(mapOverlapVO.getMapId())
|
||||
.andNameEqualTo(mapOverlapVO.getName());
|
||||
List<DraftMapOverlap> list = this.draftMapOverlapDAO.selectByExample(example);
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
throw new DBException(ExceptionMapping.DATA_EXISTS,
|
||||
String.format("名称重复"));
|
||||
}
|
||||
ensureOverlapNameNotRepeat(mapOverlapVO);
|
||||
}
|
||||
DraftMapOverlap draftMapOverlap = mapOverlapVO.convert2Draft();
|
||||
this.draftMapOverlapDAO.insert(draftMapOverlap);
|
||||
@ -1507,20 +1454,13 @@ public class DraftMapService implements IDraftMapService {
|
||||
@Override
|
||||
public MapOverlapVO getOverlapById(Long id) {
|
||||
Objects.requireNonNull(id);
|
||||
DraftMapOverlap draftMapOverlap = this.draftMapOverlapDAO.selectByPrimaryKey(id);
|
||||
if (Objects.isNull(draftMapOverlap)) {
|
||||
throw new DBException(ExceptionMapping.DATA_NOT_EXIST);
|
||||
}
|
||||
DraftMapOverlap draftMapOverlap = getDraftMapOverlapEntity(id);
|
||||
return MapOverlapVO.convert2VO(draftMapOverlap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateOverlap(Long id, MapOverlapVO mapOverlapVO) {
|
||||
DraftMapOverlap db = this.draftMapOverlapDAO.selectByPrimaryKey(id);
|
||||
if (Objects.isNull(db)) {
|
||||
throw new DBException(ExceptionMapping.DATA_NOT_EXIST);
|
||||
}
|
||||
|
||||
getDraftMapOverlapEntity(id);
|
||||
DraftMapOverlap draftMapOverlap = mapOverlapVO.convert2Draft();
|
||||
draftMapOverlap.setId(id);
|
||||
this.draftMapOverlapDAO.updateByPrimaryKeySelective(draftMapOverlap);
|
||||
@ -1536,14 +1476,7 @@ public class DraftMapService implements IDraftMapService {
|
||||
/*------------autoReentry start ---------------------*/
|
||||
@Override
|
||||
public void createAutoReentry(MapAutoReentryVO mapAutoReentryVO) {
|
||||
DraftMapAutoReentryExample example = new DraftMapAutoReentryExample();
|
||||
example.createCriteria()
|
||||
.andMapIdEqualTo(mapAutoReentryVO.getMapId())
|
||||
.andCodeEqualTo(mapAutoReentryVO.getCode());
|
||||
List<DraftMapAutoReentry> list = this.draftMapAutoReentryDAO.selectByExample(example);
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
throw new DBException(ExceptionMapping.DATA_EXISTS);
|
||||
}
|
||||
ensureAutoReentryNotExist(mapAutoReentryVO);
|
||||
DraftMapAutoReentry draftMapAutoReentry = mapAutoReentryVO.convert2Draft();
|
||||
this.draftMapAutoReentryDAO.insert(draftMapAutoReentry);
|
||||
}
|
||||
@ -1583,19 +1516,13 @@ public class DraftMapService implements IDraftMapService {
|
||||
@Override
|
||||
public MapAutoReentryVO getAutoReentryById(Long id) {
|
||||
Objects.requireNonNull(id);
|
||||
DraftMapAutoReentry draftMapAutoReentry = this.draftMapAutoReentryDAO.selectByPrimaryKey(id);
|
||||
if (Objects.isNull(draftMapAutoReentry)) {
|
||||
throw new DBException(ExceptionMapping.DATA_NOT_EXIST);
|
||||
}
|
||||
DraftMapAutoReentry draftMapAutoReentry = getDraftMapAutoReentryEntity(id);
|
||||
return MapAutoReentryVO.convert2VO(draftMapAutoReentry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAutoReentry(Long id, MapAutoReentryVO mapAutoReentryVO) {
|
||||
DraftMapAutoReentry db = this.draftMapAutoReentryDAO.selectByPrimaryKey(id);
|
||||
if (Objects.isNull(db)) {
|
||||
throw new DBException(ExceptionMapping.DATA_NOT_EXIST);
|
||||
}
|
||||
DraftMapAutoReentry db = getDraftMapAutoReentryEntity(id);
|
||||
DraftMapAutoReentry draftMapAutoReentry = mapAutoReentryVO.convert2Draft();
|
||||
draftMapAutoReentry.setId(id);
|
||||
this.draftMapAutoReentryDAO.updateByPrimaryKeySelective(draftMapAutoReentry);
|
||||
@ -2089,7 +2016,64 @@ public class DraftMapService implements IDraftMapService {
|
||||
|
||||
private DraftMapWithBLOBs getEntity(Long id) {
|
||||
DraftMapWithBLOBs entity = findEntity(id);
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(entity);
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(entity,
|
||||
String.format("id为[%s]的草稿地图不存在", id));
|
||||
return entity;
|
||||
}
|
||||
|
||||
private DraftMapAutoSignal getDraftMapAutoSignalEntity(Long autoSignalId){
|
||||
DraftMapAutoSignal autoSignal = findDraftMapAutoSignalEntity(autoSignalId);
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(autoSignal, String.format("id为[%s]的自动信号不存在", autoSignalId));
|
||||
return autoSignal;
|
||||
}
|
||||
|
||||
private void ensureRouteNotExist(Long mapId, String code) {
|
||||
DraftMapRouteExample example = new DraftMapRouteExample();
|
||||
example.createCriteria().andMapIdEqualTo(mapId).andCodeEqualTo(code);
|
||||
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertTrue(draftMapRouteDAO.countByExample(example) == 0);
|
||||
}
|
||||
|
||||
private DraftMapRoute findDraftRouteEntity(Long id) {
|
||||
return draftMapRouteDAO.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
private DraftMapRoute getDraftRouteEntity(Long id) {
|
||||
DraftMapRoute route = findDraftRouteEntity(id);
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(route);
|
||||
return route;
|
||||
}
|
||||
|
||||
private void ensureOverlapNameNotRepeat(MapOverlapVO mapOverlapVO) {
|
||||
DraftMapOverlapExample example = new DraftMapOverlapExample();
|
||||
example.createCriteria()
|
||||
.andMapIdEqualTo(mapOverlapVO.getMapId())
|
||||
.andNameEqualTo(mapOverlapVO.getName());
|
||||
List<DraftMapOverlap> list = this.draftMapOverlapDAO.selectByExample(example);
|
||||
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertTrue(CollectionUtils.isEmpty(list), "名称重复");
|
||||
}
|
||||
|
||||
private DraftMapOverlap findDraftMapOverlapEntity(Long id) {
|
||||
return this.draftMapOverlapDAO.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
private DraftMapOverlap getDraftMapOverlapEntity(Long id) {
|
||||
DraftMapOverlap draftMapOverlap = findDraftMapOverlapEntity(id);
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(draftMapOverlap);
|
||||
return draftMapOverlap;
|
||||
}
|
||||
|
||||
private void ensureAutoReentryNotExist(MapAutoReentryVO mapAutoReentryVO) {
|
||||
DraftMapAutoReentryExample example = new DraftMapAutoReentryExample();
|
||||
example.createCriteria()
|
||||
.andMapIdEqualTo(mapAutoReentryVO.getMapId())
|
||||
.andCodeEqualTo(mapAutoReentryVO.getCode());
|
||||
List<DraftMapAutoReentry> list = this.draftMapAutoReentryDAO.selectByExample(example);
|
||||
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertTrue(CollectionUtils.isEmpty(list));
|
||||
}
|
||||
|
||||
private DraftMapAutoReentry getDraftMapAutoReentryEntity(Long id) {
|
||||
DraftMapAutoReentry draftMapAutoReentry = this.draftMapAutoReentryDAO.selectByPrimaryKey(id);
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(draftMapAutoReentry);
|
||||
return draftMapAutoReentry;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
package club.joylink.rtss.services;
|
||||
|
||||
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.joylink.base.exception.BusinessException;
|
||||
import com.joylink.base.exception.DBException;
|
||||
import com.joylink.base.exception.constant.ExceptionMapping;
|
||||
import club.joylink.rtss.constants.BusinessConsts;
|
||||
import club.joylink.rtss.constants.SaleGoodsTypeEnum;
|
||||
import club.joylink.rtss.constants.StatusEnum;
|
||||
@ -15,15 +13,12 @@ import club.joylink.rtss.entity.Permission;
|
||||
import club.joylink.rtss.entity.PermissionExample;
|
||||
import club.joylink.rtss.entity.SaleGoods;
|
||||
import club.joylink.rtss.entity.SaleGoodsExample;
|
||||
import club.joylink.rtss.util.ConvertUtil;
|
||||
import club.joylink.rtss.vo.UserVO;
|
||||
import club.joylink.rtss.vo.client.GoodsTryVO;
|
||||
import club.joylink.rtss.vo.client.PageVO;
|
||||
import club.joylink.rtss.vo.client.goods.GoodsCreateVO;
|
||||
import club.joylink.rtss.vo.client.goods.GoodsQueryVO;
|
||||
import club.joylink.rtss.vo.client.goods.GoodsUpdateVO;
|
||||
import club.joylink.rtss.vo.client.goods.GoodsVO;
|
||||
import club.joylink.rtss.vo.client.permission.PermissionCreateVO;
|
||||
import club.joylink.rtss.vo.client.permission.PermissionQueryVO;
|
||||
import club.joylink.rtss.vo.client.permission.PermissionSelectVO;
|
||||
import club.joylink.rtss.vo.client.permission.PermissionVO;
|
||||
@ -31,7 +26,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
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.time.LocalDateTime;
|
||||
@ -94,87 +88,16 @@ public class GoodsService implements IGoodsService {
|
||||
|
||||
/**
|
||||
* 根据id查询商品。
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public GoodsVO selectById(long id) {
|
||||
SaleGoods goods = saleGoodsDAO.selectByPrimaryKey(id);
|
||||
SaleGoods goods = findEntity(id);
|
||||
if (goods == null) {
|
||||
return null;
|
||||
}
|
||||
return new GoodsVO(goods);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建商品。
|
||||
* 如果商品已存在,报DBException(数据已存在)
|
||||
* 如果有重名商品,报DBException(名称重复)
|
||||
*
|
||||
* @param createVO
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public GoodsVO createGoods(GoodsCreateVO createVO, UserVO user) {
|
||||
//判断商品是否已存在
|
||||
if (!findGoodsByPermissionId(createVO.getPermissionId()).isEmpty()) {
|
||||
throw new DBException(ExceptionMapping.DATA_EXISTS);
|
||||
}
|
||||
|
||||
//判断是否和已有商品重名
|
||||
if (isNameExist(createVO.getName())) {
|
||||
throw new DBException(ExceptionMapping.NAME_REPEAT, String.format("名称为[%s]的商品已存在", createVO.getName()));
|
||||
}
|
||||
|
||||
//添加商品
|
||||
SaleGoods goods = createVO.convert2DB();
|
||||
goods.setStatus(StatusEnum.Valid.getCode());
|
||||
goods.setCreateTime(LocalDateTime.now());
|
||||
goods.setCreatorId(user.getId());
|
||||
saleGoodsDAO.insertSelective(goods);
|
||||
return new GoodsVO(goods);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建多个商品。
|
||||
* 如果商品已存在,将查询到的商品加入返回的List;
|
||||
* 如果有重名商品,报DBException(名称重复!)
|
||||
*
|
||||
* @param createVOList
|
||||
* @param userVO
|
||||
* @return
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public List<GoodsVO> createManyGoods(List<GoodsCreateVO> createVOList, UserVO userVO) {
|
||||
List<GoodsVO> returnGoodsVOList = new ArrayList<>();
|
||||
for (GoodsCreateVO createVO : createVOList) {
|
||||
GoodsVO goods = new GoodsVO();
|
||||
try {
|
||||
goods = createGoods(createVO, userVO);
|
||||
} catch (DBException e) {
|
||||
switch (e.getErrcode()) {
|
||||
case 20001:
|
||||
goods = selectGoodsByPermissionId(createVO.getPermissionId());
|
||||
break;
|
||||
case 20003:
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
returnGoodsVOList.add(goods);
|
||||
}
|
||||
return returnGoodsVOList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteGoods(long id) {
|
||||
saleGoodsDAO.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tryUse(Long id, Map<String, Long> map, UserVO user) {
|
||||
|
||||
@ -183,8 +106,6 @@ public class GoodsService implements IGoodsService {
|
||||
/**
|
||||
* 改变商品状态(有效/无效)。
|
||||
* 如果要改变状态的商品不存在,报DBException(DATA_NOT_EXIST)
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@Override
|
||||
public void toggleGoodsStatus(long id) {
|
||||
@ -202,20 +123,9 @@ public class GoodsService implements IGoodsService {
|
||||
saleGoodsDAO.updateByPrimaryKeySelective(goods);
|
||||
}
|
||||
|
||||
private SaleGoods getEntityById(long id) {
|
||||
SaleGoods goods = saleGoodsDAO.selectByPrimaryKey(id);
|
||||
if (goods == null) {
|
||||
throw new DBException(ExceptionMapping.DATA_NOT_EXIST, String.format("id为[%s]的商品不存在", id));
|
||||
}
|
||||
return goods;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过权限id查询商品。
|
||||
* 如果不存在,return一个只有permissionName和permissionType的GoodsVO
|
||||
*
|
||||
* @param permissionId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public GoodsVO selectGoodsByPermissionId(Long permissionId) {
|
||||
@ -239,9 +149,6 @@ public class GoodsService implements IGoodsService {
|
||||
* 根据关联权限ids查询权限包是否有对应的商品。
|
||||
* 如果权限包和商品都没有,return null
|
||||
* 如果有权限包但没有对应的商品,返回一个只有permissionId和permissionName的goodsVO
|
||||
*
|
||||
* @param relPermissionIds
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public GoodsVO findGoodsByPermissionIds(Long[] relPermissionIds) {
|
||||
@ -259,39 +166,8 @@ public class GoodsService implements IGoodsService {
|
||||
return goodsVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过关联权限创建权限包商品。
|
||||
*
|
||||
* @param createVO
|
||||
* @param userVO
|
||||
* @return
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public GoodsVO createGoodsByRelPermissions(GoodsCreateVO createVO, UserVO userVO) {
|
||||
//创建权限包
|
||||
List<Long> permissionIds = createVO.getRelPermissionIds();
|
||||
PermissionCreateVO permissionCreateVO = new PermissionCreateVO();
|
||||
permissionCreateVO.setRelPermissions(permissionIds);
|
||||
permissionCreateVO.setName(createVO.getName());
|
||||
permissionCreateVO.setRemarks(createVO.getRemarks());
|
||||
Long permissionId;
|
||||
try {
|
||||
permissionId = Long.parseLong(iPermissionService.create(permissionCreateVO, userVO));
|
||||
} catch (BusinessException e) {
|
||||
permissionId = iPermissionService.getPermissionByRelPermissionIds(createVO.getRelPermissionIds()).get(0).getId();
|
||||
}
|
||||
|
||||
//创建商品
|
||||
createVO.setPermissionId(permissionId);
|
||||
GoodsVO goods = createGoods(createVO, userVO);
|
||||
return goods;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定地图、产品(课程)下的权限对应的商品
|
||||
* @param queryVO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageVO<GoodsVO> queryPagedGoodsByPermission(PermissionQueryVO queryVO) {
|
||||
@ -326,7 +202,8 @@ public class GoodsService implements IGoodsService {
|
||||
GoodsVO goodsVO = new GoodsVO();
|
||||
goodsVO.setId(saleGoods.getId());
|
||||
goodsVO.setName(saleGoods.getName());
|
||||
goodsVO.setPrice(ConvertUtil.long2FloatByWeight(saleGoods.getPrice(), 100));
|
||||
Float price = saleGoods.getPrice() == null ? null : (float) saleGoods.getPrice() / 100;
|
||||
goodsVO.setPrice(price);
|
||||
return goodsVO;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
@ -336,23 +213,12 @@ public class GoodsService implements IGoodsService {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<SaleGoods> findGoodsByPermissionId(Long permissionId) {
|
||||
SaleGoodsExample example = new SaleGoodsExample();
|
||||
example.createCriteria().andPermissionIdEqualTo(permissionId);
|
||||
return saleGoodsDAO.selectByExample(example);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品。
|
||||
* 如果要更新的商品不存在,报DBException(数据不存在)
|
||||
* @param id
|
||||
* @param updateVO
|
||||
* @param user
|
||||
*/
|
||||
public void updateGoods(Long id, GoodsUpdateVO updateVO, UserVO user) {
|
||||
if (!isExist(id)) {
|
||||
throw new DBException(ExceptionMapping.DATA_NOT_EXIST, String.format("id为[%s]的商品不存在", id));
|
||||
}
|
||||
ensureExist(id);
|
||||
SaleGoods goods = updateVO.convert2DB();
|
||||
goods.setId(id);
|
||||
goods.setUpdateUserId(user.getId());
|
||||
@ -361,60 +227,25 @@ public class GoodsService implements IGoodsService {
|
||||
saleGoodsDAO.updateByPrimaryKeySelective(goods);
|
||||
}
|
||||
|
||||
private void ensureExist(Long id) {
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotTrue(isExist(id),
|
||||
String.format("id为[%s]的商品不存在", id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExist(Long id) {
|
||||
SaleGoods goods = saleGoodsDAO.selectByPrimaryKey(id);
|
||||
if (goods == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
SaleGoods goods = findEntity(id);
|
||||
return goods != null;
|
||||
}
|
||||
|
||||
public boolean isNameExist(String name) {
|
||||
SaleGoodsExample example = new SaleGoodsExample();
|
||||
example.createCriteria()
|
||||
.andNameEqualTo(name);
|
||||
if (saleGoodsDAO.selectByExample(example).isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public SaleGoods findById(Long id) {
|
||||
public SaleGoods findEntity(Long id) {
|
||||
return saleGoodsDAO.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public GoodsVO getById(Long id) {
|
||||
SaleGoods goods = saleGoodsDAO.selectByPrimaryKey(id);
|
||||
if (goods == null) {
|
||||
throw new DBException(ExceptionMapping.DATA_NOT_EXIST, String.format("id为[%s]的商品不存在", id));
|
||||
}
|
||||
return new GoodsVO(goods);
|
||||
}
|
||||
|
||||
public SaleGoods findByPermissionId(Long permissionId) {
|
||||
Objects.requireNonNull(permissionId);
|
||||
SaleGoodsExample example = new SaleGoodsExample();
|
||||
example.createCriteria()
|
||||
.andPermissionIdEqualTo(permissionId);
|
||||
List<SaleGoods> goodsList = saleGoodsDAO.selectByExample(example);
|
||||
if (goodsList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return goodsList.get(0);
|
||||
}
|
||||
|
||||
private SaleGoods getEntieyByPermissionId(Long permissionId) {
|
||||
SaleGoods goods = findByPermissionId(permissionId);
|
||||
if (goods == null) {
|
||||
throw new DBException(ExceptionMapping.DATA_NOT_EXIST, String.format("权限id为[%s]的商品不存在", permissionId));
|
||||
}
|
||||
return goods;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GoodsVO getByPermissionId(Long permissionId) {
|
||||
SaleGoods goods = getEntieyByPermissionId(permissionId);
|
||||
SaleGoods goods = findEntity(id);
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(goods,
|
||||
String.format("id为[%s]的商品不存在", id));
|
||||
return new GoodsVO(goods);
|
||||
}
|
||||
|
||||
@ -424,7 +255,7 @@ public class GoodsService implements IGoodsService {
|
||||
SaleGoods goods = new SaleGoods();
|
||||
goods.setPermissionId(permissionVO.getId());
|
||||
goods.setName(permissionVO.getName());
|
||||
goods.setPrice(getPermissionPrice(permissionVO));
|
||||
goods.setPrice(getPermissionPrice());
|
||||
goods.setTryUse(false);
|
||||
goods.setStatus(StatusEnum.Valid.getCode());
|
||||
goods.setCreateTime(LocalDateTime.now());
|
||||
@ -435,17 +266,13 @@ public class GoodsService implements IGoodsService {
|
||||
|
||||
/**
|
||||
* 根据权限类型获取价格
|
||||
* @param permission
|
||||
* @return
|
||||
*/
|
||||
private Long getPermissionPrice(PermissionVO permission) {
|
||||
return 10000l;
|
||||
private Long getPermissionPrice() {
|
||||
return 10000L;
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限商品是否已经存在
|
||||
* @param permissionId
|
||||
* @return
|
||||
*/
|
||||
private boolean isPermissionGoodsExist(Long permissionId) {
|
||||
SaleGoodsExample example = new SaleGoodsExample();
|
||||
@ -453,4 +280,15 @@ public class GoodsService implements IGoodsService {
|
||||
.andPermissionIdEqualTo(permissionId);
|
||||
return this.saleGoodsDAO.countByExample(example) > 0;
|
||||
}
|
||||
|
||||
private SaleGoods findEntity(long id) {
|
||||
return saleGoodsDAO.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
private SaleGoods getEntityById(long id) {
|
||||
SaleGoods goods = findEntity(id);
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(goods,
|
||||
String.format("id为[%s]的商品不存在", id));
|
||||
return goods;
|
||||
}
|
||||
}
|
||||
|
@ -3,14 +3,12 @@ package club.joylink.rtss.services;
|
||||
import club.joylink.rtss.vo.UserVO;
|
||||
import club.joylink.rtss.vo.client.GoodsTryVO;
|
||||
import club.joylink.rtss.vo.client.PageVO;
|
||||
import club.joylink.rtss.vo.client.goods.GoodsCreateVO;
|
||||
import club.joylink.rtss.vo.client.goods.GoodsQueryVO;
|
||||
import club.joylink.rtss.vo.client.goods.GoodsUpdateVO;
|
||||
import club.joylink.rtss.vo.client.goods.GoodsVO;
|
||||
import club.joylink.rtss.vo.client.permission.PermissionQueryVO;
|
||||
import club.joylink.rtss.vo.client.permission.PermissionSelectVO;
|
||||
import club.joylink.rtss.vo.client.permission.PermissionVO;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -19,82 +17,39 @@ public interface IGoodsService {
|
||||
|
||||
/**
|
||||
* 分页查询商品
|
||||
*
|
||||
* @param queryVO
|
||||
* @return
|
||||
*/
|
||||
PageVO<GoodsVO> queryPagedGoods(GoodsQueryVO queryVO);
|
||||
|
||||
/**
|
||||
* 查询商品详情
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
GoodsVO selectById(@PathVariable long id);
|
||||
|
||||
/**
|
||||
* 创建商品
|
||||
*
|
||||
* @param createVO
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
GoodsVO createGoods(GoodsCreateVO createVO, UserVO user);
|
||||
|
||||
/**
|
||||
* 批量创建商品
|
||||
* @param createVOList
|
||||
* @param userVO
|
||||
* @return
|
||||
*/
|
||||
List<GoodsVO> createManyGoods(List<GoodsCreateVO> createVOList, UserVO userVO);
|
||||
GoodsVO selectById(long id);
|
||||
|
||||
/**
|
||||
* 更新商品
|
||||
* @param id
|
||||
* @param updateVO
|
||||
* @param user
|
||||
*/
|
||||
void updateGoods(Long id, GoodsUpdateVO updateVO, UserVO user);
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
* @param id
|
||||
*/
|
||||
void deleteGoods(long id);
|
||||
|
||||
/**
|
||||
* 更新试用时间
|
||||
* @param id
|
||||
* @param map
|
||||
* @param user
|
||||
*/
|
||||
void tryUse(Long id, Map<String, Long> map, UserVO user);
|
||||
|
||||
/**
|
||||
* 切换商品是否可用
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
void toggleGoodsStatus(long id);
|
||||
|
||||
/**
|
||||
* 根据权限id查询商品
|
||||
* @param permissionId
|
||||
* @return
|
||||
*/
|
||||
GoodsVO selectGoodsByPermissionId(Long permissionId);
|
||||
|
||||
/**
|
||||
* 通过关联权限ids查询权限包商品
|
||||
* @param relPermissionIds
|
||||
* @return
|
||||
*/
|
||||
GoodsVO findGoodsByPermissionIds(Long[] relPermissionIds);
|
||||
|
||||
GoodsVO createGoodsByRelPermissions(GoodsCreateVO createVO, UserVO userVO);
|
||||
|
||||
PageVO<GoodsVO> queryPagedGoodsByPermission(PermissionQueryVO queryVO);
|
||||
|
||||
List<GoodsVO> selectValidGoodsList();
|
||||
@ -103,8 +58,6 @@ public interface IGoodsService {
|
||||
|
||||
/**
|
||||
* 自动生成权限商品
|
||||
* @param permissionVO
|
||||
* @param user
|
||||
*/
|
||||
void autoGenerateGoods(PermissionVO permissionVO, UserVO user);
|
||||
|
||||
@ -112,5 +65,4 @@ public interface IGoodsService {
|
||||
|
||||
boolean isExist(Long goodsId);
|
||||
|
||||
GoodsVO getByPermissionId(Long id);
|
||||
}
|
||||
|
@ -1,12 +1,9 @@
|
||||
package club.joylink.rtss.services;
|
||||
|
||||
import club.joylink.rtss.simulation.UserSimulationCache;
|
||||
import club.joylink.rtss.simulation.websocket.entity.SubscribeDestination;
|
||||
import club.joylink.rtss.vo.client.BaseUserVO;
|
||||
import club.joylink.rtss.vo.client.SocketMessageVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -1,7 +1,5 @@
|
||||
package club.joylink.rtss.services;
|
||||
|
||||
import com.joylink.base.exception.DBException;
|
||||
import com.joylink.base.exception.constant.ExceptionMapping;
|
||||
import club.joylink.rtss.dao.OrganizationDAO;
|
||||
import club.joylink.rtss.entity.Organization;
|
||||
import club.joylink.rtss.entity.OrganizationExample;
|
||||
|
@ -3,9 +3,6 @@ package club.joylink.rtss.services;
|
||||
import club.joylink.rtss.services.auth.IAuthenticateService;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.joylink.base.exception.BusinessException;
|
||||
import com.joylink.base.exception.DBException;
|
||||
import com.joylink.base.exception.constant.ExceptionMapping;
|
||||
import club.joylink.rtss.configuration.configProp.OtherConfig;
|
||||
import club.joylink.rtss.configuration.configProp.WeChatConfig;
|
||||
import club.joylink.rtss.constants.PermissionDistributeSourceEnum;
|
||||
|
@ -1,10 +1,9 @@
|
||||
package club.joylink.rtss.services;
|
||||
|
||||
import club.joylink.rtss.exception.BusinessException;
|
||||
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.joylink.base.exception.BusinessException;
|
||||
import com.joylink.base.exception.DBException;
|
||||
import com.joylink.base.exception.constant.ExceptionMapping;
|
||||
import club.joylink.rtss.constants.MapPrdTypeEnum;
|
||||
import club.joylink.rtss.constants.PermissionTypeEnum;
|
||||
import club.joylink.rtss.constants.StatusEnum;
|
||||
@ -26,6 +25,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@ -121,10 +121,8 @@ public class PermissionService implements IPermissionService {
|
||||
@Override
|
||||
public PageVO<PermissionVO> getPackageDetail(Long id, PermissionQueryVO queryVO) {
|
||||
PermissionVO permissionVO = getById(id);
|
||||
if (CollectionUtils.isEmpty(permissionVO.getRelPermissionIds())) {
|
||||
throw new BusinessException(ExceptionMapping.DATA_NOT_EXIST, "该权限不是权限包");
|
||||
}
|
||||
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(!CollectionUtils.isEmpty(permissionVO.getRelPermissionIds()),
|
||||
"该权限不是权限包");
|
||||
//构建查询条件
|
||||
List<Long> relPermissionIds = permissionVO.getRelPermissionIds();
|
||||
PermissionExample example = new PermissionExample();
|
||||
@ -149,9 +147,7 @@ public class PermissionService implements IPermissionService {
|
||||
*/
|
||||
@Override
|
||||
public String create(PermissionCreateVO createVO, UserVO user) {
|
||||
if (this.isNameExist(createVO.getName())) {
|
||||
throw new BusinessException(ExceptionMapping.NAME_REPEAT);
|
||||
}
|
||||
confirmNameNotRepeat(createVO.getName());
|
||||
|
||||
//校验relPermission数量
|
||||
List<Long> relPermissionIds = createVO.getRelPermissions();
|
||||
@ -197,6 +193,15 @@ public class PermissionService implements IPermissionService {
|
||||
return permission.getId().toString();
|
||||
}
|
||||
|
||||
private void confirmNameNotRepeat(String name) throws BusinessException {
|
||||
//确认没有重名权限
|
||||
PermissionExample example = new PermissionExample();
|
||||
PermissionExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andNameEqualTo(name);
|
||||
List<Permission> permissions = permissionDAO.selectByExample(example);
|
||||
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(CollectionUtils.isEmpty(permissions));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionVO getById(Long id) {
|
||||
PermissionVO vo = findById(id);
|
||||
@ -429,24 +434,6 @@ public class PermissionService implements IPermissionService {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限名称是否存在
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
private boolean isNameExist(String name) {
|
||||
//确认没有重名权限
|
||||
PermissionExample example = new PermissionExample();
|
||||
PermissionExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andNameEqualTo(name);
|
||||
List<Permission> permissions = permissionDAO.selectByExample(example);
|
||||
if (!CollectionUtils.isEmpty(permissions)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建指定类型的permission
|
||||
*
|
||||
|
@ -2,8 +2,6 @@ package club.joylink.rtss.services;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.joylink.base.exception.DBException;
|
||||
import com.joylink.base.exception.constant.ExceptionMapping;
|
||||
import club.joylink.rtss.dao.RealLineDAO;
|
||||
import club.joylink.rtss.entity.RealLine;
|
||||
import club.joylink.rtss.entity.RealLineExample;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package club.joylink.rtss.services;
|
||||
|
||||
import club.joylink.rtss.services.script.IScriptService;
|
||||
import club.joylink.rtss.vo.client.script.ScriptVO;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package club.joylink.rtss.services;
|
||||
|
||||
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
|
||||
import club.joylink.rtss.services.script.IScriptService;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||
|
@ -2,9 +2,6 @@ package club.joylink.rtss.services.draftData;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.joylink.base.exception.BusinessException;
|
||||
import com.joylink.base.exception.DBException;
|
||||
import com.joylink.base.exception.constant.ExceptionMapping;
|
||||
import club.joylink.rtss.dao.DraftIbpDAO;
|
||||
import club.joylink.rtss.entity.DraftIbp;
|
||||
import club.joylink.rtss.entity.DraftIbpExample;
|
||||
|
@ -1,7 +1,5 @@
|
||||
package club.joylink.rtss.services.draftData;
|
||||
|
||||
import com.joylink.base.exception.BusinessException;
|
||||
import com.joylink.base.exception.constant.ExceptionMapping;
|
||||
import club.joylink.rtss.simulation.cbtc.build.SimulationBuilder;
|
||||
import club.joylink.rtss.simulation.cbtc.data.CalculateService;
|
||||
import club.joylink.rtss.simulation.cbtc.data.map.*;
|
||||
|
@ -2,8 +2,6 @@ package club.joylink.rtss.services.draftData;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.joylink.base.exception.BusinessException;
|
||||
import com.joylink.base.exception.constant.ExceptionMapping;
|
||||
import club.joylink.rtss.dao.DraftMapRouteFlankProtectionDAO;
|
||||
import club.joylink.rtss.entity.DraftMapRouteFlankProtection;
|
||||
import club.joylink.rtss.entity.DraftMapRouteFlankProtectionExample;
|
||||
|
@ -2,9 +2,6 @@ package club.joylink.rtss.services.draftData;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.joylink.base.exception.BusinessException;
|
||||
import com.joylink.base.exception.DBException;
|
||||
import com.joylink.base.exception.constant.ExceptionMapping;
|
||||
import club.joylink.rtss.simulation.cbtc.build.SimulationBuilder;
|
||||
import club.joylink.rtss.simulation.cbtc.data.CalculateService;
|
||||
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
|
||||
|
@ -2,8 +2,6 @@ package club.joylink.rtss.services.publishData;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.joylink.base.exception.DBException;
|
||||
import com.joylink.base.exception.constant.ExceptionMapping;
|
||||
import club.joylink.rtss.dao.IbpDAO;
|
||||
import club.joylink.rtss.entity.Ibp;
|
||||
import club.joylink.rtss.entity.IbpExample;
|
||||
|
@ -1,5 +1,9 @@
|
||||
package club.joylink.rtss.services.script;
|
||||
|
||||
import club.joylink.rtss.entity.ScriptDraftWithBLOBs;
|
||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||
import club.joylink.rtss.simulation.cbtc.script.ScriptBO;
|
||||
import club.joylink.rtss.vo.UserVO;
|
||||
import club.joylink.rtss.vo.client.PageVO;
|
||||
import club.joylink.rtss.vo.client.script.ScriptVO;
|
||||
import club.joylink.rtss.vo.client.script.ScriptQueryVO;
|
||||
@ -22,4 +26,8 @@ public interface IScriptService {
|
||||
* 根据id获取剧本基础BO对象
|
||||
*/
|
||||
ScriptVO getDetailById(Long id);
|
||||
|
||||
ScriptBO getScriptBOById(Long scriptId, Simulation simulation);
|
||||
|
||||
void publish(ScriptDraftWithBLOBs entity, UserVO user);
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
package club.joylink.rtss.services.script;
|
||||
|
||||
import club.joylink.rtss.entity.ScriptDraftWithBLOBs;
|
||||
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
|
||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||
import club.joylink.rtss.simulation.cbtc.script.ScriptBO;
|
||||
import club.joylink.rtss.vo.UserVO;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import club.joylink.rtss.constants.BusinessConsts;
|
||||
@ -13,6 +17,7 @@ import club.joylink.rtss.vo.client.script.ScriptVO;
|
||||
import club.joylink.rtss.vo.client.script.ScriptQueryVO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -54,6 +59,47 @@ public class ScriptService implements IScriptService {
|
||||
return new ScriptVO(getEntity(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScriptBO getScriptBOById(Long scriptId, Simulation simulation) {
|
||||
return new ScriptBO(getEntity(scriptId), simulation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish(ScriptDraftWithBLOBs draftScript, UserVO user) {
|
||||
ScriptWithBLOBs scriptWithBLOBs = this.convertScriptDraft2Script(draftScript);
|
||||
ScriptExample example = new ScriptExample();
|
||||
example.createCriteria().andMapIdEqualTo(draftScript.getMapId()).andNameEqualTo(draftScript.getName());
|
||||
List<Script> scriptList = scriptDAO.selectByExample(example);
|
||||
if (CollectionUtils.isEmpty(scriptList)) {
|
||||
scriptWithBLOBs.setCreatorId(user.getId());
|
||||
scriptDAO.insert(scriptWithBLOBs);
|
||||
} else {
|
||||
scriptWithBLOBs.setId(scriptList.get(0).getId());
|
||||
scriptDAO.updateByPrimaryKeySelective(scriptWithBLOBs);
|
||||
}
|
||||
}
|
||||
|
||||
private ScriptWithBLOBs convertScriptDraft2Script(ScriptDraftWithBLOBs scriptDraft) {
|
||||
ScriptWithBLOBs script = new ScriptWithBLOBs();
|
||||
script.setMapId(scriptDraft.getMapId());
|
||||
script.setName(scriptDraft.getName());
|
||||
script.setLang(scriptDraft.getLang());
|
||||
script.setDescription(scriptDraft.getDescription());
|
||||
script.setMapLocationJson(scriptDraft.getMapLocationJson());
|
||||
script.setBgScenesJson(scriptDraft.getBgScenesJson());
|
||||
script.setFinalScenesJson(scriptDraft.getFinalScenesJson());
|
||||
script.setMembersJson(scriptDraft.getMembersJson());
|
||||
script.setPlayersJson(scriptDraft.getPlayersJson());
|
||||
script.setActionsJson(scriptDraft.getActionsJson());
|
||||
script.setFullMarksDuration(scriptDraft.getFullMarksDuration());
|
||||
script.setPassingGradeDuration(scriptDraft.getPassingGradeDuration());
|
||||
script.setZeroDuration(scriptDraft.getZeroDuration());
|
||||
script.setStatus(BusinessConsts.STATUS_USE);
|
||||
script.setCreatorId(scriptDraft.getCreatorId());
|
||||
script.setCreateTime(scriptDraft.getCreateTime());
|
||||
return script;
|
||||
}
|
||||
|
||||
private ScriptWithBLOBs findEntity(Long id) {
|
||||
return scriptDAO.selectByPrimaryKey(id);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package club.joylink.rtss.services.simulation;
|
||||
|
||||
import com.joylink.base.exception.DBException;
|
||||
import com.joylink.base.exception.constant.ExceptionMapping;
|
||||
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
|
||||
import club.joylink.rtss.simulation.cbtc.ATS.operation.AtsOperationDispatcher;
|
||||
import club.joylink.rtss.simulation.cbtc.ATS.operation.Operation;
|
||||
import club.joylink.rtss.simulation.cbtc.GroupSimulationService;
|
||||
@ -124,7 +123,7 @@ public class ScriptExecuteService {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new DBException(ExceptionMapping.ARGUMENT_ILLEGAL, String.format("无法识别[%s]类型的动作", action.getType()));
|
||||
throw BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.exception();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1,14 +1,19 @@
|
||||
package club.joylink.rtss.services.simulation;
|
||||
|
||||
import club.joylink.rtss.simulation.cbtc.ATS.ATSMessageCollectAndDispatcher;
|
||||
import club.joylink.rtss.simulation.cbtc.ATS.operation.Operation;
|
||||
import club.joylink.rtss.simulation.cbtc.GroupSimulationCache;
|
||||
import club.joylink.rtss.simulation.cbtc.GroupSimulationService;
|
||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||
import club.joylink.rtss.simulation.cbtc.SimulationLifeCycleService;
|
||||
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
|
||||
import club.joylink.rtss.simulation.cbtc.conversation.Conversation;
|
||||
import club.joylink.rtss.simulation.cbtc.conversation.ConversationManagerService;
|
||||
import club.joylink.rtss.simulation.cbtc.conversation.ConversationMessage;
|
||||
import club.joylink.rtss.simulation.cbtc.data.CalculateService;
|
||||
import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition;
|
||||
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
|
||||
import club.joylink.rtss.simulation.cbtc.event.*;
|
||||
import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
|
||||
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
|
||||
import club.joylink.rtss.simulation.cbtc.member.MemberManager;
|
||||
@ -17,7 +22,6 @@ import club.joylink.rtss.simulation.cbtc.robot.RobotLogicLoop;
|
||||
import club.joylink.rtss.simulation.cbtc.script.ScriptActionBO;
|
||||
import club.joylink.rtss.simulation.cbtc.script.ScriptBO;
|
||||
import club.joylink.rtss.entity.ScriptDraftWithBLOBs;
|
||||
import club.joylink.rtss.listener.simulation.script.ScriptWritingListener;
|
||||
import club.joylink.rtss.services.IScriptDraftService;
|
||||
import club.joylink.rtss.services.script.IScriptService;
|
||||
import club.joylink.rtss.vo.LoginUserInfoVO;
|
||||
@ -31,6 +35,7 @@ import club.joylink.rtss.vo.client.script.ScriptActionVO;
|
||||
import club.joylink.rtss.vo.client.script.ScriptVO;
|
||||
import club.joylink.rtss.vo.client.simulationv1.SimulationMemberVO;
|
||||
import club.joylink.rtss.websocket.StompMessageService;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -75,12 +80,6 @@ public class ScriptSimulationService implements IScriptSimulationService {
|
||||
@Autowired
|
||||
private IScriptService iScriptService;
|
||||
|
||||
@Autowired
|
||||
private club.joylink.rtss.services.IScriptService iScriptService;
|
||||
|
||||
@Autowired
|
||||
private ScriptWritingListener scriptWritingListener;
|
||||
|
||||
@Override
|
||||
public String scriptWriteSimulation(Long scriptId, LoginUserInfoVO loginUserInfoVO) {
|
||||
// 先拿到剧本
|
||||
@ -153,7 +152,7 @@ public class ScriptSimulationService implements IScriptSimulationService {
|
||||
public void saveData(String group) {
|
||||
Simulation simulation = groupSimulationCache.getSimulationByGroup(group);
|
||||
ScriptBO script = simulation.getScript();
|
||||
if (StringUtils.isBlank(script.getBgScenesJson())) {
|
||||
if (script.getBgScenesJson().isBlank()) {
|
||||
throw new SimulationException(SimulationExceptionType.Invalid_Operation, "未保存背景");
|
||||
}
|
||||
if (!simulation.isAllConversationOver()) {
|
||||
@ -190,7 +189,7 @@ public class ScriptSimulationService implements IScriptSimulationService {
|
||||
public String preview(Long draftScriptId, LoginUserInfoVO loginUserInfoVO) {
|
||||
// 先拿到剧本
|
||||
ScriptDraftWithBLOBs draftScript = this.iScriptDraftService.getEntityById(draftScriptId);
|
||||
if (StringUtils.isBlank(draftScript.getBgScenesJson())) {
|
||||
if (draftScript.getBgScenesJson().isBlank()) {
|
||||
throw new SimulationException(SimulationExceptionType.Invalid_Operation, String.format("剧本{id:[%s]}没有背景", draftScriptId));
|
||||
}
|
||||
// 构建一个仿真
|
||||
@ -269,7 +268,7 @@ public class ScriptSimulationService implements IScriptSimulationService {
|
||||
|
||||
train.setRobotTargetPosition(targetPosition);
|
||||
//给剧本添加动作
|
||||
if (!scriptWritingListener.canRecordAction(simulation)) {
|
||||
if (!canRecordAction(simulation)) {
|
||||
return;
|
||||
}
|
||||
ScriptBO script = simulation.getScript();
|
||||
@ -453,6 +452,104 @@ public class ScriptSimulationService implements IScriptSimulationService {
|
||||
return script.getActionCondition(actionId);
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void handle(SimulationConversationCreateEvent event) {
|
||||
Simulation simulation = event.getSimulation();
|
||||
if (!canRecordAction(simulation)) {
|
||||
return;
|
||||
}
|
||||
Conversation conversation = event.getConversation();
|
||||
ScriptActionBO bo = new ScriptActionBO();
|
||||
bo.setMember(conversation.getCreator());
|
||||
bo.setConversationMemberIds(conversation.getSimulationMemberList().stream().map(SimulationMember::getId).collect(Collectors.toList()));
|
||||
bo.setConversationId(conversation.getId());
|
||||
bo.setCommunicationObject(conversation.getObject());
|
||||
bo.setTime(simulation.getSystemTime());
|
||||
bo.setType(ScriptActionBO.ActionType.Start_Conversation);
|
||||
addAction(simulation, bo);
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void handle(SimulationConversationMemberConnectEvent event) {
|
||||
Simulation simulation = event.getSimulation();
|
||||
if (!canRecordAction(simulation)) {
|
||||
return;
|
||||
}
|
||||
SimulationMember member = event.getMember();
|
||||
ScriptActionBO bo = new ScriptActionBO();
|
||||
bo.setMember(member);
|
||||
bo.setTime(simulation.getSystemTime());
|
||||
bo.setType(ScriptActionBO.ActionType.Accept_Conversation_Invitation);
|
||||
addAction(simulation, bo);
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void handle(SimulationConversationChatEvent event) {
|
||||
Simulation simulation = event.getSimulation();
|
||||
if (!canRecordAction(simulation)) {
|
||||
return;
|
||||
}
|
||||
ConversationMessage message = event.getConversationMessage();
|
||||
ScriptActionBO action = new ScriptActionBO();
|
||||
action.setMember(message.getMember());
|
||||
action.setConversationId(event.getConversation().getId());
|
||||
action.setContent(message.getContent());
|
||||
action.setType(ScriptActionBO.ActionType.Conversation);
|
||||
action.setTime(message.getTime().minusHours(SimulationConstants.RUN_DIAGRAM_TRANS_TIME));
|
||||
addAction(simulation, action);
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void handle(SimulationConversationExitEvent event) {
|
||||
Simulation simulation = event.getSimulation();
|
||||
if (!canRecordAction(simulation)) {
|
||||
return;
|
||||
}
|
||||
ScriptActionBO action = new ScriptActionBO();
|
||||
action.setMember(event.getMember());
|
||||
action.setType(ScriptActionBO.ActionType.Exit_Conversation);
|
||||
action.setTime(simulation.getSystemTime());
|
||||
addAction(simulation, action);
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void handle(SimulationOperationEvent event) {
|
||||
Simulation simulation = event.getSimulation();
|
||||
if (!canRecordAction(simulation)) {
|
||||
return;
|
||||
}
|
||||
if (!Objects.equals(true, event.getSuccessful())) { //如果操作没有执行成功
|
||||
return;
|
||||
}
|
||||
if (Operation.Type.Driver_Force_Change.name().equals(event.getOperate())) { //推列车控制杆动作特别记录
|
||||
return;
|
||||
}
|
||||
ScriptActionBO action = new ScriptActionBO();
|
||||
action.setMember(event.getMember());
|
||||
action.setOperationType(Operation.Type.valueOf(event.getOperate()));
|
||||
action.setOperationParamMap(event.getParams());
|
||||
action.setType(ScriptActionBO.ActionType.Operation);
|
||||
action.setTime(event.getSimulationTime());
|
||||
addAction(simulation, action);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查仿真是否可以记录动作了
|
||||
*/
|
||||
public boolean canRecordAction(Simulation simulation) {
|
||||
if (!Simulation.FunctionalType.SCRIPT_MAKING.equals(simulation.getBuildParams().getFunctionalType())) {
|
||||
return false;
|
||||
}
|
||||
ScriptBO script = simulation.getScript();
|
||||
if (script.getBgScenesJson().isBlank()) { //如果剧本还没保存背景
|
||||
return false;
|
||||
}
|
||||
if (script.isReplacing()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void checkActionBO(ScriptActionBO action) {
|
||||
if (action.getMember() == null) {
|
||||
throw new SimulationException(SimulationExceptionType.System_Fault, "剧本动作主体成员为空");
|
||||
@ -473,10 +570,10 @@ public class ScriptSimulationService implements IScriptSimulationService {
|
||||
}
|
||||
break;
|
||||
case Conversation:
|
||||
if (StringUtils.isBlank(action.getContent())) {
|
||||
if (action.getContent().isBlank()) {
|
||||
throw new SimulationException(SimulationExceptionType.System_Fault, "会话类型动作,消息内容为空");
|
||||
}
|
||||
if (StringUtils.isBlank(action.getConversationId())) {
|
||||
if (action.getConversationId().isBlank()) {
|
||||
throw new SimulationException(SimulationExceptionType.System_Fault, "会话类型动作,会话id为空");
|
||||
}
|
||||
break;
|
||||
|
@ -11,7 +11,6 @@ import club.joylink.rtss.simulation.cbtc.data.vo.*;
|
||||
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
|
||||
import club.joylink.rtss.simulation.cbtc.event.SimulationOperationMessageEvent;
|
||||
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
|
||||
import club.joylink.rtss.event.simulation.DeviceStatusChangeEvent;
|
||||
import club.joylink.rtss.vo.client.SocketMessageVO;
|
||||
import club.joylink.rtss.vo.client.WebSocketMessageType;
|
||||
import club.joylink.rtss.vo.client.factory.SocketMessageFactory;
|
||||
|
@ -10,7 +10,6 @@ import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
|
||||
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
|
||||
import club.joylink.rtss.constants.MapPrdTypeEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -75,8 +75,7 @@ public class PermissionVO {
|
||||
private String mapName;
|
||||
|
||||
@ApiModelProperty(value = "创建者")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long creatorUserName;
|
||||
private String creatorUserName;
|
||||
|
||||
private String creatorNickname;
|
||||
|
||||
@ -123,7 +122,6 @@ public class PermissionVO {
|
||||
this.mapId = permission.getMapId();
|
||||
this.prdType = permission.getPrdType();
|
||||
this.lessonId = permission.getLessonId();
|
||||
this.creatorUserName = permission.getCreatorId();
|
||||
this.createTime = permission.getCreateTime();
|
||||
this.remarks = permission.getRemarks();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user