diff --git a/src/main/java/club/joylink/rtss/simulation/Simulation.java b/src/main/java/club/joylink/rtss/simulation/Simulation.java index 226801803..364e87d81 100644 --- a/src/main/java/club/joylink/rtss/simulation/Simulation.java +++ b/src/main/java/club/joylink/rtss/simulation/Simulation.java @@ -166,6 +166,11 @@ public abstract class Simulation T getRepository(String name, Class cls) { + public R getRepository(String name, Class cls) { Objects.requireNonNull(name); - return (T) this.repositoryMap.get(name); + return (R) this.repositoryMap.get(name); } public M querySimulationMemberById(String id) { @@ -515,4 +520,9 @@ public abstract class Simulation getSimulationUsers() { + ArrayList list = new ArrayList(this.simulationUserMap.values()); + return list; + } } diff --git a/src/main/java/club/joylink/rtss/simulation/SimulationCommonController.java b/src/main/java/club/joylink/rtss/simulation/SimulationCommonController.java index 15735e01e..92f028742 100644 --- a/src/main/java/club/joylink/rtss/simulation/SimulationCommonController.java +++ b/src/main/java/club/joylink/rtss/simulation/SimulationCommonController.java @@ -4,7 +4,9 @@ import club.joylink.rtss.simulation.operation.SimulationOperationDispatcher; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * 仿真通用接口 @@ -17,6 +19,14 @@ public class SimulationCommonController { @Autowired private SimulationOperationDispatcher simulationOperationDispatcher; + @GetMapping("/list") + public List queryInfo() { + List simulationList = this.simulationManager.getSimulationList(); + return simulationList.stream() + .map(simulation -> new SimulationInfoVO(simulation)) + .collect(Collectors.toList()); + } + @PutMapping("/{id}/pause") public void pause(@PathVariable String id) { this.simulationManager.pause(id); diff --git a/src/main/java/club/joylink/rtss/simulation/SimulationInfoVO.java b/src/main/java/club/joylink/rtss/simulation/SimulationInfoVO.java new file mode 100644 index 000000000..051fb0386 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/SimulationInfoVO.java @@ -0,0 +1,48 @@ +package club.joylink.rtss.simulation; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +@Getter +@Setter +@NoArgsConstructor +public class SimulationInfoVO { + String id; + String name; + Integer speed; + LocalDateTime sysTime; + Integer state; + List userInfoList; + + public SimulationInfoVO(Simulation simulation) { + this.id = simulation.getId(); + this.name = simulation.debugStr(); + this.speed = simulation.getSpeed(); + this.sysTime = simulation.getSystemTime(); + this.state = simulation.getState(); + List simulationUsers = simulation.getSimulationUsers(); + this.userInfoList = simulationUsers.stream() + .map(user -> new SimulationUserInfoVO((SimulationUser) user)) + .collect(Collectors.toList()); + } + + @Getter + public static class SimulationUserInfoVO { + String id; + private Map> subscribeMap; + + public SimulationUserInfoVO(SimulationUser user) { + this.id = user.getId(); + this.subscribeMap = user.getSubscribeMap(); + } + } + +} diff --git a/src/main/java/club/joylink/rtss/simulation/SimulationManager.java b/src/main/java/club/joylink/rtss/simulation/SimulationManager.java index 679ed6dd1..87d0071a7 100644 --- a/src/main/java/club/joylink/rtss/simulation/SimulationManager.java +++ b/src/main/java/club/joylink/rtss/simulation/SimulationManager.java @@ -8,6 +8,8 @@ import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -138,4 +140,8 @@ public class SimulationManager { this.applicationContext.publishEvent(new SimulationMemberPlayChangeEvent(this, simulation, member)); } } + + public List getSimulationList() { + return new ArrayList<>(simulationCache.values()); + } } diff --git a/src/main/java/club/joylink/rtss/simulation/SimulationUser.java b/src/main/java/club/joylink/rtss/simulation/SimulationUser.java index 09c3645be..56d63f77d 100644 --- a/src/main/java/club/joylink/rtss/simulation/SimulationUser.java +++ b/src/main/java/club/joylink/rtss/simulation/SimulationUser.java @@ -76,4 +76,8 @@ public abstract class SimulationUser { this.memberId = null; } } + + public Map> getSubscribeMap() { + return this.wsSubscribeMap; + } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/device/StorageSignal.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/device/StorageSignal.java index 688c736e2..3fc9eb57c 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/device/StorageSignal.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/device/StorageSignal.java @@ -42,6 +42,10 @@ public class StorageSignal extends StorageMayOutOfOrderDevice { @JsonDeserialize(using = Boolean2NumDeserializer.class) private Boolean reblockade; + @JsonSerialize(using = Boolean2NumSerializer.class) + @JsonDeserialize(using = Boolean2NumDeserializer.class) + private Boolean fpl; + /** * 逻辑点灯/物理点灯 */ @@ -108,6 +112,10 @@ public class StorageSignal extends StorageMayOutOfOrderDevice { change = true; storageSignal.setReblockade(signal.isReblockade()); } + if (signal.isFpl()) { + change = true; + storageSignal.setFpl(signal.isFpl()); + } if (!signal.isLogicLight()) { change = true; storageSignal.setLogicLight(signal.isLogicLight()); @@ -151,6 +159,7 @@ public class StorageSignal extends StorageMayOutOfOrderDevice { signal.setBlockade(blockade != null ? blockade : false); signal.setLevel(this.level != null ? this.level : 1); signal.setReblockade(this.reblockade != null ? this.reblockade : false); + signal.setFpl(this.fpl != null ? this.fpl : false); signal.setLogicLight(logicLight != null ? logicLight : true); signal.setGreenOpen(greenOpen != null ? greenOpen : false); signal.setYellowOpen(yellowOpen != null ? yellowOpen : false);