fix(Mock测试): 修复因项目ID重复出现的Mock测试不通过:修改项目ID的生成方式,增加重复数据的处理
修复因项目ID重复出现的Mock测试不通过:修改项目ID的生成方式,增加重复数据的处理
This commit is contained in:
parent
dcc45e3143
commit
2da24153a4
|
@ -7,6 +7,7 @@ import io.metersphere.api.dto.ApiTestEnvironmentDTO;
|
||||||
import io.metersphere.api.dto.mockconfig.MockConfigStaticData;
|
import io.metersphere.api.dto.mockconfig.MockConfigStaticData;
|
||||||
import io.metersphere.base.domain.ApiTestEnvironmentExample;
|
import io.metersphere.base.domain.ApiTestEnvironmentExample;
|
||||||
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
||||||
|
import io.metersphere.base.domain.Project;
|
||||||
import io.metersphere.base.mapper.ApiTestEnvironmentMapper;
|
import io.metersphere.base.mapper.ApiTestEnvironmentMapper;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
|
@ -330,7 +331,10 @@ public class ApiTestEnvironmentService {
|
||||||
|
|
||||||
private String getSystemIdByProjectId(String projectId){
|
private String getSystemIdByProjectId(String projectId){
|
||||||
ProjectService projectService = CommonBeanFactory.getBean(ProjectService.class);
|
ProjectService projectService = CommonBeanFactory.getBean(ProjectService.class);
|
||||||
|
|
||||||
if(projectService != null){
|
if(projectService != null){
|
||||||
|
Project project = projectService.getProjectById(projectId);
|
||||||
|
project = projectService.checkSystemId(project);
|
||||||
return projectService.getSystemIdByProjectId(projectId);
|
return projectService.getSystemIdByProjectId(projectId);
|
||||||
}else {
|
}else {
|
||||||
return "";
|
return "";
|
||||||
|
|
|
@ -19,4 +19,6 @@ public interface ExtProjectMapper {
|
||||||
String getSystemIdByProjectId(String projectId);
|
String getSystemIdByProjectId(String projectId);
|
||||||
|
|
||||||
List<String> getProjectIds();
|
List<String> getProjectIds();
|
||||||
|
|
||||||
|
String getMaxSystemId();
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,10 @@
|
||||||
select id from project;
|
select id from project;
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getMaxSystemId" resultType="java.lang.String">
|
||||||
|
SELECT max(system_id) FROM project
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
<update id="removeIssuePlatform">
|
<update id="removeIssuePlatform">
|
||||||
update project
|
update project
|
||||||
|
|
|
@ -100,10 +100,7 @@ public class ProjectService {
|
||||||
}
|
}
|
||||||
project.setId(UUID.randomUUID().toString());
|
project.setId(UUID.randomUUID().toString());
|
||||||
|
|
||||||
|
String systemId = this.genSystemId();
|
||||||
long allCount = projectMapper.countByExample(null);
|
|
||||||
String systemId = String.valueOf(100001 + allCount);
|
|
||||||
|
|
||||||
long createTime = System.currentTimeMillis();
|
long createTime = System.currentTimeMillis();
|
||||||
project.setCreateTime(createTime);
|
project.setCreateTime(createTime);
|
||||||
project.setUpdateTime(createTime);
|
project.setUpdateTime(createTime);
|
||||||
|
@ -126,6 +123,32 @@ public class ProjectService {
|
||||||
return project;
|
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) {
|
public List<ProjectDTO> getProjectList(ProjectRequest request) {
|
||||||
if (StringUtils.isNotBlank(request.getName())) {
|
if (StringUtils.isNotBlank(request.getName())) {
|
||||||
request.setName(StringUtils.wrapIfMissing(request.getName(), "%"));
|
request.setName(StringUtils.wrapIfMissing(request.getName(), "%"));
|
||||||
|
|
Loading…
Reference in New Issue