修复业务流量与时间轴错位问题。
This commit is contained in:
+58
-12
@@ -42,6 +42,9 @@ public class EchartsMoreDataUtils {
|
|||||||
Set<Date> allTimePoints = new TreeSet<>();
|
Set<Date> allTimePoints = new TreeSet<>();
|
||||||
Map<String, Map<Long, T>> interfaceTimeMap = new LinkedHashMap<>();
|
Map<String, Map<Long, T>> interfaceTimeMap = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
// 检查是否有任何网卡有真实数据
|
||||||
|
boolean hasRealData = false;
|
||||||
|
|
||||||
// 为每个网卡处理数据
|
// 为每个网卡处理数据
|
||||||
for (Map.Entry<String, List<T>> entry : interfaceDataMap.entrySet()) {
|
for (Map.Entry<String, List<T>> entry : interfaceDataMap.entrySet()) {
|
||||||
String interfaceName = entry.getKey();
|
String interfaceName = entry.getKey();
|
||||||
@@ -72,6 +75,15 @@ public class EchartsMoreDataUtils {
|
|||||||
// 添加时间点到总集合
|
// 添加时间点到总集合
|
||||||
for (T item : sortedList) {
|
for (T item : sortedList) {
|
||||||
allTimePoints.add(timeExtractor.apply(item));
|
allTimePoints.add(timeExtractor.apply(item));
|
||||||
|
// 检查是否有真实数据(非null)
|
||||||
|
if (!hasRealData) {
|
||||||
|
BigDecimal inSpeed = inSpeedExtractor.apply(item);
|
||||||
|
BigDecimal outSpeed = outSpeedExtractor.apply(item);
|
||||||
|
if ((inSpeed != null && inSpeed.compareTo(BigDecimal.ZERO) != 0) ||
|
||||||
|
(outSpeed != null && outSpeed.compareTo(BigDecimal.ZERO) != 0)) {
|
||||||
|
hasRealData = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +108,8 @@ public class EchartsMoreDataUtils {
|
|||||||
yData.put("totalNetOutTraffic", totalNetOutTraffic);
|
yData.put("totalNetOutTraffic", totalNetOutTraffic);
|
||||||
|
|
||||||
// 遍历所有时间点
|
// 遍历所有时间点
|
||||||
for (Date time : fullTimeSeries) {
|
for (int timeIndex = 0; timeIndex < fullTimeSeries.size(); timeIndex++) {
|
||||||
|
Date time = fullTimeSeries.get(timeIndex);
|
||||||
// X轴数据
|
// X轴数据
|
||||||
xAxisData.add(parseDateToStr(time));
|
xAxisData.add(parseDateToStr(time));
|
||||||
|
|
||||||
@@ -107,6 +120,9 @@ public class EchartsMoreDataUtils {
|
|||||||
BigDecimal timeTotalInSpeed = BigDecimal.ZERO;
|
BigDecimal timeTotalInSpeed = BigDecimal.ZERO;
|
||||||
BigDecimal timeTotalOutSpeed = BigDecimal.ZERO;
|
BigDecimal timeTotalOutSpeed = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
// 是否有数据点存在
|
||||||
|
boolean hasDataAtThisTime = false;
|
||||||
|
|
||||||
// 处理每个网卡的数据
|
// 处理每个网卡的数据
|
||||||
for (Map.Entry<String, Map<Long, T>> entry : interfaceTimeMap.entrySet()) {
|
for (Map.Entry<String, Map<Long, T>> entry : interfaceTimeMap.entrySet()) {
|
||||||
String interfaceName = entry.getKey();
|
String interfaceName = entry.getKey();
|
||||||
@@ -136,22 +152,31 @@ public class EchartsMoreDataUtils {
|
|||||||
outSpeedList.add(convertedOutSpeed);
|
outSpeedList.add(convertedOutSpeed);
|
||||||
|
|
||||||
// 累加到总流量
|
// 累加到总流量
|
||||||
if (convertedInSpeed != null) {
|
if (convertedInSpeed != null && convertedInSpeed.compareTo(BigDecimal.ZERO) != 0) {
|
||||||
timeTotalInSpeed = timeTotalInSpeed.add(convertedInSpeed);
|
timeTotalInSpeed = timeTotalInSpeed.add(convertedInSpeed);
|
||||||
}
|
}
|
||||||
if (convertedOutSpeed != null) {
|
if (convertedOutSpeed != null && convertedOutSpeed.compareTo(BigDecimal.ZERO) != 0) {
|
||||||
timeTotalOutSpeed = timeTotalOutSpeed.add(convertedOutSpeed);
|
timeTotalOutSpeed = timeTotalOutSpeed.add(convertedOutSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasDataAtThisTime = true;
|
||||||
} else {
|
} else {
|
||||||
// 无数据的时间点,补null
|
// 无数据的时间点,使用智能补全逻辑
|
||||||
inSpeedList.add(null);
|
inSpeedList.add(getDefaultSpeedValue(hasRealData, timeIndex));
|
||||||
outSpeedList.add(null);
|
outSpeedList.add(getDefaultSpeedValue(hasRealData, timeIndex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加当前时间点的总流量
|
// 添加当前时间点的总流量(使用智能补全逻辑)
|
||||||
|
if (hasDataAtThisTime) {
|
||||||
|
// 有真实数据,正常添加
|
||||||
totalNetInTraffic.add(timeTotalInSpeed.compareTo(BigDecimal.ZERO) == 0 ? null : timeTotalInSpeed);
|
totalNetInTraffic.add(timeTotalInSpeed.compareTo(BigDecimal.ZERO) == 0 ? null : timeTotalInSpeed);
|
||||||
totalNetOutTraffic.add(timeTotalOutSpeed.compareTo(BigDecimal.ZERO) == 0 ? null : timeTotalOutSpeed);
|
totalNetOutTraffic.add(timeTotalOutSpeed.compareTo(BigDecimal.ZERO) == 0 ? null : timeTotalOutSpeed);
|
||||||
|
} else {
|
||||||
|
// 没有真实数据,使用智能补全逻辑
|
||||||
|
totalNetInTraffic.add(getDefaultSpeedValue(hasRealData, timeIndex));
|
||||||
|
totalNetOutTraffic.add(getDefaultSpeedValue(hasRealData, timeIndex));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
@@ -166,6 +191,26 @@ public class EchartsMoreDataUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取默认速度值(根据智能补全策略)
|
||||||
|
* 策略:
|
||||||
|
* 1. 如果整个数据集有真实数据:所有缺失点都补null
|
||||||
|
* 2. 如果整个数据集没有真实数据:第一个点补0,其他点补null
|
||||||
|
*/
|
||||||
|
private static BigDecimal getDefaultSpeedValue(boolean hasRealData, int timeIndex) {
|
||||||
|
if (hasRealData) {
|
||||||
|
// 数据集中有真实数据:所有缺失点都补null
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
// 数据集中没有真实数据:第一个点补0,其他点补null
|
||||||
|
if (timeIndex == 0) {
|
||||||
|
return BigDecimal.ZERO;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为多网卡生成完整的时间序列
|
* 为多网卡生成完整的时间序列
|
||||||
*/
|
*/
|
||||||
@@ -227,9 +272,9 @@ public class EchartsMoreDataUtils {
|
|||||||
fullTimeSeries.addAll(afterSeries);
|
fullTimeSeries.addAll(afterSeries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 在generateFullTimeSeriesForMultiInterface方法的最后添加:
|
|
||||||
|
// 排序和去重
|
||||||
fullTimeSeries.sort(Date::compareTo);
|
fullTimeSeries.sort(Date::compareTo);
|
||||||
// 去重
|
|
||||||
List<Date> uniqueSeries = new ArrayList<>();
|
List<Date> uniqueSeries = new ArrayList<>();
|
||||||
Date lastDate = null;
|
Date lastDate = null;
|
||||||
for (Date date : fullTimeSeries) {
|
for (Date date : fullTimeSeries) {
|
||||||
@@ -242,7 +287,7 @@ public class EchartsMoreDataUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建多网卡空结果(带汇总流量)
|
* 创建多网卡空结果(带汇总流量)- 使用智能补全策略
|
||||||
*/
|
*/
|
||||||
private static Map<String, Object> createEmptyMultiInterfaceResultWithTotal(
|
private static Map<String, Object> createEmptyMultiInterfaceResultWithTotal(
|
||||||
Set<String> interfaceNames, String startTime, String endTime) {
|
Set<String> interfaceNames, String startTime, String endTime) {
|
||||||
@@ -274,7 +319,7 @@ public class EchartsMoreDataUtils {
|
|||||||
}
|
}
|
||||||
result.put("xData", xAxisData);
|
result.put("xData", xAxisData);
|
||||||
|
|
||||||
// 构建y轴数据(空数据集)
|
// 构建y轴数据(空数据集)- 使用智能补全策略
|
||||||
Map<String, Object> yData = new LinkedHashMap<>();
|
Map<String, Object> yData = new LinkedHashMap<>();
|
||||||
int dataSize = xAxisData.size();
|
int dataSize = xAxisData.size();
|
||||||
|
|
||||||
@@ -299,7 +344,7 @@ public class EchartsMoreDataUtils {
|
|||||||
yData.put(interfaceName + "netOutTraffic", outSpeedSeries);
|
yData.put(interfaceName + "netOutTraffic", outSpeedSeries);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建汇总流量的空数据系列
|
// 创建汇总流量的空数据系列 - 使用相同的智能补全策略
|
||||||
List<Object> totalInSpeedSeries = new ArrayList<>();
|
List<Object> totalInSpeedSeries = new ArrayList<>();
|
||||||
List<Object> totalOutSpeedSeries = new ArrayList<>();
|
List<Object> totalOutSpeedSeries = new ArrayList<>();
|
||||||
for (int i = 0; i < dataSize; i++) {
|
for (int i = 0; i < dataSize; i++) {
|
||||||
@@ -429,6 +474,7 @@ public class EchartsMoreDataUtils {
|
|||||||
long timeMillis = time.getTime();
|
long timeMillis = time.getTime();
|
||||||
return ((timeMillis + interval - 1) / interval) * interval;
|
return ((timeMillis + interval - 1) / interval) * interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, String> sortInterfaceMap(Map<String, String> interfaceMap, String mainName, boolean hasSub) {
|
public static Map<String, String> sortInterfaceMap(Map<String, String> interfaceMap, String mainName, boolean hasSub) {
|
||||||
List<Map.Entry<String, String>> list = new ArrayList<>(interfaceMap.entrySet());
|
List<Map.Entry<String, String>> list = new ArrayList<>(interfaceMap.entrySet());
|
||||||
|
|
||||||
|
|||||||
+2
@@ -215,6 +215,8 @@
|
|||||||
<if test="totalIpv4OutSpeed != null and totalIpv4OutSpeed != ''"> and total_ipv4_out_speed = #{totalIpv4OutSpeed}</if>
|
<if test="totalIpv4OutSpeed != null and totalIpv4OutSpeed != ''"> and total_ipv4_out_speed = #{totalIpv4OutSpeed}</if>
|
||||||
<if test="totalIpv6InSpeed != null and totalIpv6InSpeed != ''"> and total_ipv6_in_speed = #{totalIpv6InSpeed}</if>
|
<if test="totalIpv6InSpeed != null and totalIpv6InSpeed != ''"> and total_ipv6_in_speed = #{totalIpv6InSpeed}</if>
|
||||||
<if test="totalIpv6OutSpeed != null and totalIpv6OutSpeed != ''"> and total_ipv6_out_speed = #{totalIpv6OutSpeed}</if>
|
<if test="totalIpv6OutSpeed != null and totalIpv6OutSpeed != ''"> and total_ipv6_out_speed = #{totalIpv6OutSpeed}</if>
|
||||||
|
<if test="startTime != null and startTime != ''"> and create_time >= #{startTime}</if>
|
||||||
|
<if test="endTime != null and endTime != ''"> and create_time <= #{endTime}</if>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user