长时间没有接收数据重新获取基础数据(行车计划)调整

This commit is contained in:
tiger_zhou 2023-09-07 17:37:29 +08:00
parent b51b9f7bba
commit f78920ea33
3 changed files with 12 additions and 7 deletions

View File

@ -27,6 +27,8 @@ public class OccMessageManage implements ApplicationRunner {
private Integer lineId; private Integer lineId;
@Value("${occ.collectorData:false}") @Value("${occ.collectorData:false}")
private Boolean collectorData; private Boolean collectorData;
@Value("${receive-msg-timeout:6}")
private Integer receiveMsgTimeout;
Map<Integer, XianOccMessagingClient> clientMap = new HashMap<>(); Map<Integer, XianOccMessagingClient> clientMap = new HashMap<>();
public void sendMsg(Integer lineId, MessageData md, boolean isRealTime) { 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 { public void run(ApplicationArguments args) throws Exception {
DeviceNameChangerManage.init(); 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()) { for (XianOccMessagingClient client : this.clientMap.values()) {
client.connect(); client.connect();
} }

View File

@ -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;
import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest.ApplyTypeEnum; import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest.ApplyTypeEnum;
import java.sql.Time;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -34,6 +35,8 @@ public class XianOccMessagingClient {
*/ */
private AtomicBoolean requestBaseDataFlag = new AtomicBoolean(false); private AtomicBoolean requestBaseDataFlag = new AtomicBoolean(false);
private final Long requestBaseTime;
public void send(MessageData md, boolean isRealTime) { public void send(MessageData md, boolean isRealTime) {
OccTcpClientConnection conn = isRealTime ? rtConnection : nrtConnection; OccTcpClientConnection conn = isRealTime ? rtConnection : nrtConnection;
if (conn.connected) { 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.host = host;
this.lineId = lineId; this.lineId = lineId;
this.requestBaseTime = TimeUnit.HOURS.toMillis(receiveMsgTimeout);
// 创建实时和非实时消息连接 // 创建实时和非实时消息连接
this.rtConnection = new OccTcpClientConnection(this, host, realPort, collectorData); this.rtConnection = new OccTcpClientConnection(this, host, realPort, collectorData);
this.nrtConnection = new OccTcpClientConnection(this, host, unRealPort, false); this.nrtConnection = new OccTcpClientConnection(this, host, unRealPort, false);
} }
private final static long RESET_REQUEST_BASE_TIME = TimeUnit.HOURS.toMillis(2);
/** /**
* 重置重新获取基础数据 * 重置重新获取基础数据
*/ */
public void resetRequestBaseDataFlag() { public void resetRequestBaseDataFlag() {
//实时数据客户端断开并且最新的获取时间 + 2小时小于当前时间 //实时数据客户端断开并且最新的获取时间 + 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); this.requestBaseDataFlag.set(false);
} }
} }

View File

@ -42,5 +42,7 @@ jwt:
key: key:
pub: classpath:app.pub pub: classpath:app.pub
prv: classpath:app.key prv: classpath:app.key
#过滤OCC 数据中的rtu
occ-not-handle-rtu: '{3: "81,82"}' occ-not-handle-rtu: '{3: "81,82"}'
#长时间没有接收occ数据超时重新获取基础数据时间小时
receive-msg-timeout: 1