根据心跳更新风机通讯状态

This commit is contained in:
谷成伟 2024-12-05 14:01:54 +08:00
parent ab64bf4ee3
commit 68c15b469a

View File

@ -1,7 +1,10 @@
package com.das.modules.node.command;
import com.das.common.constant.EquipmentTypeIds;
import com.das.common.utils.AdminRedisTemplate;
import com.das.common.utils.StringUtils;
import com.das.modules.cache.domain.DeviceInfoCache;
import com.das.modules.cache.service.CacheService;
import com.das.modules.node.constant.NodeConstant;
import com.das.modules.node.domain.bo.TerminalMessage;
import com.fasterxml.jackson.databind.JsonNode;
@ -17,6 +20,9 @@ public class HeartbeatCommand implements BaseCommand{
@Autowired
AdminRedisTemplate adminRedisTemplate;
@Autowired
CacheService cacheService;
@Override
public void doCommand(TerminalMessage data) {
JsonNode dataInfo = data.getData();
@ -39,6 +45,27 @@ public class HeartbeatCommand implements BaseCommand{
adminRedisTemplate.expire(key, 300L);
}
}
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 keyPLCDeviceStatus = String.format("RT:%d:iturbineoperationmode", deviceId);
String keyDeviceStatus = String.format("RT:%d:commfaultstate");
Integer plcDeviceStatus = adminRedisTemplate.get(keyPLCDeviceStatus);
if (plcDeviceStatus == null){
adminRedisTemplate.set(keyDeviceStatus, online ? 1 : 0);
}
else{
adminRedisTemplate.set(keyDeviceStatus, online && plcDeviceStatus == 1 ? 1 : 0);
}
}
}
}
}
}