feat(系统设置): 模块树分支节点数量不能超过200个

This commit is contained in:
song-tianyang 2023-12-25 14:54:59 +08:00 committed by f2c-ci-robot[bot]
parent b096908da6
commit 335e298b27
8 changed files with 69 additions and 4 deletions

View File

@ -25,4 +25,11 @@ public class Translator {
public static String get(String key, String defaultMessage) {
return messageSource.getMessage(key, null, defaultMessage, LocaleContextHolder.getLocale());
}
/**
* 带参数
*/
public static String getWithArgs(String key, Object... args) {
return messageSource.getMessage(key, args, "Not Support Key: " + key, LocaleContextHolder.getLocale());
}
}

View File

@ -431,6 +431,7 @@ resource_pool_not_exist=资源池不存在
#file management
file_module.not.exist=文件模块不存在
drag_node.not.exist=拖拽节点不存在
module.branches.size.limit=模块所在分支总节点数量不能超过{0}个
drop_node.not.exist=目标节点不存在
file_module.parent.not.exist=文件模块父节点不存在
upload.file.error=上传文件失败

View File

@ -466,6 +466,7 @@ resource_pool_not_exist=Resource pool does not exist
#file management
file_module.not.exist=File module does not exist
module.branches.size.limit=Module branches size limit {0}
drag_node.not.exist=Drag node is not exist
drop_node.not.exist=Drop node is not exist
file_module.parent.not.exist=File module parent does not exist

View File

@ -465,6 +465,7 @@ resource_pool_not_exist=资源池不存在
#file management
file_module.not.exist=文件模块不存在
module.branches.size.limit=模块所在分支总节点数量不能超过{0}个
drag_node.not.exist=拖拽节点不存在
drop_node.not.exist=目标节点不存在
file_module.parent.not.exist=文件模块父节点不存在

View File

@ -466,6 +466,7 @@ message.domain.schedule_enable=是否開啟
resource_pool_not_exist=資源池不存在
#file management
file_module.not.exist=文件模塊不存在
module.branches.size.limit=模塊所在分支總節點數量不能超過{0}个
drag_node.not.exist=拖拽節點不存在
drop_node.not.exist=目標節點不存在
file_module.parent.not.exist=文件模塊父節點不存在

View File

@ -114,8 +114,23 @@ public class FileModuleService extends ModuleTreeService implements CleanupProje
throw new MSException(Translator.get("node.name.repeat"));
}
example.clear();
//非默认节点检查该节点所在分支的总长度确保不超过阈值
if (!StringUtils.equals(fileModule.getId(), ModuleConstants.DEFAULT_NODE_ID)) {
this.checkBranchModules(this.getRootNodeId(fileModule), extFileModuleMapper::selectChildrenIdsByParentIds);
}
}
private String getRootNodeId(FileModule fileModule) {
if (StringUtils.equals(fileModule.getParentId(), ModuleConstants.ROOT_NODE_PARENT_ID)) {
return fileModule.getId();
} else {
FileModule parentModule = fileModuleMapper.selectByPrimaryKey(fileModule.getParentId());
return this.getRootNodeId(parentModule);
}
}
public void update(FileModuleUpdateRequest request, String userId) {
FileModule module = fileModuleMapper.selectByPrimaryKey(request.getId());
if (module == null) {

View File

@ -14,10 +14,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -25,11 +22,26 @@ public abstract class ModuleTreeService {
protected static final long LIMIT_POS = 64;
//默认节点所在分支最大数量不超过200 后续会根据需求排期进行调整
protected static final int MAX_BRANCHES_NODE_SIZE = 200;
public BaseTreeNode getDefaultModule(String name) {
//默认模块下不允许创建子模块 它本身也就是叶子节点
return new BaseTreeNode(ModuleConstants.DEFAULT_NODE_ID, name, ModuleConstants.NODE_TYPE_DEFAULT, ModuleConstants.ROOT_NODE_PARENT_ID);
}
public void checkBranchModules(String rootNodeId, Function<List<String>, List<String>> selectIdByParentIdFunc) {
long count = 1;
List<String> child = selectIdByParentIdFunc.apply(Collections.singletonList(rootNodeId));
while (CollectionUtils.isNotEmpty(child)) {
count += child.size();
if (count < MAX_BRANCHES_NODE_SIZE) {
child = selectIdByParentIdFunc.apply(child);
} else {
throw new MSException(Translator.getWithArgs("module.branches.size.limit", MAX_BRANCHES_NODE_SIZE));
}
}
}
//构建树结构并为每个节点计算资源数量
public List<BaseTreeNode> buildTreeAndCountResource(List<BaseTreeNode> traverseList, @NotNull List<ModuleCountDTO> moduleCountDTOList, boolean haveVirtualRootNode, String virtualRootName) {

View File

@ -297,6 +297,33 @@ public class FileManagementControllerTests extends BaseTest {
LOG_CHECK_LIST.add(
new CheckLogModel(a1b1c1Node.getId(), OperationLogType.ADD, FileManagementRequestUtils.URL_MODULE_ADD)
);
/**
测试能否正常做200个节点
*/
String parentId = null;
for (int i = 0; i < 210; i++) {
FileModuleCreateRequest perfRequest = new FileModuleCreateRequest();
perfRequest.setProjectId(project.getId());
perfRequest.setName("500-test-root-" + i);
if (StringUtils.isNotEmpty(parentId)) {
perfRequest.setParentId(parentId);
}
if (i < 200) {
MvcResult result = this.requestPostWithOkAndReturn(FileManagementRequestUtils.URL_MODULE_ADD, perfRequest);
ResultHolder holder = JSON.parseObject(result.getResponse().getContentAsString(), ResultHolder.class);
if (i % 50 == 0) {
//到20换下一层级
parentId = holder.getData().toString();
}
} else {
//测试超过500会报错
this.requestPost(FileManagementRequestUtils.URL_MODULE_ADD, perfRequest).andExpect(status().is5xxServerError());
}
}
treeNodes = this.getFileModuleTreeNode();
preliminaryTreeNodes = treeNodes;
}
@Test