fix(X-Pack): 定时报告-导出视图数据选择的是双轴图会报错

This commit is contained in:
fit2cloud-chenyw 2024-09-14 15:27:31 +08:00
parent d5a914e6cd
commit a3511e13b0

View File

@ -8,7 +8,6 @@ import io.dataease.constant.CommonConstants;
import io.dataease.dataset.server.DatasetFieldServer;
import io.dataease.engine.constant.DeTypeConstants;
import io.dataease.exception.DEException;
import io.dataease.extensions.datasource.dto.DatasetTableFieldDTO;
import io.dataease.extensions.view.dto.ChartExtFilterDTO;
import io.dataease.extensions.view.dto.ChartExtRequest;
import io.dataease.extensions.view.dto.ChartViewDTO;
@ -73,27 +72,14 @@ public class CoreVisualizationExportManage {
}
view.getChartExtRequest().setUser(AuthUtils.getUser().getUserId());
view.setTitle((i + 1) + "-" + view.getTitle());
sheets.add(exportViewData(view));
sheets.addAll(exportViewData(view));
}
return VisualizationExcelUtils.exportExcel(sheets, visualization.getName(), visualization.getId().toString());
}
private ExcelSheetModel exportViewData(ChartViewDTO request) {
private ExcelSheetModel exportSingleData(Map<String, Object> chart, String title) {
ExcelSheetModel result = new ExcelSheetModel();
ChartViewDTO chartViewDTO = null;
if (CommonConstants.VIEW_DATA_FROM.TEMPLATE.equalsIgnoreCase(request.getDataFrom())) {
chartViewDTO = extendDataManage.getChartDataInfo(request.getId(), request);
} else {
try {
chartViewDTO = chartDataManage.calcData(request);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
String title = chartViewDTO.getTitle();
Map<String, Object> chart = chartViewDTO.getData();
Object objectFields = chart.get("fields");
List<ChartViewFieldDTO> fields = (List<ChartViewFieldDTO>) objectFields;
List<String> heads = new ArrayList<>();
@ -116,6 +102,9 @@ public class CoreVisualizationExportManage {
});
}
Object objectTableRow = chart.get("tableRow");
if (objectTableRow == null) {
objectTableRow = chart.get("sourceData");
}
List<Map<String, Object>> tableRow = (List<Map<String, Object>>) objectTableRow;
List<List<String>> details = tableRow.stream().map(row -> {
@ -140,6 +129,40 @@ public class CoreVisualizationExportManage {
return result;
}
private List<ExcelSheetModel> exportViewData(ChartViewDTO request) {
ChartViewDTO chartViewDTO = null;
request.setIsExcelExport(true);
if (CommonConstants.VIEW_DATA_FROM.TEMPLATE.equalsIgnoreCase(request.getDataFrom())) {
chartViewDTO = extendDataManage.getChartDataInfo(request.getId(), request);
} else {
try {
chartViewDTO = chartDataManage.calcData(request);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
String title = chartViewDTO.getTitle();
Map<String, Object> chart = chartViewDTO.getData();
List<ExcelSheetModel> resultList = new ArrayList<>();
boolean leftExist = ObjectUtils.isNotEmpty(chart.get("left"));
boolean rightExist = ObjectUtils.isNotEmpty(chart.get("right"));
if (!leftExist && !rightExist) {
ExcelSheetModel sheetModel = exportSingleData(chart, title);
resultList.add(sheetModel);
return resultList;
}
if (leftExist) {
ExcelSheetModel sheetModel = exportSingleData((Map<String, Object>) chart.get("left"), title + "_left");
resultList.add(sheetModel);
}
if (rightExist) {
ExcelSheetModel sheetModel = exportSingleData((Map<String, Object>) chart.get("right"), title + "_right");
resultList.add(sheetModel);
}
return resultList;
}
private String filterInvalidDecimal(String sourceNumberStr) {
if (StringUtils.isNotBlank(sourceNumberStr) && StringUtils.contains(sourceNumberStr, ".")) {
sourceNumberStr = sourceNumberStr.replaceAll("0+?$", "");