From bdc3ee6360b2ef2a43b3b47897f98474353379a6 Mon Sep 17 00:00:00 2001 From: wisonic-s Date: Tue, 2 Jul 2024 23:59:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E8=84=B1=E6=95=8F?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E9=83=A8=E5=88=86=E5=9C=BA=E6=99=AF=E5=A4=B1?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chart/charts/impl/DefaultChartHandler.java | 7 +++++++ .../chart/charts/impl/YoyChartHandler.java | 3 ++- .../charts/impl/table/TableInfoHandler.java | 3 +-- .../dataease/chart/manage/ChartDataManage.java | 16 +++++----------- .../io/dataease/chart/utils/ChartDataBuild.java | 6 ++++-- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/core/core-backend/src/main/java/io/dataease/chart/charts/impl/DefaultChartHandler.java b/core/core-backend/src/main/java/io/dataease/chart/charts/impl/DefaultChartHandler.java index 3c13d42bf7..a56f24e622 100644 --- a/core/core-backend/src/main/java/io/dataease/chart/charts/impl/DefaultChartHandler.java +++ b/core/core-backend/src/main/java/io/dataease/chart/charts/impl/DefaultChartHandler.java @@ -27,6 +27,7 @@ import jakarta.annotation.PostConstruct; import jakarta.annotation.Resource; import lombok.Getter; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -71,6 +72,12 @@ public class DefaultChartHandler extends AbstractChartPlugin { @Override public T customFilter(ChartViewDTO view, List filterList, AxisFormatResult formatResult) { + var desensitizationList = (Map) formatResult.getContext().get("desensitizationList"); + if (MapUtils.isNotEmpty(desensitizationList)) { + formatResult.getAxisMap().forEach((axis, fields) -> { + fields.removeIf(f -> desensitizationList.containsKey(f.getDataeaseName())); + }); + } return (T) new CustomFilterResult(filterList, formatResult.getContext()); } diff --git a/core/core-backend/src/main/java/io/dataease/chart/charts/impl/YoyChartHandler.java b/core/core-backend/src/main/java/io/dataease/chart/charts/impl/YoyChartHandler.java index 73b4c61f39..1f257d7df7 100644 --- a/core/core-backend/src/main/java/io/dataease/chart/charts/impl/YoyChartHandler.java +++ b/core/core-backend/src/main/java/io/dataease/chart/charts/impl/YoyChartHandler.java @@ -26,6 +26,7 @@ import java.util.Map; public class YoyChartHandler extends DefaultChartHandler { @Override public T customFilter(ChartViewDTO view, List filterList, AxisFormatResult formatResult) { + var result = super.customFilter(view, filterList, formatResult); var yAxis = formatResult.getAxisMap().get(ChartAxis.yAxis); String originFilterJson = (String) JsonUtil.toJSONString(filterList); // 如果设置了同环比的指标字段设置了过滤器,那就需要把该过滤器的时间往前回调一年 @@ -37,7 +38,7 @@ public class YoyChartHandler extends DefaultChartHandler { formatResult.getContext().put("originFilter", originFilter); formatResult.getContext().put("yoyFiltered", true); } - return (T) new CustomFilterResult(filterList, formatResult.getContext()); + return (T) result; } @Override diff --git a/core/core-backend/src/main/java/io/dataease/chart/charts/impl/table/TableInfoHandler.java b/core/core-backend/src/main/java/io/dataease/chart/charts/impl/table/TableInfoHandler.java index b0d9feecbd..6fe1f993de 100644 --- a/core/core-backend/src/main/java/io/dataease/chart/charts/impl/table/TableInfoHandler.java +++ b/core/core-backend/src/main/java/io/dataease/chart/charts/impl/table/TableInfoHandler.java @@ -62,7 +62,7 @@ public class TableInfoHandler extends DefaultChartHandler { chartExtRequest.setPageSize(null); } } - return super.customFilter(view, filterList, formatResult); + return (T) new CustomFilterResult(filterList, formatResult.getContext()); } @Override @@ -73,7 +73,6 @@ public class TableInfoHandler extends DefaultChartHandler { for (Map.Entry next : dsMap.entrySet()) { dsList.add(next.getValue().getType()); } - boolean needOrder = Utils.isNeedOrder(dsList); boolean crossDs = Utils.isCrossDs(dsMap); DatasourceRequest datasourceRequest = new DatasourceRequest(); datasourceRequest.setDsList(dsMap); diff --git a/core/core-backend/src/main/java/io/dataease/chart/manage/ChartDataManage.java b/core/core-backend/src/main/java/io/dataease/chart/manage/ChartDataManage.java index 31394eaa8a..6c319ab395 100644 --- a/core/core-backend/src/main/java/io/dataease/chart/manage/ChartDataManage.java +++ b/core/core-backend/src/main/java/io/dataease/chart/manage/ChartDataManage.java @@ -136,19 +136,9 @@ public class ChartDataManage { formatResult.getContext().put("allFields", allFields); var axisMap = formatResult.getAxisMap(); axisMap.forEach((axis, fields) -> { - Iterator iterator = fields.iterator(); - while (iterator.hasNext()) { - ChartViewFieldDTO fieldDTO = iterator.next(); - if (!dataeaseNames.contains(fieldDTO.getDataeaseName())) { - iterator.remove(); - } - } + fields.removeIf(fieldDTO -> !dataeaseNames.contains(fieldDTO.getDataeaseName())); }); - if (ObjectUtils.isEmpty(xAxis) && ObjectUtils.isEmpty(yAxis)) { - return emptyChartViewDTO(view); - } - // 过滤来自仪表板的条件 List extFilterList = new ArrayList<>(); //组件过滤条件 @@ -325,6 +315,10 @@ public class ChartDataManage { }).collect(Collectors.toList()); // 视图自定义过滤逻辑 CustomFilterResult filterResult = chartHandler.customFilter(view, extFilterList, formatResult); + + if (ObjectUtils.isEmpty(xAxis) && ObjectUtils.isEmpty(yAxis)) { + return emptyChartViewDTO(view); + } // 字段过滤器 FilterTreeObj fieldCustomFilter = view.getCustomFilter(); chartFilterTreeService.searchFieldAndSet(fieldCustomFilter); diff --git a/core/core-backend/src/main/java/io/dataease/chart/utils/ChartDataBuild.java b/core/core-backend/src/main/java/io/dataease/chart/utils/ChartDataBuild.java index 881e2550a2..a5c4b88e38 100644 --- a/core/core-backend/src/main/java/io/dataease/chart/utils/ChartDataBuild.java +++ b/core/core-backend/src/main/java/io/dataease/chart/utils/ChartDataBuild.java @@ -1311,8 +1311,10 @@ public class ChartDataBuild { data.forEach(ele -> { Map d = new HashMap<>(); for (int i = 0; i < fields.size(); i++) { - if (ObjectUtils.isNotEmpty(desensitizationList.keySet()) && desensitizationList.keySet().contains(fields.get(i).getDataeaseName())) { - d.put(fields.get(i).getDataeaseName(), desensitizationValue(desensitizationList.get(fields.get(i).getDataeaseName()), String.valueOf(ele[i]))); + if (ObjectUtils.isNotEmpty(desensitizationList.keySet()) && desensitizationList.containsKey(fields.get(i).getDataeaseName())) { + String desensitizationValue = desensitizationValue(desensitizationList.get(fields.get(i).getDataeaseName()), String.valueOf(ele[i])); + ele[i] = desensitizationValue; + d.put(fields.get(i).getDataeaseName(), desensitizationValue); continue; } if (i == ele.length) break;