From 293fd4ff876010afb0e9245d1a26eb24e0495881 Mon Sep 17 00:00:00 2001 From: Harrison Date: Fri, 10 Jun 2022 15:37:14 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-73396=E3=80=90=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=99=A8=E7=8E=AF=E5=A2=83=E7=9B=91=E6=B5=8B=E3=80=91=E5=88=A0?= =?UTF-8?q?=E9=99=A4fine-decision-11.0=EF=BC=8C=E8=A7=A6=E5=8F=91=E7=9A=84?= =?UTF-8?q?=E6=98=AF=E9=87=8D=E7=BD=AEfinedb=20=E5=BD=93=E9=81=87=E5=88=B0?= =?UTF-8?q?=20finedb=20=E5=BC=82=E5=B8=B8=E5=8D=B4=E6=98=AF=E7=BC=BA?= =?UTF-8?q?=E5=B0=91=20JAR=20=E5=AF=BC=E8=87=B4=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?=EF=BC=8C=E4=BA=A4=E4=BA=92=E8=A1=A5=E5=85=85=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/start/LifecycleFatalErrorHandler.java | 64 +++++++++++++------ 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/start/LifecycleFatalErrorHandler.java b/designer-realize/src/main/java/com/fr/start/LifecycleFatalErrorHandler.java index 37f608ee16..fbe8f1962b 100644 --- a/designer-realize/src/main/java/com/fr/start/LifecycleFatalErrorHandler.java +++ b/designer-realize/src/main/java/com/fr/start/LifecycleFatalErrorHandler.java @@ -1,15 +1,19 @@ package com.fr.start; import com.fr.common.report.ReportState; +import com.fr.common.util.Collections; import com.fr.design.RestartHelper; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.DesignerFrame; import com.fr.design.mainframe.messagecollect.StartErrorMessageCollector; import com.fr.design.mainframe.messagecollect.entity.DesignerErrorMessage; import com.fr.env.detect.base.DetectorBridge; import com.fr.env.detect.bean.DetectorResult; import com.fr.env.detect.bean.DetectorStatus; import com.fr.env.detect.bean.DetectorType; +import com.fr.env.detect.ui.DetectorErrorDialog; import com.fr.exit.DesignerExiter; import com.fr.general.IOUtils; import com.fr.io.utils.ResourceIOUtils; @@ -17,14 +21,19 @@ import com.fr.log.FineLoggerFactory; import com.fr.process.engine.core.CarryMessageEvent; import com.fr.process.engine.core.FineProcessContext; import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; import com.fr.stable.lifecycle.ErrorType; import com.fr.stable.lifecycle.ErrorTypeHelper; import com.fr.stable.lifecycle.FineLifecycleFatalError; import com.fr.stable.project.ProjectConstants; import javax.swing.JOptionPane; +import java.util.EnumMap; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * @author hades @@ -68,10 +77,30 @@ public class LifecycleFatalErrorHandler { * 自检测 */ SELF { + final EnumMap solutionMap = new EnumMap<>(DetectorType.class); + + { + solutionMap.put(DetectorType.FINE_DB_LOCKED, "Fine-Design_Error_Finedb_Dirty_Backup_Reset"); + solutionMap.put(DetectorType.FINE_DB_PERMISSION, "Fine-Design_Error_Finedb_Permission_Backup_Reset"); + solutionMap.put(DetectorType.FINE_DB_DIRTY, "Fine-Design_Error_Finedb_Dirty_Backup_Reset"); + } + @Override public void handle(FineLifecycleFatalError fatal) { - String showText = generateShowText(fatal); + Stream resultStream = DetectorBridge.getInstance().detect(fatal); + List results = resultStream + .filter((e) -> e.getStatus() == DetectorStatus.EXCEPTION) + .collect(Collectors.toList()); + + String showText = generateShowText(results); + // 如果还是异常,则抛出预期外的错误 + if (StringUtils.isEmpty(showText)) { + DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); + DetectorErrorDialog errorDialog = new DetectorErrorDialog(designerFrame, results); + errorDialog.setVisible(true); + return; + } StartErrorMessageCollector.getInstance().record(DesignerErrorMessage.FINEDB_PROBLEM.getId(), DesignerErrorMessage.FINEDB_PROBLEM.getMessage(), @@ -107,26 +136,23 @@ public class LifecycleFatalErrorHandler { /** * 生成展示信息 - * - * @param fatal 异常 - * @return 文本 */ - private String generateShowText(FineLifecycleFatalError fatal) { - - // todo 其实这里的交互还是有问题, 为什么在锁住和没权限的场景下,要重置 FineDB 呢。 - DetectorResult detectorResult = DetectorBridge.getInstance().detect(DetectorType.FINE_DB_LOCKED, fatal); - if (detectorResult.getStatus() == DetectorStatus.EXCEPTION) { - return Toolkit.i18nText("Fine-Design_Error_Finedb_Locked_Backup_Reset"); - } - detectorResult = DetectorBridge.getInstance().detect(DetectorType.FINE_DB_PERMISSION, fatal); - if (detectorResult.getStatus() == DetectorStatus.EXCEPTION) { - return Toolkit.i18nText("Fine-Design_Error_Finedb_Permission_Backup_Reset"); - } - detectorResult = DetectorBridge.getInstance().detect(DetectorType.FINE_DB_DIRTY, fatal); - if (detectorResult.getStatus() == DetectorStatus.EXCEPTION) { - return Toolkit.i18nText("Fine-Design_Error_Finedb_Dirty_Backup_Reset"); + private String generateShowText(List results) { + + String showText = StringUtils.EMPTY; + if (Collections.isEmpty(results)) { + showText = Toolkit.i18nText("Fine-Design_Error_Finedb_Backup_Reset"); + } else { + for (DetectorResult result : results) { + DetectorType type = result.getType(); + String solutionLocale = solutionMap.get(type); + if (StringUtils.isNotEmpty(solutionLocale)) { + showText = Toolkit.i18nText(solutionLocale); + break; + } + } } - return Toolkit.i18nText("Fine-Design_Error_Finedb_Backup_Reset"); + return showText; } private void afterBackupFailed() {