fix(项目管理): 修复环境的模块树返回多个重复模块的缺陷
This commit is contained in:
parent
1032b30df4
commit
1e431295b8
|
@ -328,43 +328,50 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
|
||||||
//根据选择的模块id 来补充选中的id
|
//根据选择的模块id 来补充选中的id
|
||||||
List<ApiModuleDTO> selectedModules = request.getSelectedModules();
|
List<ApiModuleDTO> selectedModules = request.getSelectedModules();
|
||||||
List<ApiModuleDTO> currentModules = new ArrayList<>();
|
List<ApiModuleDTO> currentModules = new ArrayList<>();
|
||||||
|
// 选中的模块id
|
||||||
|
List<String> moduleIds = new ArrayList<>();
|
||||||
if (CollectionUtils.isNotEmpty(selectedModules)) {
|
if (CollectionUtils.isNotEmpty(selectedModules)) {
|
||||||
//将选中的模块id转换为Map 方便后面的查询 key为id
|
//将选中的模块id转换为Map 方便后面的查询 key为id
|
||||||
Map<String, ApiModuleDTO> selectedModuleMap = selectedModules.stream().collect(Collectors.toMap(ApiModuleDTO::getModuleId, apiModuleDTO -> apiModuleDTO));
|
Map<String, ApiModuleDTO> selectedModuleMap = selectedModules.stream().collect(Collectors.toMap(ApiModuleDTO::getModuleId, apiModuleDTO -> apiModuleDTO));
|
||||||
getAllModuleIds(baseTreeNodes, currentModules, selectedModuleMap);
|
getAllModuleIds(baseTreeNodes, currentModules, selectedModuleMap, moduleIds);
|
||||||
}
|
}
|
||||||
envApiTreeDTO.setSelectedModules(currentModules);
|
envApiTreeDTO.setSelectedModules(currentModules);
|
||||||
return envApiTreeDTO;
|
return envApiTreeDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getAllModuleIds(List<BaseTreeNode> baseTreeNodes, List<ApiModuleDTO> currentModules, Map<String, ApiModuleDTO> selectedModuleMap) {
|
public void getAllModuleIds(List<BaseTreeNode> baseTreeNodes, List<ApiModuleDTO> currentModules, Map<String, ApiModuleDTO> selectedModuleMap, List<String> moduleIds) {
|
||||||
baseTreeNodes.forEach(baseTreeNode -> {
|
baseTreeNodes.forEach(baseTreeNode -> {
|
||||||
if (selectedModuleMap.containsKey(baseTreeNode.getId())) {
|
if (selectedModuleMap.containsKey(baseTreeNode.getId())) {
|
||||||
ApiModuleDTO apiModuleDTO = selectedModuleMap.get(baseTreeNode.getId());
|
ApiModuleDTO apiModuleDTO = selectedModuleMap.get(baseTreeNode.getId());
|
||||||
if (BooleanUtils.isTrue(apiModuleDTO.getContainChildModule())) {
|
if (!moduleIds.contains(baseTreeNode.getId())) {
|
||||||
currentModules.add(apiModuleDTO);
|
moduleIds.add(baseTreeNode.getId());
|
||||||
if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) {
|
if (BooleanUtils.isTrue(apiModuleDTO.getContainChildModule())) {
|
||||||
setChildren(baseTreeNode.getChildren(), currentModules);
|
moduleIds.add(baseTreeNode.getId());
|
||||||
|
currentModules.add(apiModuleDTO);
|
||||||
|
if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) {
|
||||||
|
setChildren(baseTreeNode.getChildren(), currentModules, moduleIds);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
currentModules.add(apiModuleDTO);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
currentModules.add(apiModuleDTO);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) {
|
if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) {
|
||||||
getAllModuleIds(baseTreeNode.getChildren(), currentModules, selectedModuleMap);
|
getAllModuleIds(baseTreeNode.getChildren(), currentModules, selectedModuleMap, moduleIds);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setChildren(List<BaseTreeNode> baseTreeNodes, List<ApiModuleDTO> currentModules) {
|
public void setChildren(List<BaseTreeNode> baseTreeNodes, List<ApiModuleDTO> currentModules, List<String> moduleIds) {
|
||||||
baseTreeNodes.forEach(baseTreeNode -> {
|
baseTreeNodes.forEach(baseTreeNode -> {
|
||||||
ApiModuleDTO children = new ApiModuleDTO();
|
ApiModuleDTO children = new ApiModuleDTO();
|
||||||
children.setModuleId(baseTreeNode.getId());
|
children.setModuleId(baseTreeNode.getId());
|
||||||
children.setContainChildModule(true);
|
children.setContainChildModule(true);
|
||||||
children.setDisabled(true);
|
children.setDisabled(true);
|
||||||
|
moduleIds.add(baseTreeNode.getId());
|
||||||
currentModules.add(children);
|
currentModules.add(children);
|
||||||
if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) {
|
if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) {
|
||||||
setChildren(baseTreeNode.getChildren(), currentModules);
|
setChildren(baseTreeNode.getChildren(), currentModules, moduleIds);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue