file download
This commit is contained in:
parent
09a5c11ab0
commit
2c84557bc1
|
@ -15,6 +15,9 @@
|
||||||
<if test="request.name != null">
|
<if test="request.name != null">
|
||||||
and load_test.name like CONCAT('%', #{request.name},'%')
|
and load_test.name like CONCAT('%', #{request.name},'%')
|
||||||
</if>
|
</if>
|
||||||
|
<if test="request.workspaceId != null">
|
||||||
|
AND project.workspace_id = #{request.workspaceId}
|
||||||
|
</if>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import io.metersphere.controller.request.testplan.*;
|
||||||
import io.metersphere.dto.LoadTestDTO;
|
import io.metersphere.dto.LoadTestDTO;
|
||||||
import io.metersphere.service.FileService;
|
import io.metersphere.service.FileService;
|
||||||
import io.metersphere.service.LoadTestService;
|
import io.metersphere.service.LoadTestService;
|
||||||
|
import io.metersphere.user.SessionUtils;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
@ -29,6 +30,7 @@ public class LoadTestController {
|
||||||
@PostMapping("/list/{goPage}/{pageSize}")
|
@PostMapping("/list/{goPage}/{pageSize}")
|
||||||
public Pager<List<LoadTestDTO>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanRequest request) {
|
public Pager<List<LoadTestDTO>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanRequest request) {
|
||||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||||
|
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
|
||||||
return PageUtils.setPageInfo(page, loadTestService.list(request));
|
return PageUtils.setPageInfo(page, loadTestService.list(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,12 +66,11 @@ public class LoadTestController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/file/download")
|
@PostMapping("/file/download")
|
||||||
public ResponseEntity<org.springframework.core.io.Resource> downloadJmx(@RequestBody FileOperationRequest fileOperationRequest) {
|
public ResponseEntity<byte[]> downloadJmx(@RequestBody FileOperationRequest fileOperationRequest) {
|
||||||
org.springframework.core.io.Resource resource = fileService.loadFileAsResource(fileOperationRequest.getName());
|
byte[] bytes = fileService.loadFileAsBytes(fileOperationRequest.getId());
|
||||||
|
|
||||||
return ResponseEntity.ok()
|
return ResponseEntity.ok()
|
||||||
.contentType(MediaType.parseMediaType("application/octet-stream"))
|
.contentType(MediaType.parseMediaType("application/octet-stream"))
|
||||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileOperationRequest.getName() + "\"")
|
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileOperationRequest.getName() + "\"")
|
||||||
.body(resource);
|
.body(bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,17 @@
|
||||||
package io.metersphere.controller.request.testplan;
|
package io.metersphere.controller.request.testplan;
|
||||||
|
|
||||||
public class FileOperationRequest {
|
public class FileOperationRequest {
|
||||||
|
private String id;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.controller.request.testplan;
|
||||||
|
|
||||||
public class QueryTestPlanRequest extends TestPlanRequest {
|
public class QueryTestPlanRequest extends TestPlanRequest {
|
||||||
private String name;
|
private String name;
|
||||||
|
private String workspaceId;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -12,4 +13,12 @@ public class QueryTestPlanRequest extends TestPlanRequest {
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getWorkspaceId() {
|
||||||
|
return workspaceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWorkspaceId(String workspaceId) {
|
||||||
|
this.workspaceId = workspaceId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,18 +38,10 @@ public class FileService {
|
||||||
fileMap.put(name, file);
|
fileMap.put(name, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public org.springframework.core.io.Resource loadFileAsResource(String name) {
|
public byte[] loadFileAsBytes(String id) {
|
||||||
final MultipartFile file = fileMap.get(name);
|
FileContent fileContent = fileContentMapper.selectByPrimaryKey(id);
|
||||||
|
|
||||||
if (file != null) {
|
return fileContent.getFile();
|
||||||
try {
|
|
||||||
return new InputStreamResource(file.getInputStream());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileMetadata getFileMetadataByTestId(String testId) {
|
public FileMetadata getFileMetadataByTestId(String testId) {
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Message from "element-ui";
|
import {Message} from "element-ui";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "TestPlanBasicConfig",
|
name: "TestPlanBasicConfig",
|
||||||
|
@ -91,6 +91,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
this.tableData.push({
|
this.tableData.push({
|
||||||
|
id: file.id,
|
||||||
name: file.name,
|
name: file.name,
|
||||||
size: file.size + 'Byte', /// todo: 按照大小显示Byte、KB、MB等
|
size: file.size + 'Byte', /// todo: 按照大小显示Byte、KB、MB等
|
||||||
type: 'JMX',
|
type: 'JMX',
|
||||||
|
@ -120,10 +121,16 @@
|
||||||
},
|
},
|
||||||
handleDownload(file) {
|
handleDownload(file) {
|
||||||
let data = {
|
let data = {
|
||||||
name: file.name
|
name: file.name,
|
||||||
|
id: file.id,
|
||||||
};
|
};
|
||||||
|
let config = {
|
||||||
this.result = this.$post(this.jmxDownloadPath, data, response => {
|
url: this.jmxDownloadPath,
|
||||||
|
method: 'post',
|
||||||
|
data: data,
|
||||||
|
responseType: 'blob'
|
||||||
|
};
|
||||||
|
this.result = this.$request(config).then(response => {
|
||||||
const content = response.data;
|
const content = response.data;
|
||||||
const blob = new Blob([content]);
|
const blob = new Blob([content]);
|
||||||
if ("download" in document.createElement("a")) {
|
if ("download" in document.createElement("a")) {
|
||||||
|
@ -131,13 +138,15 @@
|
||||||
// chrome/firefox
|
// chrome/firefox
|
||||||
let aTag = document.createElement('a');
|
let aTag = document.createElement('a');
|
||||||
aTag.download = file.name;
|
aTag.download = file.name;
|
||||||
aTag.href = URL.createObjectURL(blob)
|
aTag.href = URL.createObjectURL(blob);
|
||||||
aTag.click();
|
aTag.click();
|
||||||
URL.revokeObjectURL(aTag.href)
|
URL.revokeObjectURL(aTag.href)
|
||||||
} else {
|
} else {
|
||||||
// IE10+下载
|
// IE10+下载
|
||||||
navigator.msSaveBlob(blob, this.filename)
|
navigator.msSaveBlob(blob, this.filename)
|
||||||
}
|
}
|
||||||
|
}).catch(e => {
|
||||||
|
Message.error({message: e.message, showClose: true});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleDelete(file, index) {
|
handleDelete(file, index) {
|
||||||
|
|
Loading…
Reference in New Issue