diff --git a/src/main/java/club/joylink/rtss/controller/simulation/SimulationV1Controller.java b/src/main/java/club/joylink/rtss/controller/simulation/SimulationV1Controller.java index c5406585a..1ffce56ac 100644 --- a/src/main/java/club/joylink/rtss/controller/simulation/SimulationV1Controller.java +++ b/src/main/java/club/joylink/rtss/controller/simulation/SimulationV1Controller.java @@ -5,6 +5,7 @@ import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.services.IVirtualRealityIbpService; import club.joylink.rtss.services.psl.IVirtualRealityPslService; import club.joylink.rtss.services.simulation.SimulationSupportService; +import club.joylink.rtss.simulation.SimulationManager; import club.joylink.rtss.simulation.cbtc.ATS.data.AtsAlarm; import club.joylink.rtss.simulation.cbtc.ATS.data.SimulationLog; import club.joylink.rtss.simulation.cbtc.GroupSimulationService; @@ -18,6 +19,7 @@ import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityPsl; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.script.ScriptBO; import club.joylink.rtss.simulation.cbtc.vo.SimulationWorkParamVO; +import club.joylink.rtss.simulation.vo.SimulationInfoVO; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.client.PageVO; @@ -30,14 +32,12 @@ import club.joylink.rtss.vo.client.operation.DriveParamVO; import club.joylink.rtss.vo.client.psl.PslStatus; import club.joylink.rtss.vo.client.runplan.PlanTripNumberVO; import club.joylink.rtss.vo.client.runplan.RunPlanEChartsDataVO; -import club.joylink.rtss.vo.client.simulationv1.RunAsPlanParam; -import club.joylink.rtss.vo.client.simulationv1.SimulationLogPagedQueryVO; -import club.joylink.rtss.vo.client.simulationv1.SimulationMemberVO; -import club.joylink.rtss.vo.client.simulationv1.SimulationUserVO; +import club.joylink.rtss.vo.client.simulationv1.*; import club.joylink.rtss.vo.map.MapVO; import club.joylink.rtss.vo.map.graph.MapStationNewVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.util.StringUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -46,6 +46,8 @@ import javax.validation.constraints.NotNull; import java.time.LocalDateTime; import java.time.LocalTime; import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * 新仿真接口 @@ -67,6 +69,8 @@ public class SimulationV1Controller { private IVirtualRealityPslService iVirtualRealityPslService; @Autowired private SimulationService simulationService; + @Autowired + private SimulationManager simulationManager; /** * 根据产品类型创建仿真 @@ -74,7 +78,7 @@ public class SimulationV1Controller { @GetMapping("") public String simulation(Long mapId, String prdType, @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) - LoginUserInfoVO loginUserInfoVO) { + LoginUserInfoVO loginUserInfoVO) { String simulation = this.groupSimulationService.simulation(mapId, prdType, loginUserInfoVO); return simulation; } @@ -85,7 +89,7 @@ public class SimulationV1Controller { @GetMapping(path = "/training/{trainingId}") public String trainingSimulation(@PathVariable Long trainingId, @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) - LoginUserInfoVO loginUserInfoVO) { + LoginUserInfoVO loginUserInfoVO) { return this.groupSimulationService.trainingSimulation(trainingId, loginUserInfoVO); } @@ -95,7 +99,7 @@ public class SimulationV1Controller { @GetMapping(path = "/exam/{examId}") public String examSimulate(@PathVariable Long examId, @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) - LoginUserInfoVO loginUserInfoVO) { + LoginUserInfoVO loginUserInfoVO) { return this.groupSimulationService.examSimulation(examId, loginUserInfoVO); } @@ -121,7 +125,7 @@ public class SimulationV1Controller { @GetMapping("/{group}/simulationUser") public SimulationUserVO getSimulationUserInfo(@PathVariable String group, @RequestAttribute(name = AuthenticateInterceptor.LOGIN_USER_KEY) - AccountVO accountVO) { + AccountVO accountVO) { return this.groupSimulationService.getSimulationUserInfo(group, accountVO); } @@ -203,7 +207,7 @@ public class SimulationV1Controller { @PostMapping("/{group}/operate/{type}") public Object operate(@PathVariable @NotBlank String group, @PathVariable @NotNull String type, @RequestBody(required = false) Map param, @RequestAttribute AccountVO user) { - if(null == param){ + if (null == param) { param = new HashMap<>(); } return this.groupSimulationService.operate(group, type, param, user); @@ -306,21 +310,21 @@ public class SimulationV1Controller { return this.groupSimulationService.getSimulationMembers(group); } - /** - * 仿真暂停 - */ - @PutMapping(path = "/{group}/pause") - public void pause(@PathVariable String group) { - groupSimulationService.pauseSimulation(group); - } +// /** +// * 仿真暂停 +// */ +// @PutMapping(path = "/{group}/pause") +// public void pause(@PathVariable String group) { +// groupSimulationService.pauseSimulation(group); +// } - /** - * 仿真恢复运行 - */ - @PutMapping(path = "/{group}/resume") - public void resume(@PathVariable String group) { - groupSimulationService.resumeSimulation(group); - } +// /** +// * 仿真恢复运行 +// */ +// @PutMapping(path = "/{group}/resume") +// public void resume(@PathVariable String group) { +// groupSimulationService.resumeSimulation(group); +// } /** * 获取仿真设备故障列表 @@ -541,4 +545,82 @@ public class SimulationV1Controller { , @PathVariable("functionId") long mapFunctionId) { return simulationService.querySimulationByMapIdAndMapFunction(mapId, mapFunctionId); } + + /** + * 监管仿真 + */ + @GetMapping("/supervise") + public List superviseSimulation(@RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO loginUserInfoVO, SimulationInfoQueryVO queryVO) { + List simulationList = this.simulationManager.getSimulationList(); + Stream stream = simulationList.stream(); + + stream = stream.filter(simulation -> simulation instanceof club.joylink.rtss.simulation.cbtc.Simulation + && Objects.equals(loginUserInfoVO.getTopOrgId(), ((club.joylink.rtss.simulation.cbtc.Simulation) simulation).getBuildParams().getLoginUserInfo().getTopOrgId())); + + if (StringUtils.hasText(queryVO.getGroup())) { + stream = stream.filter(simulation -> simulation.getId().contains(queryVO.getGroup())); + } + if (StringUtils.hasText(queryVO.getUserName())) { + stream = stream.filter(simulation -> simulation.getSimulationUsers().stream().anyMatch(user -> user.getName().contains(queryVO.getUserName()))); + } + if (StringUtils.hasText(queryVO.getPrdType())) { + stream = stream.filter(simulation -> simulation instanceof club.joylink.rtss.simulation.cbtc.Simulation + && queryVO.getPrdType().equals(simulation.getBuildParams().getProdType().getCode())); + } + return stream.map(Simulation::convertToVO).collect(Collectors.toList()); + } + + /** + * 获取所有存在的仿真 + */ + @GetMapping("/list") + public List queryInfo(SimulationInfoQueryVO queryVO) { + List simulationList = this.simulationManager.getSimulationList(); + Stream stream = simulationList.stream(); + if (StringUtils.hasText(queryVO.getGroup())) { + stream = stream.filter(simulation -> simulation.getId().contains(queryVO.getGroup())); + } + if (StringUtils.hasText(queryVO.getUserName())) { + stream = stream.filter(simulation -> simulation.getSimulationUsers().stream().anyMatch(user -> user.getName().contains(queryVO.getUserName()))); + } + if (StringUtils.hasText(queryVO.getPrdType())) { + stream = stream.filter(simulation -> simulation instanceof club.joylink.rtss.simulation.cbtc.Simulation + && queryVO.getPrdType().equals(simulation.getBuildParams().getProdType().getCode())); + } + return stream.map(Simulation::convertToVO).collect(Collectors.toList()); + } + + /** + * 暂停 + */ + @PutMapping("/{id}/pause") + public void pause(@PathVariable String id) { + this.simulationManager.pause(id); + } + + /** + * 开始 + */ + @PutMapping("/{id}/start") + public void start(@PathVariable String id) { + this.simulationManager.start(id); + } + + /** + * 调整倍速 + */ + @PutMapping("/{id}/updateSpeed/{speed}") + public void updateSpeed(@PathVariable String id, @PathVariable int speed) { + this.simulationManager.updateSpeed(id, speed); + } + + /** + * 获取仿真中所有仿真用户 + */ + @GetMapping("/{id}/users") + public List getSimulationUsers(@PathVariable String id) { + return this.simulationManager.getSimulationUsers(id).stream() + .map(club.joylink.rtss.simulation.SimulationUser::convertToVO) + .collect(Collectors.toList()); + } } diff --git a/src/main/java/club/joylink/rtss/services/mapFunction/RtsMapFunctionServiceImpl.java b/src/main/java/club/joylink/rtss/services/mapFunction/RtsMapFunctionServiceImpl.java index f6d3491a4..9d696c7e8 100644 --- a/src/main/java/club/joylink/rtss/services/mapFunction/RtsMapFunctionServiceImpl.java +++ b/src/main/java/club/joylink/rtss/services/mapFunction/RtsMapFunctionServiceImpl.java @@ -607,7 +607,7 @@ public class RtsMapFunctionServiceImpl implements RtsMapFunctionService { } SimulationWorkParamVO.DomConfigVO domConfig = SimulationWorkParamVO.DomConfigVO.builder() .singleClient(true) - .client(Simulation.Client.SCHEDULING.name()) + .client(Simulation.Client.scheduleWork.name()) .build(); Map itemMap = new HashMap<>(); itemMap.put(SimulationWorkParamVO.Item.DEFAULT_MEMBER, dispatcherOptional.get().getId()); @@ -629,7 +629,7 @@ public class RtsMapFunctionServiceImpl implements RtsMapFunctionService { } SimulationWorkParamVO.DomConfigVO domConfig = SimulationWorkParamVO.DomConfigVO.builder() .singleClient(true) - .client(Simulation.Client.ISCS.name()) + .client(Simulation.Client.iscsView.name()) .build(); Map itemMap = new HashMap<>(); itemMap.put(SimulationWorkParamVO.Item.DEFAULT_MEMBER, dispatcherOptional.get().getId()); @@ -646,7 +646,7 @@ public class RtsMapFunctionServiceImpl implements RtsMapFunctionService { } SimulationWorkParamVO.DomConfigVO domConfig = SimulationWorkParamVO.DomConfigVO.builder() .singleClient(true) - .client(Simulation.Client.RUN_PLAN_DESIGN.name()) + .client(Simulation.Client.diagramEdit.name()) .build(); return buildCreateVO(mapId, name, name, simType, null, domConfig); }; @@ -661,7 +661,7 @@ public class RtsMapFunctionServiceImpl implements RtsMapFunctionService { } SimulationWorkParamVO.DomConfigVO domConfig = SimulationWorkParamVO.DomConfigVO.builder() .singleClient(true) - .client(Simulation.Client.C_ATS_BS.name()) + .client(Simulation.Client.bigScreen.name()) .build(); return buildCreateVO(mapId, name, name, simType, null, domConfig); }; diff --git a/src/main/java/club/joylink/rtss/simulation/SimulationManager.java b/src/main/java/club/joylink/rtss/simulation/SimulationManager.java index 1e0a0bad0..1d1666214 100644 --- a/src/main/java/club/joylink/rtss/simulation/SimulationManager.java +++ b/src/main/java/club/joylink/rtss/simulation/SimulationManager.java @@ -18,10 +18,7 @@ import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; @@ -192,8 +189,8 @@ public class SimulationManager { } } - public List getSimulationList() { - return new ArrayList<>(simulationCache.values()); + public List getSimulationList() { + return new ArrayList((Collection) simulationCache.values()); } public List getSimulationMembers(String id) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/Simulation.java b/src/main/java/club/joylink/rtss/simulation/cbtc/Simulation.java index 6cb0ca9ea..8d109b87a 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/Simulation.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/Simulation.java @@ -748,11 +748,17 @@ public class Simulation extends club.joylink.rtss.simulation.Simulation