链路心跳新增modbus和ftp状态
This commit is contained in:
parent
c0cadc9c79
commit
6bdc564427
@ -9,8 +9,12 @@ import com.das.modules.node.domain.bo.TerminalMessage;
|
|||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.ValueOperations;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service(value = NodeConstant.HEARTBEAT)
|
@Service(value = NodeConstant.HEARTBEAT)
|
||||||
public class HeartbeatCommand implements BaseCommand{
|
public class HeartbeatCommand implements BaseCommand{
|
||||||
@ -18,7 +22,7 @@ public class HeartbeatCommand implements BaseCommand{
|
|||||||
public static final long HEARTBEAT_TTL = 12L;
|
public static final long HEARTBEAT_TTL = 12L;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
AdminRedisTemplate adminRedisTemplate;
|
RedisTemplate<String,Object> redisTemplate;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
CacheService cacheService;
|
CacheService cacheService;
|
||||||
@ -35,16 +39,28 @@ public class HeartbeatCommand implements BaseCommand{
|
|||||||
// 解析心跳报文中的数据信息
|
// 解析心跳报文中的数据信息
|
||||||
JsonNode dataInfo = data.getData();
|
JsonNode dataInfo = data.getData();
|
||||||
if (!dataInfo.isEmpty()) {
|
if (!dataInfo.isEmpty()) {
|
||||||
|
ValueOperations<String,Object> ops = redisTemplate.opsForValue();
|
||||||
// 处理链路信息
|
// 处理链路信息
|
||||||
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();
|
||||||
|
JsonNode modbusNode = linkNode.get("modbus");
|
||||||
|
if (modbusNode != null){
|
||||||
|
boolean modbus = modbusNode.asBoolean();
|
||||||
|
String key = String.format("link:%s:modbus", linkId);
|
||||||
|
ops.set(key, modbus, HEARTBEAT_TTL, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
JsonNode ftpNode = linkNode.get("ftp");
|
||||||
|
if (ftpNode != null){
|
||||||
|
boolean ftp = ftpNode.asBoolean();
|
||||||
|
String key = String.format("link:%s:ftp", linkId);
|
||||||
|
ops.set(key, ftp, HEARTBEAT_TTL, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
String key = String.format("link:%s:online", linkId);
|
String key = String.format("link:%s:online", linkId);
|
||||||
// 更新链路在线状态到Redis
|
// 更新链路在线状态到Redis
|
||||||
adminRedisTemplate.set(key, online ? 1 : 0);
|
ops.set(key, online?1:0, HEARTBEAT_TTL, TimeUnit.SECONDS);
|
||||||
adminRedisTemplate.expire(key, HEARTBEAT_TTL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,19 +78,18 @@ public class HeartbeatCommand implements BaseCommand{
|
|||||||
// 判断是不是风机
|
// 判断是不是风机
|
||||||
String keyDeviceOnline = String.format("device:%d:online", deviceId);
|
String keyDeviceOnline = String.format("device:%d:online", deviceId);
|
||||||
// 更新设备在线状态到Redis
|
// 更新设备在线状态到Redis
|
||||||
adminRedisTemplate.set(keyDeviceOnline, online ? 1 : 0);
|
ops.set(keyDeviceOnline, online ? 1 : 0, HEARTBEAT_TTL, TimeUnit.SECONDS);
|
||||||
adminRedisTemplate.expire(keyDeviceOnline, HEARTBEAT_TTL);
|
|
||||||
|
|
||||||
String keyPLCDeviceStatus = String.format("RT:%d:iturbineoperationmode", deviceId);
|
String keyPLCDeviceStatus = String.format("RT:%d:iturbineoperationmode", deviceId);
|
||||||
String keyCommFaultState = String.format("RT:%d:commfaultstate",deviceId);
|
String keyCommFaultState = String.format("RT:%d:commfaultstate",deviceId);
|
||||||
Integer plcDeviceStatus = adminRedisTemplate.get(keyPLCDeviceStatus);
|
Integer plcDeviceStatus = (Integer) ops.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);
|
ops.set(keyCommFaultState, online ? 0 : 1);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
adminRedisTemplate.set(keyCommFaultState, online && (plcDeviceStatus != 0) ? 0 : 1);
|
ops.set(keyCommFaultState, online && (plcDeviceStatus != 0) ? 0 : 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user