From b51b9f7bba8e8f26315aba0c9c51930d09a02b2e Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Thu, 7 Sep 2023 14:42:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4=EF=BC=8C?= =?UTF-8?q?=E5=88=97=E8=BD=A6=E6=95=B0=E6=8D=AE=E8=8E=B7=E5=8F=96=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ats/message/OccMessageDecoder.java | 1 + .../ats/message/OccMessageHandler.java | 2 + .../ats/message/OccTcpClientConnection.java | 24 +++++------- .../ats/message/XianOccMessagingClient.java | 39 +++++++++++++++++-- .../warn/TrainAtpCutAlertMonitoringTask.java | 8 ++++ .../ats/warn/TrainModeAlertListener.java | 2 + .../device/DeviceStatusCheckTest.java | 11 +++--- 7 files changed, 62 insertions(+), 25 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/ats/message/OccMessageDecoder.java b/src/main/java/club/joylink/xiannccda/ats/message/OccMessageDecoder.java index 086bcce..9845ec1 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/OccMessageDecoder.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/OccMessageDecoder.java @@ -16,6 +16,7 @@ public class OccMessageDecoder extends ByteToMessageDecoder { @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { connection.lastReceiveMessageTime = System.currentTimeMillis(); + connection.receiveMessageLatest = System.currentTimeMillis(); List messages = FrameSchema.decode2(in); if (!(messages == null || messages.size() == 0)) { // System.out.println( diff --git a/src/main/java/club/joylink/xiannccda/ats/message/OccMessageHandler.java b/src/main/java/club/joylink/xiannccda/ats/message/OccMessageHandler.java index 5436802..7f6286d 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/OccMessageHandler.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/OccMessageHandler.java @@ -24,7 +24,9 @@ public class OccMessageHandler extends SimpleChannelInboundHandler { @@ -112,6 +105,7 @@ public class OccTcpClientConnection { log.warn("与服务断连,尝试重连: {}", this.hostPortInfo()); this.connected = false; this.channel = null; + this.client.resetRequestBaseDataFlag(); Thread.sleep(3000); connect(); } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java b/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java index 4e29548..f5a326a 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java @@ -1,5 +1,11 @@ package club.joylink.xiannccda.ats.message; +import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest; +import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest.ApplyTypeEnum; +import java.time.LocalDateTime; +import java.util.Objects; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -23,14 +29,18 @@ public class XianOccMessagingClient { * 非实时消息的连接 */ private final OccTcpClientConnection nrtConnection; + /** + * 是否需要请求基础数据 + */ + private AtomicBoolean requestBaseDataFlag = new AtomicBoolean(false); public void send(MessageData md, boolean isRealTime) { OccTcpClientConnection conn = isRealTime ? rtConnection : nrtConnection; - if (conn.connected) { conn.write(md); } else { - throw new RuntimeException("未连接occ"); + String msg = String.format("未连接occ lineId[%s] host[%s] port[%s] messageId[%s]", this.lineId, this.host, conn.port, md.msgId.name()); + throw new RuntimeException(msg); } } @@ -40,8 +50,29 @@ public class XianOccMessagingClient { this.lineId = lineId; // 创建实时和非实时消息连接 - this.rtConnection = new OccTcpClientConnection(this, host, realPort, collectorData, true); - this.nrtConnection = new OccTcpClientConnection(this, host, unRealPort, false, false); + this.rtConnection = new OccTcpClientConnection(this, host, realPort, collectorData); + this.nrtConnection = new OccTcpClientConnection(this, host, unRealPort, false); + } + + + private final static long RESET_REQUEST_BASE_TIME = TimeUnit.HOURS.toMillis(2); + + /** + * 重置重新获取基础数据 + */ + public void resetRequestBaseDataFlag() { + //实时数据客户端断开,并且最新的获取时间 + 2小时小于当前时间 + if (Objects.equals(false, this.rtConnection.connected) && (this.rtConnection.receiveMessageLatest + RESET_REQUEST_BASE_TIME) < System.currentTimeMillis()) { + this.requestBaseDataFlag.set(false); + } + } + + public void requestBaseData() { + if (this.rtConnection.connected && this.nrtConnection.connected && this.requestBaseDataFlag.compareAndSet(false, true)) { + log.info("发送计划运行图请求 lineId[{}] host[{}] 实时接口[{}]", this.lineId, this.host, false); + LoadHistoryTGDataRequest dataRequest = new LoadHistoryTGDataRequest((short) this.lineId, LocalDateTime.now(), ApplyTypeEnum.PLAN_GRAPH); + this.send(dataRequest, false); + } } public ConnectionInfo getRTClientConnectionInfo() { diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/TrainAtpCutAlertMonitoringTask.java b/src/main/java/club/joylink/xiannccda/ats/warn/TrainAtpCutAlertMonitoringTask.java index 2606263..f23c589 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/TrainAtpCutAlertMonitoringTask.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/TrainAtpCutAlertMonitoringTask.java @@ -50,6 +50,14 @@ public class TrainAtpCutAlertMonitoringTask implements AlertMonitoringTask { } } + public void updateTrainInfo(TrainInfo.Builder train) { + TrainInfo.Builder saveTrainInfo = this.trainInfoMap.get(train.getGroupId()); + if (Objects.nonNull(saveTrainInfo)) { + train.setReceiveTime(saveTrainInfo.getReceiveTime()); + this.trainInfoMap.put(train.getGroupId(), train); + } + } + /** * 判断紧致后发生atp切除并恢复 *

diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/TrainModeAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/TrainModeAlertListener.java index a3a63f7..26ff026 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/TrainModeAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/TrainModeAlertListener.java @@ -34,6 +34,8 @@ public class TrainModeAlertListener implements AlertSourceEventListener