From ec0d5a89ea2d2448941a8bce5678ac30dd22978e Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Fri, 18 Nov 2022 18:18:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=88=9B=E5=BB=BA=E5=90=8E=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E9=A1=B9=E7=9B=AE=E6=A8=A1=E5=9D=97=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/listener/ProjectCreatedListener.java | 10 +++++++++- .../metersphere/listener/ProjectCreatedListener.java | 12 ++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/listener/ProjectCreatedListener.java b/api-test/backend/src/main/java/io/metersphere/listener/ProjectCreatedListener.java index 75b5337033..af84756ec2 100644 --- a/api-test/backend/src/main/java/io/metersphere/listener/ProjectCreatedListener.java +++ b/api-test/backend/src/main/java/io/metersphere/listener/ProjectCreatedListener.java @@ -2,7 +2,9 @@ package io.metersphere.listener; import io.metersphere.base.domain.ApiModule; import io.metersphere.base.domain.ModuleNode; +import io.metersphere.base.domain.Project; import io.metersphere.base.mapper.ApiModuleMapper; +import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.ext.BaseModuleNodeMapper; import io.metersphere.commons.constants.KafkaTopicConstants; import io.metersphere.commons.constants.ProjectModuleDefaultNodeEnum; @@ -25,6 +27,8 @@ public class ProjectCreatedListener { private BaseModuleNodeMapper baseModuleNodeMapper; @Resource private ApiModuleMapper apiModuleMapper; + @Resource + private ProjectMapper projectMapper; @KafkaListener(id = CONSUME_ID, topics = KafkaTopicConstants.PROJECT_CREATED_TOPIC, groupId = "${spring.application.name}") @@ -35,9 +39,13 @@ public class ProjectCreatedListener { } private void initProjectDefaultNode(String projectId) { + Project project = projectMapper.selectByPrimaryKey(projectId); + if (project == null) { + return; + } ModuleNode record = new ModuleNode(); record.setId(UUID.randomUUID().toString()); - record.setCreateUser(SessionUtils.getUserId()); + record.setCreateUser(project.getCreateUser()); record.setPos(1.0); record.setLevel(1); record.setCreateTime(System.currentTimeMillis()); 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 8544ce16a3..71c54880ee 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,12 +1,13 @@ package io.metersphere.listener; import io.metersphere.base.domain.ModuleNode; +import io.metersphere.base.domain.Project; import io.metersphere.base.domain.TestCaseNodeExample; +import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.ext.ExtModuleNodeMapper; import io.metersphere.commons.constants.KafkaTopicConstants; import io.metersphere.commons.constants.ProjectModuleDefaultNodeEnum; import io.metersphere.commons.utils.LogUtil; -import io.metersphere.commons.utils.SessionUtils; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.springframework.kafka.annotation.KafkaListener; import org.springframework.stereotype.Component; @@ -21,6 +22,8 @@ public class ProjectCreatedListener { @Resource private ExtModuleNodeMapper extModuleNodeMapper; + @Resource + private ProjectMapper projectMapper; @KafkaListener(id = CONSUME_ID, topics = KafkaTopicConstants.PROJECT_CREATED_TOPIC, groupId = "${spring.application.name}") public void consume(ConsumerRecord record) { @@ -30,6 +33,11 @@ public class ProjectCreatedListener { } private void initProjectDefaultNode(String projectId) { + Project project = projectMapper.selectByPrimaryKey(projectId); + if (project == null) { + return; + } + // 防止重复创建功能用例默认节点 TestCaseNodeExample example = new TestCaseNodeExample(); example.createCriteria() @@ -38,7 +46,7 @@ public class ProjectCreatedListener { if (moduleNodes.size() == 0) { ModuleNode record = new ModuleNode(); record.setId(UUID.randomUUID().toString()); - record.setCreateUser(SessionUtils.getUserId()); + record.setCreateUser(project.getCreateUser()); record.setPos(1.0); record.setLevel(1); record.setCreateTime(System.currentTimeMillis());