fix: 脱敏规则展示错误

This commit is contained in:
taojinlong 2023-05-22 17:09:11 +08:00
parent 071181b2a7
commit 9408fcd0c8
2 changed files with 19 additions and 4 deletions

View File

@ -1,8 +1,8 @@
package io.dataease.service.chart.util;
import cn.hutool.core.util.ArrayUtil;
import io.dataease.plugins.common.base.domain.ChartViewWithBLOBs;
import io.dataease.dto.chart.*;
import io.dataease.plugins.common.base.domain.ChartViewWithBLOBs;
import io.dataease.plugins.common.dto.chart.ChartViewFieldDTO;
import io.dataease.plugins.xpack.auth.dto.request.ColumnPermissionItem;
import org.apache.commons.collections4.CollectionUtils;
@ -1071,11 +1071,11 @@ public class ChartDataBuild {
break;
}
if (originStr.length() >= columnPermissionItem.getDesensitizationRule().getM() && originStr.length() >= columnPermissionItem.getDesensitizationRule().getN()) {
desensitizationStr = "***" + StringUtils.substring(originStr, columnPermissionItem.getDesensitizationRule().getM() - 1, columnPermissionItem.getDesensitizationRule().getN()) + "***";
desensitizationStr = buildPrefix(columnPermissionItem.getDesensitizationRule().getM()) + StringUtils.substring(originStr, columnPermissionItem.getDesensitizationRule().getM() - 1, columnPermissionItem.getDesensitizationRule().getN()) + "***";
break;
}
if (originStr.length() >= columnPermissionItem.getDesensitizationRule().getM() && originStr.length() < columnPermissionItem.getDesensitizationRule().getN()) {
desensitizationStr = "***" + StringUtils.substring(originStr, columnPermissionItem.getDesensitizationRule().getM() - 1, originStr.length());
desensitizationStr = buildPrefix(columnPermissionItem.getDesensitizationRule().getM()) + StringUtils.substring(originStr, columnPermissionItem.getDesensitizationRule().getM() - 1, originStr.length());
}
break;
default:
@ -1086,6 +1086,18 @@ public class ChartDataBuild {
return desensitizationStr;
}
private static String buildPrefix(Integer integer) {
String prefix = "";
if (integer <= 1) {
return prefix;
}
for (int i = 0; i < integer - 1; i++) {
prefix = prefix + "*";
}
return prefix;
}
private static Map<String, Object> transTableNormal(List<ChartViewFieldDTO> fields, ChartViewWithBLOBs view, List<String[]> data, Map<String, ColumnPermissionItem> desensitizationList) {
Map<String, Object> map = new TreeMap<>();
List<Map<String, Object>> tableRow = new ArrayList<>();

View File

@ -208,7 +208,10 @@ public class PermissionService {
dataSetColumnPermissionsDTO.setDatasetId(datasetId);
dataSetColumnPermissionsDTO.setAuthTargetIds(Collections.singletonList(userId));
dataSetColumnPermissionsDTO.setAuthTargetType("user");
datasetColumnPermissions.addAll(columnPermissionService.searchPermissions(dataSetColumnPermissionsDTO));
List<DataSetColumnPermissionsDTO> dataSetColumnPermissionsDTOS = columnPermissionService.searchPermissions(dataSetColumnPermissionsDTO);
if(CollectionUtils.isNotEmpty(dataSetColumnPermissionsDTOS)){
datasetColumnPermissions.addAll(dataSetColumnPermissionsDTOS);
}
if (CollectionUtils.isNotEmpty(roleIds)) {
DataSetColumnPermissionsDTO request = new DataSetColumnPermissionsDTO();
request.setDatasetId(datasetId);