底层流量数据改为bit,测试金山云服务器API,准备1.1分支

This commit is contained in:
gaoyutao
2025-10-09 17:38:24 +08:00
parent ab578ee17f
commit 7b5c782079
16 changed files with 211 additions and 655 deletions
@@ -140,4 +140,40 @@ public class DataProcessUtil {
return devicesResponse != null ? devicesResponse.getData() : Collections.emptyList();
}
/**
* 将采集到的字节流量转化为比特流量
* 只是简单地将字节值乘以8得到比特值
* @param speed 字节数值字符串
* @return 比特数值字符串
*/
public String bytesToBits(String speed) {
if (speed == null || speed.trim().isEmpty()) {
return "0";
}
String cleanedSpeed = speed.trim();
try {
// 解析字节值并乘以8转换为比特值
long bytesValue = Long.parseLong(cleanedSpeed);
long bitsValue = bytesValue * 8;
return String.valueOf(bitsValue);
} catch (NumberFormatException e) {
// 如果解析失败,尝试使用double类型
try {
double bytesValue = Double.parseDouble(cleanedSpeed);
double bitsValue = bytesValue * 8;
// 如果是整数则返回整数形式,否则返回小数形式
if (bitsValue == (long) bitsValue) {
return String.valueOf((long) bitsValue);
} else {
return String.valueOf(bitsValue);
}
} catch (NumberFormatException ex) {
throw new IllegalArgumentException("Invalid speed format: " + speed);
}
}
}
}