fix(性能测试): 提供文件更新的功能
This commit is contained in:
parent
4e270cd409
commit
21de1ba11f
|
@ -88,7 +88,12 @@ public class ProjectController {
|
||||||
|
|
||||||
@PostMapping(value = "upload/files/{projectId}", consumes = {"multipart/form-data"})
|
@PostMapping(value = "upload/files/{projectId}", consumes = {"multipart/form-data"})
|
||||||
public List<FileMetadata> uploadFiles(@PathVariable String projectId, @RequestPart(value = "file") List<MultipartFile> files) {
|
public List<FileMetadata> uploadFiles(@PathVariable String projectId, @RequestPart(value = "file") List<MultipartFile> files) {
|
||||||
return projectService.uploadFiles(projectId, files);
|
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}")
|
@GetMapping(value = "delete/file/{fileId}")
|
||||||
|
|
|
@ -73,9 +73,13 @@ public class FileService {
|
||||||
fileContentMapper.deleteByExample(example2);
|
fileContentMapper.deleteByExample(example2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileMetadata saveFile(MultipartFile file, String projectId) {
|
public FileMetadata saveFile(MultipartFile file, String projectId, String fileId) {
|
||||||
final FileMetadata fileMetadata = new FileMetadata();
|
final FileMetadata fileMetadata = new FileMetadata();
|
||||||
fileMetadata.setId(UUID.randomUUID().toString());
|
if (StringUtils.isEmpty(fileId)) {
|
||||||
|
fileMetadata.setId(UUID.randomUUID().toString());
|
||||||
|
} else {
|
||||||
|
fileMetadata.setId(fileId);
|
||||||
|
}
|
||||||
fileMetadata.setName(file.getOriginalFilename());
|
fileMetadata.setName(file.getOriginalFilename());
|
||||||
fileMetadata.setSize(file.getSize());
|
fileMetadata.setSize(file.getSize());
|
||||||
fileMetadata.setProjectId(projectId);
|
fileMetadata.setProjectId(projectId);
|
||||||
|
@ -97,6 +101,10 @@ public class FileService {
|
||||||
return fileMetadata;
|
return fileMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FileMetadata saveFile(MultipartFile file, String projectId) {
|
||||||
|
return saveFile(file, projectId, null);
|
||||||
|
}
|
||||||
|
|
||||||
public FileMetadata saveFile(MultipartFile file) {
|
public FileMetadata saveFile(MultipartFile file) {
|
||||||
return saveFile(file, null);
|
return saveFile(file, null);
|
||||||
}
|
}
|
||||||
|
@ -205,7 +213,7 @@ public class FileService {
|
||||||
if (!StringUtils.isEmpty(request.getName())) {
|
if (!StringUtils.isEmpty(request.getName())) {
|
||||||
criteria.andNameEqualTo(request.getName());
|
criteria.andNameEqualTo(request.getName());
|
||||||
}
|
}
|
||||||
return fileMetadataMapper.selectByExample(example);
|
return fileMetadataMapper.selectByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FileMetadata> getFileMetadataByIds(List<String> fileIds) {
|
public List<FileMetadata> getFileMetadataByIds(List<String> fileIds) {
|
||||||
|
|
|
@ -186,6 +186,18 @@ public class ProjectService {
|
||||||
return result;
|
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) {
|
public void deleteFile(String fileId) {
|
||||||
LoadTestFileExample example1 = new LoadTestFileExample();
|
LoadTestFileExample example1 = new LoadTestFileExample();
|
||||||
example1.createCriteria().andFileIdEqualTo(fileId);
|
example1.createCriteria().andFileIdEqualTo(fileId);
|
||||||
|
@ -216,4 +228,5 @@ public class ProjectService {
|
||||||
}
|
}
|
||||||
fileService.deleteFileById(fileId);
|
fileService.deleteFileById(fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
:before-upload="beforeUploadFile"
|
:before-upload="beforeUploadFile"
|
||||||
:http-request="handleUpload"
|
:http-request="handleUpload"
|
||||||
:on-exceed="handleExceed"
|
:on-exceed="handleExceed"
|
||||||
:file-list="fileList">
|
>
|
||||||
<ms-table-button :is-tester-permission="true" icon="el-icon-upload2"
|
<ms-table-button :is-tester-permission="true" icon="el-icon-upload2"
|
||||||
:content="$t('load_test.upload_file')"/>
|
:content="$t('load_test.upload_file')"/>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
|
@ -46,6 +46,23 @@
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column :label="$t('commons.operating')">
|
<el-table-column :label="$t('commons.operating')">
|
||||||
<template v-slot:default="scope">
|
<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"
|
<ms-table-operator-button :is-tester-permission="true"
|
||||||
icon="el-icon-delete"
|
icon="el-icon-delete"
|
||||||
type="danger"
|
type="danger"
|
||||||
|
@ -65,7 +82,7 @@
|
||||||
import MsTablePagination from "@/business/components/common/pagination/TablePagination";
|
import MsTablePagination from "@/business/components/common/pagination/TablePagination";
|
||||||
import MsTableButton from "@/business/components/common/components/MsTableButton";
|
import MsTableButton from "@/business/components/common/components/MsTableButton";
|
||||||
import MsDialogFooter from "@/business/components/common/components/MsDialogFooter";
|
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 MsTableOperatorButton from "@/business/components/common/components/MsTableOperatorButton";
|
||||||
import {Message} from "element-ui";
|
import {Message} from "element-ui";
|
||||||
import MsTableHeader from "@/business/components/common/components/MsTableHeader";
|
import MsTableHeader from "@/business/components/common/components/MsTableHeader";
|
||||||
|
@ -87,9 +104,11 @@ export default {
|
||||||
fileNumLimit: 10,
|
fileNumLimit: 10,
|
||||||
condition: {},
|
condition: {},
|
||||||
projectId: getCurrentProjectID(),
|
projectId: getCurrentProjectID(),
|
||||||
|
currentRow: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
checkoutTestManagerOrTestUser,
|
||||||
open(project) {
|
open(project) {
|
||||||
this.projectId = project.id;
|
this.projectId = project.id;
|
||||||
this.loadFileVisible = true;
|
this.loadFileVisible = true;
|
||||||
|
@ -136,9 +155,40 @@ export default {
|
||||||
this.getProjectFiles();
|
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() {
|
handleExceed() {
|
||||||
this.$error(this.$t('load_test.file_size_limit'));
|
this.$error(this.$t('load_test.file_size_limit'));
|
||||||
},
|
},
|
||||||
|
handleEdit(row) {
|
||||||
|
this.currentRow = row;
|
||||||
|
},
|
||||||
handleDelete(row) {
|
handleDelete(row) {
|
||||||
console.log(row);
|
console.log(row);
|
||||||
this.$confirm(this.$t('project.file_delete_tip', [row.name]), '', {
|
this.$confirm(this.$t('project.file_delete_tip', [row.name]), '', {
|
||||||
|
|
|
@ -540,7 +540,8 @@ export default {
|
||||||
load_exist_jmx: 'Load Project JMX',
|
load_exist_jmx: 'Load Project JMX',
|
||||||
threadgroup_at_least_one: 'At least one ThreadGroup is enabled',
|
threadgroup_at_least_one: 'At least one ThreadGroup is enabled',
|
||||||
load_api_automation_jmx: 'Import API automation scenario',
|
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: {
|
api_test: {
|
||||||
creator: "Creator",
|
creator: "Creator",
|
||||||
|
|
|
@ -539,7 +539,8 @@ export default {
|
||||||
load_exist_jmx: '加载 JMX 文件',
|
load_exist_jmx: '加载 JMX 文件',
|
||||||
threadgroup_at_least_one: '至少启用一个线程组',
|
threadgroup_at_least_one: '至少启用一个线程组',
|
||||||
load_api_automation_jmx: '引用接口自动化场景',
|
load_api_automation_jmx: '引用接口自动化场景',
|
||||||
project_file_exist: "项目中已存在该文件,请直接引用"
|
project_file_exist: "项目中已存在该文件,请直接引用",
|
||||||
|
project_file_update_type_error: '更新的文件类型必须一致'
|
||||||
},
|
},
|
||||||
api_test: {
|
api_test: {
|
||||||
creator: "创建人",
|
creator: "创建人",
|
||||||
|
|
|
@ -539,7 +539,8 @@ export default {
|
||||||
load_exist_jmx: '加載 JMX 文件',
|
load_exist_jmx: '加載 JMX 文件',
|
||||||
threadgroup_at_least_one: '至少啟用一個線程組',
|
threadgroup_at_least_one: '至少啟用一個線程組',
|
||||||
load_api_automation_jmx: '引用接口自動化場景',
|
load_api_automation_jmx: '引用接口自動化場景',
|
||||||
project_file_exist: "項目中已存在該文件,請直接引用"
|
project_file_exist: "項目中已存在該文件,請直接引用",
|
||||||
|
project_file_update_type_error: '更新的文件類型必須一致'
|
||||||
},
|
},
|
||||||
api_test: {
|
api_test: {
|
||||||
creator: "創建人",
|
creator: "創建人",
|
||||||
|
|
Loading…
Reference in New Issue