fix(性能测试): 提供文件更新的功能

This commit is contained in:
Captain.B 2021-03-25 11:20:03 +08:00
parent 4e270cd409
commit 21de1ba11f
7 changed files with 88 additions and 9 deletions

View File

@ -91,6 +91,11 @@ public class ProjectController {
return projectService.uploadFiles(projectId, files);
}
@PostMapping(value = "/update/file/{projectId}/{fileId}", consumes = {"multipart/form-data"})
public FileMetadata updateFile(@PathVariable String projectId, @PathVariable String fileId, @RequestPart(value = "file") MultipartFile file) {
return projectService.updateFile(projectId, fileId, file);
}
@GetMapping(value = "delete/file/{fileId}")
public void deleteFile(@PathVariable String fileId) {
projectService.deleteFile(fileId);

View File

@ -73,9 +73,13 @@ public class FileService {
fileContentMapper.deleteByExample(example2);
}
public FileMetadata saveFile(MultipartFile file, String projectId) {
public FileMetadata saveFile(MultipartFile file, String projectId, String fileId) {
final FileMetadata fileMetadata = new FileMetadata();
if (StringUtils.isEmpty(fileId)) {
fileMetadata.setId(UUID.randomUUID().toString());
} else {
fileMetadata.setId(fileId);
}
fileMetadata.setName(file.getOriginalFilename());
fileMetadata.setSize(file.getSize());
fileMetadata.setProjectId(projectId);
@ -97,6 +101,10 @@ public class FileService {
return fileMetadata;
}
public FileMetadata saveFile(MultipartFile file, String projectId) {
return saveFile(file, projectId, null);
}
public FileMetadata saveFile(MultipartFile file) {
return saveFile(file, null);
}

View File

@ -186,6 +186,18 @@ public class ProjectService {
return result;
}
public FileMetadata updateFile(String projectId, String fileId, MultipartFile file) {
QueryProjectFileRequest request = new QueryProjectFileRequest();
request.setName(file.getOriginalFilename());
if (CollectionUtils.isEmpty(fileService.getProjectFiles(projectId, request))) {
fileService.deleteFileById(fileId);
return fileService.saveFile(file, projectId);
} else {
MSException.throwException(Translator.get("project_file_already_exists"));
}
return null;
}
public void deleteFile(String fileId) {
LoadTestFileExample example1 = new LoadTestFileExample();
example1.createCriteria().andFileIdEqualTo(fileId);
@ -216,4 +228,5 @@ public class ProjectService {
}
fileService.deleteFileById(fileId);
}
}

View File

@ -16,7 +16,7 @@
: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>
@ -46,6 +46,23 @@
</el-table-column>
<el-table-column :label="$t('commons.operating')">
<template v-slot:default="scope">
<el-upload
style="width: 38px; float: left;"
accept=".jmx,.jar,.csv,.json,.pdf,.jpg,.png,.jpeg,.doc,.docx,.xlsx"
action=""
:limit="fileNumLimit"
:show-file-list="false"
:before-upload="beforeUploadFile"
:http-request="handleUpdateUpload"
:on-exceed="handleExceed"
>
<el-button circle
type="success"
:disabled="!checkoutTestManagerOrTestUser()"
icon="el-icon-edit"
@click="handleEdit(scope.row)"
size="mini"/>
</el-upload>
<ms-table-operator-button :is-tester-permission="true"
icon="el-icon-delete"
type="danger"
@ -65,7 +82,7 @@
import MsTablePagination from "@/business/components/common/pagination/TablePagination";
import MsTableButton from "@/business/components/common/components/MsTableButton";
import MsDialogFooter from "@/business/components/common/components/MsDialogFooter";
import {getCurrentProjectID} from "@/common/js/utils";
import {checkoutTestManagerOrTestUser, 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";
@ -87,9 +104,11 @@ export default {
fileNumLimit: 10,
condition: {},
projectId: getCurrentProjectID(),
currentRow: null,
}
},
methods: {
checkoutTestManagerOrTestUser,
open(project) {
this.projectId = project.id;
this.loadFileVisible = true;
@ -136,9 +155,40 @@ export default {
this.getProjectFiles();
});
},
handleUpdateUpload(uploadResources) {
let file = uploadResources.file;
let i1 = file.name.lastIndexOf(".");
let i2 = this.currentRow.name.lastIndexOf(".");
let suffix1 = file.name.substring(i1);
let suffix2 = this.currentRow.name.substring(i2);
if (suffix1 !== suffix2) {
this.$error(this.$t('load_test.project_file_update_type_error'));
return;
}
let formData = new FormData();
let url = '/project/update/file/' + this.projectId + '/' + this.currentRow.id
formData.append("file", file);
let options = {
method: 'POST',
url: url,
data: formData,
headers: {
'Content-Type': undefined
}
}
this.$request(options, (response) => {
this.$success(this.$t('commons.save_success'));
this.currentRow = null;
this.getProjectFiles();
});
},
handleExceed() {
this.$error(this.$t('load_test.file_size_limit'));
},
handleEdit(row) {
this.currentRow = row;
},
handleDelete(row) {
console.log(row);
this.$confirm(this.$t('project.file_delete_tip', [row.name]), '', {

View File

@ -540,7 +540,8 @@ export default {
load_exist_jmx: 'Load Project JMX',
threadgroup_at_least_one: 'At least one ThreadGroup is enabled',
load_api_automation_jmx: 'Import API automation scenario',
project_file_exist: "The file already exists in the project, please import it directly"
project_file_exist: "The file already exists in the project, please import it directly",
project_file_update_type_error: 'Updated file types must be consistent'
},
api_test: {
creator: "Creator",

View File

@ -539,7 +539,8 @@ export default {
load_exist_jmx: '加载 JMX 文件',
threadgroup_at_least_one: '至少启用一个线程组',
load_api_automation_jmx: '引用接口自动化场景',
project_file_exist: "项目中已存在该文件,请直接引用"
project_file_exist: "项目中已存在该文件,请直接引用",
project_file_update_type_error: '更新的文件类型必须一致'
},
api_test: {
creator: "创建人",

View File

@ -539,7 +539,8 @@ export default {
load_exist_jmx: '加載 JMX 文件',
threadgroup_at_least_one: '至少啟用一個線程組',
load_api_automation_jmx: '引用接口自動化場景',
project_file_exist: "項目中已存在該文件,請直接引用"
project_file_exist: "項目中已存在該文件,請直接引用",
project_file_update_type_error: '更新的文件類型必須一致'
},
api_test: {
creator: "創建人",