Browse Source

REPORT-89260 && REPORT-83847 远程设计下卡顿以及规则异常

【问题原因】卡顿是因为查询数据库的操作放在了UI线程里;规则异常是因为规则管理器DesensitizationRuleManager中的规则缓存对环境切换时的监听写的有点问题
【改动思路】修复卡顿问题是加SwingWorker;规则异常这个,想了下DesensitizationRuleManager中的规则缓存此前只针对了本地规则变化、远程环境切换,但是没针对远程下的规则变化,而且好像没有太好的思路。现在的做法是直接去掉规则缓存,直接查数据库,套用Config框架的缓存
【review建议】
newui
Yvan-欧阳帆 2 years ago
parent
commit
254b7ce222
  1. 12
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java
  2. 89
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java

12
designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java

@ -2,6 +2,7 @@ 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;
@ -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;
@ -107,13 +111,17 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage
}
/**
* 通过TableData获取其列名
* 通过TableData获取其列名,理论上一定存在缓存值
*
* @param tableData
* @return
*/
public List<String> 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;
}
/**

89
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,9 +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;
@ -61,17 +64,15 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
private static final String COMMA = ",";
private DesensitizationTableData tableData;
/**
* 当前数据集的所有列名
*/
private List<String> columnNames;
private List<String> columnNames = new ArrayList<>();
/**
* key为用户组唯一标识id拼接value为用户组名称
*/
private Map<String, String> roleMap;
private final Map<String, String> roleMap = new LinkedHashMap<>();
private Component parent;
@ -84,12 +85,6 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
Toolkit.i18nText("Fine-Design_Report_Desensitization_Effected_Roles"),
Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status"),
});
// 一些数据相关
this.tableData = tableData;
// 获取当前数据集的所有列名
this.columnNames = TableDataPreviewDesensitizeManager.getInstance().getColumnNamesByTableData(tableData);
// 获取当前所有用户组
this.roleMap = TableDataPreviewDesensitizeManager.getInstance().getAllRoles();
this.parent = parent;
this.setColumnClass(new Class[]{
// 列名选择
@ -103,15 +98,41 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
// 规则状态
DesensitizationRuleStatusPane.class
});
this.setDefaultEditor(ColumnNamesComboBox.class, new ColumnNamesComboBox());
ColumnNamesComboBox columnNamesComboBox = new ColumnNamesComboBox();
this.setDefaultEditor(ColumnNamesComboBox.class, columnNamesComboBox);
this.setDefaultEditor(DesensitizationRuleChooser.class, new DesensitizationRuleChooser());
this.setDefaultEditor(DesensitizationRuleDescriptionPane.class, new DesensitizationRuleDescriptionPane());
this.setDefaultEditor(EffectedRolesChooser.class, new EffectedRolesChooser());
EffectedRolesChooser effectedRolesChooser = new EffectedRolesChooser();
this.setDefaultEditor(EffectedRolesChooser.class, effectedRolesChooser);
this.setDefaultEditor(DesensitizationRuleStatusPane.class, new DesensitizationRuleStatusPane());
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
@ -210,6 +231,10 @@ 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) {
@ -328,7 +353,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
private UIComboCheckBox rolesCheckBox;
EffectedRolesChooser() {
this.rolesCheckBox = new UIComboCheckBox(roleMap.values().toArray(), true) {
this.rolesCheckBox = new UIComboCheckBox(new String[]{}, true) {
@Override
protected void setLayoutAndAddComponents() {
// 使用BorderLayout,否则默认使用的FlowLayout会让整个下拉选框使用最小Size,然后TableCell这边会出现空白
@ -362,6 +387,10 @@ 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)));
@ -444,36 +473,6 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
}
}
/**
* 标签点击后处理原规则
*/
private void ruleStatusLabelClick(TableDataDesensitizationItem currentItem) {
DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(currentItem.getRule());
if (ruleStatus == DesensitizationRuleStatus.NORMAL) {
return;
}
// 点击Label后,弹窗提示
int option = FineJOptionPane.showConfirmDialog(
parent,
ruleStatus.getDescription(),
Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"),
FineJOptionPane.OK_CANCEL_OPTION,
FineJOptionPane.INFORMATION_MESSAGE);
if (option == FineJOptionPane.OK_OPTION && table.getSelectedRow() != -1) {
int selectedRow = table.getSelectedRow();
// 点击确定后,根据规则状态对规则做处理
if (ruleStatus == DesensitizationRuleStatus.REMOVED || ruleStatus == DesensitizationRuleStatus.WRONG) {
// 规则被删除或读取错误时,直接删掉
removeRow(selectedRow);
} else if (ruleStatus == DesensitizationRuleStatus.MODIFIED) {
// 规则被修改时,用新规则替换
DesensitizationRule lastedRule = DesensitizationRuleManager.getInstance().getLastedDesentizationRule(currentItem.getRule());
currentItem.setRule(lastedRule);
setRowAt(currentItem, selectedRow);
}
}
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
refreshRuleStatus(getList().get(row));

Loading…
Cancel
Save