refactor: 下载jtl
This commit is contained in:
parent
e26d3a668e
commit
f40f0bbede
|
@ -16,6 +16,9 @@ import io.metersphere.performance.controller.request.ReportRequest;
|
|||
import io.metersphere.performance.service.ReportService;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -130,4 +133,13 @@ public class PerformanceReportController {
|
|||
public void deleteReportBatch(@RequestBody DeleteReportRequest reportRequest) {
|
||||
reportService.deleteReportBatch(reportRequest);
|
||||
}
|
||||
|
||||
@GetMapping("/jtl/download/{reportId}")
|
||||
public ResponseEntity<byte[]> downloadJtl(@PathVariable String reportId) {
|
||||
byte[] bytes = reportService.downloadJtl(reportId);
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType("application/octet-stream"))
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + reportId + ".jtl\"")
|
||||
.body(bytes);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import io.metersphere.performance.controller.request.DeleteReportRequest;
|
|||
import io.metersphere.performance.controller.request.ReportRequest;
|
||||
import io.metersphere.performance.engine.Engine;
|
||||
import io.metersphere.performance.engine.EngineFactory;
|
||||
import io.metersphere.service.FileService;
|
||||
import io.metersphere.service.TestResourceService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -47,6 +48,8 @@ public class ReportService {
|
|||
private TestResourceService testResourceService;
|
||||
@Resource
|
||||
private LoadTestReportDetailMapper loadTestReportDetailMapper;
|
||||
@Resource
|
||||
private FileService fileService;
|
||||
|
||||
public List<ReportDTO> getRecentReportList(ReportRequest request) {
|
||||
List<OrderRequest> orders = new ArrayList<>();
|
||||
|
@ -168,9 +171,9 @@ public class ReportService {
|
|||
|
||||
public void checkReportStatus(String reportId) {
|
||||
LoadTestReport loadTestReport = loadTestReportMapper.selectByPrimaryKey(reportId);
|
||||
String reportStatus="";
|
||||
if(loadTestReport!=null){
|
||||
reportStatus = loadTestReport.getStatus();
|
||||
String reportStatus = "";
|
||||
if (loadTestReport != null) {
|
||||
reportStatus = loadTestReport.getStatus();
|
||||
}
|
||||
if (StringUtils.equals(PerformanceTestStatus.Error.name(), reportStatus)) {
|
||||
MSException.throwException("Report generation error!");
|
||||
|
@ -271,4 +274,9 @@ public class ReportService {
|
|||
String content = getContent(id, ReportKeys.ResponseCodeChart);
|
||||
return JSON.parseArray(content, ChartsData.class);
|
||||
}
|
||||
|
||||
public byte[] downloadJtl(String reportId) {
|
||||
LoadTestReportWithBLOBs report = getReport(reportId);
|
||||
return fileService.loadFileAsBytes(report.getFileId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
<el-button :disabled="isReadOnly" type="info" plain size="mini" @click="handleExport(reportName)">
|
||||
{{ $t('test_track.plan_view.export_report') }}
|
||||
</el-button>
|
||||
<el-button :disabled="isReadOnly" type="warning" plain size="mini" @click="downloadJtl()">
|
||||
下载JTL
|
||||
</el-button>
|
||||
|
||||
<!--<el-button :disabled="isReadOnly" type="warning" plain size="mini">-->
|
||||
<!--{{$t('report.compare')}}-->
|
||||
|
@ -95,6 +98,7 @@ import MsMainContainer from "../../common/components/MsMainContainer";
|
|||
import {checkoutTestManagerOrTestUser, exportPdf} from "@/common/js/utils";
|
||||
import html2canvas from 'html2canvas';
|
||||
import MsPerformanceReportExport from "./PerformanceReportExport";
|
||||
import {Message} from "element-ui";
|
||||
|
||||
|
||||
export default {
|
||||
|
@ -281,6 +285,31 @@ export default {
|
|||
this.reportExportVisible = false;
|
||||
this.result.loading = false;
|
||||
},
|
||||
downloadJtl() {
|
||||
let config = {
|
||||
url: "/performance/report/jtl/download/" + this.reportId,
|
||||
method: 'get',
|
||||
responseType: 'blob'
|
||||
};
|
||||
this.result = this.$request(config).then(response => {
|
||||
const content = response.data;
|
||||
const blob = new Blob([content]);
|
||||
if ("download" in document.createElement("a")) {
|
||||
// 非IE下载
|
||||
// chrome/firefox
|
||||
let aTag = document.createElement('a');
|
||||
aTag.download = this.reportId + ".jtl";
|
||||
aTag.href = URL.createObjectURL(blob);
|
||||
aTag.click();
|
||||
URL.revokeObjectURL(aTag.href)
|
||||
} else {
|
||||
// IE10+下载
|
||||
navigator.msSaveBlob(blob, this.filename)
|
||||
}
|
||||
}).catch(e => {
|
||||
Message.error({message: e.message, showClose: true});
|
||||
});
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.isReadOnly = false;
|
||||
|
|
|
@ -360,6 +360,7 @@ export default {
|
|||
test_stop_now_confirm: 'Are you sure you want to stop the current test immediately?',
|
||||
test_rerun_confirm: 'Are you sure you want to rerun the current test immediately?',
|
||||
test_stop_success: 'Test stop successfully',
|
||||
downloadJtl: 'Download JTL',
|
||||
test_execute_again: 'Test Execute Again',
|
||||
export: 'Export',
|
||||
compare: 'Compare',
|
||||
|
|
|
@ -360,6 +360,7 @@ export default {
|
|||
test_rerun_confirm: '确定要再次执行当前测试吗?',
|
||||
test_stop_success: '停止成功',
|
||||
test_execute_again: '再次执行',
|
||||
downloadJtl: '下载JTL',
|
||||
export: '导出',
|
||||
compare: '比较',
|
||||
generation_error: '报告生成错误, 无法查看, 请检查日志详情!',
|
||||
|
|
|
@ -360,6 +360,7 @@ export default {
|
|||
test_stop_now: '立即停止',
|
||||
test_stop_now_confirm: '確定要立即停止當前測試嗎?',
|
||||
test_rerun_confirm: '確定要再次執行當前測試嗎?',
|
||||
downloadJtl: '下載JTL',
|
||||
test_stop_success: '停止成功',
|
||||
test_execute_again: '再次執行',
|
||||
export: '導出',
|
||||
|
|
Loading…
Reference in New Issue