更新日志
This commit is contained in:
parent
7d29d9ba91
commit
545002aea1
@ -25,31 +25,46 @@ public class HeartbeatCommand implements BaseCommand{
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
CacheService cacheService;
|
CacheService cacheService;
|
||||||
|
/**
|
||||||
|
* 执行命令方法
|
||||||
|
* 该方法处理接收到的终端消息,特别是心跳报文中的设备和链路在线状态更新
|
||||||
|
*
|
||||||
|
* @param data 包含心跳报文信息的TerminalMessage对象
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doCommand(TerminalMessage data) {
|
public void doCommand(TerminalMessage data) {
|
||||||
|
log.info("收到[heartbeat]报文");
|
||||||
|
|
||||||
|
// 解析心跳报文中的数据信息
|
||||||
JsonNode dataInfo = data.getData();
|
JsonNode dataInfo = data.getData();
|
||||||
if (!dataInfo.isEmpty()) {
|
if (!dataInfo.isEmpty()) {
|
||||||
|
// 处理链路信息
|
||||||
JsonNode links = data.getData().get("links");
|
JsonNode links = data.getData().get("links");
|
||||||
if (links != null && links.isArray()) {
|
if (links != null && links.isArray()) {
|
||||||
for (JsonNode linkNode : links) {
|
for (JsonNode linkNode : links) {
|
||||||
String linkId = linkNode.get("linkId").asText();
|
String linkId = linkNode.get("linkId").asText();
|
||||||
boolean online = linkNode.get("online").asBoolean();
|
boolean online = linkNode.get("online").asBoolean();
|
||||||
String key = String.format("link:%s:online", linkId);
|
String key = String.format("link:%s:online", linkId);
|
||||||
|
// 更新链路在线状态到Redis
|
||||||
adminRedisTemplate.set(key, online ? 1 : 0);
|
adminRedisTemplate.set(key, online ? 1 : 0);
|
||||||
adminRedisTemplate.expire(key, HEARTBEAT_TTL);
|
adminRedisTemplate.expire(key, HEARTBEAT_TTL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理设备信息
|
||||||
JsonNode devices = data.getData().get("devices");
|
JsonNode devices = data.getData().get("devices");
|
||||||
if (devices != null && devices.isArray()) {
|
if (devices != null && devices.isArray()) {
|
||||||
for (JsonNode device : devices) {
|
for (JsonNode device : devices) {
|
||||||
long deviceId = device.get("deviceId").asLong();
|
long deviceId = device.get("deviceId").asLong();
|
||||||
boolean online = device.get("online").asBoolean();
|
boolean online = device.get("online").asBoolean();
|
||||||
|
// 获取设备缓存信息
|
||||||
DeviceInfoCache deviceInfoCacheById = cacheService.getEquipmentCache().getDeviceInfoCacheById(deviceId);
|
DeviceInfoCache deviceInfoCacheById = cacheService.getEquipmentCache().getDeviceInfoCacheById(deviceId);
|
||||||
if (deviceInfoCacheById == null || !deviceInfoCacheById.getObjectType().equals(EquipmentTypeIds.EQUIPMENT_TYPE_STATION_WTG)) {
|
if (deviceInfoCacheById == null || !deviceInfoCacheById.getObjectType().equals(EquipmentTypeIds.EQUIPMENT_TYPE_STATION_WTG)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// 判断是不是风机
|
// 判断是不是风机
|
||||||
String keyDeviceOnline = String.format("device:%d:online", deviceId);
|
String keyDeviceOnline = String.format("device:%d:online", deviceId);
|
||||||
|
// 更新设备在线状态到Redis
|
||||||
adminRedisTemplate.set(keyDeviceOnline, online ? 1 : 0);
|
adminRedisTemplate.set(keyDeviceOnline, online ? 1 : 0);
|
||||||
adminRedisTemplate.expire(keyDeviceOnline, HEARTBEAT_TTL);
|
adminRedisTemplate.expire(keyDeviceOnline, HEARTBEAT_TTL);
|
||||||
|
|
||||||
@ -57,6 +72,7 @@ public class HeartbeatCommand implements BaseCommand{
|
|||||||
String keyCommFaultState = String.format("RT:%d:commfaultstate",deviceId);
|
String keyCommFaultState = String.format("RT:%d:commfaultstate",deviceId);
|
||||||
Integer plcDeviceStatus = adminRedisTemplate.get(keyPLCDeviceStatus);
|
Integer plcDeviceStatus = adminRedisTemplate.get(keyPLCDeviceStatus);
|
||||||
log.debug("设备ID:{},在线状态:{},通讯状态: {}", deviceId, online, plcDeviceStatus);
|
log.debug("设备ID:{},在线状态:{},通讯状态: {}", deviceId, online, plcDeviceStatus);
|
||||||
|
// 根据设备在线状态和通讯状态更新通讯故障状态
|
||||||
if (plcDeviceStatus == null){
|
if (plcDeviceStatus == null){
|
||||||
adminRedisTemplate.set(keyCommFaultState, online ? 0 : 1);
|
adminRedisTemplate.set(keyCommFaultState, online ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user