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
</if>
<include refid="io.metersphere.base.mapper.TestCaseNodeMapper.Base_Column_List"/>
,module_path
from ${tableName}
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>

View File

@ -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<ModuleNode> 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);
}
}
}