fix(性能测试): 修复性能测试导入多文件时顺序不一致的问题

This commit is contained in:
CaptainB 2022-03-01 15:16:52 +08:00 committed by 刘瑞斌
parent c5239741c7
commit 545a91fcd1
3 changed files with 21 additions and 9 deletions

View File

@ -37,4 +37,6 @@ public interface ExtLoadTestMapper {
void clearLatestVersion(String refId);
List<String> selectRefIdsForVersionChange(@Param("versionId") String versionId, @Param("projectId") String projectId);
List<FileMetadata> getFileMetadataByIds(@Param("testId") String testId);
}

View File

@ -341,4 +341,12 @@
WHERE version_id = #{versionId} AND project_id = #{projectId}
) AND project_id = #{projectId}
</select>
<select id="getFileMetadataByIds" resultType="io.metersphere.base.domain.FileMetadata">
SELECT file_metadata.*
FROM load_test_file
JOIN file_metadata ON file_id = file_metadata.id
WHERE test_id = #{testId}
ORDER BY sort
</select>
</mapper>

View File

@ -323,6 +323,16 @@ public class PerformanceTestService {
this.importFiles(addFileIds, loadTest.getId(), request.getFileSorts());
// 处理新上传的文件
this.saveUploadFiles(files, loadTest, request.getFileSorts());
// 保持文件顺序
updatedFiles.forEach(f -> {
LoadTestFile record = new LoadTestFile();
record.setSort(request.getFileSorts().get(f.getName()));
LoadTestFileExample loadTestFileExample = new LoadTestFileExample();
loadTestFileExample.createCriteria()
.andFileIdEqualTo(f.getId())
.andTestIdEqualTo(testId);
loadTestFileMapper.updateByExampleSelective(record, loadTestFileExample);
});
loadTest.setName(request.getName());
loadTest.setProjectId(request.getProjectId());
@ -736,15 +746,7 @@ public class PerformanceTestService {
}
public List<FileMetadata> getFileMetadataByTestId(String testId) {
LoadTestFileExample loadTestFileExample = new LoadTestFileExample();
loadTestFileExample.createCriteria().andTestIdEqualTo(testId);
loadTestFileExample.setOrderByClause("sort asc");
List<LoadTestFile> loadTestFiles = loadTestFileMapper.selectByExample(loadTestFileExample);
List<String> fileIds = loadTestFiles.stream().map(LoadTestFile::getFileId).collect(Collectors.toList());
FileMetadataExample example = new FileMetadataExample();
example.createCriteria().andIdIn(fileIds);
return fileService.getFileMetadataByIds(fileIds);
return extLoadTestMapper.getFileMetadataByIds(testId);
}
public Long getReportCountByTestId(String testId) {