From 5c9ae4fba47daa17d7d77e5ede4eef6b502da506 Mon Sep 17 00:00:00 2001 From: gaoyutao Date: Mon, 12 Jan 2026 18:27:57 +0800 Subject: [PATCH] =?UTF-8?q?pppoe=E9=85=8D=E7=BD=AE=E5=A2=9E=E5=8A=A05?= =?UTF-8?q?=E4=B8=AA=E5=AD=97=E6=AE=B5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/api/domain/NetworkInfo.java | 3 + .../domain/RmNetworkInterfaceChild.java | 2 + .../rocketmq/domain/RmPppoeConfigSub.java | 14 ++++ .../rocketmq/handler/MessageHandler.java | 1 + .../impl/RmPppoeConfigMainServiceImpl.java | 76 +++++++++++++++++-- .../RmNetworkInterfaceChildMapper.xml | 7 +- .../rocketmq/RmPppoeConfigSubMapper.xml | 13 +++- 7 files changed, 109 insertions(+), 7 deletions(-) diff --git a/tongran-api/tongran-api-system/src/main/java/com/tongran/system/api/domain/NetworkInfo.java b/tongran-api/tongran-api-system/src/main/java/com/tongran/system/api/domain/NetworkInfo.java index d389cbe..636dade 100644 --- a/tongran-api/tongran-api-system/src/main/java/com/tongran/system/api/domain/NetworkInfo.java +++ b/tongran-api/tongran-api-system/src/main/java/com/tongran/system/api/domain/NetworkInfo.java @@ -44,6 +44,9 @@ public class NetworkInfo { // 如果是子接口,存储父接口名称 @JsonProperty("parentInterface") private String parentInterface; + /** 网卡创建时间 */ + @JsonProperty("netCreateTime") + private Long netCreateTime; // 如果是父接口,存储子接口列表 @JsonProperty("subInterfaces") diff --git a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/RmNetworkInterfaceChild.java b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/RmNetworkInterfaceChild.java index 44fc930..0e024a9 100644 --- a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/RmNetworkInterfaceChild.java +++ b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/RmNetworkInterfaceChild.java @@ -76,6 +76,8 @@ public class RmNetworkInterfaceChild extends BaseEntity /** 是否连通外网(0否,1是) */ @Excel(name = "是否连通外网(0否,1是)") private String status; + /** 网卡创建时间 */ + private Long netCreateTime; /** 虚拟网卡上报带宽值(Mbps) */ private BigDecimal bandwidthResult; /** 有ipv4的标识 */ diff --git a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/RmPppoeConfigSub.java b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/RmPppoeConfigSub.java index b0bb002..4152019 100644 --- a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/RmPppoeConfigSub.java +++ b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/RmPppoeConfigSub.java @@ -52,6 +52,20 @@ public class RmPppoeConfigSub extends BaseEntity private String clientId; /** 接口名称 */ private String interfaceName; + /** 网卡创建时间 */ + private Long netCreateTime; + /** 网卡运行时间 */ + private String netRunTime; + /** 接收带宽(bit) */ + private String inSpeed; + + /** 发送带宽(bit) */ + private String outSpeed; + /** 总接收带宽 */ + private String totalInSpeed; + + /** 总发送带宽 */ + private String totalOutSpeed; public RmPppoeConfigSubVo toVo() { RmPppoeConfigSubVo vo = new RmPppoeConfigSubVo(); diff --git a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/handler/MessageHandler.java b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/handler/MessageHandler.java index 6559bed..5aa27f2 100644 --- a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/handler/MessageHandler.java +++ b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/handler/MessageHandler.java @@ -1356,6 +1356,7 @@ public class MessageHandler { networkInterface.setPublicIp(networkInfo.getPublicIp()); networkInterface.setInterfaceType(networkInfo.getType()); networkInterface.setStatus(networkInfo.getStatus()); + networkInterface.setNetCreateTime(networkInfo.getNetCreateTime()); } /** diff --git a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/service/impl/RmPppoeConfigMainServiceImpl.java b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/service/impl/RmPppoeConfigMainServiceImpl.java index a261a52..c5af84e 100644 --- a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/service/impl/RmPppoeConfigMainServiceImpl.java +++ b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/service/impl/RmPppoeConfigMainServiceImpl.java @@ -3,10 +3,7 @@ package com.tongran.rocketmq.service.impl; import com.alibaba.fastjson.JSONObject; import com.tongran.common.core.enums.MsgEnum; import com.tongran.common.core.utils.DateUtils; -import com.tongran.rocketmq.domain.DeviceMessage; -import com.tongran.rocketmq.domain.RmNetworkInterfaceChild; -import com.tongran.rocketmq.domain.RmPppoeConfigMain; -import com.tongran.rocketmq.domain.RmPppoeConfigSub; +import com.tongran.rocketmq.domain.*; import com.tongran.rocketmq.domain.vo.PolicyTypeVo; import com.tongran.rocketmq.domain.vo.PppoeVo; import com.tongran.rocketmq.domain.vo.RmPppoeConfigSubVo; @@ -15,11 +12,13 @@ import com.tongran.rocketmq.mapper.RmPppoeConfigMainMapper; import com.tongran.rocketmq.mapper.RmPppoeConfigSubMapper; import com.tongran.rocketmq.model.ProducerMode; import com.tongran.rocketmq.producer.MessageProducer; +import com.tongran.rocketmq.service.IInitialBandwidthTrafficService; import com.tongran.rocketmq.service.IRmPppoeConfigMainService; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -41,10 +40,13 @@ public class RmPppoeConfigMainServiceImpl implements IRmPppoeConfigMainService private ProducerMode producerMode; @Autowired private RmNetworkInterfaceChildMapper rmNetworkInterfaceChildMapper; + @Autowired + private IInitialBandwidthTrafficService initialBandwidthTrafficService; @Override public RmPppoeConfigMain selectRmPppoeConfigMainByClientId(RmPppoeConfigMain rmPppoeConfigMain) { + long nowTime = Instant.now().getEpochSecond(); RmPppoeConfigMain pppoeConfigMain = rmPppoeConfigMainMapper.selectRmPppoeConfigMainByClientId(rmPppoeConfigMain.getClientId()); if(pppoeConfigMain == null){ pppoeConfigMain = new RmPppoeConfigMain(); @@ -53,7 +55,21 @@ public class RmPppoeConfigMainServiceImpl implements IRmPppoeConfigMainService RmPppoeConfigSub rmPppoeConfigSub = new RmPppoeConfigSub(); rmPppoeConfigSub.setClientId(rmPppoeConfigMain.getClientId()); List subList = rmPppoeConfigSubMapper.selectRmPppoeConfigSubList(rmPppoeConfigSub); - if("2".equals(pppoeConfigMain.getPppoeConfigMode())){ + if("1".equals(pppoeConfigMain.getPppoeConfigMode())){ + for (RmPppoeConfigSub pppoeConfigSub : subList) { + // 查询流量信息 + InitialBandwidthTraffic initialBandwidthTraffic = new InitialBandwidthTraffic(); + initialBandwidthTraffic.setClientId(pppoeConfigSub.getClientId()); + initialBandwidthTraffic.setName(pppoeConfigSub.getInterfaceName()); + InitialBandwidthTraffic netMsg = initialBandwidthTrafficService.getNetInterfaceDetailsMsg(initialBandwidthTraffic); + if(netMsg != null){ + pppoeConfigSub.setInSpeed(convert(netMsg.getInSpeed(), "mbps")); + pppoeConfigSub.setOutSpeed(convert(netMsg.getOutSpeed(), "mbps")); + pppoeConfigSub.setTotalInSpeed(convert(netMsg.getTotalInSpeed(),"gb")); + pppoeConfigSub.setTotalOutSpeed(convert(netMsg.getTotalOutSpeed(),"gb")); + } + } + }else if("2".equals(pppoeConfigMain.getPppoeConfigMode())){ subList = new ArrayList<>(); // 查询虚拟网卡信息 RmNetworkInterfaceChild childQuery = new RmNetworkInterfaceChild(); @@ -63,6 +79,11 @@ public class RmPppoeConfigMainServiceImpl implements IRmPppoeConfigMainService List childList = rmNetworkInterfaceChildMapper.selectRmNetworkInterfaceChildList(childQuery); if(childList != null && !childList.isEmpty()){ for (RmNetworkInterfaceChild child : childList) { + // 查询流量信息 + InitialBandwidthTraffic initialBandwidthTraffic = new InitialBandwidthTraffic(); + initialBandwidthTraffic.setClientId(child.getClientId()); + initialBandwidthTraffic.setName(child.getInterfaceName()); + InitialBandwidthTraffic netMsg = initialBandwidthTrafficService.getNetInterfaceDetailsMsg(initialBandwidthTraffic); RmPppoeConfigSub pppoeConfigSub = new RmPppoeConfigSub(); pppoeConfigSub.setClientId(child.getClientId()); pppoeConfigSub.setInterfaceName(child.getInterfaceName()); @@ -71,6 +92,28 @@ public class RmPppoeConfigMainServiceImpl implements IRmPppoeConfigMainService pppoeConfigSub.setIpv4Gateway(child.getGateway()); pppoeConfigSub.setStatus(child.getStatus()); pppoeConfigSub.setBandwidthResult(child.getBandwidthResult()); + if(netMsg != null){ + pppoeConfigSub.setInSpeed(convert(netMsg.getInSpeed(), "mbps")); + pppoeConfigSub.setOutSpeed(convert(netMsg.getOutSpeed(), "mbps")); + pppoeConfigSub.setTotalInSpeed(convert(netMsg.getTotalInSpeed(),"gb")); + pppoeConfigSub.setTotalOutSpeed(convert(netMsg.getTotalOutSpeed(),"gb")); + } + // 计算运行时间 + if (child.getNetCreateTime() != null) { + long createTime = child.getNetCreateTime(); // 秒级时间戳 + long uptimeSeconds = nowTime - createTime; + + if (uptimeSeconds > 0) { + long hours = uptimeSeconds / 3600; + long minutes = (uptimeSeconds % 3600) / 60; + String runTime = String.format("%dh%02dm", hours, minutes); + pppoeConfigSub.setNetRunTime(runTime); + } else { + pppoeConfigSub.setNetRunTime("0h00m"); + } + } else { + pppoeConfigSub.setNetRunTime(null); + } subList.add(pppoeConfigSub); } } @@ -78,7 +121,30 @@ public class RmPppoeConfigMainServiceImpl implements IRmPppoeConfigMainService pppoeConfigMain.setSubList(subList); return pppoeConfigMain; } + /** + * 转换bit值 + * @param bitStr bit值的字符串 + * @param toUnit 目标单位:"Mbps" 或 "GB"(不区分大小写) + * @return 转换后的值字符串,保留两位小数 + */ + public String convert(String bitStr, String toUnit) { + if (bitStr == null || bitStr.trim().isEmpty()) { + throw new IllegalArgumentException("bit值不能为空"); + } + double bits = Double.parseDouble(bitStr.trim()); + double result; + + if ("mbps".equalsIgnoreCase(toUnit)) { + result = bits / 1_000_000.0; // 1 Mbps = 1,000,000 bits + } else if ("gb".equalsIgnoreCase(toUnit)) { + result = bits / 8_000_000_000.0; // 1 GB = 8,000,000,000 bits (1000³ * 8) + } else { + throw new IllegalArgumentException("单位只支持 Mbps 或 GB"); + } + + return String.format("%.2f", result); + } /** * 查询PPPoE配置主表列表 * diff --git a/tongran-rocketmq/src/main/resources/mapper/rocketmq/RmNetworkInterfaceChildMapper.xml b/tongran-rocketmq/src/main/resources/mapper/rocketmq/RmNetworkInterfaceChildMapper.xml index b5a3a09..4b13fcf 100644 --- a/tongran-rocketmq/src/main/resources/mapper/rocketmq/RmNetworkInterfaceChildMapper.xml +++ b/tongran-rocketmq/src/main/resources/mapper/rocketmq/RmNetworkInterfaceChildMapper.xml @@ -26,10 +26,11 @@ + - select id, client_id, parent_interface, isp, province, city, public_ip, interface_name, mac_address, interface_type, ipv4_address, ipv6_address, gateway, create_time, update_time, create_by, update_by, bind_ip, new_flag, status, bandwidth_result from rm_network_interface_child + select id, client_id, parent_interface, isp, province, city, public_ip, interface_name, mac_address, interface_type, ipv4_address, ipv6_address, gateway, create_time, update_time, create_by, update_by, bind_ip, new_flag, status, bandwidth_result, net_create_time from rm_network_interface_child