fix(接口测试): 解决全新安装默认项目初始化模块重复问题
--bug=1021358 --user=赵勇 【接口测试】在安装过ms的环境重新安装ms,会出现2个未规划模块 https://www.tapd.cn/55049933/s/1320747
This commit is contained in:
parent
5639088349
commit
3d80530beb
|
@ -3,15 +3,13 @@ package io.metersphere.listener;
|
||||||
import com.mchange.lang.IntegerUtils;
|
import com.mchange.lang.IntegerUtils;
|
||||||
import io.metersphere.api.exec.queue.ExecThreadPoolExecutor;
|
import io.metersphere.api.exec.queue.ExecThreadPoolExecutor;
|
||||||
import io.metersphere.api.jmeter.JMeterService;
|
import io.metersphere.api.jmeter.JMeterService;
|
||||||
import io.metersphere.service.ApiExecutionQueueService;
|
|
||||||
import io.metersphere.service.MockConfigService;
|
|
||||||
import io.metersphere.service.PluginService;
|
|
||||||
import io.metersphere.commons.constants.ScheduleGroup;
|
import io.metersphere.commons.constants.ScheduleGroup;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
import io.metersphere.dto.BaseSystemConfigDTO;
|
import io.metersphere.dto.BaseSystemConfigDTO;
|
||||||
import io.metersphere.service.BaseScheduleService;
|
import io.metersphere.service.*;
|
||||||
import io.metersphere.service.SystemParameterService;
|
import io.metersphere.service.definition.ApiModuleService;
|
||||||
|
import io.metersphere.service.scenario.ApiScenarioModuleService;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.python.core.Options;
|
import org.python.core.Options;
|
||||||
import org.python.util.PythonInterpreter;
|
import org.python.util.PythonInterpreter;
|
||||||
|
@ -36,6 +34,10 @@ public class ApiAppStartListener implements ApplicationRunner {
|
||||||
private PluginService pluginService;
|
private PluginService pluginService;
|
||||||
@Resource
|
@Resource
|
||||||
private ApiExecutionQueueService apiExecutionQueueService;
|
private ApiExecutionQueueService apiExecutionQueueService;
|
||||||
|
@Resource
|
||||||
|
private ApiModuleService apiModuleService;
|
||||||
|
@Resource
|
||||||
|
private ApiScenarioModuleService apiScenarioModuleService;
|
||||||
|
|
||||||
@Value("${jmeter.home}")
|
@Value("${jmeter.home}")
|
||||||
private String jmeterHome;
|
private String jmeterHome;
|
||||||
|
@ -59,6 +61,12 @@ public class ApiAppStartListener implements ApplicationRunner {
|
||||||
LogUtil.info("处理重启导致未执行完成的报告");
|
LogUtil.info("处理重启导致未执行完成的报告");
|
||||||
apiExecutionQueueService.exceptionHandling();
|
apiExecutionQueueService.exceptionHandling();
|
||||||
|
|
||||||
|
LogUtil.info("初始化默认项目接口模块");
|
||||||
|
apiModuleService.initDefaultNode();
|
||||||
|
|
||||||
|
LogUtil.info("初始化默认项目场景模块");
|
||||||
|
apiScenarioModuleService.initDefaultModule();
|
||||||
|
|
||||||
BaseSystemConfigDTO dto = systemParameterService.getBaseInfo();
|
BaseSystemConfigDTO dto = systemParameterService.getBaseInfo();
|
||||||
LogUtil.info("设置并发队列核心数", dto.getConcurrency());
|
LogUtil.info("设置并发队列核心数", dto.getConcurrency());
|
||||||
if (StringUtils.isNotEmpty(dto.getConcurrency())) {
|
if (StringUtils.isNotEmpty(dto.getConcurrency())) {
|
||||||
|
|
|
@ -6,11 +6,13 @@ import io.metersphere.api.parse.api.ApiDefinitionImport;
|
||||||
import io.metersphere.base.domain.*;
|
import io.metersphere.base.domain.*;
|
||||||
import io.metersphere.base.mapper.ApiDefinitionMapper;
|
import io.metersphere.base.mapper.ApiDefinitionMapper;
|
||||||
import io.metersphere.base.mapper.ApiModuleMapper;
|
import io.metersphere.base.mapper.ApiModuleMapper;
|
||||||
|
import io.metersphere.base.mapper.ProjectMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtApiDefinitionMapper;
|
import io.metersphere.base.mapper.ext.ExtApiDefinitionMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtApiModuleMapper;
|
import io.metersphere.base.mapper.ext.ExtApiModuleMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper;
|
import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper;
|
||||||
import io.metersphere.commons.constants.ProjectModuleDefaultNodeEnum;
|
import io.metersphere.commons.constants.ProjectModuleDefaultNodeEnum;
|
||||||
import io.metersphere.commons.constants.PropertyConstant;
|
import io.metersphere.commons.constants.PropertyConstant;
|
||||||
|
import io.metersphere.commons.constants.RequestTypeConstants;
|
||||||
import io.metersphere.commons.constants.TestCaseConstants;
|
import io.metersphere.commons.constants.TestCaseConstants;
|
||||||
import io.metersphere.commons.enums.ApiTestDataStatus;
|
import io.metersphere.commons.enums.ApiTestDataStatus;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
|
@ -31,7 +33,6 @@ import org.apache.ibatis.session.SqlSession;
|
||||||
import org.apache.ibatis.session.SqlSessionFactory;
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.mybatis.spring.SqlSessionUtils;
|
import org.mybatis.spring.SqlSessionUtils;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@ -54,6 +55,8 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
||||||
private ApiDefinitionService apiDefinitionService;
|
private ApiDefinitionService apiDefinitionService;
|
||||||
@Resource
|
@Resource
|
||||||
private ExtApiTestCaseMapper extApiTestCaseMapper;
|
private ExtApiTestCaseMapper extApiTestCaseMapper;
|
||||||
|
@Resource
|
||||||
|
private ProjectMapper projectMapper;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
SqlSessionFactory sqlSessionFactory;
|
SqlSessionFactory sqlSessionFactory;
|
||||||
|
@ -141,8 +144,6 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ApiModuleDTO> getNodeTreeByProjectId(String projectId, String protocol, String versionId) {
|
public List<ApiModuleDTO> getNodeTreeByProjectId(String projectId, String protocol, String versionId) {
|
||||||
// 判断当前项目下是否有默认模块,没有添加默认模块
|
|
||||||
this.getDefaultNode(projectId, protocol);
|
|
||||||
ApiDefinitionRequest request = new ApiDefinitionRequest();
|
ApiDefinitionRequest request = new ApiDefinitionRequest();
|
||||||
List<ApiModuleDTO> apiModules = getApiModulesByProjectAndPro(projectId, protocol);
|
List<ApiModuleDTO> apiModules = getApiModulesByProjectAndPro(projectId, protocol);
|
||||||
request.setProjectId(projectId);
|
request.setProjectId(projectId);
|
||||||
|
@ -189,8 +190,6 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ApiModuleDTO> getNodeTreeByCondition(String projectId, String protocol, String versionId, ApiDefinitionRequest request) {
|
public List<ApiModuleDTO> getNodeTreeByCondition(String projectId, String protocol, String versionId, ApiDefinitionRequest request) {
|
||||||
// 判断当前项目下是否有默认模块,没有添加默认模块
|
|
||||||
this.getDefaultNode(projectId, protocol);
|
|
||||||
List<ApiModuleDTO> apiModules = getApiModulesByProjectAndPro(projectId, protocol);
|
List<ApiModuleDTO> apiModules = getApiModulesByProjectAndPro(projectId, protocol);
|
||||||
request.setProjectId(projectId);
|
request.setProjectId(projectId);
|
||||||
request.setProtocol(protocol);
|
request.setProtocol(protocol);
|
||||||
|
@ -570,19 +569,29 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
||||||
return apiModuleMapper.countByExample(example);
|
return apiModuleMapper.countByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void initDefaultNode() {
|
||||||
|
ProjectExample projectExample = new ProjectExample();
|
||||||
|
projectExample.createCriteria().andNameEqualTo("默认项目");
|
||||||
|
List<Project> projects = projectMapper.selectByExample(projectExample);
|
||||||
|
if (CollectionUtils.isNotEmpty(projects)) {
|
||||||
|
String[] protocols = {RequestTypeConstants.HTTP, RequestTypeConstants.DUBBO, RequestTypeConstants.SQL, RequestTypeConstants.TCP};
|
||||||
|
for (String protocol : protocols) {
|
||||||
|
saveDefault(projects.get(0).getId(), protocol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ApiModule getDefaultNode(String projectId, String protocol) {
|
public ApiModule getDefaultNode(String projectId, String protocol) {
|
||||||
ApiModuleExample example = new ApiModuleExample();
|
ApiModuleExample example = new ApiModuleExample();
|
||||||
example.createCriteria().andProjectIdEqualTo(projectId).andProtocolEqualTo(protocol).andNameEqualTo(ProjectModuleDefaultNodeEnum.API_MODULE_DEFAULT_NODE.getNodeName()).andParentIdIsNull();
|
example.createCriteria().andProjectIdEqualTo(projectId).andProtocolEqualTo(protocol).andNameEqualTo(ProjectModuleDefaultNodeEnum.API_MODULE_DEFAULT_NODE.getNodeName()).andParentIdIsNull();
|
||||||
List<ApiModule> list = apiModuleMapper.selectByExample(example);
|
List<ApiModule> list = apiModuleMapper.selectByExample(example);
|
||||||
if (CollectionUtils.isEmpty(list)) {
|
if (CollectionUtils.isNotEmpty(list)) {
|
||||||
return saveDefault(projectId, protocol);
|
|
||||||
} else {
|
|
||||||
return list.get(0);
|
return list.get(0);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Async
|
public ApiModule saveDefault(String projectId, String protocol) {
|
||||||
public synchronized ApiModule saveDefault(String projectId, String protocol) {
|
|
||||||
ApiModuleExample example = new ApiModuleExample();
|
ApiModuleExample example = new ApiModuleExample();
|
||||||
example.createCriteria().andProjectIdEqualTo(projectId).andProtocolEqualTo(protocol).andNameEqualTo(ProjectModuleDefaultNodeEnum.API_MODULE_DEFAULT_NODE.getNodeName()).andParentIdIsNull();
|
example.createCriteria().andProjectIdEqualTo(projectId).andProtocolEqualTo(protocol).andNameEqualTo(ProjectModuleDefaultNodeEnum.API_MODULE_DEFAULT_NODE.getNodeName()).andParentIdIsNull();
|
||||||
List<ApiModule> list = apiModuleMapper.selectByExample(example);
|
List<ApiModule> list = apiModuleMapper.selectByExample(example);
|
||||||
|
|
|
@ -3,12 +3,10 @@ package io.metersphere.service.scenario;
|
||||||
|
|
||||||
import io.metersphere.api.dto.ApiTestImportRequest;
|
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||||
import io.metersphere.api.dto.automation.*;
|
import io.metersphere.api.dto.automation.*;
|
||||||
import io.metersphere.base.domain.ApiScenario;
|
import io.metersphere.base.domain.*;
|
||||||
import io.metersphere.base.domain.ApiScenarioModule;
|
|
||||||
import io.metersphere.base.domain.ApiScenarioModuleExample;
|
|
||||||
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
|
||||||
import io.metersphere.base.mapper.ApiScenarioMapper;
|
import io.metersphere.base.mapper.ApiScenarioMapper;
|
||||||
import io.metersphere.base.mapper.ApiScenarioModuleMapper;
|
import io.metersphere.base.mapper.ApiScenarioModuleMapper;
|
||||||
|
import io.metersphere.base.mapper.ProjectMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtApiScenarioMapper;
|
import io.metersphere.base.mapper.ext.ExtApiScenarioMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtApiScenarioModuleMapper;
|
import io.metersphere.base.mapper.ext.ExtApiScenarioModuleMapper;
|
||||||
import io.metersphere.commons.constants.ProjectModuleDefaultNodeEnum;
|
import io.metersphere.commons.constants.ProjectModuleDefaultNodeEnum;
|
||||||
|
@ -30,10 +28,9 @@ import org.apache.ibatis.session.ExecutorType;
|
||||||
import org.apache.ibatis.session.SqlSession;
|
import org.apache.ibatis.session.SqlSession;
|
||||||
import org.apache.ibatis.session.SqlSessionFactory;
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
import org.mybatis.spring.SqlSessionUtils;
|
import org.mybatis.spring.SqlSessionUtils;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -55,14 +52,14 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
||||||
SqlSessionFactory sqlSessionFactory;
|
SqlSessionFactory sqlSessionFactory;
|
||||||
@Resource
|
@Resource
|
||||||
private ExtApiScenarioMapper extApiScenarioMapper;
|
private ExtApiScenarioMapper extApiScenarioMapper;
|
||||||
|
@Resource
|
||||||
|
private ProjectMapper projectMapper;
|
||||||
|
|
||||||
public ApiScenarioModuleService() {
|
public ApiScenarioModuleService() {
|
||||||
super(ApiScenarioModuleDTO.class);
|
super(ApiScenarioModuleDTO.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ApiScenarioModuleDTO> getNodeTreeByProjectId(String projectId) {
|
public List<ApiScenarioModuleDTO> getNodeTreeByProjectId(String projectId) {
|
||||||
// 判断当前项目下是否有默认模块,没有添加默认模块
|
|
||||||
this.getDefaultNode(projectId);
|
|
||||||
List<ApiScenarioModuleDTO> nodes = extApiScenarioModuleMapper.getNodeTreeByProjectId(projectId);
|
List<ApiScenarioModuleDTO> nodes = extApiScenarioModuleMapper.getNodeTreeByProjectId(projectId);
|
||||||
ApiScenarioRequest request = new ApiScenarioRequest();
|
ApiScenarioRequest request = new ApiScenarioRequest();
|
||||||
request.setProjectId(projectId);
|
request.setProjectId(projectId);
|
||||||
|
@ -103,8 +100,6 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ApiScenarioModuleDTO> getNodeTreeByProjectId(String projectId, ApiScenarioRequest request) {
|
public List<ApiScenarioModuleDTO> getNodeTreeByProjectId(String projectId, ApiScenarioRequest request) {
|
||||||
// 判断当前项目下是否有默认模块,没有添加默认模块
|
|
||||||
this.getDefaultNode(projectId);
|
|
||||||
List<ApiScenarioModuleDTO> nodes = extApiScenarioModuleMapper.getNodeTreeByProjectId(projectId);
|
List<ApiScenarioModuleDTO> nodes = extApiScenarioModuleMapper.getNodeTreeByProjectId(projectId);
|
||||||
request.setProjectId(projectId);
|
request.setProjectId(projectId);
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
|
@ -174,7 +169,7 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initApiCount(List<ApiScenarioModuleDTO> moduleDTOList, Map<String, List<ApiScenario>> scenarioMap) {
|
private void initApiCount(List<ApiScenarioModuleDTO> moduleDTOList, Map<String, List<ApiScenario>> scenarioMap) {
|
||||||
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(moduleDTOList) && MapUtils.isNotEmpty(scenarioMap)) {
|
if (CollectionUtils.isNotEmpty(moduleDTOList) && MapUtils.isNotEmpty(scenarioMap)) {
|
||||||
moduleDTOList.forEach(node -> {
|
moduleDTOList.forEach(node -> {
|
||||||
List<String> moduleIds = new ArrayList<>();
|
List<String> moduleIds = new ArrayList<>();
|
||||||
moduleIds = this.nodeList(moduleDTOList, node.getId(), moduleIds);
|
moduleIds = this.nodeList(moduleDTOList, node.getId(), moduleIds);
|
||||||
|
@ -191,7 +186,7 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ApiScenarioModuleDTO> selectTreeStructModuleById(Collection<String> ids) {
|
private List<ApiScenarioModuleDTO> selectTreeStructModuleById(Collection<String> ids) {
|
||||||
if (org.apache.commons.collections.CollectionUtils.isEmpty(ids)) {
|
if (CollectionUtils.isEmpty(ids)) {
|
||||||
return new ArrayList<>(0);
|
return new ArrayList<>(0);
|
||||||
} else {
|
} else {
|
||||||
List<String> parentIdList = new ArrayList<>();
|
List<String> parentIdList = new ArrayList<>();
|
||||||
|
@ -246,7 +241,7 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
||||||
|
|
||||||
public double getNextLevelPos(String projectId, int level, String parentId) {
|
public double getNextLevelPos(String projectId, int level, String parentId) {
|
||||||
List<ApiScenarioModule> list = getPos(projectId, level, parentId, "pos desc");
|
List<ApiScenarioModule> list = getPos(projectId, level, parentId, "pos desc");
|
||||||
if (!CollectionUtils.isEmpty(list) && list.get(0) != null && list.get(0).getPos() != null) {
|
if (CollectionUtils.isNotEmpty(list) && list.get(0) != null && list.get(0).getPos() != null) {
|
||||||
return list.get(0).getPos() + DEFAULT_POS;
|
return list.get(0).getPos() + DEFAULT_POS;
|
||||||
} else {
|
} else {
|
||||||
return DEFAULT_POS;
|
return DEFAULT_POS;
|
||||||
|
@ -463,7 +458,7 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
||||||
ApiScenarioModuleExample example = new ApiScenarioModuleExample();
|
ApiScenarioModuleExample example = new ApiScenarioModuleExample();
|
||||||
example.createCriteria().andIdIn(ids);
|
example.createCriteria().andIdIn(ids);
|
||||||
List<ApiScenarioModule> nodes = apiScenarioModuleMapper.selectByExample(example);
|
List<ApiScenarioModule> nodes = apiScenarioModuleMapper.selectByExample(example);
|
||||||
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(nodes)) {
|
if (CollectionUtils.isNotEmpty(nodes)) {
|
||||||
List<String> names = nodes.stream().map(ApiScenarioModule::getName).collect(Collectors.toList());
|
List<String> names = nodes.stream().map(ApiScenarioModule::getName).collect(Collectors.toList());
|
||||||
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(ids), nodes.get(0).getProjectId(), String.join(",", names), nodes.get(0).getCreateUser(), new LinkedList<>());
|
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(ids), nodes.get(0).getProjectId(), String.join(",", names), nodes.get(0).getCreateUser(), new LinkedList<>());
|
||||||
return JSON.toJSONString(details);
|
return JSON.toJSONString(details);
|
||||||
|
@ -489,7 +484,7 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
||||||
criteria.andIdNotEqualTo(node.getId());
|
criteria.andIdNotEqualTo(node.getId());
|
||||||
}
|
}
|
||||||
List<ApiScenarioModule> list = apiScenarioModuleMapper.selectByExample(example);
|
List<ApiScenarioModule> list = apiScenarioModuleMapper.selectByExample(example);
|
||||||
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(list)) {
|
if (CollectionUtils.isNotEmpty(list)) {
|
||||||
module = list.get(0);
|
module = list.get(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -509,34 +504,40 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
||||||
|
|
||||||
public ApiScenarioModule getDefaultNode(String projectId) {
|
public ApiScenarioModule getDefaultNode(String projectId) {
|
||||||
ApiScenarioModuleExample example = new ApiScenarioModuleExample();
|
ApiScenarioModuleExample example = new ApiScenarioModuleExample();
|
||||||
example.createCriteria().andProjectIdEqualTo(projectId).andNameEqualTo(ProjectModuleDefaultNodeEnum.API_SCENARIO_DEFAULT_NODE.getNodeName()).andParentIdIsNull();
|
example.createCriteria()
|
||||||
|
.andProjectIdEqualTo(projectId)
|
||||||
|
.andNameEqualTo(ProjectModuleDefaultNodeEnum.API_SCENARIO_DEFAULT_NODE.getNodeName())
|
||||||
|
.andParentIdIsNull();
|
||||||
List<ApiScenarioModule> list = apiScenarioModuleMapper.selectByExample(example);
|
List<ApiScenarioModule> list = apiScenarioModuleMapper.selectByExample(example);
|
||||||
if (CollectionUtils.isEmpty(list)) {
|
if (!CollectionUtils.isEmpty(list)) {
|
||||||
return saveDefault(projectId);
|
|
||||||
} else {
|
|
||||||
return list.get(0);
|
return list.get(0);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Async
|
public void initDefaultModule() {
|
||||||
public synchronized ApiScenarioModule saveDefault(String projectId) {
|
ProjectExample projectExample = new ProjectExample();
|
||||||
ApiScenarioModuleExample example = new ApiScenarioModuleExample();
|
projectExample.createCriteria().andNameEqualTo("默认项目");
|
||||||
example.createCriteria().andProjectIdEqualTo(projectId).andNameEqualTo(ProjectModuleDefaultNodeEnum.API_SCENARIO_DEFAULT_NODE.getNodeName()).andParentIdIsNull();
|
List<Project> projects = projectMapper.selectByExample(projectExample);
|
||||||
List<ApiScenarioModule> list = apiScenarioModuleMapper.selectByExample(example);
|
if (!CollectionUtils.isEmpty(projects)) {
|
||||||
if (CollectionUtils.isEmpty(list)) {
|
ApiScenarioModuleExample example = new ApiScenarioModuleExample();
|
||||||
ApiScenarioModule module = new ApiScenarioModule();
|
example.createCriteria()
|
||||||
module.setId(UUID.randomUUID().toString());
|
.andProjectIdEqualTo(projects.get(0).getId())
|
||||||
module.setName(ProjectModuleDefaultNodeEnum.API_SCENARIO_DEFAULT_NODE.getNodeName());
|
.andNameEqualTo(ProjectModuleDefaultNodeEnum.API_SCENARIO_DEFAULT_NODE.getNodeName())
|
||||||
module.setPos(1.0);
|
.andParentIdIsNull();
|
||||||
module.setLevel(1);
|
List<ApiScenarioModule> list = apiScenarioModuleMapper.selectByExample(example);
|
||||||
module.setCreateTime(System.currentTimeMillis());
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
module.setUpdateTime(System.currentTimeMillis());
|
ApiScenarioModule module = new ApiScenarioModule();
|
||||||
module.setProjectId(projectId);
|
module.setId(UUID.randomUUID().toString());
|
||||||
module.setCreateUser(SessionUtils.getUserId());
|
module.setName(ProjectModuleDefaultNodeEnum.API_SCENARIO_DEFAULT_NODE.getNodeName());
|
||||||
apiScenarioModuleMapper.insert(module);
|
module.setPos(1.0);
|
||||||
return module;
|
module.setLevel(1);
|
||||||
} else {
|
module.setCreateTime(System.currentTimeMillis());
|
||||||
return list.get(0);
|
module.setUpdateTime(System.currentTimeMillis());
|
||||||
|
module.setProjectId(projects.get(0).getId());
|
||||||
|
module.setCreateUser(SessionUtils.getUserId());
|
||||||
|
apiScenarioModuleMapper.insert(module);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue