feat: 保存的测试报告支持导出报告

This commit is contained in:
chenjianxing 2021-08-25 13:36:29 +08:00 committed by jianxing
parent c81813f8fa
commit 9bb48e54ed
5 changed files with 87 additions and 47 deletions

View File

@ -213,6 +213,11 @@ public class TestPlanController {
testPlanService.exportPlanReport(planId, response);
}
@GetMapping("/report/db/export/{reportId}")
public void exportHtmlDbReport(@PathVariable String reportId, HttpServletResponse response) throws UnsupportedEncodingException {
testPlanService.exportPlanDbReport(reportId, response);
}
@GetMapping("/report/{planId}")
public TestPlanSimpleReportDTO getReport(@PathVariable String planId) {
return testPlanService.getReport(planId);

View File

@ -927,6 +927,9 @@ public class TestPlanReportService {
TestPlanReportDataExample example = new TestPlanReportDataExample();
example.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId);
testPlanReportDataMapper.deleteByExample(example);
TestPlanReportContentExample contentExample = new TestPlanReportContentExample();
contentExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId);
testPlanReportContentMapper.deleteByExample(contentExample);
// TestPlanReportResourceExample resourceExample = new TestPlanReportResourceExample();
// resourceExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId);
// testPlanReportResourceService.deleteByExample(resourceExample);
@ -954,6 +957,10 @@ public class TestPlanReportService {
example.createCriteria().andTestPlanReportIdIn(deleteReportIds);
testPlanReportDataMapper.deleteByExample(example);
TestPlanReportContentExample contentExample = new TestPlanReportContentExample();
contentExample.createCriteria().andTestPlanReportIdIn(deleteReportIds);
testPlanReportContentMapper.deleteByExample(contentExample);
// TestPlanReportResourceExample resourceExample = new TestPlanReportResourceExample();
// resourceExample.createCriteria().andTestPlanReportIdIn(deleteReportIds);
// testPlanReportResourceService.deleteByExample(resourceExample);
@ -1096,6 +1103,9 @@ public class TestPlanReportService {
if (StringUtils.isNotBlank(testPlanReportContent.getLoadFailureCases())) {
testPlanReportDTO.setLoadFailureCases(JSONObject.parseArray(testPlanReportContent.getLoadFailureCases(), TestPlanLoadCaseDTO.class));
}
testPlanReportDTO.setId(reportId);
TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(testPlanReportContent.getTestPlanReportId());
testPlanReportDTO.setName(testPlanReport.getName());
return testPlanReportDTO;
}
}

View File

