1、优化服务器管理列表运营商、省、ip展示。
2、服务器管理列表搜索条件增加子网卡ip筛选。
This commit is contained in:
+5
-1
@@ -58,7 +58,11 @@ public class RmNetworkInterfaceRemote extends BaseEntity {
|
||||
private String clientIds;
|
||||
/** 查询所有网卡的clientId集合 */
|
||||
private String allClientIds;
|
||||
|
||||
// 如果是子接口,存储父接口名称
|
||||
private String parentInterface;
|
||||
/** 服务器列表传参 */
|
||||
private String queryParam;
|
||||
/** 有ipv4的标识 */
|
||||
private boolean ipv4Flag;
|
||||
|
||||
}
|
||||
|
||||
+2
@@ -287,4 +287,6 @@ public class RmResourceRegistration extends BaseEntity
|
||||
private String maxAgentVersion;
|
||||
/** id集合 */
|
||||
private Long[] ids;
|
||||
/** 批量查询 */
|
||||
private String clientIds;
|
||||
}
|
||||
+124
-10
@@ -29,6 +29,7 @@ import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.tongran.common.core.utils.PageUtils.startPage;
|
||||
@@ -112,9 +113,25 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
resultMap.put("list", list);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
// 情况2: 有查询参数或需要排序,全量查询+内存处理
|
||||
List<RmResourceRegistration> allData = rmResourceRegistrationMapper.getRegistrationTableInfoList(rmResourceRegistration);
|
||||
// 先查询ip是否存在子网卡列表中
|
||||
StringBuilder clientIdsBuilder = new StringBuilder();
|
||||
List<RmResourceRegistration> allData = rmResourceRegistrationMapper.getRegistrationTableInfoList(rmResourceRegistration);
|
||||
List<RmResourceRegistration> childData = new ArrayList<>();
|
||||
RmNetworkInterfaceRemote query = new RmNetworkInterfaceRemote();
|
||||
query.setQueryParam(queryParam);
|
||||
R<List<RmNetworkInterfaceRemote>> children = remoteRocketMqService.innerGetChildList(query, SecurityConstants.INNER);
|
||||
if(children != null && children.getData()!=null && !children.getData().isEmpty()){
|
||||
for (RmNetworkInterfaceRemote datum : children.getData()) {
|
||||
if(clientIdsBuilder.length() > 0) {
|
||||
clientIdsBuilder.append(",");
|
||||
}
|
||||
clientIdsBuilder.append(datum.getClientId());
|
||||
}
|
||||
String clientIds = clientIdsBuilder.toString();
|
||||
rmResourceRegistration.setClientIds(clientIds);
|
||||
childData = rmResourceRegistrationMapper.getRegistrationTableInfoList(rmResourceRegistration);
|
||||
}
|
||||
batchSetNetWorkMsg(allData);
|
||||
|
||||
// 1. 过滤
|
||||
@@ -124,7 +141,21 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
.filter(item -> item != null && quickMatches(item, queryValue))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if(!childData.isEmpty()){
|
||||
filteredList.addAll(childData);
|
||||
}
|
||||
// 按 clientId 去重(保留第一个出现的元素)
|
||||
filteredList = filteredList.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.collectingAndThen(
|
||||
Collectors.toMap(
|
||||
RmResourceRegistration::getClientId,
|
||||
Function.identity(),
|
||||
(first, second) -> first,
|
||||
LinkedHashMap::new
|
||||
),
|
||||
map -> new ArrayList<>(map.values())
|
||||
));
|
||||
// 2. 排序
|
||||
if (bandwidthResultSort != null && bandwidthResultSort != 3) {
|
||||
sortList(filteredList, bandwidthResultSort);
|
||||
@@ -168,14 +199,35 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
*/
|
||||
@Override
|
||||
public List<RmResourceRegistration> selectRmResourceRegistrationList(RmResourceRegistration rmResourceRegistration) {
|
||||
List<RmResourceRegistration> allData = rmResourceRegistrationMapper.getRegistrationTableInfoList(rmResourceRegistration);
|
||||
batchSetNetWorkMsg(allData);
|
||||
|
||||
// 获取参数
|
||||
String queryParam = rmResourceRegistration.getQueryParam();
|
||||
Integer bandwidthResultSort = rmResourceRegistration.getBandwidthResultSort();
|
||||
boolean hasQueryParam = queryParam != null && !queryParam.trim().isEmpty();
|
||||
String queryValue = hasQueryParam ? queryParam.trim().toLowerCase() : null;
|
||||
List<RmResourceRegistration> allData = rmResourceRegistrationMapper.getRegistrationTableInfoList(rmResourceRegistration);
|
||||
List<RmResourceRegistration> childData = new ArrayList<>();
|
||||
if(hasQueryParam){
|
||||
// 先查询ip是否存在子网卡列表中
|
||||
StringBuilder clientIdsBuilder = new StringBuilder();
|
||||
RmNetworkInterfaceRemote query = new RmNetworkInterfaceRemote();
|
||||
query.setQueryParam(queryParam);
|
||||
R<List<RmNetworkInterfaceRemote>> children = remoteRocketMqService.innerGetChildList(query, SecurityConstants.INNER);
|
||||
if(children != null && children.getData()!=null && !children.getData().isEmpty()){
|
||||
for (RmNetworkInterfaceRemote datum : children.getData()) {
|
||||
if(clientIdsBuilder.length() > 0) {
|
||||
clientIdsBuilder.append(",");
|
||||
}
|
||||
clientIdsBuilder.append(datum.getClientId());
|
||||
}
|
||||
String clientIds = clientIdsBuilder.toString();
|
||||
rmResourceRegistration.setClientIds(clientIds);
|
||||
childData = rmResourceRegistrationMapper.getRegistrationTableInfoList(rmResourceRegistration);
|
||||
}else{
|
||||
allData = rmResourceRegistrationMapper.getRegistrationTableInfoList(rmResourceRegistration);
|
||||
}
|
||||
}
|
||||
batchSetNetWorkMsg(allData);
|
||||
|
||||
|
||||
// 过滤
|
||||
List<RmResourceRegistration> filteredList = allData;
|
||||
@@ -184,7 +236,21 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
.filter(item -> item != null && quickMatches(item, queryValue))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if(!childData.isEmpty()){
|
||||
filteredList.addAll(childData);
|
||||
}
|
||||
// 按 clientId 去重(保留第一个出现的元素)
|
||||
filteredList = filteredList.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.collectingAndThen(
|
||||
Collectors.toMap(
|
||||
RmResourceRegistration::getClientId,
|
||||
Function.identity(),
|
||||
(first, second) -> first,
|
||||
LinkedHashMap::new
|
||||
),
|
||||
map -> new ArrayList<>(map.values())
|
||||
));
|
||||
// 排序
|
||||
if (bandwidthResultSort != null && bandwidthResultSort != 3) {
|
||||
sortList(filteredList, bandwidthResultSort);
|
||||
@@ -501,15 +567,63 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
}
|
||||
if ("2".equals(network.getBindIp()) || "3".equals(network.getBindIp())) {
|
||||
// ip提前
|
||||
if(registration.getIp1PublicIp() == null){
|
||||
// 先尝试从当前network对象设置值
|
||||
if(registration.getIp1PublicIp() == null && network.getPublicIp() != null){
|
||||
registration.setIp1PublicIp(network.getPublicIp());
|
||||
}
|
||||
if(registration.getIp1Isp() == null){
|
||||
if(registration.getIp1Isp() == null && network.getIsp() != null){
|
||||
registration.setIp1Isp(network.getIsp());
|
||||
}
|
||||
if(registration.getIp1Province() == null){
|
||||
if(registration.getIp1Province() == null && network.getProvince() != null){
|
||||
registration.setIp1Province(network.getProvince());
|
||||
}
|
||||
|
||||
// 如果还有字段为null,再尝试从子网卡中获取
|
||||
if(registration.getIp1PublicIp() == null || registration.getIp1Isp() == null || registration.getIp1Province() == null){
|
||||
// 查询子网卡信息
|
||||
RmNetworkInterfaceRemote query = new RmNetworkInterfaceRemote();
|
||||
query.setClientId(registration.getClientId());
|
||||
query.setIpv4Flag(true);
|
||||
R<List<RmNetworkInterfaceRemote>> children = remoteRocketMqService.innerGetChildList(query, SecurityConstants.INNER);
|
||||
|
||||
if(children != null && children.getData() != null && !children.getData().isEmpty()){
|
||||
// 按ip最后一位排序取最小的
|
||||
RmNetworkInterfaceRemote minIpChild = null;
|
||||
int minLastOctet = Integer.MAX_VALUE;
|
||||
|
||||
for (RmNetworkInterfaceRemote child : children.getData()) {
|
||||
if (child.getIpv4Address() != null && !child.getIpv4Address().isEmpty()) {
|
||||
String ip = child.getIpv4Address();
|
||||
String[] ipParts = ip.split("\\.");
|
||||
|
||||
if (ipParts.length == 4) {
|
||||
try {
|
||||
int lastOctet = Integer.parseInt(ipParts[3]);
|
||||
if (lastOctet < minLastOctet) {
|
||||
minLastOctet = lastOctet;
|
||||
minIpChild = child;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
// 忽略格式错误的IP
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (minIpChild != null) {
|
||||
// 只设置还为空的值
|
||||
if(registration.getIp1PublicIp() == null){
|
||||
registration.setIp1PublicIp(minIpChild.getPublicIp());
|
||||
}
|
||||
if(registration.getIp1Isp() == null){
|
||||
registration.setIp1Isp(minIpChild.getIsp());
|
||||
}
|
||||
if(registration.getIp1Province() == null){
|
||||
registration.setIp1Province(minIpChild.getProvince());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 管理网IP处理
|
||||
registration.setMgmtIsp(network.getIsp());
|
||||
registration.setMgmtProvince(network.getProvince());
|
||||
|
||||
+6
@@ -302,6 +302,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="multiPublicIpStatus != null and multiPublicIpStatus != ''"> and a.multi_public_ip_status = #{multiPublicIpStatus}</if>
|
||||
<if test="businessEmpty"> and a.business_name is null</if>
|
||||
<if test="logicalNodeEmpty"> and a.logical_node_id is null</if>
|
||||
<if test="clientIds != null">
|
||||
and a.client_id in
|
||||
<foreach collection="clientIds.split(',')" item="clientId" open="(" separator="," close=")">
|
||||
#{clientId}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
order by a.create_time desc
|
||||
</select>
|
||||
|
||||
+2
@@ -86,4 +86,6 @@ public class RmNetworkInterfaceChild extends BaseEntity
|
||||
private String tableName;
|
||||
/** ping丢包率 */
|
||||
private Double pingDropped;
|
||||
/** 服务器列表传参 */
|
||||
public String queryParam;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,11 @@
|
||||
<if test="province != null and province != ''"> and province = #{province}</if>
|
||||
<if test="city != null and city != ''"> and city = #{city}</if>
|
||||
<if test="publicIp != null and publicIp != ''"> and public_ip = #{publicIp}</if>
|
||||
<if test="queryParam != null and queryParam != ''">
|
||||
and (public_ip like concat('%', #{queryParam}, '%')
|
||||
or ipv4_address like concat('%', #{queryParam}, '%')
|
||||
or ipv6_address like concat('%', #{queryParam}, '%'))
|
||||
</if>
|
||||
<if test="interfaceName != null and interfaceName != ''"> and interface_name like concat('%', #{interfaceName}, '%')</if>
|
||||
<if test="macAddress != null and macAddress != ''"> and mac_address = #{macAddress}</if>
|
||||
<if test="interfaceType != null and interfaceType != ''"> and interface_type = #{interfaceType}</if>
|
||||
|
||||
Reference in New Issue
Block a user