From 545002aea1e07e0eda5535e8440cc09ac244bb86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=B7=E6=88=90=E4=BC=9F?= Date: Thu, 12 Dec 2024 10:01:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/node/command/HeartbeatCommand.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/das/src/main/java/com/das/modules/node/command/HeartbeatCommand.java b/das/src/main/java/com/das/modules/node/command/HeartbeatCommand.java index 6487f3a2..aad67993 100644 --- a/das/src/main/java/com/das/modules/node/command/HeartbeatCommand.java +++ b/das/src/main/java/com/das/modules/node/command/HeartbeatCommand.java @@ -25,31 +25,46 @@ public class HeartbeatCommand implements BaseCommand{ @Autowired CacheService cacheService; + /** + * 执行命令方法 + * 该方法处理接收到的终端消息,特别是心跳报文中的设备和链路在线状态更新 + * + * @param data 包含心跳报文信息的TerminalMessage对象 + */ @Override public void doCommand(TerminalMessage data) { + log.info("收到[heartbeat]报文"); + + // 解析心跳报文中的数据信息 JsonNode dataInfo = data.getData(); if (!dataInfo.isEmpty()) { + // 处理链路信息 JsonNode links = data.getData().get("links"); if (links != null && links.isArray()) { for (JsonNode linkNode : links) { String linkId = linkNode.get("linkId").asText(); boolean online = linkNode.get("online").asBoolean(); String key = String.format("link:%s:online", linkId); + // 更新链路在线状态到Redis adminRedisTemplate.set(key, online ? 1 : 0); adminRedisTemplate.expire(key, HEARTBEAT_TTL); } } + + // 处理设备信息 JsonNode devices = data.getData().get("devices"); if (devices != null && devices.isArray()) { for (JsonNode device : devices) { long deviceId = device.get("deviceId").asLong(); boolean online = device.get("online").asBoolean(); + // 获取设备缓存信息 DeviceInfoCache deviceInfoCacheById = cacheService.getEquipmentCache().getDeviceInfoCacheById(deviceId); if (deviceInfoCacheById == null || !deviceInfoCacheById.getObjectType().equals(EquipmentTypeIds.EQUIPMENT_TYPE_STATION_WTG)) { continue; } - //判断是不是风机 + // 判断是不是风机 String keyDeviceOnline = String.format("device:%d:online", deviceId); + // 更新设备在线状态到Redis adminRedisTemplate.set(keyDeviceOnline, online ? 1 : 0); adminRedisTemplate.expire(keyDeviceOnline, HEARTBEAT_TTL); @@ -57,6 +72,7 @@ public class HeartbeatCommand implements BaseCommand{ String keyCommFaultState = String.format("RT:%d:commfaultstate",deviceId); Integer plcDeviceStatus = adminRedisTemplate.get(keyPLCDeviceStatus); log.debug("设备ID:{},在线状态:{},通讯状态: {}", deviceId, online, plcDeviceStatus); + // 根据设备在线状态和通讯状态更新通讯故障状态 if (plcDeviceStatus == null){ adminRedisTemplate.set(keyCommFaultState, online ? 0 : 1); }