优化平台ppoe和非平台ppoe配置方式的虚拟网卡上报带宽值处理.
优化pppoe虚拟网卡处理逻辑
This commit is contained in:
@@ -1134,7 +1134,7 @@ public class MessageHandler {
|
||||
Date createTime = new Date(millis / 1000 * 1000);
|
||||
|
||||
List<NetworkInfo> networkInfoList = registerMsg.getNetworkInfo();
|
||||
if(networkInfoList.isEmpty()) {
|
||||
if (networkInfoList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1148,6 +1148,7 @@ public class MessageHandler {
|
||||
// 构建数据库中当前网卡MAC地址的集合
|
||||
Set<String> currentMacSet = currentInterfaces.stream()
|
||||
.map(RmNetworkInterface::getMacAddress)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 构建新数据中网卡MAC地址的集合
|
||||
@@ -1169,8 +1170,27 @@ public class MessageHandler {
|
||||
if (!macsToDelete.isEmpty() && !isRegister) {
|
||||
deleteNetworkInterfaces(clientId, macsToDelete);
|
||||
}
|
||||
|
||||
// 获取当前客户端的所有子网卡
|
||||
RmNetworkInterfaceChild childQuery = new RmNetworkInterfaceChild();
|
||||
childQuery.setClientId(clientId);
|
||||
List<RmNetworkInterfaceChild> existingChildren = rmNetworkInterfaceChildService.selectRmNetworkInterfaceChildList(childQuery);
|
||||
if(existingChildren == null){
|
||||
existingChildren = new ArrayList<>();
|
||||
}
|
||||
// 构建数据库中所有子网卡的key集合 (clientId_mac_name)
|
||||
Map<String, RmNetworkInterfaceChild> existingChildMap = new HashMap<>();
|
||||
for (RmNetworkInterfaceChild child : existingChildren) {
|
||||
String key = child.getClientId() + "_" + child.getMacAddress() + "_" + child.getInterfaceName();
|
||||
existingChildMap.put(key, child);
|
||||
}
|
||||
|
||||
// 构建本次接收到的所有子网卡key集合
|
||||
Set<String> newChildKeys = new HashSet<>();
|
||||
|
||||
for (NetworkInfo networkInfo : networkInfoList) {
|
||||
List<NetworkInfo> childList = networkInfo.getSubInterfaces();
|
||||
|
||||
// 查询该网卡信息是否存在
|
||||
RmNetworkInterface queryParam = new RmNetworkInterface();
|
||||
queryParam.setClientId(clientId);
|
||||
@@ -1178,7 +1198,7 @@ public class MessageHandler {
|
||||
queryParam.setNewFlag(1);
|
||||
List<RmNetworkInterface> exits = rmNetworkInterfaceService.selectRmNetworkInterfaceList(queryParam);
|
||||
|
||||
if(exits.isEmpty()) {
|
||||
if (exits.isEmpty()) {
|
||||
// 新增网卡信息
|
||||
RmNetworkInterface insertData = new RmNetworkInterface();
|
||||
setNetworkInterfaceData(insertData, networkInfo, clientId);
|
||||
@@ -1188,18 +1208,27 @@ public class MessageHandler {
|
||||
insertData.setBindIp("3");
|
||||
}
|
||||
rmNetworkInterfaceService.insertRmNetworkInterface(insertData);
|
||||
if(childList != null && !childList.isEmpty()){
|
||||
rmNetworkInterfaceChildService.deleteRmNetworkInterfaceChildByClientId(clientId);
|
||||
|
||||
// 处理子网卡
|
||||
if (childList != null && !childList.isEmpty()) {
|
||||
for (NetworkInfo info : childList) {
|
||||
RmNetworkInterfaceChild insertChild = new RmNetworkInterfaceChild();
|
||||
setNetworkInterfaceChildData(insertChild, info, clientId, networkInfo.getName());
|
||||
insertChild.setUpdateTime(DateUtils.getNowDate());
|
||||
// 设置bindIp
|
||||
if (isSingleInterface) {
|
||||
insertChild.setBindIp("3");
|
||||
}
|
||||
|
||||
// 构建子网卡唯一key
|
||||
String childKey = clientId + "_" + info.getMac() + "_" + info.getName();
|
||||
newChildKeys.add(childKey);
|
||||
|
||||
// 插入或更新子网卡
|
||||
rmNetworkInterfaceChildService.insertRmNetworkInterfaceChild(insertChild);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果网卡数量有变动,需要更新网卡绑定状态
|
||||
if (!isRegister && interfaceCountChanged && !isSingleInterface) {
|
||||
RmResourceRegistrationRemote updateParam = new RmResourceRegistrationRemote();
|
||||
@@ -1210,22 +1239,48 @@ public class MessageHandler {
|
||||
} else {
|
||||
// 更新网卡信息
|
||||
RmNetworkInterface oldInterfaceMsg = exits.get(0);
|
||||
// cleanChildOldRecords(clientId, networkInfo.getMac());
|
||||
// 判断是否需要创建新记录
|
||||
boolean needCreateNew = (!StringUtils.equals(networkInfo.getName(), oldInterfaceMsg.getInterfaceName())
|
||||
|| !StringUtils.equals(networkInfo.getGateway(), oldInterfaceMsg.getGateway())) && StringUtils.equals(networkInfo.getMac(), oldInterfaceMsg.getMacAddress());
|
||||
if(childList != null && !childList.isEmpty()){
|
||||
rmNetworkInterfaceChildService.deleteRmNetworkInterfaceChildByClientId(clientId);
|
||||
|
||||
// 处理子网卡
|
||||
if (childList != null && !childList.isEmpty()) {
|
||||
for (NetworkInfo info : childList) {
|
||||
RmNetworkInterfaceChild insertChild = new RmNetworkInterfaceChild();
|
||||
setNetworkInterfaceChildData(insertChild, info, clientId, networkInfo.getName());
|
||||
insertChild.setUpdateTime(DateUtils.getNowDate());
|
||||
// 构建子网卡唯一key
|
||||
String childKey = clientId + "_" + info.getMac() + "_" + info.getName();
|
||||
newChildKeys.add(childKey);
|
||||
// 插入或更新子网卡
|
||||
rmNetworkInterfaceChildService.insertRmNetworkInterfaceChild(insertChild);
|
||||
}
|
||||
}
|
||||
// 判断是否需要创建新记录
|
||||
boolean needCreateNew = (!StringUtils.equals(networkInfo.getName(), oldInterfaceMsg.getInterfaceName())
|
||||
|| !StringUtils.equals(networkInfo.getGateway(), oldInterfaceMsg.getGateway())) && StringUtils.equals(networkInfo.getMac(), oldInterfaceMsg.getMacAddress());
|
||||
// 更新现有记录
|
||||
updateNetworkInterface(networkInfo, clientId, oldInterfaceMsg, isSingleInterface, isRegister);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除数据库中不存在于本次接收数据中的子网卡
|
||||
// 计算需要删除的子网卡:数据库中有的,但本次没有接收到的
|
||||
Set<String> childKeysToDelete = new HashSet<>(existingChildMap.keySet());
|
||||
childKeysToDelete.removeAll(newChildKeys);
|
||||
|
||||
if (!childKeysToDelete.isEmpty() && !isRegister) {
|
||||
for (String keyToDelete : childKeysToDelete) {
|
||||
String[] parts = keyToDelete.split("_", 3);
|
||||
if (parts.length == 3) {
|
||||
String clientIdPart = parts[0];
|
||||
String mac = parts[1];
|
||||
String name = parts[2];
|
||||
|
||||
// 只删除当前客户端的子网卡
|
||||
if (clientId.equals(clientIdPart)) {
|
||||
deleteChildNetworkInterfaces(clientId, mac, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除过时的网卡信息
|
||||
@@ -1249,7 +1304,28 @@ public class MessageHandler {
|
||||
// 记录删除操作日志
|
||||
log.info("删除客户端 {} 的过时网卡信息,MAC地址: {}", clientId, macsToDelete);
|
||||
}
|
||||
/**
|
||||
* 删除过时的子网卡信息
|
||||
* @param clientId
|
||||
* @param name
|
||||
* @param mac
|
||||
*/
|
||||
private void deleteChildNetworkInterfaces(String clientId, String mac, String name) {
|
||||
RmNetworkInterfaceChild query = new RmNetworkInterfaceChild();
|
||||
query.setClientId(clientId);
|
||||
query.setMacAddress(mac);
|
||||
query.setInterfaceName(name);
|
||||
query.setNewFlag(1);
|
||||
List<RmNetworkInterfaceChild> oldExits = rmNetworkInterfaceChildService.selectRmNetworkInterfaceChildList(query);
|
||||
if(!oldExits.isEmpty()) {
|
||||
oldExits.forEach(oldMsg -> {
|
||||
rmNetworkInterfaceChildService.deleteRmNetworkInterfaceChildById(oldMsg.getId());
|
||||
});
|
||||
}
|
||||
|
||||
// 记录删除操作日志
|
||||
log.info("删除客户端 {} 的过时子网卡信息,MAC地址: {},网卡名称:{}", clientId, mac, name);
|
||||
}
|
||||
/**
|
||||
* 设置网卡信息公共字段
|
||||
*/
|
||||
@@ -1350,6 +1426,10 @@ public class MessageHandler {
|
||||
updateData.setInterfaceType(networkInfo.getType());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getGateway(), oldInterfaceMsg.getGateway())) {
|
||||
updateData.setGateway(networkInfo.getGateway());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getName(), oldInterfaceMsg.getInterfaceName())) {
|
||||
if(networkInfo.getName() != null){
|
||||
// 添加业务变更记录
|
||||
|
||||
Reference in New Issue
Block a user