1、新增业务进程与名称对应表。
2、新增业务流量查询逻辑。
This commit is contained in:
+38
-12
@@ -150,7 +150,7 @@ public class SpeedUtils {
|
||||
}
|
||||
}
|
||||
public static String calculateUnit(List<?> list,
|
||||
String inSpeedField, String outSpeedField)
|
||||
String inSpeedField, String outSpeedField)
|
||||
throws NoSuchFieldException, IllegalAccessException {
|
||||
|
||||
if (list == null || list.isEmpty()) {
|
||||
@@ -159,10 +159,6 @@ public class SpeedUtils {
|
||||
|
||||
BigDecimal totalInSpeedBit = BigDecimal.ZERO;
|
||||
BigDecimal totalOutSpeedBit = BigDecimal.ZERO;
|
||||
BigDecimal maxInSpeedGb = BigDecimal.ZERO;
|
||||
BigDecimal maxOutSpeedGb = BigDecimal.ZERO;
|
||||
BigDecimal lastInSpeedGb = BigDecimal.ZERO;
|
||||
BigDecimal lastOutSpeedGb = BigDecimal.ZERO;
|
||||
|
||||
final BigDecimal GB_DIVISOR = new BigDecimal("1000000000");
|
||||
|
||||
@@ -175,8 +171,9 @@ public class SpeedUtils {
|
||||
inField.setAccessible(true);
|
||||
outField.setAccessible(true);
|
||||
|
||||
BigDecimal inSpeedBit = (BigDecimal) inField.get(obj) == null ? BigDecimal.ZERO : (BigDecimal) inField.get(obj);
|
||||
BigDecimal outSpeedBit = (BigDecimal) outField.get(obj) == null ? BigDecimal.ZERO : (BigDecimal) outField.get(obj);
|
||||
// 安全地获取字段值并转换为BigDecimal
|
||||
BigDecimal inSpeedBit = convertToBigDecimal(inField.get(obj));
|
||||
BigDecimal outSpeedBit = convertToBigDecimal(outField.get(obj));
|
||||
|
||||
// 累加bit值(用于计算平均值)
|
||||
totalInSpeedBit = totalInSpeedBit.add(inSpeedBit);
|
||||
@@ -188,24 +185,53 @@ public class SpeedUtils {
|
||||
|
||||
// 计算Gb平均值
|
||||
BigDecimal size = new BigDecimal(list.size());
|
||||
BigDecimal avgInSpeedGb = totalInSpeedBit.divide(size, 2, RoundingMode.HALF_UP);
|
||||
BigDecimal avgOutSpeedGb = totalOutSpeedBit.divide(size, 2, RoundingMode.HALF_UP);
|
||||
BigDecimal avgInSpeedBit = totalInSpeedBit.divide(size, 2, RoundingMode.HALF_UP);
|
||||
BigDecimal avgOutSpeedBit = totalOutSpeedBit.divide(size, 2, RoundingMode.HALF_UP);
|
||||
|
||||
// 基于平均值的较大值确定推荐单位
|
||||
BigDecimal maxAvgBit = avgInSpeedGb.compareTo(avgOutSpeedGb) > 0 ?
|
||||
avgInSpeedGb : avgOutSpeedGb;
|
||||
BigDecimal maxAvgBit = avgInSpeedBit.compareTo(avgOutSpeedBit) > 0 ?
|
||||
avgInSpeedBit : avgOutSpeedBit;
|
||||
|
||||
String recommendedUnit;
|
||||
if (maxAvgBit.compareTo(new BigDecimal("1000000000")) >= 0) {
|
||||
recommendedUnit = "Gb";
|
||||
} else if (maxAvgBit.compareTo(new BigDecimal("1000000")) >= 0) {
|
||||
recommendedUnit = "Mb";
|
||||
} else{
|
||||
} else {
|
||||
recommendedUnit = "Kb";
|
||||
}
|
||||
|
||||
return recommendedUnit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全地将不同类型转换为BigDecimal
|
||||
*/
|
||||
private static BigDecimal convertToBigDecimal(Object value) {
|
||||
if (value == null) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
try {
|
||||
if (value instanceof BigDecimal) {
|
||||
return (BigDecimal) value;
|
||||
} else if (value instanceof String) {
|
||||
String strValue = ((String) value).trim();
|
||||
if (strValue.isEmpty()) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return new BigDecimal(strValue);
|
||||
} else if (value instanceof Number) {
|
||||
return new BigDecimal(value.toString());
|
||||
} else {
|
||||
// 尝试转换为字符串再解析
|
||||
return new BigDecimal(value.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 转换失败时返回0
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 计算String类型(存储数字)的速度统计结果
|
||||
* @param list 数据列表
|
||||
|
||||
Reference in New Issue
Block a user