fix(Mock测试): 修复因项目ID重复出现的Mock测试不通过:修改项目ID的生成方式,增加重复数据的处理

修复因项目ID重复出现的Mock测试不通过:修改项目ID的生成方式,增加重复数据的处理
This commit is contained in:
song-tianyang 2021-07-16 18:21:47 +08:00 committed by 刘瑞斌
parent dcc45e3143
commit 2da24153a4
4 changed files with 37 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import io.metersphere.api.dto.ApiTestEnvironmentDTO;
import io.metersphere.api.dto.mockconfig.MockConfigStaticData;
import io.metersphere.base.domain.ApiTestEnvironmentExample;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.base.domain.Project;
import io.metersphere.base.mapper.ApiTestEnvironmentMapper;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.CommonBeanFactory;
@ -330,7 +331,10 @@ public class ApiTestEnvironmentService {
private String getSystemIdByProjectId(String projectId){
ProjectService projectService = CommonBeanFactory.getBean(ProjectService.class);
if(projectService != null){
Project project = projectService.getProjectById(projectId);
project = projectService.checkSystemId(project);
return projectService.getSystemIdByProjectId(projectId);
}else {
return "";

View File

@ -19,4 +19,6 @@ public interface ExtProjectMapper {
String getSystemIdByProjectId(String projectId);
List<String> getProjectIds();
String getMaxSystemId();
}

View File

@ -114,6 +114,10 @@
select id from project;
</select>
<select id="getMaxSystemId" resultType="java.lang.String">
SELECT max(system_id) FROM project
</select>
<update id="removeIssuePlatform">
update project

View File

@ -100,10 +100,7 @@ public class ProjectService {
}
project.setId(UUID.randomUUID().toString());
long allCount = projectMapper.countByExample(null);
String systemId = String.valueOf(100001 + allCount);
String systemId = this.genSystemId();
long createTime = System.currentTimeMillis();
project.setCreateTime(createTime);
project.setUpdateTime(createTime);
@ -126,6 +123,32 @@ public class ProjectService {
return project;
}
private String genSystemId() {
String maxSystemIdInDb = extProjectMapper.getMaxSystemId();
String systemId = "10001";
if(StringUtils.isNotEmpty(maxSystemIdInDb)){
systemId = String.valueOf(Long.parseLong(maxSystemIdInDb) + 1);
}
return systemId;
}
public Project checkSystemId(Project project){
if(project!=null){
ProjectExample example = new ProjectExample();
example.createCriteria().andSystemIdEqualTo(project.getSystemId());
long count = projectMapper.countByExample(example);
if(count > 1){
String systemId = this.genSystemId();
Project updateModel = new Project();
updateModel.setId(project.getId());
updateModel.setSystemId(systemId);
projectMapper.updateByPrimaryKeySelective(updateModel);
project = this.getProjectById(project.getId());
}
}
return project;
}
public List<ProjectDTO> getProjectList(ProjectRequest request) {
if (StringUtils.isNotBlank(request.getName())) {
request.setName(StringUtils.wrapIfMissing(request.getName(), "%"));