查看报告时检查报告状态

This commit is contained in:
shiziyuan9527 2020-04-03 14:12:20 +08:00
parent d421965476
commit 66b6a1a63b
1 changed files with 15 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import io.metersphere.base.domain.LoadTestReportExample;
import io.metersphere.base.domain.LoadTestReportWithBLOBs; import io.metersphere.base.domain.LoadTestReportWithBLOBs;
import io.metersphere.base.mapper.LoadTestReportMapper; import io.metersphere.base.mapper.LoadTestReportMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper; import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper;
import io.metersphere.commons.constants.TestStatus;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.controller.request.ReportRequest; import io.metersphere.controller.request.ReportRequest;
import io.metersphere.dto.ReportDTO; import io.metersphere.dto.ReportDTO;
@ -52,6 +53,7 @@ public class ReportService {
} }
public RequestStatisticsDTO getReport(String id) { public RequestStatisticsDTO getReport(String id) {
checkReportStatus(id);
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id);
String content = loadTestReport.getContent(); String content = loadTestReport.getContent();
RequestStatisticsDTO requestStatistics = JtlResolver.getRequestStatistics(content); RequestStatisticsDTO requestStatistics = JtlResolver.getRequestStatistics(content);
@ -59,6 +61,7 @@ public class ReportService {
} }
public List<Errors> getReportErrors(String id) { public List<Errors> getReportErrors(String id) {
checkReportStatus(id);
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id);
String content = loadTestReport.getContent(); String content = loadTestReport.getContent();
List<Errors> errors = JtlResolver.getErrorsList(content); List<Errors> errors = JtlResolver.getErrorsList(content);
@ -66,6 +69,7 @@ public class ReportService {
} }
public ErrorsTop5DTO getReportErrorsTOP5(String id) { public ErrorsTop5DTO getReportErrorsTOP5(String id) {
checkReportStatus(id);
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id);
String content = loadTestReport.getContent(); String content = loadTestReport.getContent();
ErrorsTop5DTO errors = JtlResolver.getErrorsTop5DTO(content); ErrorsTop5DTO errors = JtlResolver.getErrorsTop5DTO(content);
@ -73,6 +77,7 @@ public class ReportService {
} }
public TestOverview getTestOverview(String id) { public TestOverview getTestOverview(String id) {
checkReportStatus(id);
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id);
String content = loadTestReport.getContent(); String content = loadTestReport.getContent();
TestOverview testOverview = JtlResolver.getTestOverview(content); TestOverview testOverview = JtlResolver.getTestOverview(content);
@ -80,19 +85,22 @@ public class ReportService {
} }
public ChartsData getLoadChartData(String id) { public ChartsData getLoadChartData(String id) {
checkReportStatus(id);
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id);
String content = loadTestReport.getContent(); String content = loadTestReport.getContent();
ChartsData chartsData = JtlResolver.getLoadChartData(content); ChartsData chartsData = JtlResolver.getLoadChartData(content);
return chartsData; return chartsData;
} }
// public void checkReportStatus(String id) { public void checkReportStatus(String reportId) {
// LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(reportId);
// String status=loadTestReport.getStatus(); String reportStatus = loadTestReport.getStatus();
// if (StringUtils.equals("Error",status)) { if (StringUtils.equals(TestStatus.Running.name(), reportStatus)) {
// MSException.throwException("test run error!"); MSException.throwException("Reporting in progress...");
// } } else if (StringUtils.equals(TestStatus.Error.name(), reportStatus)) {
// } MSException.throwException("Report generation error!");
}
}
public LoadTestReport getLoadTestReport(String id) { public LoadTestReport getLoadTestReport(String id) {
return extLoadTestReportMapper.selectByPrimaryKey(id); return extLoadTestReportMapper.selectByPrimaryKey(id);