Browse Source

REPORT-80693 数据脱敏远程设计下的性能问题

【问题原因】rt
【改动思路】再改一版远程下的性能问题
1. 之前的SwingWorker提前到父容器页面,只查询一次数据库,此后面板与子面板均复用
2. 增加Loading页面,避免卡UI的误会
3. 修改规则管理器DesensitizationRuleManager中的接口方法,倒逼调用者使用一次性的查询;以及相应调用接口方法适配
【review建议】
release/11.0
Yvan-欧阳帆 2 years ago
parent
commit
76a26bb37f
  1. 14
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleChoosePane.java
  2. 11
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRulePane.java
  3. 76
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java
  4. 97
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTablePane.java

14
designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleChoosePane.java

@ -28,6 +28,7 @@ import java.awt.Component;
import java.awt.event.ActionEvent;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@ -48,7 +49,10 @@ public class DesensitizationRuleChoosePane extends JPanel {
private DesensitizationRuleSource currentRuleSource;
public DesensitizationRuleChoosePane() {
private Map<DesensitizationRuleSource, Map<String, DesensitizationRule>> lastedRules;
public DesensitizationRuleChoosePane(Map<DesensitizationRuleSource, Map<String, DesensitizationRule>> lastedRules) {
this.lastedRules = lastedRules;
this.cardLayout = new CardLayout();
this.setLayout(cardLayout);
serverRuleEditPane = new UITableEditorPane<>(new DesensitizationRuleChooseTableModel(this, true));
@ -76,8 +80,8 @@ public class DesensitizationRuleChoosePane extends JPanel {
* 展示当前规则
*/
private void populateDesensitizationRules() {
serverRuleEditPane.populate(DesensitizationRuleManager.getInstance().getRules(DesensitizationRuleSource.SERVER));
customRuleEditPane.populate(DesensitizationRuleManager.getInstance().getRules(DesensitizationRuleSource.CUSTOM));
serverRuleEditPane.populate(lastedRules.get(DesensitizationRuleSource.SERVER).values().toArray(new DesensitizationRule[0]));
customRuleEditPane.populate(lastedRules.get(DesensitizationRuleSource.CUSTOM).values().toArray(new DesensitizationRule[0]));
}
/**
@ -143,7 +147,7 @@ public class DesensitizationRuleChoosePane extends JPanel {
return DesensitizationRule.getDescription(rule);
case 3:
// 脱敏规则状态
DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule);
DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule, lastedRules);
// 非正常状态需要标记为异常
return ruleStatus == DesensitizationRuleStatus.NORMAL ? StringUtils.EMPTY : Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status_Abnormal");
default:
@ -192,7 +196,7 @@ public class DesensitizationRuleChoosePane extends JPanel {
* @param rule
*/
public void refreshRuleStatus(DesensitizationRule rule) {
DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule);
DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule, lastedRules);
if (ruleStatus == DesensitizationRuleStatus.NORMAL) {
// 正常规则时,重置提示Label
this.ruleStatusLabel.setText(StringUtils.EMPTY);

11
designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRulePane.java

@ -9,6 +9,7 @@ import com.fr.design.layout.FRGUIPaneFactory;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.util.Map;
/**
* 脱敏规则展示页
@ -29,13 +30,19 @@ public class DesensitizationRulePane extends BasicBeanPane<DesensitizationRule>
*/
private DesensitizationRuleChoosePane ruleChoosePane;
/**
* 最新的所有规则
*/
private Map<DesensitizationRuleSource, Map<String, DesensitizationRule>> lastedRules;
/**
* 内容面板
*/
private JPanel contentPane;
public DesensitizationRulePane() {
public DesensitizationRulePane(Map<DesensitizationRuleSource, Map<String, DesensitizationRule>> lastedRules) {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.lastedRules = lastedRules;
initPane();
}
@ -47,7 +54,7 @@ public class DesensitizationRulePane extends BasicBeanPane<DesensitizationRule>
// 规则来源选择Pane
ruleSourceChoosePane = new DesensitizationRuleSourceChoosePane(this);
// 规则选择Pane
ruleChoosePane = new DesensitizationRuleChoosePane();
ruleChoosePane = new DesensitizationRuleChoosePane(lastedRules);
contentPane.add(ruleSourceChoosePane, BorderLayout.NORTH);
contentPane.add(ruleChoosePane, BorderLayout.CENTER);
}

76
designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java

@ -4,8 +4,8 @@ import com.fr.data.desensitize.base.DesensitizationTableData;
import com.fr.data.desensitize.base.TableDataDesensitizationItem;
import com.fr.data.desensitize.rule.DesensitizationRuleManager;
import com.fr.data.desensitize.rule.base.DesensitizationRule;
import com.fr.data.desensitize.rule.base.DesensitizationRuleSource;
import com.fr.data.desensitize.rule.base.DesensitizationRuleStatus;
import com.fr.design.data.datapane.preview.desensitization.TableDataPreviewDesensitizeManager;
import com.fr.design.data.datapane.preview.desensitization.view.rule.DesensitizationRulePane;
import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.DialogActionAdapter;
@ -20,7 +20,6 @@ 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,7 +28,6 @@ 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;
@ -72,11 +70,16 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
/**
* key为用户组唯一标识id拼接value为用户组名称
*/
private final Map<String, String> roleMap = new LinkedHashMap<>();
private Map<String, String> roleMap = new LinkedHashMap<>();
/**
* 当前最新的所有规则
*/
private Map<DesensitizationRuleSource, Map<String, DesensitizationRule>> lastedRules = new LinkedHashMap<>();
private Component parent;
public TableDataDesensitizationTableModel(DesensitizationTableData tableData, Component parent) {
public TableDataDesensitizationTableModel(DesensitizationTableData tableData, Component parent, List<String> columnNames, Map<String, String> roleMap, Map<DesensitizationRuleSource, Map<String, DesensitizationRule>> lastedRules) {
// table相关
super(new String[]{
Toolkit.i18nText("Fine-Design_Report_Desensitization_Column"),
@ -86,6 +89,17 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status"),
});
this.parent = parent;
this.columnNames = columnNames;
this.roleMap = roleMap;
this.lastedRules = lastedRules;
initTable();
}
/**
* 初始化Table
*/
private void initTable() {
this.setColumnClass(new Class[]{
// 列名选择
ColumnNamesComboBox.class,
@ -108,31 +122,6 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
this.setDefaultRenderer(DesensitizationRuleStatusPane.class, new DesensitizationRuleStatusPane());
this.createTable().getColumnModel().getColumn(TableSequences.DesensitizationRuleStatus.getNum()).setMaxWidth(60);
new SwingWorker<Void, Void>() {
@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
@ -231,14 +220,6 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
});
}
/**
* 查询到数据集列名后更新到下拉框中
*/
public void refresh() {
columnNameComboBox.refreshBoxItems(columnNames);
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
columnNameComboBox.setSelectedItem(getList().get(row).getColumnName());
@ -269,14 +250,14 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
private ActionListener chooseRuleListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DesensitizationRulePane rulePane = new DesensitizationRulePane();
DesensitizationRulePane rulePane = new DesensitizationRulePane(lastedRules);
TableDataDesensitizationItem desensitizationItem = getCurrentSelectBean();
int selectedRow = table.getSelectedRow();
BasicDialog ruleDialog = rulePane.showWindowWithCustomSize(SwingUtilities.getWindowAncestor(parent), new DialogActionAdapter() {
@Override
public void doOk() {
DesensitizationRule rule = rulePane.updateBean();
if (Objects.nonNull(desensitizationItem) && Objects.nonNull(rule)) {
if (Objects.nonNull(desensitizationItem) && DesensitizationRule.valid(rule)) {
desensitizationItem.setRule(rule);
desensitizationItem.setRuleName(rule.getRuleName());
// 刷新规则名称、描述、状态
@ -356,7 +337,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
private UIComboCheckBox rolesCheckBox;
EffectedRolesChooser() {
this.rolesCheckBox = new UIComboCheckBox(new String[]{}, true) {
this.rolesCheckBox = new UIComboCheckBox(roleMap.values().toArray(), true) {
@Override
protected void setLayoutAndAddComponents() {
// 使用BorderLayout,否则默认使用的FlowLayout会让整个下拉选框使用最小Size,然后TableCell这边会出现空白
@ -390,13 +371,6 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
});
}
/**
* 查询到所有用户组后更新到下拉框中
*/
public void refresh() {
rolesCheckBox.refreshCombo(roleMap.values().toArray());
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
rolesCheckBox.setSelectedValues(generateRolesCheckBoxSelectedValues(getList().get(row)));
@ -469,7 +443,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
DesensitizationRule rule = currentItem.getRule();
if (needMarkRule(rule)) {
// 非正常规则,根据规则状态展示不同提示文字
DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule);
DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule, lastedRules);
this.ruleStatusLabel.setText(Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status_Abnormal"));
this.ruleStatusLabel.setToolTipText(ruleStatus.getDescription());
} else {
@ -542,13 +516,13 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
Iterator<TableDataDesensitizationItem> iterator = items.iterator();
while (iterator.hasNext()) {
TableDataDesensitizationItem item = iterator.next();
DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(item.getRule());
DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(item.getRule(), lastedRules);
if (ruleStatus == DesensitizationRuleStatus.REMOVED) {
// 规则被移除,则删除整条脱敏Item
iterator.remove();
} else {
// 规则被修改、禁用等,更新一下规则
item.setRule(DesensitizationRuleManager.getInstance().getLastedDesentizationRule(item.getRule()));
item.setRule(DesensitizationRuleManager.getInstance().getLastedDesentizationRule(item.getRule(), lastedRules));
}
}
fireTableDataChanged();

97
designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTablePane.java

@ -2,13 +2,25 @@ package com.fr.design.data.datapane.preview.desensitization.view.setting;
import com.fr.data.desensitize.base.DesensitizationTableData;
import com.fr.data.desensitize.base.TableDataDesensitizationItem;
import com.fr.data.desensitize.rule.DesensitizationRuleManager;
import com.fr.data.desensitize.rule.base.DesensitizationRule;
import com.fr.data.desensitize.rule.base.DesensitizationRuleSource;
import com.fr.design.data.datapane.preview.desensitization.TableDataPreviewDesensitizeManager;
import com.fr.design.data.tabledata.tabledatapane.loading.TipsPane;
import com.fr.design.gui.itableeditorpane.UITableEditorPane;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.log.FineLoggerFactory;
import javax.swing.JPanel;
import javax.swing.SwingWorker;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Component;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 脱敏字段设置页面中的Table
@ -34,6 +46,15 @@ public class TableDataDesensitizationTablePane extends JPanel {
*/
private UITableEditorPane<TableDataDesensitizationItem> editorPane;
private static final String LOADING_PANE = "loading";
private static final String CONTENT_PANE = "content";
private CardLayout card;
private JPanel loadingPane;
private JPanel contentPane;
public TableDataDesensitizationTablePane(DesensitizationTableData tableData, Component parent) {
this.tableData = tableData;
this.parent = parent;
@ -41,10 +62,65 @@ public class TableDataDesensitizationTablePane extends JPanel {
}
private void initComponent() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.editorPane = new UITableEditorPane<>(new TableDataDesensitizationTableModel(tableData, parent));
this.editorPane.setHeaderResizing(false);
this.add(editorPane, BorderLayout.CENTER);
card = new CardLayout();
this.setLayout(card);
// 初始化Loading面板
loadingPane = new TipsPane(true);
this.add(LOADING_PANE, loadingPane);
switchTo(LOADING_PANE);
// 在SwingWorker中初始化Content面板并切换
initContent();
}
/**
* 初始化内容面板
* 考虑到远程设计下的性能需要限制查询数据库的次数所以这里查一次之后子面板内复用
*/
private void initContent() {
final List<String> columnNames = new ArrayList<>();
final Map<String, String> roleMap = new LinkedHashMap<>();
final Map<DesensitizationRuleSource, Map<String, DesensitizationRule>> lastedRules = new LinkedHashMap<>();
new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
// 获取当前数据集的所有列名
columnNames.addAll(TableDataPreviewDesensitizeManager.getInstance().getColumnNamesByTableData(tableData));
// 获取当前所有用户组
roleMap.putAll(TableDataPreviewDesensitizeManager.getInstance().getAllRoles());
// 获取当前最新的所有规则
lastedRules.putAll(DesensitizationRuleManager.getInstance().getAllRules());
return null;
}
@Override
protected void done() {
contentPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
editorPane = new UITableEditorPane<>(new TableDataDesensitizationTableModel(tableData, parent, columnNames, roleMap, lastedRules));
editorPane.setHeaderResizing(false);
editorPane.populate(tableData.getDesensitizationConfig().getDesensitizationItems().toArray(new TableDataDesensitizationItem[0]));
contentPane.add(editorPane, BorderLayout.CENTER);
add(CONTENT_PANE, contentPane);
switchTo(CONTENT_PANE);
}
}.execute();
}
/**
* 切换面板
*
* @param panelName
*/
public void switchTo(String panelName) {
try {
if (panelName != null) {
card.show(this, panelName);
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
/**
@ -54,13 +130,22 @@ public class TableDataDesensitizationTablePane extends JPanel {
*/
public void populateDesensitizationSetting(DesensitizationTableData tableData) {
this.tableData = tableData;
editorPane.populate(tableData.getDesensitizationConfig().getDesensitizationItems().toArray(new TableDataDesensitizationItem[0]));
if (editorPane != null) {
// editorPane的初始化在SwingWorker中完成,这里做个判空
editorPane.populate(tableData.getDesensitizationConfig().getDesensitizationItems().toArray(new TableDataDesensitizationItem[0]));
}
}
/**
* 获取当前对TableData的配置脱敏规则信息
*/
public List<TableDataDesensitizationItem> updateDesensitizationSetting() {
return editorPane.update();
return editorPane == null ?
new ArrayList<>() :
editorPane.update()
.stream()
.filter(item -> TableDataDesensitizationItem.valid(item))
.collect(Collectors.toList());
}
}

Loading…
Cancel
Save