fix(测试跟踪): 创建项目时测试跟踪默认模块重复创建的问题

--bug=1018836 --user=宋昌昌 【测试跟踪】功能用例列表中出现两个未规划模块(只有俩项目出现) https://www.tapd.cn/55049933/s/1276852
This commit is contained in:
song-cc-rock 2022-10-25 18:54:20 +08:00 committed by 刘瑞斌
parent e9527bf39a
commit d35e1eb4e4
2 changed files with 19 additions and 11 deletions

View File

@ -159,7 +159,6 @@
distinct distinct
</if> </if>
<include refid="io.metersphere.base.mapper.TestCaseNodeMapper.Base_Column_List"/> <include refid="io.metersphere.base.mapper.TestCaseNodeMapper.Base_Column_List"/>
,module_path
from ${tableName} from ${tableName}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause"/> <include refid="Example_Where_Clause"/>

View File

@ -1,6 +1,7 @@
package io.metersphere.listener; package io.metersphere.listener;
import io.metersphere.base.domain.ModuleNode; import io.metersphere.base.domain.ModuleNode;
import io.metersphere.base.domain.TestCaseNodeExample;
import io.metersphere.base.mapper.ext.ExtModuleNodeMapper; import io.metersphere.base.mapper.ext.ExtModuleNodeMapper;
import io.metersphere.commons.constants.KafkaTopicConstants; import io.metersphere.commons.constants.KafkaTopicConstants;
import io.metersphere.commons.constants.ProjectModuleDefaultNodeEnum; import io.metersphere.commons.constants.ProjectModuleDefaultNodeEnum;
@ -11,6 +12,7 @@ import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
import java.util.UUID; import java.util.UUID;
@Component @Component
@ -28,6 +30,12 @@ public class ProjectCreatedListener {
} }
private void initProjectDefaultNode(String projectId) { private void initProjectDefaultNode(String projectId) {
// 防止重复创建功能用例默认节点
TestCaseNodeExample example = new TestCaseNodeExample();
example.createCriteria()
.andProjectIdEqualTo(projectId).andNameEqualTo(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getNodeName());
List<ModuleNode> moduleNodes = extModuleNodeMapper.selectByExample(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getTableName(), example);
if (moduleNodes.size() == 0) {
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());
@ -39,4 +47,5 @@ public class ProjectCreatedListener {
record.setName(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getNodeName()); record.setName(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getNodeName());
extModuleNodeMapper.insert(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getTableName(), record); extModuleNodeMapper.insert(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getTableName(), record);
} }
}
} }