This commit is contained in:
wenyann 2020-11-13 17:06:51 +08:00
commit 085af5b862
9 changed files with 65 additions and 3 deletions

View File

@ -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);
}
}

View File

@ -13,11 +13,13 @@ import io.metersphere.commons.utils.ServiceUtils;
import io.metersphere.controller.request.OrderRequest;
import io.metersphere.dto.LogDetailDTO;
import io.metersphere.dto.ReportDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.performance.base.*;
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 +49,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,8 +172,8 @@ public class ReportService {
public void checkReportStatus(String reportId) {
LoadTestReport loadTestReport = loadTestReportMapper.selectByPrimaryKey(reportId);
String reportStatus="";
if(loadTestReport!=null){
String reportStatus = "";
if (loadTestReport != null) {
reportStatus = loadTestReport.getStatus();
}
if (StringUtils.equals(PerformanceTestStatus.Error.name(), reportStatus)) {
@ -271,4 +275,12 @@ public class ReportService {
String content = getContent(id, ReportKeys.ResponseCodeChart);
return JSON.parseArray(content, ChartsData.class);
}
public byte[] downloadJtl(String reportId) {
LoadTestReportWithBLOBs report = getReport(reportId);
if (StringUtils.isBlank(report.getFileId())) {
throw new RuntimeException(Translator.get("load_test_report_file_not_exist"));
}
return fileService.loadFileAsBytes(report.getFileId());
}
}

View File

@ -48,6 +48,7 @@ related_case_del_fail_prefix=Connected to
related_case_del_fail_suffix=TestCase, please disassociate first
jmx_content_valid=JMX content is invalid
container_delete_fail=The container failed to stop, please try again
load_test_report_file_not_exist=There is no JTL file in the current report, please execute it again to get it
#workspace
workspace_name_is_null=Workspace name cannot be null
workspace_name_already_exists=The workspace name already exists

View File

@ -48,6 +48,7 @@ related_case_del_fail_prefix=已关联到
related_case_del_fail_suffix=测试用例,请先解除关联
jmx_content_valid=JMX 内容无效,请检查
container_delete_fail=容器由于网络原因停止失败,请重试
load_test_report_file_not_exist=当前报告没有JTL文件请重新执行以便获取
#workspace
workspace_name_is_null=工作空间名不能为空
workspace_name_already_exists=工作空间名已存在

View File

@ -48,6 +48,7 @@ related_case_del_fail_prefix=已關聯到
related_case_del_fail_suffix=測試用例,請先解除關聯
jmx_content_valid=JMX 內容無效,請檢查
container_delete_fail=容器由於網絡原因停止失敗,請重試
load_test_report_file_not_exist=當前報告沒有JTL文件請重新執行以便獲取
#workspace
workspace_name_is_null=工作空間名不能為空
workspace_name_already_exists=工作空間名已存在

View File

@ -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()">
{{ $t('report.downloadJtl') }}
</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,34 @@ 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 => {
let text = e.response.data.text();
text.then((data) => {
Message.error({message: JSON.parse(data).message || e.message, showClose: true});
});
});
}
},
created() {
this.isReadOnly = false;

View File

@ -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',

View File

@ -360,6 +360,7 @@ export default {
test_rerun_confirm: '确定要再次执行当前测试吗?',
test_stop_success: '停止成功',
test_execute_again: '再次执行',
downloadJtl: '下载JTL',
export: '导出',
compare: '比较',
generation_error: '报告生成错误, 无法查看, 请检查日志详情!',

View File

@ -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: '導出',