fix: 下载视图原始数据时,不计算聚合字段

This commit is contained in:
taojinlong 2024-09-19 20:01:07 +08:00
parent c2a3f632f6
commit 51fa222980
2 changed files with 25 additions and 6 deletions

View File

@ -12,6 +12,7 @@ import io.dataease.extensions.datasource.provider.Provider;
import io.dataease.extensions.view.dto.*;
import io.dataease.extensions.view.util.ChartDataUtil;
import io.dataease.extensions.view.util.FieldUtil;
import io.dataease.utils.JsonUtil;
import lombok.Getter;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
@ -85,6 +86,20 @@ public class TableInfoHandler extends DefaultChartHandler {
pageInfo.setPageSize(chartExtRequest.getPageSize());
}
Dimension2SQLObj.dimension2sqlObj(sqlMeta, xAxis, FieldUtil.transFields(allFields), crossDs, dsMap, Utils.getParams(FieldUtil.transFields(allFields)), view.getCalParams(), pluginManage);
if(view.getIsExcelExport()){
for (int i = 0; i < xAxis.size(); i++) {
ChartViewFieldDTO fieldDTO = null;
for (int i1 = 0; i1 < allFields.size(); i1++) {
if (allFields.get(i1).getId().equals(xAxis.get(i).getId())) {
fieldDTO = allFields.get(i1);
}
}
if (fieldDTO.isAgg()) {
sqlMeta.getXFields().get(i).setFieldName("'-'");
}
}
}
String originSql = SQLProvider.createQuerySQL(sqlMeta, false, true, view);// 明细表强制加排序
String limit = ((pageInfo.getGoPage() != null && pageInfo.getPageSize() != null) ? " LIMIT " + pageInfo.getPageSize() + " OFFSET " + (pageInfo.getGoPage() - 1) * chartExtRequest.getPageSize() : "");
var querySql = originSql + limit;

View File

@ -423,7 +423,7 @@ public class ChartDataBuild {
axisChartDataDTO.setValue(new BigDecimal(0));
}
axisChartDataDTO.setCategory(StringUtils.defaultIfBlank(yAxis.get(j).getChartShowName(), yAxis.get(j).getName()));
buildDynamicValue(view, axisChartDataDTO, row, size, ObjectUtils.isNotEmpty(extBubble)?extSize-1:extSize);
buildDynamicValue(view, axisChartDataDTO, row, size, ObjectUtils.isNotEmpty(extBubble) ? extSize - 1 : extSize);
// pop
if (ObjectUtils.isNotEmpty(extBubble)) {
try {
@ -1296,7 +1296,11 @@ public class ChartDataBuild {
if (chartViewFieldDTO.getDeType() == 0 || chartViewFieldDTO.getDeType() == 1 || chartViewFieldDTO.getDeType() == 5 || chartViewFieldDTO.getDeType() == 7) {
d.put(fields.get(i).getDataeaseName(), StringUtils.isEmpty(ele[i]) ? "" : ele[i]);
} else if (chartViewFieldDTO.getDeType() == 2 || chartViewFieldDTO.getDeType() == 3 || chartViewFieldDTO.getDeType() == 4) {
d.put(fields.get(i).getDataeaseName(), StringUtils.isEmpty(ele[i]) ? null : new BigDecimal(ele[i]).setScale(8, RoundingMode.HALF_UP));
if (view.getIsExcelExport()) {
d.put(fields.get(i).getDataeaseName(), StringUtils.isEmpty(ele[i]) ? "" : ele[i]);
} else {
d.put(fields.get(i).getDataeaseName(), StringUtils.isEmpty(ele[i]) ? null : new BigDecimal(ele[i]).setScale(8, RoundingMode.HALF_UP));
}
}
}
tableRow.add(d);
@ -1764,7 +1768,7 @@ public class ChartDataBuild {
List<Map<String, Object>> tableRow = (List<Map<String, Object>>) map.get("tableRow");
final int xEndIndex = detailIndex;
Map<String, List<String[]>> groupDataList = detailData.stream().collect(Collectors.groupingBy(item -> "(" + StringUtils.join(ArrayUtils.subarray(item, 0, xEndIndex), ")-de-(") + ")"));
String extBubbleDataeaseName = ObjectUtils.isNotEmpty(extBubble)?extBubble.get(0).getDataeaseName():"";
String extBubbleDataeaseName = ObjectUtils.isNotEmpty(extBubble) ? extBubble.get(0).getDataeaseName() : "";
tableRow.forEach(row -> {
BigDecimal rowValue = row.get(extBubbleDataeaseName) == null ? BigDecimal.ZERO : new BigDecimal(row.get(extBubbleDataeaseName).toString());
String key = xAxis.stream().map(x -> String.format(format, row.get(x.getDataeaseName()).toString())).collect(Collectors.joining("-de-"));
@ -1773,16 +1777,16 @@ public class ChartDataBuild {
Map<String, Object> temp = new HashMap<>();
for (int i = 0; i < realDetailFields.size(); i++) {
ChartViewFieldDTO realDetailField = realDetailFields.get(i);
if(StringUtils.equalsIgnoreCase(extBubbleDataeaseName,realDetailField.getDataeaseName())){
if (StringUtils.equalsIgnoreCase(extBubbleDataeaseName, realDetailField.getDataeaseName())) {
temp.put(realDetailField.getDataeaseName(), rowValue);
}else{
} else {
temp.put(realDetailField.getDataeaseName(), detailArr[detailIndex + i]);
}
}
return temp;
})).collect(Collectors.toList());
//详情只要一个
row.put("details", !detailValueMapList.isEmpty() ?Collections.singletonList(detailValueMapList.getFirst()):detailValueMapList);
row.put("details", !detailValueMapList.isEmpty() ? Collections.singletonList(detailValueMapList.getFirst()) : detailValueMapList);
});
// 先过滤掉所有记录数字段
List<ChartViewFieldDTO> filterCountAxis = fields.stream()