EasyExcel导出报表(多table包含合并策略)
导入Pom
<!-- easyexcel -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.2.8</version>
</dependency>
数据
多集群环境下的,资源类型:deploy ,statefulset,dameonset的控制的Pod对应的CPU,内存,存储PVC,以及所属的租户信息等,这些数据是可以从prometheus中进行获取的,是时序向量数据,其中七牛云存储的数据无法从prometheus获取,所以需要从平台中获取数据。
核心代码
使用到的地方
List<ReportForm> reportForms = monitorCenterService.getReportForm(subNamespacesList, timeMap,rangeMap,startTime,endTime);
if (Objects.nonNull(reportForms) && reportForms.size() > 0) {
List<ReportFormEasyExcelDto> multiPvcDtoList = new ArrayList<>();
List<ReportFormEasyExcelDto> nonOrSinglePvcDtoList = new ArrayList<>();
List<WriteHandler> mergeMultiPvcHandlerList = getWriteHandlerList(reportForms, multiPvcDtoList, nonOrSinglePvcDtoList);
EasyExcelUtil.mergeCall(multiPvcDtoList, nonOrSinglePvcDtoList, getEasyExcelHeadList(), mergeMultiPvcHandlerList, httpResponse);
return ActionReturnUtil.returnSuccess();
} else if (Objects.nonNull(reportForms) && reportForms.size() == 0) {
return ActionReturnUtil.returnSuccessWithData("没有报表数据可以导出");
} else {
logger.error("获取的报表数据出现异常");
return ActionReturnUtil.returnErrorWithData("获取的报表数据出现异常");
}
private List<WriteHandler> getWriteHandlerList(List<ReportForm> reportForms,List<ReportFormEasyExcelDto> multiPvcDtoList, List<ReportFormEasyExcelDto> nonOrSinglePvcDtoList) {
List<WriteHandler> writeHandlerList = new ArrayList<>();
int beginRow = 1,endRow = 0;
for (ReportForm reportForm : reportForms) {
if (!CollectionUtils.isEmpty(reportForm.getStorageUsageMap()) && !CollectionUtils.isEmpty(reportForm.getStorageRequestMap())) {
int size = reportForm.getStorageRequestMap().size();
if (size > 1) {
endRow += size;
for (int i = 0; i < reportFormAttrsLength - 4; i++) {
OnceAbsoluteMergeStrategy onceAbsoluteMergeStrategy = new OnceAbsoluteMergeStrategy(beginRow, endRow, i, i);
writeHandlerList.add(onceAbsoluteMergeStrategy);
}
beginRow = beginRow + size