月均日95值计算方式新增1024,资源监控模块接口新增
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package com.ruoyi.rocketmq.utils;
|
||||
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EchartsDataUtils {
|
||||
|
||||
/**
|
||||
* 构建ECharts图表数据
|
||||
* @param list 原始数据列表
|
||||
* @param timeExtractor 时间字段提取函数
|
||||
* @param dataExtractors 数据提取器Map (key: 数据名称, value: 数据提取函数)
|
||||
* @param <T> 数据类型泛型
|
||||
* @return 包含xData和yData的Map
|
||||
*/
|
||||
public static <T> Map<String, Object> buildEchartsData(
|
||||
List<T> list,
|
||||
Function<T, Date> timeExtractor,
|
||||
Map<String, Function<T, ?>> dataExtractors) {
|
||||
|
||||
// 按时间排序
|
||||
List<T> sortedList = list.stream()
|
||||
.sorted(Comparator.comparing(timeExtractor))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 准备X轴数据
|
||||
List<String> xAxisData = sortedList.stream()
|
||||
.map(item -> DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", timeExtractor.apply(item)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 准备Y轴数据
|
||||
Map<String, Object> yData = new LinkedHashMap<>();
|
||||
dataExtractors.forEach((name, extractor) -> {
|
||||
yData.put(name, sortedList.stream().map(extractor).collect(Collectors.toList()));
|
||||
});
|
||||
|
||||
// 构建返回结果
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("xData", xAxisData);
|
||||
result.put("yData", yData);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 微秒转秒
|
||||
*/
|
||||
public static double convertMicrosecondsToSeconds(long microseconds) {
|
||||
return microseconds / 1_000_000.0;
|
||||
}
|
||||
}
|
||||
@@ -7,14 +7,16 @@ import java.util.Set;
|
||||
|
||||
public class TableRouterUtil {
|
||||
|
||||
// 日期格式
|
||||
private static final DateTimeFormatter YEAR_MONTH_FORMAT =
|
||||
DateTimeFormatter.ofPattern("yyyy_MM");
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER =
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
// 表名前缀
|
||||
private static final String TABLE_PREFIX = "eps_initial_traffic";
|
||||
// 表名前缀
|
||||
private static final String TABLE_PREFIX_INITIAL = "initial_bandwidth_traffic";
|
||||
|
||||
// 日期格式
|
||||
private static final DateTimeFormatter YEAR_MONTH_FORMAT =
|
||||
DateTimeFormatter.ofPattern("yyyy_MM");
|
||||
|
||||
/**
|
||||
* 根据创建时间获取表名
|
||||
@@ -43,24 +45,36 @@ public class TableRouterUtil {
|
||||
|
||||
/**
|
||||
* 获取时间范围内涉及的所有表名
|
||||
* @param startTime 开始时间(包含)
|
||||
* @param endTime 结束时间(包含)
|
||||
* @param startTime 开始时间 (格式: "yyyy-MM-dd HH:mm:ss")
|
||||
* @param endTime 结束时间 (格式: "yyyy-MM-dd HH:mm:ss")
|
||||
* @return 按时间顺序排列的表名集合
|
||||
*/
|
||||
public static Set<String> getTableNamesBetween(LocalDateTime startTime, LocalDateTime endTime) {
|
||||
validateTimeRange(startTime, endTime);
|
||||
public static Set<String> getTableNamesBetween(String startTime, String endTime) {
|
||||
LocalDateTime start = parseDateTime(startTime);
|
||||
LocalDateTime end = parseDateTime(endTime);
|
||||
validateTimeRange(start, end);
|
||||
|
||||
Set<String> tableNames = new LinkedHashSet<>();
|
||||
LocalDateTime current = startTime.withHour(0).withMinute(0).withSecond(0);
|
||||
LocalDateTime current = start.withHour(0).withMinute(0).withSecond(0);
|
||||
|
||||
while (!current.isAfter(endTime)) {
|
||||
while (!current.isAfter(end)) {
|
||||
tableNames.add(getTableName(current));
|
||||
current = current.plusDays(1);
|
||||
}
|
||||
|
||||
return tableNames;
|
||||
}
|
||||
|
||||
// 解析字符串为LocalDateTime
|
||||
private static LocalDateTime parseDateTime(String dateTimeStr) {
|
||||
if (dateTimeStr == null || dateTimeStr.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("时间字符串不能为空");
|
||||
}
|
||||
try {
|
||||
return LocalDateTime.parse(dateTimeStr, DATE_TIME_FORMATTER);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("时间格式必须为: yyyy-MM-dd HH:mm:ss", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取日期区间
|
||||
private static String getDayRange(int day) {
|
||||
|
||||
Reference in New Issue
Block a user