fix(性能测试): 修复从接口自动化创建性能测试没有场景的bug

This commit is contained in:
Captain.B 2021-03-25 00:19:39 +08:00
parent 73e9824c5f
commit 0664c5a569
4 changed files with 26 additions and 9 deletions

View File

@ -2,6 +2,7 @@ package io.metersphere.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.FileMetadata;
import io.metersphere.base.domain.Project;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils;
@ -86,8 +87,8 @@ public class ProjectController {
}
@PostMapping(value = "upload/files/{projectId}", consumes = {"multipart/form-data"})
public void uploadFiles(@PathVariable String projectId, @RequestPart(value = "file") List<MultipartFile> files) {
projectService.uploadFiles(projectId, files);
public List<FileMetadata> uploadFiles(@PathVariable String projectId, @RequestPart(value = "file") List<MultipartFile> files) {
return projectService.uploadFiles(projectId, files);
}
@GetMapping(value = "delete/file/{fileId}")

View File

@ -28,6 +28,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@ -169,18 +170,20 @@ public class ProjectService {
return projectMapper.selectByPrimaryKey(id);
}
public void uploadFiles(String projectId, List<MultipartFile> files) {
public List<FileMetadata> uploadFiles(String projectId, List<MultipartFile> files) {
List<FileMetadata> result = new ArrayList<>();
if (files != null) {
for (MultipartFile file : files) {
QueryProjectFileRequest request = new QueryProjectFileRequest();
request.setName(file.getOriginalFilename());
if (CollectionUtils.isEmpty(fileService.getProjectFiles(projectId, request))) {
fileService.saveFile(file, projectId);
result.add(fileService.saveFile(file, projectId));
} else {
MSException.throwException(Translator.get("project_file_already_exists"));
}
}
}
return result;
}
public void deleteFile(String fileId) {

View File

@ -141,7 +141,13 @@ export default {
this.existFiles = data.listObject;
})
},
handleImport() {
handleImport(file) {
if (file) { //
console.log(file);
this.selectIds.add(file.id);
this.getJmxContents();
return;
}
if (this.selectIds.size === 0) {
this.loadFileVisible = false;
return;
@ -163,7 +169,7 @@ export default {
this.tableData.push({
name: row.name,
size: (row.size / 1024).toFixed(2) + ' KB',
type: 'JMX',
type: row.type.toUpperCase(),
updateTime: row.lastModified,
});
})
@ -173,6 +179,9 @@ export default {
return;
}
this.getJmxContents();
},
getJmxContents() {
this.projectLoadingResult = this.$post('/performance/export/jmx', [...this.selectIds], (response) => {
let data = response.data;
if (!data) {
@ -199,7 +208,6 @@ export default {
this.loadFileVisible = false;
this.selectIds.clear();
});
},
beforeUploadFile(file) {
if (!this.fileValidator(file)) {
@ -227,7 +235,7 @@ export default {
}
});
},
handleUpload(uploadResources) {
handleUpload(uploadResources, apiImport) {
let self = this;
let file = uploadResources.file;
@ -246,6 +254,10 @@ export default {
self.$request(options, (response) => {
self.$success(this.$t('commons.save_success'));
self.getProjectFiles();
if (apiImport) {
let row = response.data[0];
self.handleImport(row);
}
});
})
},

View File

@ -333,7 +333,8 @@ export default {
this.$refs.existFiles.beforeUploadFile(file);
},
handleUpload(file) {
this.$refs.existFiles.handleUpload(file);
// api
this.$refs.existFiles.handleUpload(file, true);
},
},
}