From 190600158925b24538f248f7298c9ef7cfa3ac1c Mon Sep 17 00:00:00 2001 From: ruying408 <1877972603@qq.com> Date: Mon, 22 Jul 2024 23:08:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8F=92=E4=BB=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/service/CoolPluginService.java | 38 ++++++------------- .../java/com/cool/core/util/EntityUtils.java | 4 +- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/cool/core/plugin/service/CoolPluginService.java b/src/main/java/com/cool/core/plugin/service/CoolPluginService.java index 49fae6f..1595963 100644 --- a/src/main/java/com/cool/core/plugin/service/CoolPluginService.java +++ b/src/main/java/com/cool/core/plugin/service/CoolPluginService.java @@ -188,9 +188,9 @@ public class CoolPluginService { pluginInfo.setConfig(one.getConfig()); pluginInfo.getPluginJson().setConfig(one.getConfig()); CopyOptions options = CopyOptions.create().setIgnoreNullValue(true); - BeanUtil.copyProperties(pluginInfo, one, options); - // 忽略为更新的字段 + // 忽略无变更,无需更新的字段 ignoreNoChange(pluginInfo, one); + BeanUtil.copyProperties(pluginInfo, one, options); one.updateById(); } } @@ -209,16 +209,16 @@ public class CoolPluginService { } /** - * 忽略为更新的字段 + * 忽略无变更,无需更新的字段 */ private static void ignoreNoChange(PluginInfoEntity pluginInfo, PluginInfoEntity one) { if (ObjUtil.equals(pluginInfo.getLogo(), one.getLogo())) { - // 头像没变,不更新 - one.setLogo(null); + // 头像没变,无需更新 + pluginInfo.setLogo(null); } if (ObjUtil.equals(pluginInfo.getReadme(), one.getReadme())) { - // readme没变,不更新 - one.setReadme(null); + // readme没变,无需更新 + pluginInfo.setReadme(null); } } @@ -257,11 +257,11 @@ public class CoolPluginService { } if (!ObjUtil.equals(entity.getStatus(), dbPluginInfoEntity.getStatus())) { // 更新状态 - updateConfig = updateStatus(entity, dbPluginInfoEntity, updateConfig); + updateStatus(entity, dbPluginInfoEntity); } if (updateConfig) { // 更新配置 - CoolPluginInvokers.setPluginJson(getKeyById(entity.getId()), entity); + CoolPluginInvokers.setPluginJson(dbPluginInfoEntity.getKey(), entity); } pluginInfoService.update(entity); } @@ -269,8 +269,7 @@ public class CoolPluginService { /** * 更新插件状态 */ - private boolean updateStatus(PluginInfoEntity entity, PluginInfoEntity dbPluginInfoEntity, - boolean updateConfig) { + private void updateStatus(PluginInfoEntity entity, PluginInfoEntity dbPluginInfoEntity) { // 更新状态 Integer status = entity.getStatus(); if (ObjUtil.equals(status, 1)) { @@ -287,14 +286,12 @@ public class CoolPluginService { hookPlugin.getName()); } } - // 充关闭置为开启,触发重新加载jar + // 从关闭置为开启,触发重新加载jar initInstall(dbPluginInfoEntity); - updateConfig = false; } else if (ObjUtil.equals(status, 0)) { // 插件关闭 卸载jar dynamicJarLoaderService.uninstall(dbPluginInfoEntity.getKey()); } - return updateConfig; } /** @@ -304,21 +301,10 @@ public class CoolPluginService { return pluginInfoService.getPluginInfoEntityByHookNoJarFile(hook); } - /** - * 通过id 获取key - */ - private String getKeyById(Long id) { - PluginInfoEntity one = pluginInfoService.getPluginInfoEntityByIdNoJarFile(id); - if (ObjUtil.isNotEmpty(one)) { - return one.getKey(); - } - return null; - } - /** * 获取插件实例对象 */ public Object getInstance(String key) { return dynamicJarLoaderService.getBeanInstance(key); } -} +} \ No newline at end of file diff --git a/src/main/java/com/cool/core/util/EntityUtils.java b/src/main/java/com/cool/core/util/EntityUtils.java index 4bd47ef..6bb418f 100644 --- a/src/main/java/com/cool/core/util/EntityUtils.java +++ b/src/main/java/com/cool/core/util/EntityUtils.java @@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjUtil; import com.mybatisflex.annotation.Table; import com.mybatisflex.core.query.QueryColumn; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -72,8 +73,9 @@ public class EntityUtils { public static List getFieldNamesListWithSuperClass(QueryColumn[] queryColumns, String... excludeNames) { + ArrayList excludeList = new ArrayList<>(List.of(excludeNames)); return Arrays.stream(queryColumns).toList().stream() - .filter(o -> ObjUtil.equals(o.getName(), excludeNames)).toList(); + .filter(o -> !excludeList.contains(o.getName())).toList(); } /**