From b1ec5a85ecd3b0678c243a03f4719c6857eae6b4 Mon Sep 17 00:00:00 2001 From: "Bruce.Deng" Date: Wed, 29 Nov 2023 10:36:08 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-108302=20=E6=A8=A1=E6=9D=BF=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/mainframe/JTemplate.java | 7 +++ .../chart/info/ChartInfoCollector.java | 54 +++++++++++-------- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index 29861255f2..00906a3117 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -1951,6 +1951,13 @@ public abstract class JTemplate> @Override public void saveDirectly() { + if (isSaving()) { + // 处理连按ctrl+s触发多线程保存的问题 + // 这里为什么可以不用加锁而直接判断isSaving: + // 实测actionPerformed有线程安全的特性,同一时间只有一个AWT线程走到这里,setSaving是线程安全的(SaveTemplateAction.actionPerformed) + // 多线程场景是因为我们用了SwingWorker子线程处理保存 + return; + } new SaveTypeWorker(getSaveTypeCallable(), this) { @Override protected void done() { diff --git a/designer-base/src/main/java/com/fr/design/mainframe/chart/info/ChartInfoCollector.java b/designer-base/src/main/java/com/fr/design/mainframe/chart/info/ChartInfoCollector.java index 7c19278c20..e8b726b2d6 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/chart/info/ChartInfoCollector.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/chart/info/ChartInfoCollector.java @@ -7,6 +7,7 @@ import com.fr.chartx.config.info.constant.ConfigType; import com.fr.design.mainframe.burying.point.AbstractPointCollector; import com.fr.design.mainframe.template.info.TemplateProcessInfo; import com.fr.general.ComparatorUtils; +import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLableReader; @@ -184,33 +185,44 @@ public class ChartInfoCollector extends AbstractPointCollector { */ @Override public void collectInfo(String templateId, String originID, TemplateProcessInfo processInfo, int timeConsume) { - if (!shouldCollectInfo()) { - return; - } - if (StringUtils.isEmpty(originID)) { - originID = templateId; - } - boolean testTemplate = isTestTemplate(processInfo); + // 捕获RuntimeException,不中断保存模板核心逻辑,避免出现保存失败弹窗 + try { + if (!shouldCollectInfo()) { + return; + } + if (StringUtils.isEmpty(originID)) { + originID = templateId; + } + boolean testTemplate = isTestTemplate(processInfo); - for (ChartInfo chartInfo : pointInfoMap.values()) { - if (originID.equals(chartInfo.getTemplateId())) { - chartInfo.setTemplateId(templateId); - chartInfo.setTestTemplate(testTemplate); + for (ChartInfo chartInfo : pointInfoMap.values()) { + if (chartInfo != null && originID.equals(chartInfo.getTemplateId())) { + chartInfo.setTemplateId(templateId); + chartInfo.setTestTemplate(testTemplate); + } } - } - for (ChartInfo chartInfo : chartInfoCacheMap.values()) { - BaseBook book = chartInfo.getBook(); - if ((book != null && templateId.equals(book.getTemplateID())) || - originID.equals(chartInfo.getTemplateId())) { - chartInfo.setTemplateId(templateId); - chartInfo.setTestTemplate(testTemplate); - pointInfoMap.put(chartInfo.getChartId(), chartInfo); + for (ChartInfo chartInfo : chartInfoCacheMap.values()) { + if (chartInfo == null) { + continue; + } + BaseBook book = chartInfo.getBook(); + if (accept(templateId, originID, chartInfo, book)) { + chartInfo.setTemplateId(templateId); + chartInfo.setTestTemplate(testTemplate); + pointInfoMap.put(chartInfo.getChartId(), chartInfo); + } } + // 每次更新之后,都同步到暂存文件中 + saveInfo(); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); } + } - // 每次更新之后,都同步到暂存文件中 - saveInfo(); + private static boolean accept(String templateId, String originID, ChartInfo chartInfo, BaseBook book) { + return (book != null && templateId.equals(book.getTemplateID())) || + originID.equals(chartInfo.getTemplateId()); } private boolean isTestTemplate(TemplateProcessInfo processInfo) {