Skip to content

Commit

Permalink
feat-ModuleController-优化系统启动时对模块数据的自检逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
aruis committed Nov 5, 2024
1 parent 2bd1cd9 commit a0e34b4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
12 changes: 11 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
allprojects {
group = "net.ximatai.muyun"
version = "1.0.0-SNAPSHOT"
// version = "0.1.2"
// version = "0.1.3"

repositories {
mavenLocal()
Expand Down Expand Up @@ -123,5 +123,15 @@ subprojects {
tasks.withType<Test> {
maxHeapSize = "2g"
}

tasks.register("publishModule") {
dependsOn("publishMavenJavaPublicationToMavenRepository")
dependsOn("publishToSonatype")
}

}

tasks.register("releaseAllJars") {
group = "release"
dependsOn(subprojects.flatMap { it.tasks.matching { task -> task.name == "publishModule" } })
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ public String getMainTable() {
return "app_module";
}

private List<Map<String, Object>> systemModuleList;

private List<Map<String, Object>> getSystemModuleList() {
if (systemModuleList == null) {
systemModuleList = getDB().query("select * from %s.%s where b_system = true".formatted(getSchemaName(), getMainTable()));
}
return systemModuleList;
}

@Override
public void fitOut(TableWrapper wrapper) {
wrapper
Expand Down Expand Up @@ -143,6 +152,8 @@ private void initData() {

String root3 = this.lockModule(null, "日常办公", "void", null, null, null);
this.lockModule(root3, "通知发布", "notice", "platform.app_notice", "platform/notice/index", null);

systemModuleList = null;
}

/**
Expand All @@ -156,12 +167,12 @@ private void initData() {
* @return
*/
private String lockModule(String pid, String name, String alias, String table, String url, List<ModuleAction> moduleActions) {
List<Map<String, Object>> list;
Map<String, Object> hitModule;

if ("void".equals(alias)) { // 说明不是叶子节点
list = getDB().query("select id from platform.app_module where b_system = true and v_alias = 'void' and v_name = ?", name);
hitModule = getSystemModuleList().stream().filter(it -> it.get("v_name").equals(name)).findFirst().orElse(null);
} else {
list = getDB().query("select id from platform.app_module where b_system = true and v_alias = ?", alias);
hitModule = getSystemModuleList().stream().filter(it -> it.get("v_alias").equals(alias)).findFirst().orElse(null);
}

String moduleID;
Expand All @@ -171,7 +182,7 @@ private String lockModule(String pid, String name, String alias, String table, S
actions = moduleActions.stream().map(ModuleAction::toMap).toList();
}

if (list.isEmpty()) { // 新增模块
if (hitModule == null) { // 新增模块
HashMap map = new HashMap();
if (pid != null) {
map.put("pid", pid);
Expand All @@ -185,7 +196,7 @@ private String lockModule(String pid, String name, String alias, String table, S
map.put("b_system", true);
moduleID = this.create(map);
} else {
moduleID = list.getFirst().get("id").toString();
moduleID = hitModule.get("id").toString();

if (moduleActions != null) { // 修改时可以根据 moduleActions 进行增量补充
List<Map> actionList = this.getChildTableList(moduleID, "app_module_action", null);
Expand All @@ -210,5 +221,6 @@ public List<QueryItem> queryItemList() {

public void register(ModuleConfig config) {
this.lockModule(null, config.getName(), config.getAlias(), config.getTable(), config.getUrl(), config.getActions());
systemModuleList = null;
}
}

0 comments on commit a0e34b4

Please sign in to comment.