refactor(性能测试): 加载已有的文件支持查询

This commit is contained in:
Captain.B 2021-03-22 16:47:53 +08:00
parent fa0a57a6af
commit 8fe70457a5
10 changed files with 92 additions and 74 deletions

View File

@ -3,6 +3,7 @@ package io.metersphere.base.mapper.ext;
import io.metersphere.base.domain.FileMetadata;
import io.metersphere.base.domain.LoadTest;
import io.metersphere.dto.LoadTestDTO;
import io.metersphere.performance.request.QueryProjectFileRequest;
import io.metersphere.performance.request.QueryTestPlanRequest;
import org.apache.ibatis.annotations.Param;
@ -18,6 +19,7 @@ public interface ExtLoadTestMapper {
LoadTest getNextNum(@Param("projectId") String projectId);
List<FileMetadata> getProjectFiles(@Param("projectId") String projectId, @Param("loadTypes") List<String> loadType);
List<FileMetadata> getProjectFiles(@Param("projectId") String projectId, @Param("loadTypes") List<String> loadType,
@Param("request") QueryProjectFileRequest request);
}

View File

@ -145,5 +145,8 @@
#{id}
</foreach>
AND project_id = #{projectId,jdbcType=VARCHAR}
<if test="request.name!=null">
AND file_metadata.name LIKE CONCAT('%', #{request.name}, '%')
</if>
</select>
</mapper>

View File

@ -120,12 +120,13 @@ public class PerformanceTestController {
return performanceTestService.exportJmx(fileIds);
}
@GetMapping("/project/{loadType}/{projectId}/{goPage}/{pageSize}")
@PostMapping("/project/{loadType}/{projectId}/{goPage}/{pageSize}")
public Pager<List<FileMetadata>> getProjectFiles(@PathVariable String projectId, @PathVariable String loadType,
@PathVariable int goPage, @PathVariable int pageSize) {
@PathVariable int goPage, @PathVariable int pageSize,
@RequestBody QueryProjectFileRequest request) {
checkPermissionService.checkProjectOwner(projectId);
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, performanceTestService.getProjectFiles(projectId, loadType));
return PageUtils.setPageInfo(page, performanceTestService.getProjectFiles(projectId, loadType, request));
}
@PostMapping("/delete")

View File

@ -4,5 +4,5 @@ import lombok.Data;
@Data
public class QueryProjectFileRequest {
private String filename;
private String name;
}

View File

