fix(系统设置): 项目创建后初始化项目模块问题

This commit is contained in:
shiziyuan9527 2022-11-18 18:18:11 +08:00 committed by lyh
parent e6622291d3
commit 998c6ff12c
2 changed files with 19 additions and 3 deletions

View File

@ -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());

View File

@ -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<?, String> 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());