fix: 接口定义导入用例id重复

This commit is contained in:
chenjianxing 2021-07-16 11:48:26 +08:00 committed by jianxing
parent bc12d5573d
commit 1260687c9f
2 changed files with 11 additions and 4 deletions

View File

@ -497,7 +497,14 @@ public class ApiDefinitionService {
SaveApiTestCaseRequest checkRequest = new SaveApiTestCaseRequest();
if (CollectionUtils.isNotEmpty(cases)) {
int batchCount = 0;
cases.forEach(item -> {
int nextNum = 0;
for (int i = 0; i < cases.size(); i++) {
ApiTestCaseWithBLOBs item = cases.get(i);
if (i == 0) {
nextNum = apiTestCaseService.getNextNum(item.getApiDefinitionId());
} else {
nextNum ++;
}
checkRequest.setName(item.getName());
checkRequest.setApiDefinitionId(item.getApiDefinitionId());
if (!apiTestCaseService.hasSameCase(checkRequest)) {
@ -507,10 +514,10 @@ public class ApiDefinitionService {
item.setCreateUserId(SessionUtils.getUserId());
item.setUpdateUserId(SessionUtils.getUserId());
item.setProjectId(SessionUtils.getCurrentProjectId());
item.setNum(getNextNum(item.getApiDefinitionId()));
item.setNum(nextNum);
apiTestCaseMapper.insert(item);
}
});
}
if (batchCount % 300 == 0) {
sqlSession.flushStatements();
}

View File

@ -325,7 +325,7 @@ public class ApiTestCaseService {
return test;
}
private int getNextNum(String definitionId) {
public int getNextNum(String definitionId) {
ApiTestCase apiTestCase = extApiTestCaseMapper.getNextNum(definitionId);
if (apiTestCase == null) {
int n = apiDefinitionMapper.selectByPrimaryKey(definitionId).getNum();