fix(系统设置): 项目创建后初始化项目模块问题
This commit is contained in:
parent
e6622291d3
commit
998c6ff12c
|
@ -2,7 +2,9 @@ package io.metersphere.listener;
|
||||||
|
|
||||||
import io.metersphere.base.domain.ApiModule;
|
import io.metersphere.base.domain.ApiModule;
|
||||||
import io.metersphere.base.domain.ModuleNode;
|
import io.metersphere.base.domain.ModuleNode;
|
||||||
|
import io.metersphere.base.domain.Project;
|
||||||
import io.metersphere.base.mapper.ApiModuleMapper;
|
import io.metersphere.base.mapper.ApiModuleMapper;
|
||||||
|
import io.metersphere.base.mapper.ProjectMapper;
|
||||||
import io.metersphere.base.mapper.ext.BaseModuleNodeMapper;
|
import io.metersphere.base.mapper.ext.BaseModuleNodeMapper;
|
||||||
import io.metersphere.commons.constants.KafkaTopicConstants;
|
import io.metersphere.commons.constants.KafkaTopicConstants;
|
||||||
import io.metersphere.commons.constants.ProjectModuleDefaultNodeEnum;
|
import io.metersphere.commons.constants.ProjectModuleDefaultNodeEnum;
|
||||||
|
@ -25,6 +27,8 @@ public class ProjectCreatedListener {
|
||||||
private BaseModuleNodeMapper baseModuleNodeMapper;
|
private BaseModuleNodeMapper baseModuleNodeMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private ApiModuleMapper apiModuleMapper;
|
private ApiModuleMapper apiModuleMapper;
|
||||||
|
@Resource
|
||||||
|
private ProjectMapper projectMapper;
|
||||||
|
|
||||||
|
|
||||||
@KafkaListener(id = CONSUME_ID, topics = KafkaTopicConstants.PROJECT_CREATED_TOPIC, groupId = "${spring.application.name}")
|
@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) {
|
private void initProjectDefaultNode(String projectId) {
|
||||||
|
Project project = projectMapper.selectByPrimaryKey(projectId);
|
||||||
|
if (project == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ModuleNode record = new ModuleNode();
|
ModuleNode record = new ModuleNode();
|
||||||
record.setId(UUID.randomUUID().toString());
|
record.setId(UUID.randomUUID().toString());
|
||||||
record.setCreateUser(SessionUtils.getUserId());
|
record.setCreateUser(project.getCreateUser());
|
||||||
record.setPos(1.0);
|
record.setPos(1.0);
|
||||||
record.setLevel(1);
|
record.setLevel(1);
|
||||||
record.setCreateTime(System.currentTimeMillis());
|
record.setCreateTime(System.currentTimeMillis());
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
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.Project;
|
||||||
import io.metersphere.base.domain.TestCaseNodeExample;
|
import io.metersphere.base.domain.TestCaseNodeExample;
|
||||||
|
import io.metersphere.base.mapper.ProjectMapper;
|
||||||
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;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
import io.metersphere.commons.utils.SessionUtils;
|
|
||||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||||
import org.springframework.kafka.annotation.KafkaListener;
|
import org.springframework.kafka.annotation.KafkaListener;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -21,6 +22,8 @@ public class ProjectCreatedListener {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ExtModuleNodeMapper extModuleNodeMapper;
|
private ExtModuleNodeMapper extModuleNodeMapper;
|
||||||
|
@Resource
|
||||||
|
private ProjectMapper projectMapper;
|
||||||
|
|
||||||
@KafkaListener(id = CONSUME_ID, topics = KafkaTopicConstants.PROJECT_CREATED_TOPIC, groupId = "${spring.application.name}")
|
@KafkaListener(id = CONSUME_ID, topics = KafkaTopicConstants.PROJECT_CREATED_TOPIC, groupId = "${spring.application.name}")
|
||||||
public void consume(ConsumerRecord<?, String> record) {
|
public void consume(ConsumerRecord<?, String> record) {
|
||||||
|
@ -30,6 +33,11 @@ public class ProjectCreatedListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initProjectDefaultNode(String projectId) {
|
private void initProjectDefaultNode(String projectId) {
|
||||||
|
Project project = projectMapper.selectByPrimaryKey(projectId);
|
||||||
|
if (project == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 防止重复创建功能用例默认节点
|
// 防止重复创建功能用例默认节点
|
||||||
TestCaseNodeExample example = new TestCaseNodeExample();
|
TestCaseNodeExample example = new TestCaseNodeExample();
|
||||||
example.createCriteria()
|
example.createCriteria()
|
||||||
|
@ -38,7 +46,7 @@ public class ProjectCreatedListener {
|
||||||
if (moduleNodes.size() == 0) {
|
if (moduleNodes.size() == 0) {
|
||||||
ModuleNode record = new ModuleNode();
|
ModuleNode record = new ModuleNode();
|
||||||
record.setId(UUID.randomUUID().toString());
|
record.setId(UUID.randomUUID().toString());
|
||||||
record.setCreateUser(SessionUtils.getUserId());
|
record.setCreateUser(project.getCreateUser());
|
||||||
record.setPos(1.0);
|
record.setPos(1.0);
|
||||||
record.setLevel(1);
|
record.setLevel(1);
|
||||||
record.setCreateTime(System.currentTimeMillis());
|
record.setCreateTime(System.currentTimeMillis());
|
||||||
|
|
Loading…
Reference in New Issue