增加存储子网卡信息、修复子网卡流量递增问题
子网卡流量图合并
This commit is contained in:
+52
@@ -0,0 +1,52 @@
|
||||
package com.tongran.rocketmq.controller;
|
||||
|
||||
import com.tongran.common.core.domain.R;
|
||||
import com.tongran.common.core.web.controller.BaseController;
|
||||
import com.tongran.common.core.web.domain.AjaxResult;
|
||||
import com.tongran.common.security.annotation.InnerAuth;
|
||||
import com.tongran.common.security.annotation.RequiresPermissions;
|
||||
import com.tongran.rocketmq.domain.RmNetworkInterfaceChild;
|
||||
import com.tongran.rocketmq.service.IRmNetworkInterfaceChildService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户端网络接口子接口信息Controller
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-12-15
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/networkInterfaceChild")
|
||||
@RequiresPermissions("system:registration")
|
||||
public class RmNetworkInterfaceChildController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IRmNetworkInterfaceChildService rmNetworkInterfaceChildService;
|
||||
|
||||
/**
|
||||
* 查询客户端网络接口子接口信息列表
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public AjaxResult list(@RequestBody RmNetworkInterfaceChild rmNetworkInterfaceChild)
|
||||
{
|
||||
List<RmNetworkInterfaceChild> list = rmNetworkInterfaceChildService.selectRmNetworkInterfaceChildList(rmNetworkInterfaceChild);
|
||||
return success(list);
|
||||
}
|
||||
/**
|
||||
* 查询客户端网络接口子接口信息列表
|
||||
*/
|
||||
@PostMapping("/innerGetChildList")
|
||||
@InnerAuth
|
||||
public R innerGetChildList(@RequestBody RmNetworkInterfaceChild rmNetworkInterfaceChild)
|
||||
{
|
||||
List<RmNetworkInterfaceChild> list = rmNetworkInterfaceChildService.selectRmNetworkInterfaceChildList(rmNetworkInterfaceChild);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package com.tongran.rocketmq.domain;
|
||||
|
||||
import com.tongran.common.core.annotation.Excel;
|
||||
import com.tongran.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 客户端网络接口子接口信息对象 rm_network_interface_child
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-12-15
|
||||
*/
|
||||
@Data
|
||||
public class RmNetworkInterfaceChild extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 客户端ID */
|
||||
@Excel(name = "客户端ID")
|
||||
private String clientId;
|
||||
/** 父接口名称 */
|
||||
private String parentInterface;
|
||||
|
||||
/** 运营商 */
|
||||
@Excel(name = "运营商")
|
||||
private String isp;
|
||||
|
||||
/** 省 */
|
||||
@Excel(name = "省")
|
||||
private String province;
|
||||
|
||||
/** 市 */
|
||||
@Excel(name = "市")
|
||||
private String city;
|
||||
|
||||
/** 公网IP */
|
||||
@Excel(name = "公网IP")
|
||||
private String publicIp;
|
||||
|
||||
/** 接口名称 */
|
||||
@Excel(name = "接口名称")
|
||||
private String interfaceName;
|
||||
|
||||
/** MAC地址 */
|
||||
@Excel(name = "MAC地址")
|
||||
private String macAddress;
|
||||
|
||||
/** 接口类型 */
|
||||
@Excel(name = "接口类型")
|
||||
private String interfaceType;
|
||||
|
||||
/** IPv4地址 */
|
||||
@Excel(name = "IPv4地址")
|
||||
private String ipv4Address;
|
||||
|
||||
/** IPv6地址 */
|
||||
@Excel(name = "IPv6地址")
|
||||
private String ipv6Address;
|
||||
|
||||
/** 网关 */
|
||||
@Excel(name = "网关")
|
||||
private String gateway;
|
||||
|
||||
/** 绑定公网ip类型(0未绑定,1业务ip,2管理ip,3管理和业务ip) */
|
||||
@Excel(name = "绑定公网ip类型(0未绑定,1业务ip,2管理ip,3管理和业务ip)")
|
||||
private String bindIp;
|
||||
|
||||
/** 是否为新的(0否 1是) */
|
||||
@Excel(name = "是否为新的(0否 1是)")
|
||||
private Integer newFlag;
|
||||
}
|
||||
@@ -89,6 +89,8 @@ public class MessageHandler {
|
||||
@Autowired
|
||||
private IRmNetworkInterfaceService rmNetworkInterfaceService;
|
||||
@Autowired
|
||||
private IRmNetworkInterfaceChildService rmNetworkInterfaceChildService;
|
||||
@Autowired
|
||||
private IRmMonitorPolicyService rmMonitorPolicyService;
|
||||
@Autowired
|
||||
private IRmDeploymentPolicyService rmDeploymentPolicyService;
|
||||
@@ -260,10 +262,10 @@ public class MessageHandler {
|
||||
temp.setClientId(clientId);
|
||||
List<InitialBandwidthTrafficTemp> tempList = initialBandwidthTrafficTempService.selectInitialBandwidthTrafficTempList(temp);
|
||||
if(!tempList.isEmpty()){
|
||||
// 1. 构建快速查找的Map
|
||||
// 1. 构建快速查找的Map,使用MAC地址+网卡名称作为唯一键
|
||||
Map<String, InitialBandwidthTrafficTemp> tempMap = tempList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
InitialBandwidthTrafficTemp::getMac,
|
||||
tempItem -> generateKey(tempItem.getMac(), tempItem.getName()),
|
||||
Function.identity(),
|
||||
(existing, replacement) -> existing
|
||||
));
|
||||
@@ -290,7 +292,9 @@ public class MessageHandler {
|
||||
iface.setIpv6InSpeed(null);
|
||||
iface.setIpv6OutSpeed(null);
|
||||
|
||||
InitialBandwidthTrafficTemp tempInfo = tempMap.get(iface.getMac());
|
||||
// 使用MAC地址+网卡名称作为查找键
|
||||
String key = generateKey(iface.getMac(), iface.getName());
|
||||
InitialBandwidthTrafficTemp tempInfo = tempMap.get(key);
|
||||
if (tempInfo != null) {
|
||||
// 计算总流入速率
|
||||
if (iface.getTotalInSpeed() != null && tempInfo.getTotalInSpeed() != null) {
|
||||
@@ -387,6 +391,15 @@ public class MessageHandler {
|
||||
throw new RuntimeException("NET流量data数据为空");
|
||||
}
|
||||
}
|
||||
private String generateKey(String mac, String name) {
|
||||
if (mac == null) {
|
||||
mac = "";
|
||||
}
|
||||
if (name == null) {
|
||||
name = "";
|
||||
}
|
||||
return mac + "|" + name;
|
||||
}
|
||||
/**
|
||||
* docker数据入库
|
||||
* @param message
|
||||
@@ -1031,6 +1044,7 @@ public class MessageHandler {
|
||||
boolean isSingleInterface = networkInfoList.size() == 1;
|
||||
|
||||
for (NetworkInfo networkInfo : networkInfoList) {
|
||||
List<NetworkInfo> childList = networkInfo.getSubInterfaces();
|
||||
// 查询该网卡信息是否存在
|
||||
RmNetworkInterface queryParam = new RmNetworkInterface();
|
||||
queryParam.setClientId(clientId);
|
||||
@@ -1048,14 +1062,31 @@ public class MessageHandler {
|
||||
insertData.setBindIp("3");
|
||||
}
|
||||
rmNetworkInterfaceService.insertRmNetworkInterface(insertData);
|
||||
if(childList != null && !childList.isEmpty()){
|
||||
for (NetworkInfo info : childList) {
|
||||
RmNetworkInterfaceChild insertChild = new RmNetworkInterfaceChild();
|
||||
setNetworkInterfaceChildData(insertChild, info, clientId, networkInfo.getName());
|
||||
// 设置bindIp
|
||||
if (isSingleInterface) {
|
||||
insertChild.setBindIp("3");
|
||||
}
|
||||
rmNetworkInterfaceChildService.insertRmNetworkInterfaceChild(insertChild);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 更新网卡信息
|
||||
RmNetworkInterface oldInterfaceMsg = exits.get(0);
|
||||
|
||||
cleanChildOldRecords(clientId, networkInfo.getMac());
|
||||
// 判断是否需要创建新记录
|
||||
boolean needCreateNew = !StringUtils.equals(networkInfo.getName(), oldInterfaceMsg.getInterfaceName())
|
||||
|| !StringUtils.equals(networkInfo.getGateway(), oldInterfaceMsg.getGateway());
|
||||
|
||||
if(childList != null && !childList.isEmpty()){
|
||||
for (NetworkInfo info : childList) {
|
||||
RmNetworkInterfaceChild insertChild = new RmNetworkInterfaceChild();
|
||||
setNetworkInterfaceChildData(insertChild, info, clientId, networkInfo.getName());
|
||||
rmNetworkInterfaceChildService.insertRmNetworkInterfaceChild(insertChild);
|
||||
}
|
||||
}
|
||||
if(needCreateNew) {
|
||||
// 清理旧的历史数据
|
||||
cleanOldRecords(clientId, networkInfo.getMac());
|
||||
@@ -1095,6 +1126,20 @@ public class MessageHandler {
|
||||
networkInterface.setPublicIp(networkInfo.getPublicIp());
|
||||
networkInterface.setInterfaceType(networkInfo.getType());
|
||||
}
|
||||
private void setNetworkInterfaceChildData(RmNetworkInterfaceChild networkInterface, NetworkInfo networkInfo, String clientId, String parentName) {
|
||||
networkInterface.setClientId(clientId);
|
||||
networkInterface.setParentInterface(parentName);
|
||||
networkInterface.setIsp(networkInfo.getCarrier());
|
||||
networkInterface.setCity(networkInfo.getCity());
|
||||
networkInterface.setGateway(networkInfo.getGateway());
|
||||
networkInterface.setInterfaceName(networkInfo.getName());
|
||||
networkInterface.setIpv4Address(networkInfo.getIpv4());
|
||||
networkInterface.setIpv6Address(networkInfo.getIpv6());
|
||||
networkInterface.setMacAddress(networkInfo.getMac());
|
||||
networkInterface.setProvince(networkInfo.getProvince());
|
||||
networkInterface.setPublicIp(networkInfo.getPublicIp());
|
||||
networkInterface.setInterfaceType(networkInfo.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理旧记录
|
||||
@@ -1111,7 +1156,20 @@ public class MessageHandler {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理旧记录
|
||||
*/
|
||||
private void cleanChildOldRecords(String clientId, String macAddress) {
|
||||
RmNetworkInterfaceChild childQuery = new RmNetworkInterfaceChild();
|
||||
childQuery.setClientId(clientId);
|
||||
childQuery.setMacAddress(macAddress);
|
||||
List<RmNetworkInterfaceChild> oldChildExits = rmNetworkInterfaceChildService.selectRmNetworkInterfaceChildList(childQuery);
|
||||
if(!oldChildExits.isEmpty()) {
|
||||
oldChildExits.forEach(oldMsg -> {
|
||||
rmNetworkInterfaceChildService.deleteRmNetworkInterfaceChildById(oldMsg.getId());
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 更新网卡信息
|
||||
*/
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.tongran.rocketmq.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.tongran.rocketmq.domain.RmNetworkInterfaceChild;
|
||||
|
||||
/**
|
||||
* 客户端网络接口子接口信息Mapper接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-12-15
|
||||
*/
|
||||
public interface RmNetworkInterfaceChildMapper
|
||||
{
|
||||
/**
|
||||
* 查询客户端网络接口子接口信息
|
||||
*
|
||||
* @param id 客户端网络接口子接口信息主键
|
||||
* @return 客户端网络接口子接口信息
|
||||
*/
|
||||
public RmNetworkInterfaceChild selectRmNetworkInterfaceChildById(Long id);
|
||||
|
||||
/**
|
||||
* 查询客户端网络接口子接口信息列表
|
||||
*
|
||||
* @param rmNetworkInterfaceChild 客户端网络接口子接口信息
|
||||
* @return 客户端网络接口子接口信息集合
|
||||
*/
|
||||
public List<RmNetworkInterfaceChild> selectRmNetworkInterfaceChildList(RmNetworkInterfaceChild rmNetworkInterfaceChild);
|
||||
|
||||
/**
|
||||
* 新增客户端网络接口子接口信息
|
||||
*
|
||||
* @param rmNetworkInterfaceChild 客户端网络接口子接口信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmNetworkInterfaceChild(RmNetworkInterfaceChild rmNetworkInterfaceChild);
|
||||
|
||||
/**
|
||||
* 修改客户端网络接口子接口信息
|
||||
*
|
||||
* @param rmNetworkInterfaceChild 客户端网络接口子接口信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmNetworkInterfaceChild(RmNetworkInterfaceChild rmNetworkInterfaceChild);
|
||||
|
||||
/**
|
||||
* 删除客户端网络接口子接口信息
|
||||
*
|
||||
* @param id 客户端网络接口子接口信息主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmNetworkInterfaceChildById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除客户端网络接口子接口信息
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmNetworkInterfaceChildByIds(Long[] ids);
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.tongran.rocketmq.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.tongran.rocketmq.domain.RmNetworkInterfaceChild;
|
||||
|
||||
/**
|
||||
* 客户端网络接口子接口信息Service接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-12-15
|
||||
*/
|
||||
public interface IRmNetworkInterfaceChildService
|
||||
{
|
||||
/**
|
||||
* 查询客户端网络接口子接口信息
|
||||
*
|
||||
* @param id 客户端网络接口子接口信息主键
|
||||
* @return 客户端网络接口子接口信息
|
||||
*/
|
||||
public RmNetworkInterfaceChild selectRmNetworkInterfaceChildById(Long id);
|
||||
|
||||
/**
|
||||
* 查询客户端网络接口子接口信息列表
|
||||
*
|
||||
* @param rmNetworkInterfaceChild 客户端网络接口子接口信息
|
||||
* @return 客户端网络接口子接口信息集合
|
||||
*/
|
||||
public List<RmNetworkInterfaceChild> selectRmNetworkInterfaceChildList(RmNetworkInterfaceChild rmNetworkInterfaceChild);
|
||||
|
||||
/**
|
||||
* 新增客户端网络接口子接口信息
|
||||
*
|
||||
* @param rmNetworkInterfaceChild 客户端网络接口子接口信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmNetworkInterfaceChild(RmNetworkInterfaceChild rmNetworkInterfaceChild);
|
||||
|
||||
/**
|
||||
* 修改客户端网络接口子接口信息
|
||||
*
|
||||
* @param rmNetworkInterfaceChild 客户端网络接口子接口信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmNetworkInterfaceChild(RmNetworkInterfaceChild rmNetworkInterfaceChild);
|
||||
|
||||
/**
|
||||
* 批量删除客户端网络接口子接口信息
|
||||
*
|
||||
* @param ids 需要删除的客户端网络接口子接口信息主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmNetworkInterfaceChildByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除客户端网络接口子接口信息信息
|
||||
*
|
||||
* @param id 客户端网络接口子接口信息主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmNetworkInterfaceChildById(Long id);
|
||||
}
|
||||
+69
-16
@@ -2,9 +2,12 @@ package com.tongran.rocketmq.service.impl;
|
||||
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.common.core.utils.EchartsDataUtils;
|
||||
import com.tongran.common.core.utils.EchartsMoreDataUtils;
|
||||
import com.tongran.common.core.utils.SpeedUtils;
|
||||
import com.tongran.rocketmq.domain.InitialBandwidthTraffic;
|
||||
import com.tongran.rocketmq.domain.RmNetworkInterfaceChild;
|
||||
import com.tongran.rocketmq.mapper.InitialBandwidthTrafficMapper;
|
||||
import com.tongran.rocketmq.mapper.RmNetworkInterfaceChildMapper;
|
||||
import com.tongran.rocketmq.service.IInitialBandwidthTrafficService;
|
||||
import com.tongran.rocketmq.utils.TableRouterUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -34,6 +37,8 @@ public class InitialBandwidthTrafficServiceImpl implements IInitialBandwidthTraf
|
||||
{
|
||||
@Autowired
|
||||
private InitialBandwidthTrafficMapper initialBandwidthTrafficMapper;
|
||||
@Autowired
|
||||
private RmNetworkInterfaceChildMapper rmNetworkInterfaceChildMapper;
|
||||
|
||||
/**
|
||||
* 查询初始带宽流量
|
||||
@@ -217,6 +222,11 @@ public class InitialBandwidthTrafficServiceImpl implements IInitialBandwidthTraf
|
||||
.collect(Collectors.toList());
|
||||
return list;
|
||||
}
|
||||
private boolean isEthernetInterface(String name) {
|
||||
return name.startsWith("eth") || // Linux 传统
|
||||
name.startsWith("en") || // systemd 命名 (enp3s0)
|
||||
name.startsWith("em"); // 有些主板网卡
|
||||
}
|
||||
/**
|
||||
* 查询eth0流量信息并封装为多折线ECharts图表数据
|
||||
* @param initialBandwidthTraffic
|
||||
@@ -224,34 +234,77 @@ public class InitialBandwidthTrafficServiceImpl implements IInitialBandwidthTraf
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> netInterfaceTrafficEcharts(InitialBandwidthTraffic initialBandwidthTraffic) {
|
||||
// 流量信息
|
||||
List<InitialBandwidthTraffic> list = getListByTableName(initialBandwidthTraffic);
|
||||
// 主网卡流量信息
|
||||
List<InitialBandwidthTraffic> mainList = getListByTableName(initialBandwidthTraffic);
|
||||
String originalName = initialBandwidthTraffic.getName();
|
||||
String name = originalName;
|
||||
|
||||
if (originalName != null && originalName.contains("(")) {
|
||||
int index = originalName.indexOf("(");
|
||||
name = originalName.substring(0, index);
|
||||
}
|
||||
|
||||
// 存储所有网卡的数据
|
||||
Map<String, List<InitialBandwidthTraffic>> interfaceDataMap = new LinkedHashMap<>();
|
||||
// 展示关系
|
||||
Map<String, String> showRealation = new HashMap<>();
|
||||
interfaceDataMap.put(name, mainList);
|
||||
showRealation.put(name+"netInTraffic", name+"入站流量");
|
||||
showRealation.put(name+"netOutTraffic", name+"出站流量");
|
||||
|
||||
// 如果是Ethernet类型,查询子网卡
|
||||
if(isEthernetInterface(name)){
|
||||
RmNetworkInterfaceChild query = new RmNetworkInterfaceChild();
|
||||
query.setClientId(initialBandwidthTraffic.getClientId());
|
||||
query.setParentInterface(name);
|
||||
List<RmNetworkInterfaceChild> children = rmNetworkInterfaceChildMapper.selectRmNetworkInterfaceChildList(query);
|
||||
if(children != null && !children.isEmpty()){
|
||||
for (RmNetworkInterfaceChild child : children) {
|
||||
InitialBandwidthTraffic childTraffic = new InitialBandwidthTraffic();
|
||||
BeanUtils.copyProperties(initialBandwidthTraffic, childTraffic);
|
||||
childTraffic.setName(child.getInterfaceName());
|
||||
List<InitialBandwidthTraffic> childTrafficList = getListByTableName(childTraffic);
|
||||
|
||||
if(childTrafficList != null && !childTrafficList.isEmpty()){
|
||||
interfaceDataMap.put(child.getInterfaceName(), childTrafficList);
|
||||
showRealation.put(child.getInterfaceName()+"netInTraffic", child.getInterfaceName()+"入站流量");
|
||||
showRealation.put(child.getInterfaceName()+"netOutTraffic", child.getInterfaceName()+"出站流量");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
String unit = SpeedUtils.calculateUnitWithStringTraffic(list, "inSpeed", "outSpeed");
|
||||
// 计算单位
|
||||
String unit = SpeedUtils.calculateUnitWithStringTraffic(mainList, "inSpeed", "outSpeed");
|
||||
if(initialBandwidthTraffic.getUnit() != null){
|
||||
unit = initialBandwidthTraffic.getUnit();
|
||||
}
|
||||
BigDecimal divisor = SpeedUtils.getDivisor(unit);
|
||||
Map<String, Function<InitialBandwidthTraffic, ?>> extractors = new LinkedHashMap<>();
|
||||
extractors.put("netInSpeedData", info ->
|
||||
info != null && info.getInSpeed() != null ?
|
||||
new BigDecimal(info.getInSpeed()).divide(divisor, 2, RoundingMode.HALF_UP) :
|
||||
null);
|
||||
|
||||
extractors.put("netOutSpeedData", info ->
|
||||
info != null && info.getOutSpeed() != null ?
|
||||
new BigDecimal(info.getOutSpeed()).divide(divisor, 2, RoundingMode.HALF_UP) :
|
||||
null);
|
||||
Map<String, Object> resultMap = EchartsDataUtils.buildEchartsDataAutoPadding(
|
||||
list, InitialBandwidthTraffic::getCreateTime, extractors,
|
||||
initialBandwidthTraffic.getStartTime(), initialBandwidthTraffic.getEndTime()
|
||||
// 使用工具类构建多网卡图表数据
|
||||
Map<String, Object> resultMap = EchartsMoreDataUtils.buildMultiInterfaceEchartsDataWithTotal(
|
||||
interfaceDataMap,
|
||||
InitialBandwidthTraffic::getCreateTime,
|
||||
info -> info.getInSpeed() != null ? new BigDecimal(info.getInSpeed()) : null,
|
||||
info -> info.getOutSpeed() != null ? new BigDecimal(info.getOutSpeed()) : null,
|
||||
initialBandwidthTraffic.getStartTime(),
|
||||
initialBandwidthTraffic.getEndTime(),
|
||||
divisor
|
||||
);
|
||||
|
||||
resultMap.put("unit", unit);
|
||||
if(!showRealation.isEmpty()){
|
||||
showRealation.put("totalNetInTraffic", name+"总入站流量");
|
||||
showRealation.put("totalNetOutTraffic", name+"总出站流量");
|
||||
}
|
||||
resultMap.put("showRealation", showRealation);
|
||||
return resultMap;
|
||||
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return new HashMap<>();
|
||||
}
|
||||
return new HashMap<>();
|
||||
}
|
||||
// 安全转换方法(处理可能的NumberFormatException)
|
||||
private Double safeConvertToKB(String byteValue) {
|
||||
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
package com.tongran.rocketmq.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.tongran.rocketmq.mapper.RmNetworkInterfaceChildMapper;
|
||||
import com.tongran.rocketmq.domain.RmNetworkInterfaceChild;
|
||||
import com.tongran.rocketmq.service.IRmNetworkInterfaceChildService;
|
||||
|
||||
/**
|
||||
* 客户端网络接口子接口信息Service业务层处理
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-12-15
|
||||
*/
|
||||
@Service
|
||||
public class RmNetworkInterfaceChildServiceImpl implements IRmNetworkInterfaceChildService
|
||||
{
|
||||
@Autowired
|
||||
private RmNetworkInterfaceChildMapper rmNetworkInterfaceChildMapper;
|
||||
|
||||
/**
|
||||
* 查询客户端网络接口子接口信息
|
||||
*
|
||||
* @param id 客户端网络接口子接口信息主键
|
||||
* @return 客户端网络接口子接口信息
|
||||
*/
|
||||
@Override
|
||||
public RmNetworkInterfaceChild selectRmNetworkInterfaceChildById(Long id)
|
||||
{
|
||||
return rmNetworkInterfaceChildMapper.selectRmNetworkInterfaceChildById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询客户端网络接口子接口信息列表
|
||||
*
|
||||
* @param rmNetworkInterfaceChild 客户端网络接口子接口信息
|
||||
* @return 客户端网络接口子接口信息
|
||||
*/
|
||||
@Override
|
||||
public List<RmNetworkInterfaceChild> selectRmNetworkInterfaceChildList(RmNetworkInterfaceChild rmNetworkInterfaceChild)
|
||||
{
|
||||
return rmNetworkInterfaceChildMapper.selectRmNetworkInterfaceChildList(rmNetworkInterfaceChild);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增客户端网络接口子接口信息
|
||||
*
|
||||
* @param rmNetworkInterfaceChild 客户端网络接口子接口信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertRmNetworkInterfaceChild(RmNetworkInterfaceChild rmNetworkInterfaceChild)
|
||||
{
|
||||
rmNetworkInterfaceChild.setCreateTime(DateUtils.getNowDate());
|
||||
return rmNetworkInterfaceChildMapper.insertRmNetworkInterfaceChild(rmNetworkInterfaceChild);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改客户端网络接口子接口信息
|
||||
*
|
||||
* @param rmNetworkInterfaceChild 客户端网络接口子接口信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateRmNetworkInterfaceChild(RmNetworkInterfaceChild rmNetworkInterfaceChild)
|
||||
{
|
||||
rmNetworkInterfaceChild.setUpdateTime(DateUtils.getNowDate());
|
||||
return rmNetworkInterfaceChildMapper.updateRmNetworkInterfaceChild(rmNetworkInterfaceChild);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除客户端网络接口子接口信息
|
||||
*
|
||||
* @param ids 需要删除的客户端网络接口子接口信息主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmNetworkInterfaceChildByIds(Long[] ids)
|
||||
{
|
||||
return rmNetworkInterfaceChildMapper.deleteRmNetworkInterfaceChildByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除客户端网络接口子接口信息信息
|
||||
*
|
||||
* @param id 客户端网络接口子接口信息主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmNetworkInterfaceChildById(Long id)
|
||||
{
|
||||
return rmNetworkInterfaceChildMapper.deleteRmNetworkInterfaceChildById(id);
|
||||
}
|
||||
}
|
||||
+31
@@ -5,7 +5,9 @@ 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.RmNetworkInterface;
|
||||
import com.tongran.rocketmq.domain.RmNetworkInterfaceChild;
|
||||
import com.tongran.rocketmq.domain.vo.PolicyTypeVo;
|
||||
import com.tongran.rocketmq.mapper.RmNetworkInterfaceChildMapper;
|
||||
import com.tongran.rocketmq.mapper.RmNetworkInterfaceMapper;
|
||||
import com.tongran.rocketmq.model.ProducerMode;
|
||||
import com.tongran.rocketmq.producer.MessageProducer;
|
||||
@@ -15,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -32,6 +35,8 @@ public class RmNetworkInterfaceServiceImpl implements IRmNetworkInterfaceService
|
||||
@Autowired
|
||||
private RmNetworkInterfaceMapper rmNetworkInterfaceMapper;
|
||||
@Autowired
|
||||
private RmNetworkInterfaceChildMapper rmNetworkInterfaceChildMapper;
|
||||
@Autowired
|
||||
private ProducerMode producerMode;
|
||||
|
||||
/**
|
||||
@@ -185,15 +190,41 @@ public class RmNetworkInterfaceServiceImpl implements IRmNetworkInterfaceService
|
||||
RmNetworkInterface rmNetworkInterface = new RmNetworkInterface();
|
||||
rmNetworkInterface.setClientIds(clientId);
|
||||
List<RmNetworkInterface> networkInterfaces = rmNetworkInterfaceMapper.selectRmNetworkInterfaceList(rmNetworkInterface);
|
||||
List<RmNetworkInterfaceChild> childList = new ArrayList<>();
|
||||
networkInterfaces.forEach(netMsg -> {
|
||||
RmNetworkInterfaceChild query = new RmNetworkInterfaceChild();
|
||||
query.setClientId(clientId);
|
||||
query.setParentInterface(netMsg.getInterfaceName());
|
||||
List<RmNetworkInterfaceChild> children = rmNetworkInterfaceChildMapper.selectRmNetworkInterfaceChildList(query);
|
||||
childList.addAll(children);
|
||||
});
|
||||
|
||||
// 拼接所有符合条件的网络接口名称,用分号隔开
|
||||
StringBuilder netNameBuilder = new StringBuilder();
|
||||
|
||||
// 添加父接口名称
|
||||
for (int i = 0; i < networkInterfaces.size(); i++) {
|
||||
if (i > 0) {
|
||||
netNameBuilder.append(";");
|
||||
}
|
||||
netNameBuilder.append(networkInterfaces.get(i).getInterfaceName());
|
||||
}
|
||||
|
||||
// 添加子接口名称
|
||||
for (int i = 0; i < childList.size(); i++) {
|
||||
if (netNameBuilder.length() > 0 || i > 0) {
|
||||
netNameBuilder.append(";");
|
||||
}
|
||||
netNameBuilder.append(childList.get(i).getInterfaceName());
|
||||
}
|
||||
|
||||
String netName = netNameBuilder.toString();
|
||||
|
||||
// 如果没有找到任何接口,可以设置为空或特定值
|
||||
if (netName.isEmpty()) {
|
||||
netName = ""; // 或者设置为 "none" 等其他标识
|
||||
}
|
||||
|
||||
MessageProducer messageProducer = new MessageProducer();
|
||||
PolicyTypeVo policyTypeVo = new PolicyTypeVo();
|
||||
policyTypeVo.setNetName(netName);
|
||||
|
||||
Reference in New Issue
Block a user