From 6a3c4ad64564cad27bb29f5a69f3189720a7432d Mon Sep 17 00:00:00 2001 From: tiger_zhou <123456> Date: Wed, 7 Sep 2022 08:57:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AD=A6=E6=B1=898=E5=8F=B7=E7=BA=BF=E5=88=97?= =?UTF-8?q?=E8=BD=A6=E4=BD=8D=E7=BD=AE=E6=98=BE=E7=A4=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rtss/constants/MapPrdTypeEnum.java | 1 + .../ATS/service/TrainPositionService.java | 67 +++++++++++++++++++ .../cbtc/SimulationLifeCycleServiceImpl.java | 10 ++- .../joylink/rtss/vo/ws/TrainPosition.java | 12 ++++ .../rtss/websocket/WebSocketController.java | 8 +++ .../rtss/websocket/WebsocketConfig.java | 4 +- .../websocket/client/StompClientManager.java | 18 ++++- 7 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionService.java create mode 100644 src/main/java/club/joylink/rtss/vo/ws/TrainPosition.java diff --git a/src/main/java/club/joylink/rtss/constants/MapPrdTypeEnum.java b/src/main/java/club/joylink/rtss/constants/MapPrdTypeEnum.java index 3e093ca1b..b5f2b4b42 100644 --- a/src/main/java/club/joylink/rtss/constants/MapPrdTypeEnum.java +++ b/src/main/java/club/joylink/rtss/constants/MapPrdTypeEnum.java @@ -13,6 +13,7 @@ public enum MapPrdTypeEnum { BIG_SCREEN("07", "大屏工作站", null), RUN_PLAN_MAKE("08", "运行图编制工作站", null), DEPOT_IL("09", "车辆段联锁工作站", null), + BIG_SCREEN_TRAIN_POSITION("10", "大屏车辆真实工作站", null), // CTC("10", "CTC工作站") ; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionService.java new file mode 100644 index 000000000..f0d900c13 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionService.java @@ -0,0 +1,67 @@ +package club.joylink.rtss.simulation.cbtc.ATS.service; + + +import club.joylink.rtss.constants.MapPrdTypeEnum; +import club.joylink.rtss.simulation.SimulationManager; +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.build.SimulationBuildParams; +import club.joylink.rtss.simulation.cbtc.data.map.Section; +import club.joylink.rtss.vo.ws.TrainPosition; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +import javax.annotation.Resource; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class TrainPositionService { + @Resource + AtsTrainLoadService atsTrainLoadService; + @Resource + SimulationManager simulationManager; + final Map> map = new ConcurrentHashMap<>(); + public void initTrainOrUpdate(String mapName,TrainPosition tp){ +// this.simulationManager.getSimulationList().stream().filter(d->d.getb) + + List simulationList = this.findSimulationList(mapName); + if(Objects.equals(true, CollectionUtils.isEmpty(simulationList))){ + log.error(""); + return; + } + + for (Simulation sim : simulationList) { + + } + } + + private void findSection(Simulation sim,TrainPosition tp,Section.SectionRoadType roadType){ + /* Section.SectionRoadType roadType = Section.SectionRoadType.LEFT; + if(tp.getDirection() == 1){ + roadType = Section.SectionRoadType.RIGHT; + }*/ + List
list = sim.getRepository().getSectionList(); + + list.stream().filter(d->d.getRoadType() == roadType).sorted((o1, o2) -> Integer.compare(1,2)).collect(Collectors.toList()); + + } + private List findSimulationList(String mapName){ + return this.simulationManager.getSimulationList().stream().filter(d->{ + if(d instanceof Simulation){ + Simulation sim = (Simulation) d; + SimulationBuildParams params = sim.getBuildParams(); + boolean same = Objects.equals(mapName,params.getMap().getName()) && params.getProdType() == MapPrdTypeEnum.BIG_SCREEN_TRAIN_POSITION; + return same; + } + return false; + }).map(d->(Simulation) d).collect(Collectors.toList()); + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java index 26e6fca67..5043a11f0 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java @@ -1,5 +1,6 @@ package club.joylink.rtss.simulation.cbtc; +import club.joylink.rtss.constants.MapPrdTypeEnum; import club.joylink.rtss.entity.Ibp; import club.joylink.rtss.services.IVirtualRealityIbpService; import club.joylink.rtss.services.IVoiceCommandService; @@ -191,14 +192,19 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic iscsLogicLoop.addJob(simulation); } atpLogicLoop.addJobs(simulation); - atsLogicLoop.addJobs(simulation); + + if(simulation.getBuildParams().getProdType() != MapPrdTypeEnum.BIG_SCREEN_TRAIN_POSITION){ + //非武汉大屏车辆定位 + atsLogicLoop.addJobs(simulation); + simulationRobotService.addJobs(simulation); + } vrTrainRunningService.addJobs(simulation); ciLogic.addJobs(simulation); vrDeviceLogicLoop.addJobs(simulation); atsMessageCollectAndDispatcher.addJobs(simulation); joylink3DMessageService.addJobs(simulation); faultGenerator.addJobs(simulation); - simulationRobotService.addJobs(simulation); + } @Override diff --git a/src/main/java/club/joylink/rtss/vo/ws/TrainPosition.java b/src/main/java/club/joylink/rtss/vo/ws/TrainPosition.java new file mode 100644 index 000000000..32d053f17 --- /dev/null +++ b/src/main/java/club/joylink/rtss/vo/ws/TrainPosition.java @@ -0,0 +1,12 @@ +package club.joylink.rtss.vo.ws; + +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class TrainPosition { + private String trainTripNum; + private int direction; + private float location; +} diff --git a/src/main/java/club/joylink/rtss/websocket/WebSocketController.java b/src/main/java/club/joylink/rtss/websocket/WebSocketController.java index a3076b8fc..b9f34914c 100644 --- a/src/main/java/club/joylink/rtss/websocket/WebSocketController.java +++ b/src/main/java/club/joylink/rtss/websocket/WebSocketController.java @@ -28,4 +28,12 @@ public class WebSocketController { SocketMessageVO message = SocketMessageFactory.buildVrMessage(group, json); stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); } + + @MessageMapping("/{mapId}/trainPosition") + public void mlbs( String json,@DestinationVariable String mapId) { +// Simulation simulation = groupSimulationCache.getSimulationByGroup(group); +// SocketMessageVO message = SocketMessageFactory.buildVrMessage(group, json); +// stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); + System.out.println("aaaaaaaaaaaaa"); + } } diff --git a/src/main/java/club/joylink/rtss/websocket/WebsocketConfig.java b/src/main/java/club/joylink/rtss/websocket/WebsocketConfig.java index 78ffde9aa..3de9ee643 100644 --- a/src/main/java/club/joylink/rtss/websocket/WebsocketConfig.java +++ b/src/main/java/club/joylink/rtss/websocket/WebsocketConfig.java @@ -43,13 +43,11 @@ public class WebsocketConfig implements WebSocketMessageBrokerConfigurer { registry.addEndpoint("/joylink-websocket") .addInterceptors(new SessionAuthHandshakeInterceptor(loginSessionManager)) .setHandshakeHandler(new DefaultHandshakeHandler() { - @Override protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler, Map attributes) { return new MyPrincipal((LoginUserInfoVO) attributes.get(SessionAuthHandshakeInterceptor.ATTR_USER_KEY)); } - }) .setAllowedOrigins("*"); registry.addEndpoint("/joylink-wm-websocket") @@ -64,6 +62,8 @@ public class WebsocketConfig implements WebSocketMessageBrokerConfigurer { }) .setAllowedOrigins("*"); + registry.addEndpoint("/joylink-tbi-websocket") + .setAllowedOrigins("*"); } /** diff --git a/src/main/java/club/joylink/rtss/websocket/client/StompClientManager.java b/src/main/java/club/joylink/rtss/websocket/client/StompClientManager.java index bca561755..47f57cc14 100644 --- a/src/main/java/club/joylink/rtss/websocket/client/StompClientManager.java +++ b/src/main/java/club/joylink/rtss/websocket/client/StompClientManager.java @@ -1,11 +1,16 @@ package club.joylink.rtss.websocket.client; +import club.joylink.rtss.util.JsonUtils; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.messaging.simp.stomp.StompSession; import org.springframework.util.concurrent.ListenableFuture; import org.springframework.web.socket.client.standard.StandardWebSocketClient; import org.springframework.web.socket.messaging.WebSocketStompClient; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.ExecutionException; @Slf4j @@ -18,10 +23,17 @@ public class StompClientManager { WebSocketStompClient stompClient = new WebSocketStompClient(socketClient); SimulationSessionHandler handler = new SimulationSessionHandler(); ListenableFuture future = stompClient - .connect("ws://192.168.3.120:9000/joylink-websocket?token=cc789dc2b2f003b2593f5eafbf4763bd", - handler, "null"); + .connect("ws://127.0.0.1:9000/joylink-tbi-websocket",handler, "null"); StompSession stompSession = future.get(); - stompSession.subscribe("/user/queue/simulation/11/ats", handler); + + Map dataMap = new HashMap<>(); + dataMap.put("trainTripNum","train001"); + dataMap.put("direction",1); + dataMap.put("location",19.99); + ObjectMapper om = new ObjectMapper(); + String val = JsonUtils.writeValueNullableFieldAsString(dataMap); + System.out.println(val); + stompSession.send("/app/测试中文/trainPosition",val.getBytes(StandardCharsets.UTF_8)); } }