refactor(ui 测试): moduleservice 优化

This commit is contained in:
zhangdahai112 2022-03-27 16:09:31 +08:00 committed by 刘瑞斌
parent a6801d9430
commit ae3975145b
3 changed files with 35 additions and 30 deletions

View File

@ -108,15 +108,15 @@ public class BaseModuleService extends NodeTreeService<ModuleNodeDTO> {
} }
} }
public ModuleNode getDefaultNode(String projectId) { public ModuleNode getDefaultNode(String projectId, String defaultName) {
TestCaseNodeExample example = new TestCaseNodeExample(); TestCaseNodeExample example = new TestCaseNodeExample();
example.createCriteria().andProjectIdEqualTo(projectId).andNameEqualTo("未规划用例").andParentIdIsNull(); example.createCriteria().andProjectIdEqualTo(projectId).andNameEqualTo(Optional.ofNullable(defaultName).orElse("未规划用例")).andParentIdIsNull();
List<ModuleNode> list = extModuleNodeMapper.selectByExample(tableName, example); List<ModuleNode> list = extModuleNodeMapper.selectByExample(tableName, example);
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
ModuleNode record = new ModuleNode(); ModuleNode record = new ModuleNode();
record.setId(UUID.randomUUID().toString()); record.setId(UUID.randomUUID().toString());
record.setCreateUser(SessionUtils.getUserId()); record.setCreateUser(SessionUtils.getUserId());
record.setName("未规划用例"); record.setName(Optional.ofNullable(defaultName).orElse("未规划用例"));
record.setPos(1.0); record.setPos(1.0);
record.setLevel(1); record.setLevel(1);
record.setCreateTime(System.currentTimeMillis()); record.setCreateTime(System.currentTimeMillis());
@ -130,9 +130,9 @@ public class BaseModuleService extends NodeTreeService<ModuleNodeDTO> {
} }
} }
public List<ModuleNodeDTO> getNodeTreeByProjectIdWithCount(String projectId, Function<QueryNodeRequest, List<Map<String,Object>>> getModuleCountFunc) { public List<ModuleNodeDTO> getNodeTreeByProjectIdWithCount(String projectId, Function<QueryNodeRequest, List<Map<String, Object>>> getModuleCountFunc, String defaultName) {
// 判断当前项目下是否有默认模块没有添加默认模块 // 判断当前项目下是否有默认模块没有添加默认模块
this.getDefaultNode(projectId); this.getDefaultNode(projectId, defaultName);
List<ModuleNodeDTO> moduleNodes = extModuleNodeMapper.getNodeTreeByProjectId(tableName, projectId); List<ModuleNodeDTO> moduleNodes = extModuleNodeMapper.getNodeTreeByProjectId(tableName, projectId);
@ -143,8 +143,8 @@ public class BaseModuleService extends NodeTreeService<ModuleNodeDTO> {
return getNodeTrees(moduleNodes); return getNodeTrees(moduleNodes);
} }
public List<ModuleNodeDTO> getNodeTreeByProjectId(String projectId) { public List<ModuleNodeDTO> getNodeTreeByProjectId(String projectId, String defaultName) {
return getNodeTreeByProjectIdWithCount(projectId, null); return getNodeTreeByProjectIdWithCount(projectId, null, defaultName);
} }
private void buildNodeCount(String projectId, List<ModuleNodeDTO> moduleNodes, Function<QueryNodeRequest, List<Map<String, Object>>> getModuleCountFunc) { private void buildNodeCount(String projectId, List<ModuleNodeDTO> moduleNodes, Function<QueryNodeRequest, List<Map<String, Object>>> getModuleCountFunc) {
@ -227,6 +227,7 @@ public class BaseModuleService extends NodeTreeService<ModuleNodeDTO> {
/** /**
* nodeIds 包含了删除节点ID及其所有子节点ID * nodeIds 包含了删除节点ID及其所有子节点ID
*
* @param nodeIds * @param nodeIds
* @param deleteNodeDataFunc * @param deleteNodeDataFunc
* @return * @return
@ -268,6 +269,7 @@ public class BaseModuleService extends NodeTreeService<ModuleNodeDTO> {
/** /**
* 获取当前项目下的 * 获取当前项目下的
*
* @param projectId * @param projectId
* @param pruningTreeIds * @param pruningTreeIds
* @return * @return
@ -285,15 +287,15 @@ public class BaseModuleService extends NodeTreeService<ModuleNodeDTO> {
return nodeTrees; return nodeTrees;
} }
public Map<String, String> createNodeByTestCases(List<TestCaseWithBLOBs> testCases, String projectId) { public Map<String, String> createNodeByTestCases(List<TestCaseWithBLOBs> testCases, String projectId, String defaultName) {
List<String> nodePaths = testCases.stream() List<String> nodePaths = testCases.stream()
.map(TestCase::getNodePath) .map(TestCase::getNodePath)
.collect(Collectors.toList()); .collect(Collectors.toList());
return this.createNodes(nodePaths, projectId); return this.createNodes(nodePaths, projectId, defaultName);
} }
public Map<String, String> createNodes(List<String> nodePaths, String projectId) { public Map<String, String> createNodes(List<String> nodePaths, String projectId, String defaultName) {
List<ModuleNodeDTO> nodeTrees = getNodeTreeByProjectId(projectId); List<ModuleNodeDTO> nodeTrees = getNodeTreeByProjectId(projectId, defaultName);
Map<String, String> pathMap = new HashMap<>(); Map<String, String> pathMap = new HashMap<>();
for (String item : nodePaths) { for (String item : nodePaths) {
if (item == null) { if (item == null) {
@ -351,6 +353,7 @@ public class BaseModuleService extends NodeTreeService<ModuleNodeDTO> {
/** /**
* 拖拽批量修改模块以及模块下数据的 modulePath 字段 * 拖拽批量修改模块以及模块下数据的 modulePath 字段
*
* @param request * @param request
* @param getNodeDataFunc 通过 nodeIds 获取需要修改的数据 * @param getNodeDataFunc 通过 nodeIds 获取需要修改的数据
* @param editNodeDataFunc 修改 modulePath 的方法 * @param editNodeDataFunc 修改 modulePath 的方法
@ -359,7 +362,9 @@ public class BaseModuleService extends NodeTreeService<ModuleNodeDTO> {
Function<List<String>, List<EditModuleDateDTO>> getNodeDataFunc, Function<List<String>, List<EditModuleDateDTO>> getNodeDataFunc,
Consumer<List<EditModuleDateDTO>> editNodeDataFunc) { Consumer<List<EditModuleDateDTO>> editNodeDataFunc) {
if (request.getNodeTree() == null) { return; } if (request.getNodeTree() == null) {
return;
}
checkTestCaseNodeExist(request); checkTestCaseNodeExist(request);

@ -1 +1 @@
Subproject commit 08b2e75b6a6a3fd75aa6d499c9eb8d0491dc84b2 Subproject commit 11cabd3dacc6b8aafca3fe2684b328b47c0a4cb6

@ -1 +1 @@
Subproject commit c6dee3b598a42259d26ac900c978f3f9461f2bd0 Subproject commit f5f8c639cc1ed537bdb12f3d0b386148ae62812c