增加存储子网卡信息、修复子网卡流量递增问题
子网卡流量图合并
This commit is contained in:
+8
@@ -122,6 +122,8 @@ public class RmResourceRegistration extends BaseEntity
|
||||
|
||||
@Excel(name = "IP1-网关")
|
||||
private String ip1Gateway; // IP1-网关
|
||||
/** ip1是否存在子网卡 */
|
||||
private boolean ip1IsVirth;
|
||||
|
||||
// IP2 相关字段
|
||||
@Excel(name = "IP2-运营商")
|
||||
@@ -153,6 +155,8 @@ public class RmResourceRegistration extends BaseEntity
|
||||
|
||||
@Excel(name = "IP2-网关")
|
||||
private String ip2Gateway;
|
||||
/** ip2是否存在子网卡 */
|
||||
private boolean ip2IsVirth;
|
||||
|
||||
// IP3 相关字段
|
||||
@Excel(name = "IP3-运营商")
|
||||
@@ -184,6 +188,8 @@ public class RmResourceRegistration extends BaseEntity
|
||||
|
||||
@Excel(name = "IP3-网关")
|
||||
private String ip3Gateway;
|
||||
/** ip3是否存在子网卡 */
|
||||
private boolean ip3IsVirth;
|
||||
|
||||
// 管理网相关字段
|
||||
@Excel(name = "管理网-运营商")
|
||||
@@ -215,6 +221,8 @@ public class RmResourceRegistration extends BaseEntity
|
||||
|
||||
@Excel(name = "管理网-网关")
|
||||
private String mgmtGateway; // 管理网-网关地址
|
||||
/** 管理网-是否存在子网卡 */
|
||||
private boolean mgmIsVirth;
|
||||
|
||||
/** 多条件查询 */
|
||||
private String queryParam;
|
||||
|
||||
+10
@@ -1,6 +1,7 @@
|
||||
package com.tongran.system.mapper;
|
||||
|
||||
import com.tongran.system.domain.RmResourceRegistration;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -112,4 +113,13 @@ public interface RmResourceRegistrationMapper
|
||||
int updateRemark(RmResourceRegistration rmResourceRegistration);
|
||||
|
||||
int addReportedBandwidth(RmResourceRegistration rmResourceRegistration);
|
||||
|
||||
/**
|
||||
* 判断该网卡是否存在子网卡
|
||||
* @param clientId
|
||||
* @param interfaceName
|
||||
* @return
|
||||
*/
|
||||
int countChildNetwork(@Param("clientId") String clientId,
|
||||
@Param("interfaceName") String interfaceName);
|
||||
}
|
||||
|
||||
+25
-5
@@ -3,6 +3,7 @@ package com.tongran.system.service.impl;
|
||||
import com.tongran.common.core.constant.SecurityConstants;
|
||||
import com.tongran.common.core.domain.R;
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.common.core.utils.NetworkNameUtil;
|
||||
import com.tongran.system.api.RemoteRocketMqService;
|
||||
import com.tongran.system.api.domain.RmNetworkInterfaceRemote;
|
||||
import com.tongran.system.domain.AllInterfaceName;
|
||||
@@ -13,6 +14,7 @@ import com.tongran.system.service.IRmEpsTopologyManagementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -43,7 +45,6 @@ public class AllInterfaceNameServiceImpl implements IAllInterfaceNameService
|
||||
{
|
||||
return allInterfaceNameMapper.selectAllInterfaceNameById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有接口名称列表
|
||||
*
|
||||
@@ -54,16 +55,35 @@ public class AllInterfaceNameServiceImpl implements IAllInterfaceNameService
|
||||
public List<AllInterfaceName> selectAllInterfaceNameList(AllInterfaceName allInterfaceName)
|
||||
{
|
||||
List<AllInterfaceName> allInterfaceNameList = allInterfaceNameMapper.selectAllInterfaceNameList(allInterfaceName);
|
||||
|
||||
if (allInterfaceNameList == null || allInterfaceNameList.isEmpty()) {
|
||||
return allInterfaceNameList;
|
||||
}
|
||||
// 用于存储非子网卡的接口
|
||||
List<AllInterfaceName> nonSubInterfaces = new ArrayList<>();
|
||||
for (AllInterfaceName interfaceName : allInterfaceNameList) {
|
||||
String originalName = interfaceName.getInterfaceName();
|
||||
String name = originalName;
|
||||
|
||||
if (originalName != null && originalName.contains("(")) {
|
||||
int index = originalName.indexOf("(");
|
||||
name = originalName.substring(0, index);
|
||||
}
|
||||
|
||||
// 如果不是子网卡,则加入列表
|
||||
if (originalName == null || !NetworkNameUtil.isSubInterface(name)) {
|
||||
nonSubInterfaces.add(interfaceName);
|
||||
}
|
||||
}
|
||||
if (nonSubInterfaces.isEmpty()) {
|
||||
return nonSubInterfaces;
|
||||
}
|
||||
// 使用自定义排序
|
||||
return allInterfaceNameList.stream()
|
||||
return nonSubInterfaces.stream()
|
||||
.sorted((a, b) -> {
|
||||
boolean aMatched = isInterfaceMatched(a);
|
||||
boolean bMatched = isInterfaceMatched(b);
|
||||
// 根据实际业务逻辑判断是否匹配
|
||||
// 这里用接口名不为null且包含特定字符作为示例
|
||||
boolean aMatched = a.getInterfaceName() != null && a.getInterfaceName().contains("eth");
|
||||
boolean bMatched = b.getInterfaceName() != null && b.getInterfaceName().contains("eth");
|
||||
|
||||
// 匹配的排在前面(返回-1),不匹配的排在后面(返回1)
|
||||
if (aMatched && !bMatched) {
|
||||
|
||||
+33
-1
@@ -469,6 +469,12 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
|
||||
for (RmNetworkInterfaceRemote network : networkList) {
|
||||
if ("1".equals(network.getBindIp()) || "3".equals(network.getBindIp())) {
|
||||
// 查询是否存在子网卡
|
||||
int count = rmResourceRegistrationMapper.countChildNetwork(clientId, network.getInterfaceName());
|
||||
boolean isVirth = false;
|
||||
if(count > 0){
|
||||
isVirth = true;
|
||||
}
|
||||
// 业务IP处理
|
||||
if (businessIpCount > 3) {
|
||||
continue; // 最多只处理3个业务IP
|
||||
@@ -487,6 +493,7 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
registration.setIp1Ipv4Address(network.getIpv4Address());
|
||||
registration.setIp1Ipv6Address(network.getIpv6Address());
|
||||
registration.setIp1Gateway(network.getGateway());
|
||||
registration.setIp1IsVirth(isVirth);
|
||||
break;
|
||||
case 2:
|
||||
registration.setIp2Isp(network.getIsp());
|
||||
@@ -499,6 +506,7 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
registration.setIp2Ipv4Address(network.getIpv4Address());
|
||||
registration.setIp2Ipv6Address(network.getIpv6Address());
|
||||
registration.setIp2Gateway(network.getGateway());
|
||||
registration.setIp2IsVirth(isVirth);
|
||||
break;
|
||||
case 3:
|
||||
registration.setIp3Isp(network.getIsp());
|
||||
@@ -511,12 +519,19 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
registration.setIp3Ipv4Address(network.getIpv4Address());
|
||||
registration.setIp3Ipv6Address(network.getIpv6Address());
|
||||
registration.setIp3Gateway(network.getGateway());
|
||||
registration.setIp3IsVirth(isVirth);
|
||||
break;
|
||||
}
|
||||
|
||||
businessIpCount++;
|
||||
}
|
||||
if ("2".equals(network.getBindIp()) || "3".equals(network.getBindIp())) {
|
||||
// 查询是否存在子网卡
|
||||
int count = rmResourceRegistrationMapper.countChildNetwork(clientId, network.getInterfaceName());
|
||||
boolean isVirth = false;
|
||||
if(count > 0){
|
||||
isVirth = true;
|
||||
}
|
||||
// 管理网IP处理
|
||||
registration.setMgmtIsp(network.getIsp());
|
||||
registration.setMgmtProvince(network.getProvince());
|
||||
@@ -528,6 +543,7 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
registration.setMgmtIpv4Address(network.getIpv4Address());
|
||||
registration.setMgmtIpv6Address(network.getIpv6Address());
|
||||
registration.setMgmtGateway(network.getGateway());
|
||||
registration.setMgmIsVirth(isVirth);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1012,7 +1028,16 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
// 如果有符合条件的网络接口
|
||||
if (!filteredNetworks.isEmpty()) {
|
||||
updateData.setRegistrationStatus("1");
|
||||
|
||||
List<RmNetworkInterfaceRemote> childList = new ArrayList<>();
|
||||
filteredNetworks.forEach(netMsg -> {
|
||||
RmNetworkInterfaceRemote query = new RmNetworkInterfaceRemote();
|
||||
query.setClientId(clientId);
|
||||
query.setParentInterface(netMsg.getInterfaceName());
|
||||
R<List<RmNetworkInterfaceRemote>> children = remoteRocketMqService.innerGetChildList(query, SecurityConstants.INNER);
|
||||
if(children != null && children.getData()!=null && !children.getData().isEmpty()){
|
||||
childList.addAll(children.getData());
|
||||
}
|
||||
});
|
||||
// 拼接所有符合条件的网络接口名称,用分号隔开
|
||||
StringBuilder netNameBuilder = new StringBuilder();
|
||||
for (int i = 0; i < filteredNetworks.size(); i++) {
|
||||
@@ -1021,6 +1046,13 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
}
|
||||
netNameBuilder.append(filteredNetworks.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();
|
||||
|
||||
// 发送注册响应
|
||||
|
||||
+4
@@ -275,4 +275,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
update rm_resource_registration set reported_bandwidth = #{reportedBandwidth}
|
||||
where id =#{id}
|
||||
</update>
|
||||
<select id="countChildNetwork" resultType="java.lang.Integer">
|
||||
select count(1) from rm_network_interface_child
|
||||
where client_id = #{clientId} and parent_interface = #{interfaceName}
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user