diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/util/InstallComponentHelper.java b/designer-form/src/main/java/com/fr/design/mainframe/share/util/InstallComponentHelper.java index b66c2458c7..7644fbdfe9 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/util/InstallComponentHelper.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/util/InstallComponentHelper.java @@ -19,9 +19,10 @@ import java.io.InputStream; * @Date: 2020/12/4 */ public class InstallComponentHelper { - private static final String PRE_INSTALL_PATH = "/com/fr/form/share/components"; - private static final String[] PRE_INSTALL_COMPONENTS = new String[]{ + private static String sharePath = ComponentPath.SHARE_PATH.path(); + + private static final String[] OLD_PRE_INSTALL_COMPONENTS = new String[]{ "单行指标卡.f3df58b3-4302-4cab-ab77-caaf225de60a.reu", "分层雷达图-深色.49f8397c-e6a6-482a-acc7-46d8cec353a4.reu", "红绿灯表格-浅色.d0466992-328a-4ccf-ad67-6cbc844d669c.reu", @@ -29,12 +30,24 @@ public class InstallComponentHelper { "三列指标卡.61a83d18-a162-4dc3-aa57-3b954edaf82e.reu", "透明按钮切换图表.e373e13a-3da0-4c29-91bc-9ae804241023.reu" }; + private static final String[] PRE_INSTALL_COMPONENTS = new String[]{ + "三色指标卡-酷炫蓝.d96f451f-c74c-45df-b056-0906b42870c7.reu", + "刻度槽型仪表盘-酷炫蓝.982ba9a3-f38b-48df-a7ae-80fcce0d74d1.reu", + "大屏标题-酷炫蓝.35f08184-2339-4a7d-9a6a-ea5bacc6829a.reu", + "柱形折线组合图-酷炫蓝.b7d66ba1-2a51-4640-a50e-2869694b748a.reu", + "渐变柱形图-酷炫蓝.786a4e7a-22d5-4f55-a857-42e3ddd54b70.reu", + "环形饼图-酷炫蓝.c9258ee9-7dee-4f56-aa2e-31b9fd7de818.reu" + }; public static void installPreComponent() { - if (needPreInstallComponent()) { + String[] components = WorkContext.getWorkResource().list(sharePath, new ReuFilter()); + String[] dirs = WorkContext.getWorkResource().list(sharePath, new DirFilter()); + if (needPreInstallComponent(components, dirs)) { + installShareComponents(PRE_INSTALL_PATH, PRE_INSTALL_COMPONENTS); + } else if (needReplaceOldComponent(components, dirs)) { + clearOldComponent(OLD_PRE_INSTALL_COMPONENTS); installShareComponents(PRE_INSTALL_PATH, PRE_INSTALL_COMPONENTS); } - } public static void installShareComponents(String resourcePath, String[] components) { @@ -42,18 +55,36 @@ public class InstallComponentHelper { try { InputStream inputStream = InstallComponentHelper.class.getResourceAsStream(StableUtils.pathJoin(resourcePath, componentPath)); byte[] data = ResourceIOUtils.inputStream2Bytes(inputStream); - WorkContext.getWorkResource().write(StableUtils.pathJoin(ComponentPath.SHARE_PATH.path(), componentPath), data); + WorkContext.getWorkResource().write(StableUtils.pathJoin(sharePath, componentPath), data); } catch (Exception e) { FineLoggerFactory.getLogger().error("install Component filed" + e.getMessage(), e); } } } - private static boolean needPreInstallComponent() { + private static boolean needReplaceOldComponent(String[] components, String[] dirs) { + if ((dirs != null && ArrayUtils.isNotEmpty(dirs)) || (components != null && components.length != 6)) { + return false; + } + for (String componentPath : components) { + if (!ArrayUtils.contains(OLD_PRE_INSTALL_COMPONENTS, componentPath)) { + return false; + } + } + return true; + } + + private static void clearOldComponent(String[] components) { + for(String componentPath : components) { + WorkContext.getWorkResource().delete(StableUtils.pathJoin(sharePath, componentPath)); + } + } + + private static boolean needPreInstallComponent(String[] components, String[] dirs) { try { //老用户或者组件库里已有组件,不预装组件 SnapChat snapChat = SnapChatFactory.createSnapChat(false, SnapChatKeys.COMPONENT); - return !snapChat.hasRead() && !hasComponentInstalled(); + return !snapChat.hasRead() && !hasComponentInstalled(components, dirs); } catch (Throwable e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } @@ -63,10 +94,7 @@ public class InstallComponentHelper { /** * 判断是否已有组件被安装 */ - private static boolean hasComponentInstalled() { - String sharePath = ComponentPath.SHARE_PATH.path(); - String[] components = WorkContext.getWorkResource().list(sharePath, new ReuFilter()); - String[] dirs = WorkContext.getWorkResource().list(sharePath, new DirFilter()); + private static boolean hasComponentInstalled(String[] components, String[] dirs) { return components != null && ArrayUtils.isNotEmpty(components) || (dirs != null && ArrayUtils.isNotEmpty(dirs)); }