月均日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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user