@ -561,19 +561,23 @@ public class PerformanceTestService {
}
}
public List<FileMetadata> getProjectFiles(String projectId, String loadType) {
public List<FileMetadata> getProjectFiles(String projectId, String loadType, QueryProjectFileRequest request) {
List<String> loadTypes = new ArrayList<>();
loadTypes.add(StringUtils.upperCase(loadType));
if (StringUtils.equalsIgnoreCase(loadType, "resource")) {
loadTypes.add(FileType.CSV.name());
loadTypes.add(FileType.JAR.name());
List<String> fileTypes = Arrays.stream(FileType.values())
.filter(fileType -> !fileType.equals(FileType.JMX))
.map(FileType::name)
.collect(Collectors.toList());
loadTypes.addAll(fileTypes);
}
if (StringUtils.equalsIgnoreCase(loadType, "all")) {
loadTypes.add(FileType.CSV.name());
loadTypes.add(FileType.JAR.name());
loadTypes.add(FileType.JMX.name());
List<String> fileTypes = Arrays.stream(FileType.values())
.map(FileType::name)
.collect(Collectors.toList());
loadTypes.addAll(fileTypes);
}
return extLoadTestMapper.getProjectFiles(projectId, loadTypes);
return extLoadTestMapper.getProjectFiles(projectId, loadTypes, request);
}
public List<LoadTestExportJmx> exportJmx(List<String> fileIds) {

View File

@ -202,8 +202,8 @@ public class FileService {
FileMetadataExample example = new FileMetadataExample();
FileMetadataExample.Criteria criteria = example.createCriteria();
criteria.andProjectIdEqualTo(projectId);
if (!StringUtils.isEmpty(request.getFilename())) {
criteria.andNameEqualTo(request.getFilename());
if (!StringUtils.isEmpty(request.getName())) {
criteria.andNameEqualTo(request.getName());
}
return fileMetadataMapper.selectByExample(example);
}

View File

@ -173,7 +173,7 @@ public class ProjectService {
if (files != null) {
for (MultipartFile file : files) {
QueryProjectFileRequest request = new QueryProjectFileRequest();
request.setFilename(file.getOriginalFilename());
request.setName(file.getOriginalFilename());
if (CollectionUtils.isEmpty(fileService.getProjectFiles(projectId, request))) {
fileService.saveFile(file, projectId);
} else {

View File

@ -3,42 +3,42 @@
:destroy-on-close="true"
:title="$t('load_test.exist_jmx')" width="70%"
:visible.sync="loadFileVisible">
<el-row>
<el-upload
v-if="loadType === 'jmx'"
style="padding-right: 10px;"
accept=".jmx"
action=""
multiple
:limit="fileNumLimit"
:show-file-list="false"
:before-upload="beforeUploadFile"
:http-request="handleUpload"
:on-exceed="handleExceed"
:disabled="isReadOnly"
:file-list="fileList">
<ms-table-button :is-tester-permission="true" icon="el-icon-upload2"
:content="$t('load_test.upload_jmx')"/>
</el-upload>
<el-upload
v-else
style="padding-right: 10px;"
accept=".jar,.csv,.json,.pdf,.jpg,.png,.jpeg,.doc,.docx,.xlsx"
action=""
:limit="fileNumLimit"
multiple
:show-file-list="false"
:before-upload="beforeUploadFile"
:http-request="handleUpload"
:on-exceed="handleExceed"
:disabled="isReadOnly"
:file-list="fileList">
<ms-table-button :is-tester-permission="true" icon="el-icon-upload2"
:content="$t('load_test.upload_file')"/>
</el-upload>
</el-row>
<ms-table-header :is-tester-permission="true" title="" :condition.sync="condition" @search="getProjectFiles" :show-create="false">
<template v-slot:button>
<el-upload
v-if="loadType === 'jmx'"
style="margin-bottom: 10px"
accept=".jmx"
action=""
multiple
:limit="fileNumLimit"
:show-file-list="false"
:before-upload="beforeUploadFile"
:http-request="handleUpload"
:on-exceed="handleExceed"
:disabled="isReadOnly"
:file-list="fileList">
<ms-table-button :is-tester-permission="true" icon="el-icon-upload2"
:content="$t('load_test.upload_jmx')"/>
</el-upload>
<el-upload
v-else
style="margin-bottom: 10px"
accept=".jar,.csv,.json,.pdf,.jpg,.png,.jpeg,.doc,.docx,.xlsx"
action=""
:limit="fileNumLimit"
multiple
:show-file-list="false"
:before-upload="beforeUploadFile"
:http-request="handleUpload"
:on-exceed="handleExceed"
:disabled="isReadOnly"
:file-list="fileList">
<ms-table-button :is-tester-permission="true" icon="el-icon-upload2"
:content="$t('load_test.upload_file')"/>
</el-upload>
</template>
</ms-table-header>
<el-table v-loading="projectLoadingResult.loading"
class="basic-config"
:data="existFiles"
@ -78,10 +78,11 @@ import {getCurrentProjectID} from "@/common/js/utils";
import {findThreadGroup} from "@/business/components/performance/test/model/ThreadGroup";
import MsTableButton from "@/business/components/common/components/MsTableButton";
import axios from "axios";
import MsTableHeader from "@/business/components/common/components/MsTableHeader";
export default {
name: "ExistFiles",
components: {MsTableButton, MsTablePagination, MsDialogFooter},
components: {MsTableHeader, MsTableButton, MsTablePagination, MsDialogFooter},
props: {
fileList: Array,
tableData: Array,
@ -100,6 +101,7 @@ export default {
existFiles: [],
selectIds: new Set,
fileNumLimit: 10,
condition: {}
}
},
methods: {
@ -133,7 +135,7 @@ export default {
}
},
getProjectFiles() {
this.projectLoadingResult = this.$get('/performance/project/' + this.loadType + '/' + getCurrentProjectID() + "/" + this.currentPage + "/" + this.pageSize, res => {
this.projectLoadingResult = this.$post('/performance/project/' + this.loadType + '/' + getCurrentProjectID() + "/" + this.currentPage + "/" + this.pageSize, this.condition, res => {
let data = res.data;
this.total = data.itemCount;
this.existFiles = data.listObject;

View File

@ -329,10 +329,10 @@ export default {
}
return true;
},
beforeUploadJmx(file){
beforeUploadJmx(file) {
this.$refs.existFiles.beforeUploadFile(file);
},
handleUpload(file){
handleUpload(file) {
this.$refs.existFiles.handleUpload(file);
},
},
@ -341,7 +341,7 @@ export default {
<style scoped>
.basic-config {
width: 100%
width: 100%;
}
.last-modified {

View File

@ -3,22 +3,25 @@
:destroy-on-close="true"
:title="$t('load_test.exist_jmx')" width="70%"
:visible.sync="loadFileVisible">
<el-row>
<el-upload
style="padding-right: 10px;"
accept=".jmx,.jar,.csv,.json,.pdf,.jpg,.png,.jpeg,.doc,.docx,.xlsx"
action=""
:limit="fileNumLimit"
multiple
:show-file-list="false"
:before-upload="beforeUploadFile"
:http-request="handleUpload"
:on-exceed="handleExceed"
:file-list="fileList">
<ms-table-button :is-tester-permission="true" icon="el-icon-upload2"
:content="$t('load_test.upload_file')"/>
</el-upload>
</el-row>
<ms-table-header :is-tester-permission="true" title="" :condition.sync="condition" @search="getProjectFiles" :show-create="false">
<template v-slot:button>
<el-upload
style="margin-bottom: 10px;"
accept=".jmx,.jar,.csv,.json,.pdf,.jpg,.png,.jpeg,.doc,.docx,.xlsx"
action=""
:limit="fileNumLimit"
multiple
:show-file-list="false"
:before-upload="beforeUploadFile"
:http-request="handleUpload"
:on-exceed="handleExceed"
:file-list="fileList">
<ms-table-button :is-tester-permission="true" icon="el-icon-upload2"
:content="$t('load_test.upload_file')"/>
</el-upload>
</template>
</ms-table-header>
<el-table v-loading="projectLoadingResult.loading"
class="basic-config"
@ -64,10 +67,12 @@ import MsDialogFooter from "@/business/components/common/components/MsDialogFoot
import {getCurrentProjectID} from "@/common/js/utils";
import MsTableOperatorButton from "@/business/components/common/components/MsTableOperatorButton";
import {Message} from "element-ui";
import MsTableHeader from "@/business/components/common/components/MsTableHeader";
import MsTableSearchBar from "@/business/components/common/components/MsTableSearchBar";
export default {
name: "MsResourceFiles",
components: {MsTableOperatorButton, MsDialogFooter, MsTableButton, MsTablePagination},
components: {MsTableSearchBar, MsTableHeader, MsTableOperatorButton, MsDialogFooter, MsTableButton, MsTablePagination},
data() {
return {
loadFileVisible: false,
@ -79,6 +84,7 @@ export default {
fileList: [],
uploadList: [],
fileNumLimit: 10,
condition: {}
}
},
methods: {
@ -91,7 +97,7 @@ export default {
this.selectIds.clear();
},
getProjectFiles() {
this.projectLoadingResult = this.$get('/performance/project/all/' + getCurrentProjectID() + "/" + this.currentPage + "/" + this.pageSize, res => {
this.projectLoadingResult = this.$post('/performance/project/all/' + getCurrentProjectID() + "/" + this.currentPage + "/" + this.pageSize, this.condition, res => {
let data = res.data;
this.total = data.itemCount;
this.existFiles = data.listObject;