diff --git a/src/main/java/club/joylink/rtss/simulation/Simulation.java b/src/main/java/club/joylink/rtss/simulation/Simulation.java index e9aaeaba7..aa03d89e0 100644 --- a/src/main/java/club/joylink/rtss/simulation/Simulation.java +++ b/src/main/java/club/joylink/rtss/simulation/Simulation.java @@ -1,5 +1,6 @@ package club.joylink.rtss.simulation; +import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import lombok.extern.slf4j.Slf4j; import org.springframework.util.PropertyPlaceholderHelper; import org.springframework.util.StringUtils; @@ -67,7 +68,7 @@ public abstract class Simulation destinationMap = new HashMap<>(); private static final PropertyPlaceholderHelper placeholderHelper = new PropertyPlaceholderHelper("{", "}"); - private List subscribeMessageServiceList; + private Map messagePublisherMap = new HashMap<>(); private SimulationMessageSender messageSender; /** * 消息推送线程池 @@ -457,15 +458,16 @@ public abstract class Simulation list) { - this.subscribeMessageServiceList = list; + public void addMessagePublisher(SimulationMessagePublisher messagePublisher) { + BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotTrue(this.messagePublisherMap.containsKey(messagePublisher.name)); + this.messagePublisherMap.put(messagePublisher.name, messagePublisher); + this.addFixedRateJob(messagePublisher.name, () -> { + this.pushMessage(messagePublisher.destination, messagePublisher.getNextSendMessage()); + }, messagePublisher.rate); } - public void addSubscribeMessageService(SimulationSubscribeMessageService subscribeMessageService) { - if (this.subscribeMessageServiceList == null) { - this.subscribeMessageServiceList = new ArrayList<>(); - } - this.subscribeMessageServiceList.add(subscribeMessageService); + public

P getMessagePublisher(String name, Class

clz) { + return (P) this.messagePublisherMap.get(name); } public String handleDestination(String destinationPattern) { @@ -505,8 +507,8 @@ public abstract class Simulation cilSwitchList) { + AtsRepository atsRepository = this.getAtsRepository(rtSimulation); + AtsMessagePublisher messagePublisher = rtSimulation.getMessagePublisher(AtsMessagePublisher.NAME, AtsMessagePublisher.class); + for (CilSwitch cilSwitch : cilSwitchList) { + AtsSwitch atsSwitch = atsRepository.getSwitchById(cilSwitch.getId()); + boolean change = atsSwitch.applyChange(cilSwitch); + if (change) { + messagePublisher.handleSwitch(atsSwitch); + } } } - public void handle(CilDevice cilDevice) { + public void syncCilSectionState(RtSimulation rtSimulation, List cilSectionList) { + AtsRepository atsRepository = this.getAtsRepository(rtSimulation); + AtsMessagePublisher messagePublisher = rtSimulation.getMessagePublisher(AtsMessagePublisher.NAME, AtsMessagePublisher.class); + for (CilSection section : cilSectionList) { + AtsSection atsSection = atsRepository.getSectionById(section.getId()); + boolean change = atsSection.applyChange(section); + if (change) { + messagePublisher.handleSection(atsSection); + } + } + } + public void syncCilSignalState(RtSimulation rtSimulation, List cilSignalList) { + AtsRepository atsRepository = this.getAtsRepository(rtSimulation); + AtsMessagePublisher messagePublisher = rtSimulation.getMessagePublisher(AtsMessagePublisher.NAME, AtsMessagePublisher.class); + for (CilSignal cilSignal : cilSignalList) { + AtsSignal atsSignal = atsRepository.getSignalById(cilSignal.getId()); + boolean change = atsSignal.applyChange(cilSignal); + if (change) { + messagePublisher.handleSignal(atsSignal); + } + } + } + + public void syncCilRouteState(RtSimulation rtSimulation, List cilRouteList) { + AtsRepository atsRepository = this.getAtsRepository(rtSimulation); + AtsMessagePublisher messagePublisher = rtSimulation.getMessagePublisher(AtsMessagePublisher.NAME, AtsMessagePublisher.class); + for (CilRoute cilRoute : cilRouteList) { + AtsRoute atsRoute = atsRepository.getRouteById(cilRoute.getId()); + boolean change = atsRoute.applyChange(cilRoute); + if (change) { + messagePublisher.handleRoute(atsRoute); + } + } } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/AtsLogicService.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/AtsLogicService.java index bd9fa57fa..5cf911694 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/AtsLogicService.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/AtsLogicService.java @@ -9,7 +9,6 @@ import club.joylink.rtss.vo.client.map.MapVO; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; -import java.util.ArrayList; import java.util.List; /** @@ -17,14 +16,16 @@ import java.util.List; */ @Component public class AtsLogicService { - public void buildRepository(RtSimulation rtSimulation, MapVO mapVO) { + public void init(RtSimulation rtSimulation, MapVO mapVO) { AtsRepository atsRepository = AtsRepositoryBuilder.buildFrom(mapVO); rtSimulation.addRepository(atsRepository); + AtsMessagePublisher atsMessagePublisher = new AtsMessagePublisher(atsRepository); + rtSimulation.addMessagePublisher(atsMessagePublisher); } public void addJobs(RtSimulation rtSimulation) { for (RtSimulationSubscribeTopic topic : RtSimulationSubscribeTopic.values()) { - rtSimulation.addJob("MESSAGE-" + topic.name(), () -> sendMessages(rtSimulation, topic), topic.getRate()); + rtSimulation.addFixedRateJob("MESSAGE-" + topic.name(), () -> sendMessages(rtSimulation, topic), topic.getRate()); } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/AtsMessagePublisher.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/AtsMessagePublisher.java new file mode 100644 index 000000000..fee8bc760 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/AtsMessagePublisher.java @@ -0,0 +1,101 @@ +package club.joylink.rtss.simulation.rt.ATS; + +import club.joylink.rtss.simulation.SimulationMessagePublisher; +import club.joylink.rtss.simulation.rt.ATS.bo.*; +import club.joylink.rtss.simulation.rt.RtSimulationSubscribeTopic; +import lombok.Getter; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +@Getter +public class AtsMessagePublisher extends SimulationMessagePublisher { + public static final String NAME = "AMP"; + public static final int RATE = 1000; + AtsRepository atsRepository; + Map> switchMap = new ConcurrentHashMap<>(); + Map> sectionMap = new ConcurrentHashMap<>(); + Map> signalMap = new ConcurrentHashMap<>(); + Map> routeMap = new ConcurrentHashMap<>(); + + public AtsMessagePublisher(AtsRepository atsRepository) { + super(NAME, RATE, RtSimulationSubscribeTopic.ATS.getDestPattern()); + this.atsRepository = atsRepository; + } + + public void handleSwitch(AtsSwitch atsSwitch) { + if (!this.switchMap.containsKey(atsSwitch.getId())) { + this.switchMap.put(atsSwitch.getId(), atsSwitch.getStateList()); + } + } + public void handleSection(AtsSection atsSection) { + if (!this.sectionMap.containsKey(atsSection.getId())) { + this.sectionMap.put(atsSection.getId(), atsSection.getStateList()); + } + } + public void handleSignal(AtsSignal atsSignal) { + if (!this.signalMap.containsKey(atsSignal.getId())) { + this.signalMap.put(atsSignal.getId(), atsSignal.getStateList()); + } + } + public void handleRoute(AtsRoute atsRoute) { + if (!this.routeMap.containsKey(atsRoute.getId())) { + this.routeMap.put(atsRoute.getId(), atsRoute.getStateList()); + } + } + + @Override + public boolean acceptedSubscribePath(String destination) { + return RtSimulationSubscribeTopic.ATS.isMatch(destination); + } + + @Override + public Object buildMessageOfSubscribe(String destination) { + HashMap message = new HashMap<>(); + List> switchStateList = this.atsRepository.getSwitchMap().values().stream() + .map(AtsSwitch::getStateList) + .collect(Collectors.toList()); + List> sectionStateList = this.atsRepository.getSectionMap().values().stream() + .map(AtsSection::getStateList) + .collect(Collectors.toList()); + List> signalStateList = this.atsRepository.getSignalMap().values().stream() + .map(AtsSignal::getStateList) + .collect(Collectors.toList()); + List> routeStateList = this.atsRepository.getRouteMap().values().stream() + .map(AtsRoute::getStateList) + .collect(Collectors.toList()); + message.put("switch", switchStateList); + message.put("section", sectionStateList); + message.put("signal", signalStateList); + message.put("route", routeStateList); + return message; + } + + @Override + public Object getNextSendMessage() { + HashMap message = new HashMap<>(); + if (!this.switchMap.isEmpty()) { + message.put("switch", this.switchMap.values()); + this.switchMap.clear(); + } + if (!this.sectionMap.isEmpty()) { + message.put("section", this.sectionMap.values()); + this.sectionMap.clear(); + } + if (!this.signalMap.isEmpty()) { + message.put("signal", this.signalMap.values()); + this.signalMap.clear(); + } + if (!this.routeMap.isEmpty()) { + message.put("route", this.routeMap.values()); + this.routeMap.clear(); + } + if (message.isEmpty()) { + return null; + } + return message; + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsDevice.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsDevice.java index dcfefc5a0..5791377b7 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsDevice.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsDevice.java @@ -1,19 +1,32 @@ package club.joylink.rtss.simulation.rt.ATS.bo; -import club.joylink.rtss.simulation.rt.RtSimulationSubscribeTopic; import lombok.Getter; import java.util.List; @Getter public abstract class AtsDevice { + public static final int OFF = 0; + public static final int ON = 1; + + List stateList; + String id; String name; public AtsDevice(String id, String name) { this.id = id; this.name = name; + this.stateList = this.buildMessage(); } -// public abstract void buildMessage(List message, RtSimulationSubscribeTopic topic); + public int convert(boolean val) { + if (val) { + return ON; + } else { + return OFF; + } + } + + abstract List buildMessage(); } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsRepository.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsRepository.java index c2f473606..067792a91 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsRepository.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsRepository.java @@ -3,12 +3,14 @@ package club.joylink.rtss.simulation.rt.ATS.bo; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.SimulationRepository; import club.joylink.rtss.simulation.cbtc.data.map.Station; +import lombok.Getter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +@Getter public class AtsRepository extends SimulationRepository { public static final String NAME = "ATS"; @@ -43,12 +45,30 @@ public class AtsRepository extends SimulationRepository { return runPlan; } + public AtsSection getSectionById(String id) { + AtsSection atsSection = this.sectionMap.get(id); + BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(atsSection); + return atsSection; + } + public AtsSwitch getSwitchById(String id) { AtsSwitch atsSwitch = switchMap.get(id); BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(atsSwitch); return atsSwitch; } + public AtsSignal getSignalById(String id) { + AtsSignal atsSignal = this.signalMap.get(id); + BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(atsSignal); + return atsSignal; + } + + public AtsRoute getRouteById(String id) { + AtsRoute atsRoute = this.routeMap.get(id); + BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(atsRoute); + return atsRoute; + } + public void ready2Send(String id, int i, Object value) { List message = messageMap.get(id); if (message != null) { diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsRoute.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsRoute.java index c9c589bfb..08007b2b8 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsRoute.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsRoute.java @@ -1,48 +1,43 @@ package club.joylink.rtss.simulation.rt.ATS.bo; -import club.joylink.rtss.simulation.rt.RtSimulationSubscribeTopic; +import club.joylink.rtss.simulation.rt.CIL.bo.CilRoute; import lombok.Getter; -import lombok.NonNull; +import java.util.Arrays; import java.util.List; -import java.util.Objects; @Getter public class AtsRoute extends AtsDevice { - boolean ars; - boolean arc; - boolean flt; - public void setArs(boolean ars) { - if (!Objects.equals(this.ars, ars)) { - - } - this.ars = ars; - } - - public void setArc(boolean arc) { - this.arc = arc; - } - - public void setFlt(boolean flt) { - this.flt = flt; - } - public AtsRoute(String id, String name) { super(id, name); } -// @Override - public void buildMessage(@NonNull List message, RtSimulationSubscribeTopic topic) { - switch (topic) { - case ATS: - message.add(ars); - message.add(arc); - message.add(flt); - break; + @Override + List buildMessage() { + return Arrays.asList(this.id, this.convert(this.ars), this.convert(this.arc), this.convert(this.flt)); + } + + public boolean applyChange(CilRoute cilRoute) { + boolean change = false; + if (this.ars != cilRoute.isArs()) { + this.ars = cilRoute.isArs(); + this.getStateList().set(1, this.convert(this.ars)); + change = true; } + if (this.arc != cilRoute.isArc()) { + this.arc = cilRoute.isArc(); + this.getStateList().set(2, this.convert(this.arc)); + change = true; + } + if (this.flt != cilRoute.isFlt()) { + this.flt = cilRoute.isFlt(); + this.getStateList().set(3, this.convert(this.flt)); + change = true; + } + return change; } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSection.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSection.java index f11d2d97d..34bda2082 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSection.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSection.java @@ -1,17 +1,50 @@ package club.joylink.rtss.simulation.rt.ATS.bo; +import club.joylink.rtss.simulation.rt.CIL.bo.CilSection; + +import java.util.Arrays; +import java.util.List; + public class AtsSection extends AtsDevice { - boolean axcOccupy; - - String routeId; - + boolean occ;// 非通信车占用 + boolean ctOcc;// 通信车占用 boolean rl; - boolean lr; - boolean ol; public AtsSection(String id, String name) { super(id, name); } + + @Override + List buildMessage() { + return Arrays.asList(this.id, this.convert(this.occ), + this.convert(this.ctOcc), this.convert(this.rl), this.convert(this.lr), this.convert(this.ol)); + } + + public boolean applyChange(CilSection cilSection) { + List stateList = this.getStateList(); + boolean change = false; + if (this.occ != cilSection.isAxcOccupy()) { + this.occ = cilSection.isAxcOccupy(); + stateList.set(1, this.convert(this.occ)); + change = true; + } + if (this.rl != cilSection.isRl()) { + this.rl = cilSection.isRl(); + stateList.set(3, this.convert(this.rl)); + change = true; + } + if (this.lr != cilSection.isLr()) { + this.lr = cilSection.isLr(); + stateList.set(4, this.convert(this.lr)); + change = true; + } + if (this.ol != cilSection.isOl()) { + this.ol = cilSection.isOl(); + stateList.set(5, this.convert(this.ol)); + change = true; + } + return change; + } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSignal.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSignal.java index c08dfb352..e51efef27 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSignal.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSignal.java @@ -1,17 +1,63 @@ package club.joylink.rtss.simulation.rt.ATS.bo; +import club.joylink.rtss.simulation.rt.CIL.bo.CilSignal; +import lombok.Getter; + +import java.util.Arrays; +import java.util.List; + +@Getter public class AtsSignal extends AtsDevice { int signalAspect; - boolean logic; - boolean forceLight; - boolean bl; - boolean rbl; + int level; public AtsSignal(String id, String name) { super(id, name); } + + @Override + List buildMessage() { + return Arrays.asList(this.id, this.signalAspect, + this.convert(this.logic), this.convert(this.forceLight), this.convert(this.bl), this.convert(this.rbl), this.level); + } + + public boolean applyChange(CilSignal cilSignal) { + List stateList = this.getStateList(); + boolean change = false; + if (cilSignal.getSignalAspect() != this.signalAspect) { + this.signalAspect = cilSignal.getSignalAspect(); + stateList.set(1, this.signalAspect); + change = true; + } + if (this.logic != cilSignal.isLogic()) { + this.logic = cilSignal.isLogic(); + stateList.set(2, this.convert(this.logic)); + change = true; + } + if (this.forceLight != cilSignal.isForceLight()) { + this.forceLight = cilSignal.isForceLight(); + stateList.set(3, this.convert(this.forceLight)); + change = true; + } + if (this.bl != cilSignal.isBl()) { + this.bl = cilSignal.isBl(); + stateList.set(4, this.convert(this.bl)); + change = true; + } + if (this.rbl != cilSignal.isRbl()) { + this.rbl = cilSignal.isRbl(); + stateList.set(5, this.convert(this.rbl)); + change = true; + } + if (this.level != cilSignal.getLevel()) { + this.level = cilSignal.getLevel(); + stateList.set(6, this.level); + change = true; + } + return change; + } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsStand.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsStand.java index 604a81754..9bd64b61e 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsStand.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsStand.java @@ -1,7 +1,15 @@ package club.joylink.rtss.simulation.rt.ATS.bo; +import java.util.Arrays; +import java.util.List; + public class AtsStand extends AtsDevice { public AtsStand(String id, String name) { super(id, name); } + + @Override + public List buildMessage() { + return Arrays.asList(this.id); + } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsStation.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsStation.java index 0841aaa96..25e397126 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsStation.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsStation.java @@ -1,7 +1,15 @@ package club.joylink.rtss.simulation.rt.ATS.bo; +import java.util.Arrays; +import java.util.List; + public class AtsStation extends AtsDevice { public AtsStation(String id, String name) { super(id, name); } + + @Override + public List buildMessage() { + return Arrays.asList(this.id); + } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSwitch.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSwitch.java index af0fa61aa..05bb80143 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSwitch.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSwitch.java @@ -1,8 +1,7 @@ package club.joylink.rtss.simulation.rt.ATS.bo; -import club.joylink.rtss.simulation.rt.RtSimulationSubscribeTopic; +import club.joylink.rtss.simulation.rt.CIL.bo.CilSwitch; import lombok.Getter; -import lombok.NonNull; import lombok.Setter; import java.util.Arrays; @@ -12,20 +11,54 @@ import java.util.List; @Setter public class AtsSwitch extends AtsDevice { int position; - int routeUserToPosition; - boolean bl; - boolean sl; - String routeId; - boolean rl; - boolean ol; - boolean fl; + boolean bl; // 封锁 + boolean sl; // 单锁 + boolean rl; // 进路锁闭 + boolean ol; // 延续保护锁闭 + boolean fl; // 侧防锁闭 public AtsSwitch(String id, String name) { super(id, name); } - public List buildMessage() { - return Arrays.asList(id, position, routeUserToPosition, bl, sl, routeId, rl, ol, fl); + List buildMessage() { + return Arrays.asList(id, position, + this.convert(bl), this.convert(sl), this.convert(rl), this.convert(ol), this.convert(fl)); } + public boolean applyChange(CilSwitch cilSwitch) { + List stateList = this.getStateList(); + boolean change = false; + if (cilSwitch.getPosition() != this.position) { + this.position = cilSwitch.getPosition(); + stateList.set(1, this.position); + change = true; + } + if (cilSwitch.isBl() != this.bl) { + this.bl = cilSwitch.isBl(); + stateList.set(2, this.convert(this.bl)); + change = true; + } + if (cilSwitch.isSl() != this.sl) { + this.sl = cilSwitch.isSl(); + stateList.set(3, this.convert(this.sl)); + change = true; + } + if (cilSwitch.isRl() != this.rl) { + this.rl = cilSwitch.isRl(); + stateList.set(4, this.convert(this.rl)); + change = true; + } + if (cilSwitch.isOl() != this.ol) { + this.ol = cilSwitch.isOl(); + stateList.set(5, this.convert(this.ol)); + change = true; + } + if (cilSwitch.isFl() != this.fl) { + this.fl = cilSwitch.isFl(); + stateList.set(6, this.convert(this.fl)); + change = true; + } + return change; + } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsTrain.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsTrain.java index e792c6ce9..b38021e31 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsTrain.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsTrain.java @@ -1,7 +1,15 @@ package club.joylink.rtss.simulation.rt.ATS.bo; +import java.util.Arrays; +import java.util.List; + public class AtsTrain extends AtsDevice { public AtsTrain(String id, String name) { super(id, name); } + + @Override + public List buildMessage() { + return Arrays.asList(this.id); + } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilLogicService.java b/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilLogicService.java index fb156f170..cd019d498 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilLogicService.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilLogicService.java @@ -81,8 +81,10 @@ public class CilLogicService { } private void sendState2Ats(RtSimulation rtSimulation, CilRepository cilRepository) { - for (CilSwitch cilSwitch : cilRepository.getSwitches()) { - atsApiService.handle(rtSimulation, cilSwitch); - } + // 后面需根据联锁站或集中站同步 + this.atsApiService.syncCilSwitchState(rtSimulation, cilRepository.getSwitches()); + this.atsApiService.syncCilSectionState(rtSimulation, cilRepository.getSections()); + this.atsApiService.syncCilSignalState(rtSimulation, cilRepository.getSignals()); + this.atsApiService.syncCilRouteState(rtSimulation, cilRepository.getRoutes()); } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilRepository.java b/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilRepository.java index db0e52bd8..5dd64171f 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilRepository.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilRepository.java @@ -67,10 +67,22 @@ public class CilRepository extends SimulationRepository { return cilSwitch; } + public List getSections() { + return new ArrayList<>(this.sectionMap.values()); + } + public List getSwitches() { return new ArrayList<>(switchMap.values()); } + public List getSignals() { + return new ArrayList<>(this.signalMap.values()); + } + + public List getRoutes() { + return new ArrayList<>(this.routeMap.values()); + } + public CilSignal getSignalById(String id) { CilSignal cilSignal = this.signalMap.get(id); BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(cilSignal); diff --git a/src/main/java/club/joylink/rtss/simulation/rt/RtSimulationService.java b/src/main/java/club/joylink/rtss/simulation/rt/RtSimulationService.java index 16396104c..4b5182e1a 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/RtSimulationService.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/RtSimulationService.java @@ -32,8 +32,6 @@ public class RtSimulationService { private SrdLogicService srdLogicService; @Autowired private AtsLogicService atsLogicService; - @Autowired - private RtSimulationSubscribeMessageService rtSimulationSubscribeMessageService; public RtSimulation create(UserVO userVO, Long mapId, MapPrdTypeEnum prdTypeEnum) { Objects.requireNonNull(mapId); @@ -48,7 +46,6 @@ public class RtSimulationService { this.atsLogicService.addJobs(rtSimulation); this.initSimulationMember(rtSimulation); this.initCreatorPlayMember(rtSimulation); - rtSimulation.addSubscribeMessageService(rtSimulationSubscribeMessageService); simulationManager.start(rtSimulation.getId()); return rtSimulation; } @@ -74,7 +71,7 @@ public class RtSimulationService { this.commonRepoService.buildRepository(rtSimulation, mapVO); this.cilLogicService.buildRepository(rtSimulation, mapVO); this.srdLogicService.buildRepository(rtSimulation, mapVO); - this.atsLogicService.buildRepository(rtSimulation, mapVO); + this.atsLogicService.init(rtSimulation, mapVO); } public SimulationVO getBasicInfo(String id) { diff --git a/src/main/java/club/joylink/rtss/simulation/rt/RtSimulationSubscribeMessageService.java b/src/main/java/club/joylink/rtss/simulation/rt/RtSimulationSubscribeMessageService.java deleted file mode 100644 index 52ca0d301..000000000 --- a/src/main/java/club/joylink/rtss/simulation/rt/RtSimulationSubscribeMessageService.java +++ /dev/null @@ -1,41 +0,0 @@ -package club.joylink.rtss.simulation.rt; - -import club.joylink.rtss.exception.BusinessExceptionAssertEnum; -import club.joylink.rtss.simulation.Simulation; -import club.joylink.rtss.simulation.SimulationManager; -import club.joylink.rtss.simulation.SimulationSubscribeMessageService; -import club.joylink.rtss.simulation.SimulationUser; -import club.joylink.rtss.simulation.rt.ATS.AtsLogicService; -import club.joylink.rtss.simulation.rt.ATS.bo.AtsRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.List; - -@Component -public class RtSimulationSubscribeMessageService implements SimulationSubscribeMessageService { - - @Autowired - private AtsLogicService atsLogicService; - - @Autowired - private SimulationManager simulationManager; - - @Override - public boolean acceptedSubscribePath(String destination) { - return RtSimulationSubscribeTopic.hasMatched(destination); - } - - @Override - public Object buildMessageOfSubscribe(String destination) { - RtSimulationSubscribeTopic topic = RtSimulationSubscribeTopic.match(destination); - String id = topic.getId(destination); - RtSimulation simulation = simulationManager.getById(id, RtSimulation.class); - switch (topic) { - case ATS: - return atsLogicService.getAllMessages(simulation); - } - return null; - } - -} diff --git a/src/main/java/club/joylink/rtss/simulation/rt/RtSimulationSubscribeTopic.java b/src/main/java/club/joylink/rtss/simulation/rt/RtSimulationSubscribeTopic.java index 1eeca4d4a..e6b7c6d7c 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/RtSimulationSubscribeTopic.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/RtSimulationSubscribeTopic.java @@ -11,7 +11,7 @@ import java.util.Properties; @Getter public enum RtSimulationSubscribeTopic { - ATS("/ats", SrdLogicService.DEVICE_RUN_RATE), + ATS(String.format("%s%s", Simulation.MESSAGE_SUB_PREFIX, "/ats"), SrdLogicService.DEVICE_RUN_RATE), // SandBox("/queue/simulation/jl3d/{id}, ", SrdLogicService.DEVICE_RUN_RATE), // Drive("/queue/simulation/drive/{id}", SrdLogicService.TRAIN_RUN_RATE), // PassengerFlow("/queue/simulation/passenger/{id}", SrdLogicService.DEVICE_RUN_RATE), @@ -47,7 +47,7 @@ public enum RtSimulationSubscribeTopic { } public boolean isMatch(String destination) { - String destPattern = Simulation.MESSAGE_SUB_PREFIX + this.destPattern; + String destPattern = this.destPattern; String[] patterns = StringUtils.tokenizeToStringArray(destPattern, PATH_SEPARATOR); String[] dests = StringUtils.tokenizeToStringArray(destination, PATH_SEPARATOR); if (patterns.length == dests.length) { diff --git a/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrSwitch.java b/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrSwitch.java index 64cd961e8..61df29df7 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrSwitch.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrSwitch.java @@ -1,5 +1,7 @@ package club.joylink.rtss.simulation.rt.SRD.bo; +import lombok.Getter; + import java.time.LocalDateTime; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -7,6 +9,7 @@ import java.util.concurrent.atomic.AtomicInteger; /** * 虚拟真实道岔 */ +@Getter public class SrSwitch extends SrDevice { public static final int turnTime = 3000; // 默认转换时间 diff --git a/src/main/java/club/joylink/rtss/simulation/rt/operation/SwitchOperationHandler.java b/src/main/java/club/joylink/rtss/simulation/rt/operation/SwitchOperationHandler.java index d85971976..61d3b0625 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/operation/SwitchOperationHandler.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/operation/SwitchOperationHandler.java @@ -12,21 +12,18 @@ public class SwitchOperationHandler { private CilApiService cilApiService; @SimulationOperationMapping("Switch_Turn") - public boolean turn(RtSimulation simulation, String id) { + public void turn(RtSimulation simulation, String id) { this.cilApiService.turnSwitch(simulation, id); - return true; } @SimulationOperationMapping("Switch_Normal_Position") - public boolean turnToNormal(RtSimulation simulation, String id) { + public void turnToNormal(RtSimulation simulation, String id) { this.cilApiService.turnSwitchToNormal(simulation, id); - return true; } @SimulationOperationMapping("Switch_Reverse_Position") - public boolean turnToReverse(RtSimulation simulation, String id) { + public void turnToReverse(RtSimulation simulation, String id) { this.cilApiService.turnSwitchToReverse(simulation, id); - return true; } }