@ -1397,19 +1397,12 @@ public class TestPlanService {
apiAllCases = testPlanApiCaseService.getAllCases(planId);
report.setApiAllCases(apiAllCases);
if (saveResponse) {
apiAllCases.forEach(item -> {
APIReportResult dbResult = apiDefinitionService.getDbResult(item.getId());
if (dbResult != null && StringUtils.isNotBlank(dbResult.getContent())) {
item.setResponse(dbResult.getContent());
}
});
buildApiResponse(apiAllCases);
}
//场景
scenarioAllCases = testPlanScenarioCaseService.getAllCases(planId);
if (saveResponse) {
scenarioAllCases.forEach((item) -> {
item.setResponse(apiScenarioReportService.get(item.getReportId()));
});
buildScenarioResponse(scenarioAllCases);
}
report.setScenarioAllCases(scenarioAllCases);
}
@ -1425,12 +1418,7 @@ public class TestPlanService {
apiFailureCases = testPlanApiCaseService.getFailureCases(planId);
}
if (saveResponse) {
apiFailureCases.forEach(item -> {
APIReportResult dbResult = apiDefinitionService.getDbResult(item.getId());
if (dbResult != null && StringUtils.isNotBlank(dbResult.getContent())) {
item.setResponse(dbResult.getContent());
}
});
buildApiResponse(apiFailureCases);
}
report.setApiFailureCases(apiFailureCases);
@ -1445,43 +1433,66 @@ public class TestPlanService {
scenarioFailureCases = testPlanScenarioCaseService.getFailureCases(planId);
}
if (saveResponse) {
scenarioFailureCases.forEach((item) -> {
item.setResponse(apiScenarioReportService.get(item.getReportId()));
});
buildScenarioResponse(scenarioFailureCases);
}
report.setScenarioFailureCases(scenarioFailureCases);
}
}
}
public void buildApiResponse(List<TestPlanFailureApiDTO> cases) {
if (!CollectionUtils.isEmpty(cases)) {
cases.forEach(item -> {
APIReportResult dbResult = apiDefinitionService.getDbResult(item.getId());
if (dbResult != null && StringUtils.isNotBlank(dbResult.getContent())) {
item.setResponse(dbResult.getContent());
}
});
}
}
public void buildScenarioResponse(List<TestPlanFailureScenarioDTO> cases) {
if (!CollectionUtils.isEmpty(cases)) {
cases.forEach((item) -> {
item.setResponse(apiScenarioReportService.get(item.getReportId()));
});
}
}
public void buildLoadResponse(List<TestPlanLoadCaseDTO> cases) {
if (!CollectionUtils.isEmpty(cases)) {
cases.forEach(item -> {
LoadCaseReportRequest request = new LoadCaseReportRequest();
String reportId = item.getLoadReportId();
if (StringUtils.isNotBlank(reportId)) {
request.setTestPlanLoadCaseId(item.getId());
request.setReportId(reportId);
Boolean existReport = testPlanLoadCaseService.isExistReport(request);
if (existReport) {
LoadTestReportWithBLOBs loadTestReport = performanceReportService.getLoadTestReport(reportId);
ReportTimeInfo reportTimeInfo = performanceReportService.getReportTimeInfo(reportId);
TestPlanLoadCaseDTO.ReportDTO reportDTO = new TestPlanLoadCaseDTO.ReportDTO();
if (loadTestReport != null) {
BeanUtils.copyBean(reportDTO, loadTestReport);
}
if (reportTimeInfo != null) {
BeanUtils.copyBean(reportDTO, reportTimeInfo);
}
item.setResponse(reportDTO);
// todo 报告详情
}
}
});
}
}
public void buildLoadReport(TestPlanSimpleReportDTO report, JSONObject config, String planId, boolean saveResponse) {
if (checkReportConfig(config, "load")) {
List<TestPlanLoadCaseDTO> allCases = null;
if (checkReportConfig(config, "load", "all")) {
allCases = testPlanLoadCaseService.getAllCases(planId);
if (saveResponse) {
allCases.forEach(item -> {
LoadCaseReportRequest request = new LoadCaseReportRequest();
String reportId = item.getLoadReportId();
if (StringUtils.isNotBlank(reportId)) {
request.setTestPlanLoadCaseId(item.getId());
request.setReportId(reportId);
Boolean existReport = testPlanLoadCaseService.isExistReport(request);
if (existReport) {
LoadTestReportWithBLOBs loadTestReport = performanceReportService.getLoadTestReport(reportId);
ReportTimeInfo reportTimeInfo = performanceReportService.getReportTimeInfo(reportId);
TestPlanLoadCaseDTO.ReportDTO reportDTO = new TestPlanLoadCaseDTO.ReportDTO();
if (loadTestReport != null) {
BeanUtils.copyBean(reportDTO, loadTestReport);
}
if (reportTimeInfo != null) {
BeanUtils.copyBean(reportDTO, reportTimeInfo);
}
item.setResponse(reportDTO);
// todo 报告详情
}
}
});
buildLoadResponse(allCases);
}
report.setLoadAllCases(allCases);
}
@ -1659,6 +1670,16 @@ public class TestPlanService {
render(buildPlanReport(planId, true), response);
}
public void exportPlanDbReport(String reportId, HttpServletResponse response) throws UnsupportedEncodingException {
TestPlanSimpleReportDTO report = testPlanReportService.getReport(reportId);
buildApiResponse(report.getApiAllCases());
buildApiResponse(report.getApiFailureCases());
buildScenarioResponse(report.getScenarioAllCases());
buildScenarioResponse(report.getScenarioFailureCases());
buildLoadResponse(report.getLoadAllCases());
render(report, response);
}
public Boolean checkReportConfig(JSONObject config, String key) {
if (config == null) {
return true;
@ -1709,7 +1730,7 @@ public class TestPlanService {
start += 1024;
}
}
} catch (Exception e) {
} catch (Throwable e) {
LogUtil.error(e.getMessage(), e);
MSException.throwException(e.getMessage());
}

View File

@ -9,14 +9,14 @@
<el-button type="primary" size="mini" :disabled="!shareUrl"
v-clipboard:copy="shareUrl">{{ $t("commons.copy") }}</el-button>
</div>
<el-button icon="el-icon-share" slot="reference" :disabled="!isTestManagerOrTestUser"
<el-button icon="el-icon-share" v-if="!isDb" slot="reference" :disabled="!isTestManagerOrTestUser"
plain size="mini" @click="handleShare()">
{{'分享'}}
</el-button>
</el-popover>
</el-row>
<el-row>
<el-button icon="el-icon-receiving" :disabled="!isTestManagerOrTestUser" plain size="mini" @click="handleSave()">
<el-button icon="el-icon-receiving" v-if="!isDb" :disabled="!isTestManagerOrTestUser" plain size="mini" @click="handleSave()">
{{'保存'}}
</el-button>
</el-row>
@ -26,7 +26,7 @@
</el-button>
</el-row>
<el-row>
<el-button icon="el-icon-setting" :disabled="!isTestManagerOrTestUser" plain size="mini" @click="handleEditTemplate()">
<el-button icon="el-icon-setting" v-if="!isDb" :disabled="!isTestManagerOrTestUser" plain size="mini" @click="handleEditTemplate()">
{{'配置'}}
</el-button>
</el-row>
@ -49,7 +49,8 @@ export default {
props: {
planId:String,
isShare: Boolean,
report: Object
report: Object,
isDb: Boolean
},
data() {
return {
@ -91,6 +92,9 @@ export default {
method: 'get',
responseType: 'blob'
};
if (this.isDb) {
config.url = '/test/plan/report/db/export/' + this.report.id;
}
if (this.isShare) {
config.url = '/share' + config.url;
}

View File

@ -2,8 +2,8 @@
<div class="container">
<el-main>
<el-card v-loading="result ? result.loading : false">
<test-plan-report-buttons :plan-id="planId" :is-share="isShare" :report="report"
v-if="!isTemplate && !isShare && !isDb"/>
<test-plan-report-buttons :is-db="isDb" :plan-id="planId" :is-share="isShare" :report="report"
v-if="!isTemplate"/>
<test-plan-overview-report v-if="overviewEnable" :report="report"/>
<test-plan-summary-report v-if="summaryEnable" :is-db="isDb" :is-template="isTemplate" :is-share="isShare" :report="report" :plan-id="planId"/>
<test-plan-functional-report v-if="functionalEnable" :is-db="isDb" :share-id="shareId" :is-share="isShare" :is-template="isTemplate" :plan-id="planId" :report="report"/>