forked from github/dataease
Merge pull request #10741 from dataease/pr@dev-v2@fix_desensitization
fix(图表): 脱敏字段部分场景失效
This commit is contained in:
commit
0bcaee047c
@ -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 extends CustomFilterResult> T customFilter(ChartViewDTO view, List<ChartExtFilterDTO> filterList, AxisFormatResult formatResult) {
|
||||
var desensitizationList = (Map<String, ColumnPermissionItem>) 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());
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ import java.util.Map;
|
||||
public class YoyChartHandler extends DefaultChartHandler {
|
||||
@Override
|
||||
public <T extends CustomFilterResult> T customFilter(ChartViewDTO view, List<ChartExtFilterDTO> 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
|
||||
|
@ -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<Long, DatasourceSchemaDTO> 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);
|
||||
|
@ -136,19 +136,9 @@ public class ChartDataManage {
|
||||
formatResult.getContext().put("allFields", allFields);
|
||||
var axisMap = formatResult.getAxisMap();
|
||||
axisMap.forEach((axis, fields) -> {
|
||||
Iterator<ChartViewFieldDTO> 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<ChartExtFilterDTO> 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);
|
||||
|
@ -1311,8 +1311,10 @@ public class ChartDataBuild {
|
||||
data.forEach(ele -> {
|
||||
Map<String, Object> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user