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