fix(接口测试): 解决未选模块不覆盖时接口重复导入时用例导入报错问题以及接口导入查询重复数据时排除已删除状态

--user=郭雨琦
--bug=1014659
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001014659
【接口测试】sql协议导入jmeter文件,接口删除后,再次导入相同的文件,提示格式错误
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001014649
【接口测试】sql协议导入的文件删除后,再次导入文件导入失败
This commit is contained in:
guoyuqi 2022-07-05 19:46:01 +08:00 committed by xiaomeinvG
parent 5811079fd5
commit e3390ce9cd
4 changed files with 28 additions and 7 deletions

View File

@ -271,7 +271,7 @@ public class ApiScenarioImportUtil {
apiTestCase.setUpdateTime(System.currentTimeMillis()); apiTestCase.setUpdateTime(System.currentTimeMillis());
apiTestCase.setVersionId(apiDefinition.getVersionId()); apiTestCase.setVersionId(apiDefinition.getVersionId());
apiTestCase.setPriority("P0"); apiTestCase.setPriority("P0");
apiTestCase.setNum(testCaseService.getNextNum(apiTestCase.getApiDefinitionId(), apiDefinition.getNum() + i)); apiTestCase.setNum(testCaseService.getNextNum(apiTestCase.getApiDefinitionId(), apiDefinition.getNum() + i, projectId));
object.put("id", apiTestCase.getId()); object.put("id", apiTestCase.getId());
object.put("resourceId", apiTestCase.getId()); object.put("resourceId", apiTestCase.getId());
object.put("projectId", projectId); object.put("projectId", projectId);

View File

@ -1189,7 +1189,7 @@ public class ApiDefinitionService {
if (sameCase == null) { if (sameCase == null) {
apiTestCase.setId(UUID.randomUUID().toString()); apiTestCase.setId(UUID.randomUUID().toString());
apiTestCase.setStatus(""); apiTestCase.setStatus("");
apiTestCase.setNum(apiTestCaseService.getNextNum(apiTestCase.getApiDefinitionId(), apiDefinition.getNum())); apiTestCase.setNum(apiTestCaseService.getNextNum(apiTestCase.getApiDefinitionId(), apiDefinition.getNum(), apiDefinition.getProjectId()));
apiTestCase.setCreateTime(System.currentTimeMillis()); apiTestCase.setCreateTime(System.currentTimeMillis());
apiTestCase.setUpdateTime(System.currentTimeMillis()); apiTestCase.setUpdateTime(System.currentTimeMillis());
apiTestCase.setCreateUserId(SessionUtils.getUserId()); apiTestCase.setCreateUserId(SessionUtils.getUserId());

View File

@ -115,6 +115,8 @@ public class ApiTestCaseService {
private ObjectMapper mapper; private ObjectMapper mapper;
@Resource @Resource
private ApiCaseExecutionInfoService apiCaseExecutionInfoService; private ApiCaseExecutionInfoService apiCaseExecutionInfoService;
@Resource
private ExtApiDefinitionMapper extApiDefinitionMapper;
private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR; private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR;
@ -476,25 +478,43 @@ public class ApiTestCaseService {
public int getNextNum(String definitionId) { public int getNextNum(String definitionId) {
ApiTestCase apiTestCase = extApiTestCaseMapper.getNextNum(definitionId); ApiTestCase apiTestCase = extApiTestCaseMapper.getNextNum(definitionId);
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = apiDefinitionMapper.selectByPrimaryKey(definitionId);
if (apiTestCase == null) { if (apiTestCase == null) {
int n = apiDefinitionMapper.selectByPrimaryKey(definitionId).getNum(); int n = apiDefinitionWithBLOBs.getNum();
return n * 1000 + 1; return n * 1000 + 1;
} else { } else {
return Optional.of(apiTestCase.getNum() + 1) return Optional.of(apiTestCase.getNum() + 1)
.orElse(apiDefinitionMapper.selectByPrimaryKey(definitionId).getNum() * 1000 + 1); .orElse(apiDefinitionWithBLOBs.getNum() * 1000 + 1);
} }
} }
public int getNextNum(String definitionId, Integer definitionNum) { public int getNextNum(String definitionId, Integer definitionNum, String projectId) {
ApiTestCase apiTestCase = extApiTestCaseMapper.getNextNum(definitionId); ApiTestCase apiTestCase = extApiTestCaseMapper.getNextNum(definitionId);
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = apiDefinitionMapper.selectByPrimaryKey(definitionId);
int apiDefinitionNum;
if (apiDefinitionWithBLOBs != null && apiDefinitionWithBLOBs.getNum() != null) {
apiDefinitionNum = apiDefinitionWithBLOBs.getNum() * 1000 + 1;
} else {
apiDefinitionNum = getNextNumByProjectId(projectId);
}
if (apiTestCase == null) { if (apiTestCase == null) {
if (definitionNum == null) { if (definitionNum == null) {
return apiDefinitionMapper.selectByPrimaryKey(definitionId).getNum() * 1000 + 1; return apiDefinitionNum;
} }
return definitionNum * 1000 + 1; return definitionNum * 1000 + 1;
} else { } else {
return Optional.of(apiTestCase.getNum() + 1) return Optional.of(apiTestCase.getNum() + 1)
.orElse(apiDefinitionMapper.selectByPrimaryKey(definitionId).getNum() * 1000 + 1); .orElse(apiDefinitionNum);
}
}
public int getNextNumByProjectId(String projectId) {
ApiDefinition apiDefinition = extApiDefinitionMapper.getNextNum(projectId);
if (apiDefinition == null || apiDefinition.getNum() == null) {
return 100001;
} else {
return Optional.of(apiDefinition.getNum() + 1).orElse(100001);
} }
} }

View File

@ -1114,6 +1114,7 @@
#{versionId} #{versionId}
</foreach> </foreach>
and protocol = #{protocol} and protocol = #{protocol}
and status != 'Trash'
</select> </select>
<sql id="Same_Where_Clause"> <sql id="Same_Where_Clause">
<where> <where>