fix(接口定义: 修复导出metersphere格式的文件再导入,用例重复问题 (#1699)

* feat(测试跟踪): 测试用例下载模版增加标签列

* fix(接口定义): 扩大请求头键长度

* fix: schedule表对旧数据name字段兼容的补充

* fix(接口定义: 修复导出metersphere格式的文件再导入,用例重复问题
This commit is contained in:
Coooder-X 2021-03-24 19:55:14 +08:00 committed by GitHub
parent f115f25f87
commit 42b894ee97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 15 deletions

View File

@ -403,17 +403,24 @@ public class ApiDefinitionService {
private void importMsCase(ApiDefinitionImport apiImport, SqlSession sqlSession, ApiTestCaseMapper apiTestCaseMapper) {
List<ApiTestCaseWithBLOBs> cases = apiImport.getCases();
List<String> caseNames = apiTestCaseService.listPorjectAllCaseName(SessionUtils.getCurrentProjectId());
Set<String> existCaseName = new HashSet<>();
caseNames.forEach(item -> {
existCaseName.add(item);
});
if (CollectionUtils.isNotEmpty(cases)) {
int batchCount = 0;
cases.forEach(item -> {
item.setId(UUID.randomUUID().toString());
item.setCreateTime(System.currentTimeMillis());
item.setUpdateTime(System.currentTimeMillis());
item.setCreateUserId(SessionUtils.getUserId());
item.setUpdateUserId(SessionUtils.getUserId());
item.setProjectId(SessionUtils.getCurrentProjectId());
item.setNum(getNextNum(item.getApiDefinitionId()));
apiTestCaseMapper.insert(item);
if(!existCaseName.contains(item.getName())) {
item.setId(UUID.randomUUID().toString());
item.setCreateTime(System.currentTimeMillis());
item.setUpdateTime(System.currentTimeMillis());
item.setCreateUserId(SessionUtils.getUserId());
item.setUpdateUserId(SessionUtils.getUserId());
item.setProjectId(SessionUtils.getCurrentProjectId());
item.setNum(getNextNum(item.getApiDefinitionId()));
apiTestCaseMapper.insert(item);
}
});
if (batchCount % 300 == 0) {
sqlSession.flushStatements();
@ -628,12 +635,7 @@ public class ApiDefinitionService {
}
if (!CollectionUtils.isEmpty(apiImport.getCases())) {
for (int i = 0; i < apiImport.getCases().size(); i++) {
importMsCase(apiImport, sqlSession, apiTestCaseMapper);
if (i % 300 == 0) {
sqlSession.flushStatements();
}
}
importMsCase(apiImport, sqlSession, apiTestCaseMapper);
}
sqlSession.flushStatements();
}

View File

@ -80,6 +80,10 @@ public class ApiTestCaseService {
private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR;
public List<String> listPorjectAllCaseName(String projectId) {
return extApiTestCaseMapper.listPorjectAllCaseName(projectId);
}
public List<ApiTestCaseResult> list(ApiTestCaseRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
List<ApiTestCaseResult> returnList = extApiTestCaseMapper.list(request);

View File

@ -12,6 +12,8 @@ import java.util.List;
public interface ExtApiTestCaseMapper {
List<String> listPorjectAllCaseName(@Param("projectId") String projectId);
List<ApiTestCaseResult> list(@Param("request") ApiTestCaseRequest request);
List<ApiTestCaseDTO> listSimple(@Param("request") ApiTestCaseRequest request);

View File

@ -391,6 +391,8 @@
<select id="getNextNum" resultType="io.metersphere.base.domain.ApiTestCase">
SELECT * FROM api_test_case WHERE api_test_case.api_definition_id = #{definitionId} ORDER BY num DESC LIMIT 1;
</select>
<select id="listPorjectAllCaseName" resultType="java.lang.String">
select name from api_test_case where project_id = #{projectId}
</select>
</mapper>