diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtModuleNodeMapper.xml b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtModuleNodeMapper.xml
index 69fd2ca7f3..0f0b87dd34 100644
--- a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtModuleNodeMapper.xml
+++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtModuleNodeMapper.xml
@@ -159,7 +159,6 @@
distinct
- ,module_path
from ${tableName}
diff --git a/test-track/backend/src/main/java/io/metersphere/listener/ProjectCreatedListener.java b/test-track/backend/src/main/java/io/metersphere/listener/ProjectCreatedListener.java
index 8a6aa11f21..8544ce16a3 100644
--- a/test-track/backend/src/main/java/io/metersphere/listener/ProjectCreatedListener.java
+++ b/test-track/backend/src/main/java/io/metersphere/listener/ProjectCreatedListener.java
@@ -1,6 +1,7 @@
package io.metersphere.listener;
import io.metersphere.base.domain.ModuleNode;
+import io.metersphere.base.domain.TestCaseNodeExample;
import io.metersphere.base.mapper.ext.ExtModuleNodeMapper;
import io.metersphere.commons.constants.KafkaTopicConstants;
import io.metersphere.commons.constants.ProjectModuleDefaultNodeEnum;
@@ -11,6 +12,7 @@ import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
+import java.util.List;
import java.util.UUID;
@Component
@@ -28,15 +30,22 @@ public class ProjectCreatedListener {
}
private void initProjectDefaultNode(String projectId) {
- ModuleNode record = new ModuleNode();
- record.setId(UUID.randomUUID().toString());
- record.setCreateUser(SessionUtils.getUserId());
- record.setPos(1.0);
- record.setLevel(1);
- record.setCreateTime(System.currentTimeMillis());
- record.setUpdateTime(System.currentTimeMillis());
- record.setProjectId(projectId);
- record.setName(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getNodeName());
- extModuleNodeMapper.insert(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getTableName(), record);
+ // 防止重复创建功能用例默认节点
+ TestCaseNodeExample example = new TestCaseNodeExample();
+ example.createCriteria()
+ .andProjectIdEqualTo(projectId).andNameEqualTo(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getNodeName());
+ List moduleNodes = extModuleNodeMapper.selectByExample(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getTableName(), example);
+ if (moduleNodes.size() == 0) {
+ ModuleNode record = new ModuleNode();
+ record.setId(UUID.randomUUID().toString());
+ record.setCreateUser(SessionUtils.getUserId());
+ record.setPos(1.0);
+ record.setLevel(1);
+ record.setCreateTime(System.currentTimeMillis());
+ record.setUpdateTime(System.currentTimeMillis());
+ record.setProjectId(projectId);
+ record.setName(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getNodeName());
+ extModuleNodeMapper.insert(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getTableName(), record);
+ }
}
}