diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java index 29e12bfaf4..5c2b42c257 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java @@ -2,10 +2,11 @@ package com.fr.design.data.datapane.preview.desensitization; import com.fr.base.TableData; +import com.fr.data.TableDataSource; +import com.fr.data.desensitize.TableDataDesensitizeManager; import com.fr.data.desensitize.base.DesensitizationTableData; import com.fr.data.desensitize.base.TableDataDesensitizationItem; import com.fr.data.desensitize.manage.DesensitizationManager; -import com.fr.data.desensitize.rule.DesensitizationRuleManager; import com.fr.data.desensitize.util.DesentizationUtils; import com.fr.decision.webservice.bean.user.DepartmentPostBean; import com.fr.decision.webservice.bean.user.RoleBean; @@ -15,11 +16,14 @@ import com.fr.decision.webservice.v10.user.PositionService; import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.datapane.preview.PreviewTableModel; import com.fr.design.data.datapane.preview.desensitization.model.DesensitizedPreviewTableModel; +import com.fr.esd.query.StrategicTableData; import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; @@ -79,7 +83,7 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage Collection desensitizationItems = ((DesensitizationTableData) tableData).getDesensitizationConfig().getDesensitizationItems(); if (DesentizationUtils.isCollectionNotEmpty(desensitizationItems)) { // 更新规则 - dealWithLastedRules(desensitizationItems); + desensitizationItems = TableDataDesensitizeManager.getInstance().dealWithLastedRules(desensitizationItems); // 对脱敏配置项集合做过滤和排序处理 List items = desensitizationItems.stream() .filter(item -> isAvaliableItem4Preview(item, model)) @@ -107,23 +111,17 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage } /** - * 在预览计算前,将Item中的规则替换为最新规则(防止平台规则被临时修改) - */ - private void dealWithLastedRules(Collection desensitizationItems) { - desensitizationItems.forEach(item -> { - // 获取最新的规则 - item.setRule(DesensitizationRuleManager.getInstance().getLastedDesentizationRule(item.getRule())); - }); - } - - /** - * 通过TableData获取其列名 + * 通过TableData获取其列名,理论上一定存在缓存值 * * @param tableData * @return */ public List getColumnNamesByTableData(TableData tableData) { - return DesignTableDataManager.getColumnNamesByTableData(tableData); + TableDataSource editingTableDataSource = DesignTableDataManager.getEditingTableDataSource(); + if (editingTableDataSource != null && tableData instanceof StrategicTableData) { + return Arrays.asList(DesignTableDataManager.getSelectedColumnNames(editingTableDataSource, ((StrategicTableData) tableData).getDsName())); + } + return Collections.EMPTY_LIST; } /** @@ -185,7 +183,7 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage * @param positionName * @return */ - public String mergeRoleText(String departmentName, String positionName) { + private String mergeRoleText(String departmentName, String positionName) { return departmentName + positionName; } @@ -196,7 +194,7 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage * @param positionId * @return */ - public String mergeRoleId(String departmentId, String positionId) { + private String mergeRoleId(String departmentId, String positionId) { return departmentId + CONNECTOR + positionId; } diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java index 4d6cfa8ff6..e70f5e2cea 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java @@ -9,7 +9,6 @@ import com.fr.design.data.datapane.preview.desensitization.TableDataPreviewDesen import com.fr.design.data.datapane.preview.desensitization.view.rule.DesensitizationRulePane; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionAdapter; -import com.fr.design.dialog.FineJOptionPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.icombocheckbox.UIComboCheckBox; @@ -21,6 +20,7 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; +import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; import org.jetbrains.annotations.Nullable; @@ -29,6 +29,7 @@ import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.SwingUtilities; +import javax.swing.SwingWorker; import javax.swing.event.CellEditorListener; import javax.swing.event.ChangeEvent; import javax.swing.table.TableCellEditor; @@ -38,8 +39,11 @@ import java.awt.Color; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -60,17 +64,15 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter columnNames; + private List columnNames = new ArrayList<>(); /** * key为用户组唯一标识(id拼接),value为用户组名称 */ - private Map roleMap; + private final Map roleMap = new LinkedHashMap<>(); private Component parent; @@ -83,12 +85,6 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter() { + + @Override + protected Void doInBackground() throws Exception { + // 获取当前数据集的所有列名 + columnNames.addAll(TableDataPreviewDesensitizeManager.getInstance().getColumnNamesByTableData(tableData)); + // 获取当前所有用户组 + roleMap.putAll(TableDataPreviewDesensitizeManager.getInstance().getAllRoles()); + return null; + } + + @Override + protected void done() { + try { + // 更新列名选择框和生效用户组选择框 + columnNamesComboBox.refresh(); + effectedRolesChooser.refresh(); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e, "[Desensitization] get column names or all roles failed for {}", e.getMessage()); + } + } + }.execute(); + } @Override @@ -132,9 +154,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter items = getList(); + Iterator iterator = items.iterator(); + while (iterator.hasNext()) { + TableDataDesensitizationItem item = iterator.next(); + DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(item.getRule()); + if (ruleStatus == DesensitizationRuleStatus.REMOVED) { + // 规则被移除,则删除整条脱敏Item + iterator.remove(); + } else { + // 规则被修改、禁用等,更新一下规则 + item.setRule(DesensitizationRuleManager.getInstance().getLastedDesentizationRule(item.getRule())); + } + } + fireTableDataChanged(); + } + + @Override + public void checkEnabled() {} + } + /** * 规则表-列字段编号 */ @@ -580,4 +620,16 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter + + icon_刷新_normal + + + + \ No newline at end of file