From 2a217c9b0f6e8f4d328f73d04a6181d23e06876a Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Tue, 25 Oct 2022 18:54:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E9=A1=B9=E7=9B=AE=E6=97=B6=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=B7=9F=E8=B8=AA=E9=BB=98=E8=AE=A4=E6=A8=A1=E5=9D=97=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=88=9B=E5=BB=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1018836 --user=宋昌昌 【测试跟踪】功能用例列表中出现两个未规划模块(只有俩项目出现) https://www.tapd.cn/55049933/s/1276852 --- .../base/mapper/ext/ExtModuleNodeMapper.xml | 1 - .../listener/ProjectCreatedListener.java | 29 ++++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) 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); + } } }