1、定位并解决收益未自动生成问题。
2、优化服务器列表筛选条件查询速度。
This commit is contained in:
+36
-12
@@ -68,21 +68,45 @@ public class RmMtrPolicyConfigServiceImpl implements IRmMtrPolicyConfigService
|
||||
* 辅助方法,给ip集合赋值
|
||||
* @param mtrPolicyConfig
|
||||
*/
|
||||
public void setServerip(RmMtrPolicyConfig mtrPolicyConfig){
|
||||
public void setServerip(RmMtrPolicyConfig mtrPolicyConfig) {
|
||||
StringJoiner resultJoiner = new StringJoiner(";");
|
||||
String serverGroupStr = mtrPolicyConfig.getServerGroup().replace("\n",",");
|
||||
RmNetworkInterfaceRemote query = new RmNetworkInterfaceRemote();
|
||||
query.setClientIds(serverGroupStr);
|
||||
R<List<RmNetworkInterfaceRemote>> networkList = remoteRocketMqService.getNetworkInterfaceList(query, SecurityConstants.INNER);
|
||||
if(networkList != null && networkList.getData() != null){
|
||||
List<RmNetworkInterfaceRemote> rmNetworkInterfaceRemoteList = networkList.getData();
|
||||
if(!rmNetworkInterfaceRemoteList.isEmpty()){
|
||||
for (RmNetworkInterfaceRemote rmNetworkInterfaceRemote : rmNetworkInterfaceRemoteList) {
|
||||
String publicIp = rmNetworkInterfaceRemote.getPublicIp();
|
||||
resultJoiner.add(publicIp);
|
||||
String serverGroupStr = mtrPolicyConfig.getServerGroup().replace("\n", ",");
|
||||
String[] serverIds = serverGroupStr.split(",");
|
||||
|
||||
// 分批次处理,每批200个
|
||||
int batchSize = 200;
|
||||
for (int i = 0; i < serverIds.length; i += batchSize) {
|
||||
int end = Math.min(i + batchSize, serverIds.length);
|
||||
|
||||
// 构建当前批次的id字符串
|
||||
StringBuilder batchIds = new StringBuilder();
|
||||
for (int j = i; j < end; j++) {
|
||||
if (batchIds.length() > 0) {
|
||||
batchIds.append(",");
|
||||
}
|
||||
mtrPolicyConfig.setServeripGroup(resultJoiner.toString());
|
||||
batchIds.append(serverIds[j].trim());
|
||||
}
|
||||
|
||||
// 查询当前批次
|
||||
RmNetworkInterfaceRemote query = new RmNetworkInterfaceRemote();
|
||||
query.setClientIds(batchIds.toString());
|
||||
R<List<RmNetworkInterfaceRemote>> networkList = remoteRocketMqService.getNetworkInterfaceList(query, SecurityConstants.INNER);
|
||||
|
||||
// 处理结果
|
||||
if (networkList != null && networkList.getData() != null) {
|
||||
for (RmNetworkInterfaceRemote rmNetworkInterfaceRemote : networkList.getData()) {
|
||||
String publicIp = rmNetworkInterfaceRemote.getPublicIp();
|
||||
if (publicIp != null && !publicIp.trim().isEmpty()) {
|
||||
resultJoiner.add(publicIp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 设置最终结果
|
||||
String result = resultJoiner.toString();
|
||||
if (!result.isEmpty()) {
|
||||
mtrPolicyConfig.setServeripGroup(result);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
+2
@@ -289,6 +289,7 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
|
||||
log.error("计算{}的95带宽值失败,详情:{}", interfaceName.getClientId(), e.getMessage());
|
||||
}
|
||||
});
|
||||
log.info("服务器95带宽值计算完成,总计{}台设备",snList.size());
|
||||
}
|
||||
/**
|
||||
* 计算金山95带宽值/日
|
||||
@@ -755,6 +756,7 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
|
||||
calculateSegment95(queryParam, dailyStartTime, dailyEndTime, calculationMode);
|
||||
}
|
||||
}else{
|
||||
queryParam.setBusinessId(null);
|
||||
calculateNormalDeviceBandwidth(queryParam, dailyStartTime, dailyEndTime, calculationMode);
|
||||
}
|
||||
}
|
||||
|
||||
+53
-44
@@ -166,6 +166,7 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
@Override
|
||||
public List<RmResourceRegistration> selectRmResourceRegistrationList(RmResourceRegistration rmResourceRegistration) {
|
||||
List<RmResourceRegistration> allData = rmResourceRegistrationMapper.getRegistrationTableInfoList(rmResourceRegistration);
|
||||
batchSetNetWorkMsg(allData);
|
||||
|
||||
// 获取参数
|
||||
String queryParam = rmResourceRegistration.getQueryParam();
|
||||
@@ -189,7 +190,6 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
// 处理全部数据
|
||||
for (RmResourceRegistration item : filteredList) {
|
||||
if (item.getClientId() != null) {
|
||||
setNetWorkMsg(item);
|
||||
setBandwidthYestoday(item);
|
||||
}
|
||||
}
|
||||
@@ -287,61 +287,70 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
// 收集所有需要查询的clientId,用逗号分隔
|
||||
String clientIdsStr = pageList.stream()
|
||||
.map(RmResourceRegistration::getClientId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.joining(","));
|
||||
// 设置每批大小
|
||||
int batchSize = 200;
|
||||
int totalBatches = (int) Math.ceil((double) pageList.size() / batchSize);
|
||||
|
||||
if (StringUtils.isBlank(clientIdsStr)) {
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug("批量查询网络信息,clientIds: {}", clientIdsStr);
|
||||
for (int batchNum = 0; batchNum < totalBatches; batchNum++) {
|
||||
int fromIndex = batchNum * batchSize;
|
||||
int toIndex = Math.min(fromIndex + batchSize, pageList.size());
|
||||
List<RmResourceRegistration> batchList = pageList.subList(fromIndex, toIndex);
|
||||
|
||||
try {
|
||||
// 使用批量查询接口
|
||||
RmNetworkInterfaceRemote queryParam = new RmNetworkInterfaceRemote();
|
||||
queryParam.setClientIds(clientIdsStr); // 这里是逗号分隔的字符串
|
||||
queryParam.setNewFlag(1);
|
||||
|
||||
R<List<RmNetworkInterfaceRemote>> result = remoteRocketMqService.getNetworkInterfaceList(queryParam, SecurityConstants.INNER);
|
||||
|
||||
if (result == null || result.getData() == null || result.getData().isEmpty()) {
|
||||
log.warn("批量查询网络信息返回为空,clientIds: {}", clientIdsStr);
|
||||
// 回退到单条查询
|
||||
// fallbackSetNetworkInfo(pageList);
|
||||
return;
|
||||
// 收集当前批次需要查询的clientId
|
||||
String clientIdsStr = batchList.stream()
|
||||
.map(RmResourceRegistration::getClientId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.joining(","));
|
||||
if (StringUtils.isBlank(clientIdsStr)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
List<RmNetworkInterfaceRemote> networkList = result.getData();
|
||||
|
||||
// 按clientId分组
|
||||
Map<String, List<RmNetworkInterfaceRemote>> networkMap = networkList.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(item -> item.getClientId() != null)
|
||||
.collect(Collectors.groupingBy(RmNetworkInterfaceRemote::getClientId));
|
||||
try {
|
||||
// 使用批量查询接口
|
||||
RmNetworkInterfaceRemote queryParam = new RmNetworkInterfaceRemote();
|
||||
queryParam.setClientIds(clientIdsStr);
|
||||
queryParam.setNewFlag(1);
|
||||
|
||||
// 批量设置
|
||||
for (RmResourceRegistration registration : pageList) {
|
||||
String clientId = registration.getClientId();
|
||||
if (clientId != null) {
|
||||
List<RmNetworkInterfaceRemote> clientNetworks = networkMap.get(clientId);
|
||||
if (clientNetworks != null && !clientNetworks.isEmpty()) {
|
||||
// 调用原有的setNetWorkMsg方法
|
||||
setNetWorkMsgWithNetworkList(registration, clientNetworks);
|
||||
R<List<RmNetworkInterfaceRemote>> result = remoteRocketMqService.getNetworkInterfaceList(queryParam, SecurityConstants.INNER);
|
||||
|
||||
if (result == null || result.getData() == null || result.getData().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
List<RmNetworkInterfaceRemote> networkList = result.getData();
|
||||
|
||||
// 按clientId分组
|
||||
Map<String, List<RmNetworkInterfaceRemote>> networkMap = networkList.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(item -> item.getClientId() != null)
|
||||
.collect(Collectors.groupingBy(RmNetworkInterfaceRemote::getClientId));
|
||||
|
||||
// 批量设置当前批次
|
||||
for (RmResourceRegistration registration : batchList) {
|
||||
String clientId = registration.getClientId();
|
||||
if (clientId != null) {
|
||||
List<RmNetworkInterfaceRemote> clientNetworks = networkMap.get(clientId);
|
||||
if (clientNetworks != null && !clientNetworks.isEmpty()) {
|
||||
setNetWorkMsgWithNetworkList(registration, clientNetworks);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("第{}批查询网络信息异常", batchNum + 1, e);
|
||||
}
|
||||
|
||||
log.debug("批量处理网络信息完成,耗时: {}ms, 处理{}条记录, 返回{}条网络信息",
|
||||
System.currentTimeMillis() - startTime, pageList.size(), networkList.size());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("批量查询网络信息异常", e);
|
||||
// 回退到单条查询
|
||||
// fallbackSetNetworkInfo(pageList);
|
||||
// 添加小延迟,避免对下游服务造成压力
|
||||
if (batchNum < totalBatches - 1) {
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/debug.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<maxHistory>7</maxHistory> <!-- debug日志只保留7天 -->
|
||||
<maxHistory>30</maxHistory> <!-- debug日志只保留30天 -->
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
|
||||
+1
-1
@@ -166,7 +166,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<!-- 批量插入接口名称 -->
|
||||
<insert id="batchInsert" parameterType="java.util.List">
|
||||
INSERT IGNORE INTO all_interface_name
|
||||
INSERT INTO all_interface_name
|
||||
(
|
||||
interface_name,
|
||||
client_id,
|
||||
|
||||
Reference in New Issue
Block a user