优化插件更新配置

This commit is contained in:
ruying408
2024-07-22 23:08:25 +08:00
parent cdec3d18f1
commit 1906001589
2 changed files with 15 additions and 27 deletions

View File

@@ -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);
}
}
}

View File

@@ -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<QueryColumn> getFieldNamesListWithSuperClass(QueryColumn[] queryColumns,
String... excludeNames) {
ArrayList<String> 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();
}
/**