refactor(功能用例): 模块和空白节点组合树增加搜索参数

This commit is contained in:
guoyuqi 2024-06-07 10:47:01 +08:00 committed by 刘瑞斌
parent a5065b7cb4
commit e52cc072fd
3 changed files with 43 additions and 12 deletions

View File

@ -32,12 +32,12 @@ public class FunctionalCaseMinderController {
@Resource
private FunctionalCaseMinderService functionalCaseMinderService;
@GetMapping("/tree/{projectId}")
@PostMapping("/tree")
@Operation(summary = "用例管理-功能用例-脑图-获取空白节点和模块的组合树")
@RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ)
@CheckOwner(resourceId = "#projectId", resourceType = "project")
public List<BaseTreeNode> getTree(@PathVariable String projectId) {
return functionalCaseMinderService.getTree(projectId);
public List<BaseTreeNode> getTree(@Validated @RequestBody FunctionalCaseMindRequest request) {
return functionalCaseMinderService.getTree(request);
}
@PostMapping("/list")

View File

@ -292,6 +292,7 @@ public class FunctionalCaseMinderService {
List<FunctionalCaseDTO> updateNoticeList = new ArrayList<>();
List<LogDTO> updateLogDTOS = new ArrayList<>();
Map<String, String> newModuleMap = new HashMap<>();
//处理模块
dealModule(request, userId, moduleMapper, newModuleMap);
@ -371,6 +372,11 @@ public class FunctionalCaseMinderService {
//处理空白节点
dealAdditionalNode(request, userId, additionalNodeMapper, newModuleMap);
//TODO:删除转换的空白节点
sqlSession.flushStatements();
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
@ -1060,14 +1066,14 @@ public class FunctionalCaseMinderService {
}
public List<BaseTreeNode> getTree(String projectId) {
List<BaseTreeNode> functionalModuleList = extFunctionalCaseModuleMapper.selectBaseByProjectId(projectId);
List<BaseTreeNode> baseTreeNodes = extFunctionalCaseMapper.selectBaseMindNodeByProjectId(projectId);
public List<BaseTreeNode> getTree(FunctionalCaseMindRequest request) {
List<BaseTreeNode> functionalModuleList = extFunctionalCaseModuleMapper.selectBaseByProjectId(request.getProjectId());
List<BaseTreeNode> baseTreeNodes = extFunctionalCaseMapper.selectBaseMindNodeByProjectId(request.getProjectId());
functionalModuleList.addAll(baseTreeNodes);
return buildTreeAndCountResource(functionalModuleList, true, Translator.get("functional_case.module.default.name"));
return buildTreeAndCountResource(functionalModuleList, true, Translator.get("functional_case.module.default.name"), request.getModuleId());
}
public List<BaseTreeNode> buildTreeAndCountResource(List<BaseTreeNode> traverseList, boolean haveVirtualRootNode, String virtualRootName) {
public List<BaseTreeNode> buildTreeAndCountResource(List<BaseTreeNode> traverseList, boolean haveVirtualRootNode, String virtualRootName, String moduleId) {
List<BaseTreeNode> baseTreeNodeList = new ArrayList<>();
if (haveVirtualRootNode) {
@ -1097,8 +1103,26 @@ public class FunctionalCaseMinderService {
}
traverseList = notMatchedList;
}
if (StringUtils.isNotBlank(moduleId)) {
List<BaseTreeNode> filterList = new ArrayList<>();
getFilterList(moduleId, baseTreeNodeList, filterList);
return filterList;
} else {
return baseTreeNodeList;
}
}
private static void getFilterList(String moduleId, List<BaseTreeNode> baseTreeNodeList, List<BaseTreeNode> filterList) {
for (BaseTreeNode baseTreeNode : baseTreeNodeList) {
if (StringUtils.equalsIgnoreCase(baseTreeNode.getId(), moduleId)) {
filterList.add(baseTreeNode);
break;
} else {
getFilterList(moduleId, baseTreeNode.getChildren(), filterList);
}
}
}
public BaseTreeNode getDefaultModule(String name) {
//默认模块下不允许创建子模块 它本身也就是叶子节点

View File

@ -39,7 +39,7 @@ public class FunctionalCaseMinderControllerTest extends BaseTest {
public static final String FUNCTIONAL_CASE_EDIT_URL = "/functional/mind/case/edit";
public static final String FUNCTIONAL_CASE_NODE_MODULE_URL = "/functional/mind/case/tree/";
public static final String FUNCTIONAL_CASE_NODE_MODULE_URL = "/functional/mind/case/tree";
@ -265,12 +265,19 @@ public class FunctionalCaseMinderControllerTest extends BaseTest {
@Test
@Order(3)
public void testGetCaseModuleNodeList() throws Exception {
MvcResult mvcResultPage = this.requestGetWithOkAndReturn(FUNCTIONAL_CASE_NODE_MODULE_URL+"project-case-minder-test");
FunctionalCaseMindRequest request = new FunctionalCaseMindRequest();
request.setProjectId("project-case-minder-test");
MvcResult mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_NODE_MODULE_URL, request);
String contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
List<BaseTreeNode> baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), BaseTreeNode.class);
Assertions.assertNotNull(baseTreeNodes);
System.out.println(baseTreeNodes);
request.setModuleId("TEST_MINDER_MODULE_ID_GYQ");
mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_NODE_MODULE_URL, request);
contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8);
resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), BaseTreeNode.class);
Assertions.assertNotNull(baseTreeNodes);
}
@Test