更新日志
This commit is contained in:
parent
7d29d9ba91
commit
545002aea1
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user