mirror of
https://github.com/dataease/dataease.git
synced 2026-05-14 21:12:33 +08:00
fix: 【图表】明细表支持字段组合展示
This commit is contained in:
committed by
xuwei-fit2cloud
parent
283b2f7a7d
commit
12a1f018be
@@ -323,7 +323,8 @@ public class ChartDataServer implements ChartDataApi {
|
||||
xAxis.addAll(viewInfo.getXAxisExt());
|
||||
xAxis.addAll(viewInfo.getYAxisExt());
|
||||
xAxis.addAll(viewInfo.getExtStack());
|
||||
|
||||
TableHeader tableHeader = null;
|
||||
Integer totalDepth = 0;
|
||||
if (viewInfo.getType().equalsIgnoreCase("table-normal") || viewInfo.getType().equalsIgnoreCase("table-info")) {
|
||||
for (ChartViewFieldDTO xAxi : xAxis) {
|
||||
if (xAxi.getDeType().equals(DeTypeConstants.DE_INT) || xAxi.getDeType().equals(DeTypeConstants.DE_FLOAT)) {
|
||||
@@ -333,6 +334,18 @@ public class ChartDataServer implements ChartDataApi {
|
||||
styles.add(null);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> customAttr = viewInfo.getCustomAttr();
|
||||
Map<String, Object> tableHeaderMap = (Map<String, Object>) customAttr.get("tableHeader");
|
||||
if (Boolean.valueOf(tableHeaderMap.get("headerGroup").toString())) {
|
||||
tableHeader = JsonUtil.parseObject((String) JsonUtil.toJSONString(customAttr.get("tableHeader")), TableHeader.class);
|
||||
for (TableHeader.ColumnInfo column : tableHeader.getHeaderGroupConfig().getColumns()) {
|
||||
totalDepth = Math.max(totalDepth, getDepth(column, 1));
|
||||
}
|
||||
for (TableHeader.ColumnInfo column : tableHeader.getHeaderGroupConfig().getColumns()) {
|
||||
setWidth(column, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean mergeHead = false;
|
||||
@@ -379,9 +392,31 @@ public class ChartDataServer implements ChartDataApi {
|
||||
mergeHead = true;
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(details) && (!mergeHead || details.size() > 2)) {
|
||||
int realDetailRowIndex = 2;
|
||||
int realDetailRowIndex = tableHeader == null ? 2 : totalDepth;
|
||||
if (tableHeader != null) {
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN);
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);
|
||||
Map<String, Row> rowMap = new HashMap<>();
|
||||
for (Integer i = 0; i < totalDepth; i++) {
|
||||
rowMap.put("row" + i, detailsSheet.createRow(i));
|
||||
}
|
||||
int width = 0;
|
||||
Integer depth = 0;
|
||||
for (TableHeader.ColumnInfo column : tableHeader.getHeaderGroupConfig().getColumns()) {
|
||||
createCell(tableHeader, column, width, depth, detailsSheet, cellStyle, totalDepth, rowMap, xAxis);
|
||||
width = width + column.getWidth();
|
||||
}
|
||||
}
|
||||
for (int i = (mergeHead ? 2 : 0); i < details.size(); i++) {
|
||||
Row row = detailsSheet.createRow(realDetailRowIndex > 2 ? realDetailRowIndex : i);
|
||||
int rowIndex = i;
|
||||
if (tableHeader != null) {
|
||||
rowIndex = realDetailRowIndex - 1 + i;
|
||||
} else {
|
||||
rowIndex = realDetailRowIndex > 2 ? realDetailRowIndex : i;
|
||||
}
|
||||
Row row = detailsSheet.createRow(rowIndex);
|
||||
Object[] rowData = details.get(i);
|
||||
if (rowData != null) {
|
||||
for (int j = 0; j < rowData.length; j++) {
|
||||
@@ -414,8 +449,10 @@ public class ChartDataServer implements ChartDataApi {
|
||||
|
||||
Cell cell = row.createCell(j);
|
||||
if (i == 0) {// 头部
|
||||
cell.setCellValue(cellValObj.toString());
|
||||
cell.setCellStyle(cellStyle);
|
||||
if (tableHeader != null) {
|
||||
cell.setCellValue(cellValObj.toString());
|
||||
cell.setCellStyle(cellStyle);
|
||||
}
|
||||
//设置列的宽度
|
||||
detailsSheet.setColumnWidth(j, 255 * 20);
|
||||
} else if (cellValObj != null) {
|
||||
@@ -441,6 +478,7 @@ public class ChartDataServer implements ChartDataApi {
|
||||
} else {
|
||||
if (!viewInfo.getType().equalsIgnoreCase("circle-packing")) {
|
||||
Map<String, Object> senior = viewInfo.getSenior();
|
||||
viewInfo.getCustomAttr().get("");
|
||||
ChartSeniorFunctionCfgDTO functionCfgDTO = JsonUtil.parseObject((String) JsonUtil.toJSONString(senior.get("functionCfg")), ChartSeniorFunctionCfgDTO.class);
|
||||
if (functionCfgDTO != null && StringUtils.isNotEmpty(functionCfgDTO.getEmptyDataStrategy()) && functionCfgDTO.getEmptyDataStrategy().equalsIgnoreCase("setZero")) {
|
||||
if ((viewInfo.getType().equalsIgnoreCase("table-normal") || viewInfo.getType().equalsIgnoreCase("table-info"))) {
|
||||
@@ -459,6 +497,91 @@ public class ChartDataServer implements ChartDataApi {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static Integer getDepth(TableHeader.ColumnInfo column, Integer parentDepth) {
|
||||
if (org.springframework.util.CollectionUtils.isEmpty(column.getChildren())) {
|
||||
return parentDepth;
|
||||
} else {
|
||||
Integer depth = 0;
|
||||
for (TableHeader.ColumnInfo child : column.getChildren()) {
|
||||
depth = Math.max(depth, getDepth(child, parentDepth + 1));
|
||||
}
|
||||
return depth;
|
||||
}
|
||||
}
|
||||
|
||||
private static void createCell(TableHeader tableHeader, TableHeader.ColumnInfo column, Integer width, Integer depth, Sheet sheet, CellStyle cellStyle, Integer totaalDepth, Map<String, Row> rowMap, List<ChartViewFieldDTO> xAxis) {
|
||||
if (org.springframework.util.CollectionUtils.isEmpty(column.getChildren())) {
|
||||
Integer toDepth = totaalDepth - 1 > depth ? totaalDepth - 1 : depth;
|
||||
if (depth.equals(toDepth)) {
|
||||
Cell cell = rowMap.get("row" + depth).createCell(width);
|
||||
cell.setCellStyle(cellStyle);
|
||||
cell.setCellValue(getDeFieldName(xAxis, column.getKey()));
|
||||
} else {
|
||||
Cell cell1 = rowMap.get("row" + depth).createCell(width);
|
||||
cell1.setCellValue(getDeFieldName(xAxis, column.getKey()));
|
||||
cell1.setCellStyle(cellStyle);
|
||||
Cell cell2 = rowMap.get("row" + toDepth).createCell(width);
|
||||
cell2.setCellValue(getDeFieldName(xAxis, column.getKey()));
|
||||
cell2.setCellStyle(cellStyle);
|
||||
CellRangeAddress region = new CellRangeAddress(depth, toDepth, width, width);
|
||||
sheet.addMergedRegion(region);
|
||||
|
||||
Cell mergedCell = rowMap.get("row" + depth).getCell(width);
|
||||
mergedCell.setCellStyle(cellStyle);
|
||||
|
||||
}
|
||||
} else {
|
||||
Cell cell1 = rowMap.get("row" + depth).createCell(width);
|
||||
cell1.setCellValue(getGroupName(tableHeader, column.getKey()));
|
||||
cell1.setCellStyle(cellStyle);
|
||||
Cell cell2 = rowMap.get("row" + depth).createCell(width + column.getWidth() - 1);
|
||||
cell2.setCellValue(getGroupName(tableHeader, column.getKey()));
|
||||
cell2.setCellStyle(cellStyle);
|
||||
CellRangeAddress region = new CellRangeAddress(depth, depth, width, width + column.getWidth() - 1);
|
||||
sheet.addMergedRegion(region);
|
||||
Cell mergedCell = rowMap.get("row" + depth).getCell(width);
|
||||
mergedCell.setCellStyle(cellStyle);
|
||||
int subWith = width;
|
||||
for (TableHeader.ColumnInfo child : column.getChildren()) {
|
||||
createCell(tableHeader, child, subWith, depth + 1, sheet, cellStyle, totaalDepth, rowMap, xAxis);
|
||||
subWith = subWith + child.getWidth();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getGroupName(TableHeader tableHeader, String key) {
|
||||
for (TableHeader.MetaInfo metaInfo : tableHeader.getHeaderGroupConfig().getMeta()) {
|
||||
if (metaInfo.getField().equals(key)) {
|
||||
return metaInfo.getName();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static String getDeFieldName(List<ChartViewFieldDTO> xAxis, String key) {
|
||||
for (ChartViewFieldDTO xAxi : xAxis) {
|
||||
if (xAxi.getDataeaseName().equals(key)) {
|
||||
return xAxi.getName();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static Integer setWidth(TableHeader.ColumnInfo column, Integer parentWidth) {
|
||||
if (org.springframework.util.CollectionUtils.isEmpty(column.getChildren())) {
|
||||
column.setWidth(parentWidth);
|
||||
return parentWidth;
|
||||
} else {
|
||||
Integer depth = 0;
|
||||
for (TableHeader.ColumnInfo child : column.getChildren()) {
|
||||
depth = depth + setWidth(child, 1);
|
||||
}
|
||||
column.setWidth(depth);
|
||||
return depth;
|
||||
}
|
||||
}
|
||||
|
||||
private static String cellValue(FormatterCfgDTO formatterCfgDTO, BigDecimal value) {
|
||||
if (formatterCfgDTO.getType().equalsIgnoreCase("percent")) {
|
||||
return value.toString();
|
||||
|
||||
@@ -3,7 +3,6 @@ package io.dataease.exportCenter.manage;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.google.gson.Gson;
|
||||
import io.dataease.api.chart.dto.ViewDetailField;
|
||||
import io.dataease.api.chart.request.ChartExcelRequest;
|
||||
import io.dataease.api.chart.request.ChartExcelRequestInner;
|
||||
@@ -489,7 +488,6 @@ public class ExportCenterManage implements BaseExportApi {
|
||||
rowPermissionsTree = permissionManage.getRowPermissionsTree(dto.getId(), user.getUserId());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(request.getExpressionTree())) {
|
||||
Gson gson = new Gson();
|
||||
DatasetRowPermissionsTreeObj datasetRowPermissionsTreeObj = JsonUtil.parseObject(request.getExpressionTree(), DatasetRowPermissionsTreeObj.class);
|
||||
permissionManage.getField(datasetRowPermissionsTreeObj);
|
||||
DataSetRowPermissionsTreeDTO dataSetRowPermissionsTreeDTO = new DataSetRowPermissionsTreeDTO();
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package io.dataease.api.visualization.vo;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.dataease.api.visualization.request.DataVisualizationBaseRequest;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package io.dataease.extensions.view.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class TableHeader {
|
||||
private HeaderGroupConfig headerGroupConfig;
|
||||
private boolean headerGroup;
|
||||
|
||||
|
||||
@Data
|
||||
static
|
||||
public class HeaderGroupConfig {
|
||||
private List<MetaInfo> meta = new ArrayList<>();
|
||||
private List<ColumnInfo> columns = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Data
|
||||
static
|
||||
public class ColumnInfo {
|
||||
@Getter
|
||||
private String key;
|
||||
private List<ColumnInfo> children = new ArrayList<>();
|
||||
private Integer width;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Data
|
||||
static
|
||||
public class MetaInfo {
|
||||
private String field;
|
||||
private String name;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user