业务流量对齐x轴
This commit is contained in:
+39
-17
@@ -604,6 +604,8 @@ public class InitialBandwidthTrafficServiceImpl implements IInitialBandwidthTraf
|
||||
|
||||
List<AllBusinessNetName> result = new ArrayList<>(uniqueMap.values());
|
||||
|
||||
// 获取主数据的x轴时间点
|
||||
List<String> mainXData = (List<String>) resultMap.get("xData");
|
||||
// 用于存储业务的显示名称
|
||||
Map<String, String> businessDisplayNames = new HashMap<>();
|
||||
|
||||
@@ -614,44 +616,65 @@ public class InitialBandwidthTrafficServiceImpl implements IInitialBandwidthTraf
|
||||
businessTrafficQuery.setProcessName(allBusinessNetName.getProcessName());
|
||||
businessTrafficQuery.setStartTime(initialBandwidthTraffic.getStartTime());
|
||||
businessTrafficQuery.setEndTime(initialBandwidthTraffic.getEndTime());
|
||||
|
||||
// 获取业务流量图表数据(返回的是bit单位)
|
||||
Map<String, Object> businessResult = initialNetBusinessTrafficService.businessTrafficEcharts(businessTrafficQuery);
|
||||
|
||||
if (businessResult != null && !businessResult.isEmpty()) {
|
||||
// 获取业务名称作为前缀标识
|
||||
String businessPrefix = allBusinessNetName.getProcessName();
|
||||
// 如果进程名包含特殊字符,可以进一步处理为合法的key
|
||||
businessPrefix = businessPrefix.replaceAll("[^a-zA-Z0-9]", "_");
|
||||
|
||||
// 获取业务流量的y轴数据
|
||||
// 获取业务流量的y轴数据和x轴数据
|
||||
Map<String, Object> businessYData = (Map<String, Object>) businessResult.get("yData");
|
||||
if (businessYData != null && !businessYData.isEmpty()) {
|
||||
List<String> businessXData = (List<String>) businessResult.get("xData");
|
||||
|
||||
if (businessYData != null && !businessYData.isEmpty() && businessXData != null) {
|
||||
// 获取主Map的yData
|
||||
Map<String, Object> mainYData = (Map<String, Object>) resultMap.get("yData");
|
||||
|
||||
// 将业务流量数据合并到主yData中,直接除以divisor
|
||||
// 构建业务数据的时间点映射
|
||||
Map<String, Map<String, BigDecimal>> timePointDataMap = new HashMap<>();
|
||||
|
||||
// 为每个数据系列建立时间点映射
|
||||
for (Map.Entry<String, Object> entry : businessYData.entrySet()) {
|
||||
String businessKey = entry.getKey();
|
||||
Object businessValue = entry.getValue();
|
||||
List<BigDecimal> values = (List<BigDecimal>) entry.getValue();
|
||||
|
||||
// 添加业务前缀避免key冲突,格式:business_{进程名}_{数据类型}
|
||||
for (int i = 0; i < businessXData.size() && i < values.size(); i++) {
|
||||
String timeStr = businessXData.get(i);
|
||||
timePointDataMap.computeIfAbsent(timeStr, k -> new HashMap<>())
|
||||
.put(businessKey, values.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
// 按照主数据的x轴重新组织业务数据
|
||||
for (Map.Entry<String, Object> entry : businessYData.entrySet()) {
|
||||
String businessKey = entry.getKey();
|
||||
String newKey = "business_" + businessPrefix + "_" + businessKey;
|
||||
|
||||
// 直接除以divisor进行单位转换
|
||||
if (businessValue instanceof List) {
|
||||
List<BigDecimal> originalList = (List<BigDecimal>) businessValue;
|
||||
List<BigDecimal> convertedList = new ArrayList<>();
|
||||
for (BigDecimal value : originalList) {
|
||||
// 创建对齐后的数据列表
|
||||
List<BigDecimal> alignedData = new ArrayList<>();
|
||||
|
||||
// 遍历主数据的时间点
|
||||
for (String timeStr : mainXData) {
|
||||
Map<String, BigDecimal> pointData = timePointDataMap.get(timeStr);
|
||||
|
||||
if (pointData != null && pointData.containsKey(businessKey)) {
|
||||
BigDecimal value = pointData.get(businessKey);
|
||||
if (value != null) {
|
||||
convertedList.add(value.divide(divisor, 2, RoundingMode.HALF_UP));
|
||||
// 单位转换
|
||||
alignedData.add(value.divide(divisor, 2, RoundingMode.HALF_UP));
|
||||
} else {
|
||||
convertedList.add(null);
|
||||
alignedData.add(null);
|
||||
}
|
||||
} else {
|
||||
// 没有对应时间点的数据,补null
|
||||
alignedData.add(null);
|
||||
}
|
||||
mainYData.put(newKey, convertedList);
|
||||
} else {
|
||||
mainYData.put(newKey, businessValue);
|
||||
}
|
||||
|
||||
mainYData.put(newKey, alignedData);
|
||||
}
|
||||
|
||||
resultMap.put("yData", mainYData);
|
||||
@@ -686,7 +709,6 @@ public class InitialBandwidthTrafficServiceImpl implements IInitialBandwidthTraf
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 业务流量数据获取失败,记录日志但不影响主流程
|
||||
System.err.println("获取业务流量数据失败: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user