feat(性能测试): 报告支持导出详情excel
--story=1015509 --user=刘瑞斌 【百联】性能测试,测试报告,聚合报告页面,客户希望能加一个把"请求统计"页面的聚合结果导出成到excel格式文件里 https://www.tapd.cn/55049933/s/1546140
This commit is contained in:
parent
ef54dbf891
commit
7c9fec1858
|
@ -198,4 +198,10 @@ public class PerformanceReportController {
|
|||
public List<String> selectForPlanReport(@RequestBody List<String> apiReportIds) {
|
||||
return performanceReportService.selectForPlanReport(apiReportIds);
|
||||
}
|
||||
|
||||
@GetMapping("/download-content/{reportId}")
|
||||
@CheckOwner(resourceId = "#reportId", resourceType = "load_test_report")
|
||||
public void exportReportContent(HttpServletResponse response, @PathVariable String reportId) throws Exception {
|
||||
performanceReportService.exportReportStatistics(response, reportId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,38 +1,67 @@
|
|||
package io.metersphere.dto;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class Statistics {
|
||||
|
||||
@ColumnWidth(60)
|
||||
@ExcelProperty(value = "Label")
|
||||
private String label;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty("Samples")
|
||||
private BigDecimal samples;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty("Fail")
|
||||
private BigDecimal fail;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty("Error")
|
||||
private BigDecimal error;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty("Average")
|
||||
private BigDecimal average;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty("Min")
|
||||
private BigDecimal min;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty("Max")
|
||||
private BigDecimal max;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty("Median")
|
||||
private BigDecimal median;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty("90% Line")
|
||||
private BigDecimal tp90;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty("95% Line")
|
||||
private BigDecimal tp95;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty("99% Line")
|
||||
private BigDecimal tp99;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty("TPS")
|
||||
private BigDecimal transactions;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty("Received")
|
||||
private BigDecimal received;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty("Sent")
|
||||
private BigDecimal sent;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package io.metersphere.service;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.*;
|
||||
import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper;
|
||||
|
@ -586,4 +588,13 @@ public class PerformanceReportService {
|
|||
public List<String> selectForPlanReport(List<String> apiReportIds) {
|
||||
return extLoadTestReportMapper.getStatusByIds(apiReportIds);
|
||||
}
|
||||
|
||||
public void exportReportStatistics(HttpServletResponse response, String reportId) throws Exception {
|
||||
List<Statistics> reportStatistics = getReportStatistics(reportId);
|
||||
EasyExcel.write(response.getOutputStream())
|
||||
.head(Statistics.class)
|
||||
.excelType(ExcelTypeEnum.XLSX)
|
||||
.sheet("统计信息")
|
||||
.doWrite(reportStatistics);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,6 +67,17 @@ export function downloadZip(report) {
|
|||
return request(config);
|
||||
}
|
||||
|
||||
export function downloadStatExcel(report) {
|
||||
let reportId = report.id;
|
||||
let config = {
|
||||
url: `/performance/report/download-content/${reportId}`,
|
||||
method: 'get',
|
||||
responseType: 'blob'
|
||||
};
|
||||
|
||||
return request(config);
|
||||
}
|
||||
|
||||
export function initReportSocket(reportId) {
|
||||
return socket(`/websocket/performance/report/${reportId}`);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<template>
|
||||
<div>
|
||||
<el-button type="default" size="small" @click="exportStatExcel" style="float: right;margin-bottom: 5px;">导出为Excel</el-button>
|
||||
<el-table
|
||||
:data="tableData"
|
||||
stripe
|
||||
|
@ -131,6 +132,7 @@
|
|||
|
||||
<script>
|
||||
import {getPerformanceReportContent, getSharePerformanceReportContent} from "../../../api/load-test";
|
||||
import {downloadStatExcel} from "@/api/report";
|
||||
|
||||
export default {
|
||||
name: "RequestStatistics",
|
||||
|
@ -182,6 +184,25 @@ export default {
|
|||
return (item.label.toLowerCase().indexOf(queryString.toLowerCase()) !== -1);
|
||||
};
|
||||
},
|
||||
exportStatExcel() {
|
||||
downloadStatExcel(this.report)
|
||||
.then(response => {
|
||||
const filename = this.report.name + "_请求统计.xlsx";
|
||||
const blob = new Blob([response.data]);
|
||||
if ("download" in document.createElement("a")) {
|
||||
// 非IE下载
|
||||
// chrome/firefox
|
||||
let aTag = document.createElement('a');
|
||||
aTag.download = filename;
|
||||
aTag.href = URL.createObjectURL(blob);
|
||||
aTag.click();
|
||||
URL.revokeObjectURL(aTag.href);
|
||||
} else {
|
||||
// IE10+下载
|
||||
navigator.msSaveBlob(blob, filename);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
report: {
|
||||
|
|
Loading…
Reference in New Issue