链路心跳新增real和ftp状态

This commit is contained in:
谷成伟 2024-12-31 10:46:57 +08:00
parent e09f774532
commit b10503dd1b
3 changed files with 43 additions and 22 deletions

View File

@ -50,13 +50,13 @@ public class HeartbeatCommand implements BaseCommand{
if (realNode != null){ if (realNode != null){
boolean real = realNode.asBoolean(); boolean real = realNode.asBoolean();
String key = String.format("link:%s:real", linkId); String key = String.format("link:%s:real", linkId);
ops.set(key, real, HEARTBEAT_TTL, TimeUnit.SECONDS); ops.set(key, real?1:0, HEARTBEAT_TTL, TimeUnit.SECONDS);
} }
JsonNode ftpNode = linkNode.get("ftp"); JsonNode ftpNode = linkNode.get("ftp");
if (ftpNode != null){ if (ftpNode != null){
boolean ftp = ftpNode.asBoolean(); boolean ftp = ftpNode.asBoolean();
String key = String.format("link:%s:ftp", linkId); String key = String.format("link:%s:ftp", linkId);
ops.set(key, ftp, HEARTBEAT_TTL, TimeUnit.SECONDS); ops.set(key, ftp?1:0, HEARTBEAT_TTL, TimeUnit.SECONDS);
} }
String key = String.format("link:%s:online", linkId); String key = String.format("link:%s:online", linkId);
// 更新链路在线状态到Redis // 更新链路在线状态到Redis

View File

@ -38,9 +38,23 @@ public class SysCommunicationLinkVo {
private String nodeName; private String nodeName;
/** /**
* 状态 0 - 正常 1 - 通讯中断 * 链路状态 0 - 离线 1 - 正常
*/
private Integer onlineStatus;
/**
* ftp状态 0 - 异常 1 - 正常
*/
private Integer ftpStatus;
/**
* 实时数据状态 0 - 异常 1 - 正常
*/
private Integer realStatus;
/**
* 实时数据状态
*/ */
private Integer status;
/** /**
* 所属系统节点id * 所属系统节点id

View File

@ -39,6 +39,7 @@ import jakarta.servlet.http.HttpServletResponse;
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.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -81,7 +82,7 @@ public class SysNodeServiceImpl implements SysNodeService {
SysIotModelServiceMapper iotModelServiceMapper; SysIotModelServiceMapper iotModelServiceMapper;
@Autowired @Autowired
AdminRedisTemplate adminRedisTemplate; RedisTemplate<String,Integer> redisTemplate;
@Override @Override
public List<SysNodeVo> querySysNodeList() { public List<SysNodeVo> querySysNodeList() {
@ -144,6 +145,7 @@ public class SysNodeServiceImpl implements SysNodeService {
*/ */
@Override @Override
public PageDataInfo<SysCommunicationLinkVo> querySysCommunicationLinkList(SysCommunicationLinkDto sysCommunicationLinkDto) { public PageDataInfo<SysCommunicationLinkVo> querySysCommunicationLinkList(SysCommunicationLinkDto sysCommunicationLinkDto) {
ValueOperations<String,Integer> ops = redisTemplate.opsForValue();
// 初始化分页查询对象 // 初始化分页查询对象
PageQuery pageQuery = new PageQuery(); PageQuery pageQuery = new PageQuery();
pageQuery.setPageNum(sysCommunicationLinkDto.getPageNum()); pageQuery.setPageNum(sysCommunicationLinkDto.getPageNum());
@ -158,32 +160,37 @@ public class SysNodeServiceImpl implements SysNodeService {
// 根据条件判断是否需要查询在线状态 // 根据条件判断是否需要查询在线状态
if (sysCommunicationLinkDto.getWithStatus() != null && sysCommunicationLinkDto.getWithStatus() == 1) { if (sysCommunicationLinkDto.getWithStatus() != null && sysCommunicationLinkDto.getWithStatus() == 1) {
// 初始化用于存储在线状态键的列表 // 初始化用于存储在线状态键的列表
List<String> keys = new ArrayList<>(records.size()); List<String> onlines = new ArrayList<>(records.size());
List<String> ftps = new ArrayList<>(records.size());
List<String> reals = new ArrayList<>(records.size());
// 遍历查询结果构造每个通信链路的在线状态键 // 遍历查询结果构造每个通信链路的在线状态键
for (int i = 0; i < records.size(); i++) { for (int i = 0; i < records.size(); i++) {
SysCommunicationLinkVo sysCommunicationLinkVo = records.get(i); SysCommunicationLinkVo sysCommunicationLinkVo = records.get(i);
String onlineKey = String.format("link:%d:online", sysCommunicationLinkVo.getId()); onlines.add(String.format("link:%d:online", sysCommunicationLinkVo.getId()));
keys.add(onlineKey); ftps.add(String.format("link:%d:ftp", sysCommunicationLinkVo.getId()));
reals.add(String.format("link:%d:real", sysCommunicationLinkVo.getId()));
} }
// 批量获取在线状态值 // 批量获取在线状态值
List<Object> values = adminRedisTemplate.mGet(keys); List<Integer> onlinesStatus = ops.multiGet(onlines);
List<Integer> ftpsStatus = ops.multiGet(ftps);
List<Integer> realsStatus = ops.multiGet(reals);
// 遍历在线状态值更新通信链路的在线状态 // 遍历在线状态值更新通信链路的在线状态
for (int i = 0; i < values.size(); i++) { for (int i = 0; i < records.size(); i++) {
Object val = values.get(i); SysCommunicationLinkVo sysCommunicationLinkVo = records.get(i);
if (val == null) { Integer ostatus = onlinesStatus.get(i);
records.get(i).setStatus(1); Integer fstatus = ftpsStatus.get(i);
Integer rstatus = realsStatus.get(i);
if (ostatus == null) {
ostatus = 0;
} }
else{ sysCommunicationLinkVo.setOnlineStatus(ostatus);
Integer status = NumberUtil.parseInt(val.toString(), null); if (fstatus != null){
if (status == null || status == 0) { sysCommunicationLinkVo.setFtpStatus(fstatus);
records.get(i).setStatus(1); }
} if (rstatus != null ){
else{ sysCommunicationLinkVo.setRealStatus(rstatus);
records.get(i).setStatus(0);
}
} }
} }
} }