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,15 +30,22 @@ public class ProjectCreatedListener {
} }
private void initProjectDefaultNode(String projectId) { private void initProjectDefaultNode(String projectId) {
ModuleNode record = new ModuleNode(); // 防止重复创建功能用例默认节点
record.setId(UUID.randomUUID().toString()); TestCaseNodeExample example = new TestCaseNodeExample();
record.setCreateUser(SessionUtils.getUserId()); example.createCriteria()
record.setPos(1.0); .andProjectIdEqualTo(projectId).andNameEqualTo(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getNodeName());
record.setLevel(1); List<ModuleNode> moduleNodes = extModuleNodeMapper.selectByExample(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getTableName(), example);
record.setCreateTime(System.currentTimeMillis()); if (moduleNodes.size() == 0) {
record.setUpdateTime(System.currentTimeMillis()); ModuleNode record = new ModuleNode();
record.setProjectId(projectId); record.setId(UUID.randomUUID().toString());
record.setName(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getNodeName()); record.setCreateUser(SessionUtils.getUserId());
extModuleNodeMapper.insert(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getTableName(), record); 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);
}
} }
} }