diff --git a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelData.java b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelData.java index 6ec26f668b..c04bea2fc6 100644 --- a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelData.java +++ b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelData.java @@ -23,7 +23,6 @@ public class TestCaseExcelData { @Pattern(regexp = "^(?!.*//).*$", message = "格式不正确") private String nodePath; - @NotBlank @ExcelProperty("用例类型") @Pattern(regexp = "(^functional$)|(^performance$)|(^api$)", message = "必须为functional、performance、api") diff --git a/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java b/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java index 268a444328..6e53148a3f 100644 --- a/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java +++ b/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java @@ -41,6 +41,9 @@ public class TestCaseDataListener extends EasyExcelListener { if ( nodePath.split("/").length > TestCaseConstants.MAX_NODE_DEPTH + 1) { stringBuilder.append("节点最多为" + TestCaseConstants.MAX_NODE_DEPTH + "层;"); } + if ( nodePath.trim().contains(" ")) { + stringBuilder.append("所属模块不能包含空格"); + } if (!userNames.contains(data.getMaintainer())) { stringBuilder.append("该工作空间下无该用户:" + data.getMaintainer() + ";"); } diff --git a/backend/src/main/java/io/metersphere/service/TestCaseNodeService.java b/backend/src/main/java/io/metersphere/service/TestCaseNodeService.java index 5be4e3e16b..d790c20012 100644 --- a/backend/src/main/java/io/metersphere/service/TestCaseNodeService.java +++ b/backend/src/main/java/io/metersphere/service/TestCaseNodeService.java @@ -228,6 +228,7 @@ public class TestCaseNodeService { pathIterator.remove(); rootNodeName = pathIterator.next().trim(); + //原来没有,新建的树nodeTrees也不包含 for (TestCaseNodeDTO nodeTree : nodeTrees) { if (StringUtils.equals(rootNodeName, nodeTree.getName())) { hasNode = true; @@ -237,6 +238,7 @@ public class TestCaseNodeService { } } + if (!hasNode) { createNodeByPath(pathIterator, rootNodeName, null, projectId, 1, "", pathMap); } @@ -297,20 +299,34 @@ public class TestCaseNodeService { StringBuilder path = new StringBuilder(rootPath); - Integer pid = insertTestCaseNode(nodeName, pNode == null ? null : pNode.getId(), projectId, level); path.append("/" + nodeName); - pathMap.put(path.toString(), pid); + + Integer pid = null; + //创建过不创建 + if (pathMap.get(path.toString()) != null) { + pid = pathMap.get(path.toString()); + level++; + } else { + pid = insertTestCaseNode(nodeName, pNode == null ? null : pNode.getId(), projectId, level); + pathMap.put(path.toString(), pid); + } + while (pathIterator.hasNext()) { String nextNodeName = pathIterator.next(); path.append("/" + nextNodeName); - pid = insertTestCaseNode(nextNodeName, pid, projectId, ++level); - pathMap.put(path.toString(), pid); + if (pathMap.get(path.toString()) != null) { + pid = pathMap.get(path.toString()); + level++; + } else { + pid = insertTestCaseNode(nextNodeName, pid, projectId, level); + pathMap.put(path.toString(), pid); + } } } - private Integer insertTestCaseNode(String nodName, Integer pId, String projectId, Integer level) { + private Integer insertTestCaseNode(String nodeName, Integer pId, String projectId, Integer level) { TestCaseNode testCaseNode = new TestCaseNode(); - testCaseNode.setName(nodName.trim()); + testCaseNode.setName(nodeName.trim()); testCaseNode.setpId(pId); testCaseNode.setProjectId(projectId); testCaseNode.setCreateTime(System.currentTimeMillis());