From f78920ea331436a7890246f6cdfd7ae94bf50e16 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Thu, 7 Sep 2023 17:37:29 +0800 Subject: [PATCH] =?UTF-8?q?=E9=95=BF=E6=97=B6=E9=97=B4=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E6=8E=A5=E6=94=B6=E6=95=B0=E6=8D=AE=E9=87=8D=E6=96=B0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=9F=BA=E7=A1=80=E6=95=B0=E6=8D=AE(=E8=A1=8C?= =?UTF-8?q?=E8=BD=A6=E8=AE=A1=E5=88=92)=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xiannccda/ats/message/OccMessageManage.java | 4 +++- .../xiannccda/ats/message/XianOccMessagingClient.java | 11 ++++++----- src/main/resources/application.yml | 4 +++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/ats/message/OccMessageManage.java b/src/main/java/club/joylink/xiannccda/ats/message/OccMessageManage.java index 4da9488..32785ae 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/OccMessageManage.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/OccMessageManage.java @@ -27,6 +27,8 @@ public class OccMessageManage implements ApplicationRunner { private Integer lineId; @Value("${occ.collectorData:false}") private Boolean collectorData; + @Value("${receive-msg-timeout:6}") + private Integer receiveMsgTimeout; Map clientMap = new HashMap<>(); public void sendMsg(Integer lineId, MessageData md, boolean isRealTime) { @@ -46,7 +48,7 @@ public class OccMessageManage implements ApplicationRunner { public void run(ApplicationArguments args) throws Exception { DeviceNameChangerManage.init(); // 读取数据配置,创建客户端 - this.registerClient(new XianOccMessagingClient(this.lineId, this.realPort, this.unRealPort, this.serverHost, this.collectorData)); + this.registerClient(new XianOccMessagingClient(this.lineId, this.realPort, this.unRealPort, this.serverHost, this.collectorData, receiveMsgTimeout)); for (XianOccMessagingClient client : this.clientMap.values()) { client.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 f5a326a..e56202a 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java @@ -2,6 +2,7 @@ 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.sql.Time; import java.time.LocalDateTime; import java.util.Objects; import java.util.concurrent.TimeUnit; @@ -34,6 +35,8 @@ public class XianOccMessagingClient { */ private AtomicBoolean requestBaseDataFlag = new AtomicBoolean(false); + private final Long requestBaseTime; + public void send(MessageData md, boolean isRealTime) { OccTcpClientConnection conn = isRealTime ? rtConnection : nrtConnection; if (conn.connected) { @@ -45,24 +48,22 @@ public class XianOccMessagingClient { } - public XianOccMessagingClient(int lineId, Integer realPort, Integer unRealPort, String host, boolean collectorData) { + public XianOccMessagingClient(int lineId, Integer realPort, Integer unRealPort, String host, boolean collectorData, Integer receiveMsgTimeout) { this.host = host; this.lineId = lineId; - + this.requestBaseTime = TimeUnit.HOURS.toMillis(receiveMsgTimeout); // 创建实时和非实时消息连接 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()) { + if (Objects.equals(false, this.rtConnection.connected) && (this.rtConnection.receiveMessageLatest + this.requestBaseTime) < System.currentTimeMillis()) { this.requestBaseDataFlag.set(false); } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8945508..22d51a7 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -42,5 +42,7 @@ jwt: key: pub: classpath:app.pub prv: classpath:app.key - +#过滤OCC 数据中的rtu occ-not-handle-rtu: '{3: "81,82"}' +#长时间没有接收occ数据超时,重新获取基础数据时间(小时) +receive-msg-timeout: 1