提交 8001fdee 编写于 作者: C Captain.B

tmp

上级 d0ddd8d8
package io.metersphere.commons.constants;
public enum ReportKeys {
LoadChart, ResponseTimeChart, Errors, ErrorsTop5, RequestStatistics, Overview, TimeInfo
}
package io.metersphere.service; package io.metersphere.service;
import io.metersphere.base.domain.LoadTestReport; import com.alibaba.fastjson.JSON;
import io.metersphere.base.domain.LoadTestReportExample; import io.metersphere.base.domain.*;
import io.metersphere.base.domain.LoadTestReportWithBLOBs;
import io.metersphere.base.domain.LoadTestWithBLOBs;
import io.metersphere.base.mapper.LoadTestMapper; import io.metersphere.base.mapper.LoadTestMapper;
import io.metersphere.base.mapper.LoadTestReportMapper; import io.metersphere.base.mapper.LoadTestReportMapper;
import io.metersphere.base.mapper.LoadTestReportResultMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper; import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper;
import io.metersphere.commons.constants.PerformanceTestStatus; import io.metersphere.commons.constants.PerformanceTestStatus;
import io.metersphere.commons.constants.ReportKeys;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import io.metersphere.controller.request.ReportRequest; import io.metersphere.controller.request.ReportRequest;
import io.metersphere.dto.ReportDTO; import io.metersphere.dto.ReportDTO;
import io.metersphere.engine.Engine; import io.metersphere.engine.Engine;
import io.metersphere.engine.EngineFactory; import io.metersphere.engine.EngineFactory;
import io.metersphere.report.GenerateReport;
import io.metersphere.report.base.*; import io.metersphere.report.base.*;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -33,6 +32,8 @@ public class ReportService { ...@@ -33,6 +32,8 @@ public class ReportService {
private ExtLoadTestReportMapper extLoadTestReportMapper; private ExtLoadTestReportMapper extLoadTestReportMapper;
@Resource @Resource
private LoadTestMapper loadTestMapper; private LoadTestMapper loadTestMapper;
@Resource
private LoadTestReportResultMapper loadTestReportResultMapper;
public List<LoadTestReport> getRecentReportList(ReportRequest request) { public List<LoadTestReport> getRecentReportList(ReportRequest request) {
LoadTestReportExample example = new LoadTestReportExample(); LoadTestReportExample example = new LoadTestReportExample();
...@@ -84,58 +85,51 @@ public class ReportService { ...@@ -84,58 +85,51 @@ public class ReportService {
return extLoadTestReportMapper.getReportTestAndProInfo(reportId); return extLoadTestReportMapper.getReportTestAndProInfo(reportId);
} }
private String getContent(String id, ReportKeys reportKey) {
LoadTestReportResultExample example = new LoadTestReportResultExample();
example.createCriteria().andReportIdEqualTo(id).andReportKeyEqualTo(reportKey.name());
return loadTestReportResultMapper.selectByExampleWithBLOBs(example).get(0).getReportValue();
}
public List<Statistics> getReport(String id) { public List<Statistics> getReport(String id) {
checkReportStatus(id); checkReportStatus(id);
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); String reportValue = getContent(id, ReportKeys.RequestStatistics);
String content = loadTestReport.getContent(); return JSON.parseArray(reportValue, Statistics.class);
return GenerateReport.getRequestStatistics(content);
} }
public List<Errors> getReportErrors(String id) { public List<Errors> getReportErrors(String id) {
checkReportStatus(id); checkReportStatus(id);
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); String content = getContent(id, ReportKeys.Errors);
String content = loadTestReport.getContent(); return JSON.parseArray(content, Errors.class);
List<Errors> errors = GenerateReport.getErrorsList(content);
return errors;
} }
public List<ErrorsTop5> getReportErrorsTOP5(String id) { public List<ErrorsTop5> getReportErrorsTOP5(String id) {
checkReportStatus(id); checkReportStatus(id);
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); String content = getContent(id, ReportKeys.ErrorsTop5);
String content = loadTestReport.getContent(); return JSON.parseArray(content, ErrorsTop5.class);
List<ErrorsTop5> errorsTop5 = GenerateReport.getErrorsTop5List(content);
return errorsTop5;
} }
public TestOverview getTestOverview(String id) { public TestOverview getTestOverview(String id) {
checkReportStatus(id); checkReportStatus(id);
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); String content = getContent(id, ReportKeys.Overview);
String content = loadTestReport.getContent(); return JSON.parseObject(content, TestOverview.class);
TestOverview testOverview = GenerateReport.getTestOverview(content);
return testOverview;
} }
public ReportTimeInfo getReportTimeInfo(String id) { public ReportTimeInfo getReportTimeInfo(String id) {
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); String content = getContent(id, ReportKeys.TimeInfo);
String content = loadTestReport.getContent(); return JSON.parseObject(content, ReportTimeInfo.class);
ReportTimeInfo reportTimeInfo = GenerateReport.getReportTimeInfo(content);
return reportTimeInfo;
} }
public List<ChartsData> getLoadChartData(String id) { public List<ChartsData> getLoadChartData(String id) {
checkReportStatus(id); checkReportStatus(id);
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); String content = getContent(id, ReportKeys.LoadChart);
String content = loadTestReport.getContent(); return JSON.parseArray(content, ChartsData.class);
List<ChartsData> chartsDataList = GenerateReport.getLoadChartData(content);
return chartsDataList;
} }
public List<ChartsData> getResponseTimeChartData(String id) { public List<ChartsData> getResponseTimeChartData(String id) {
checkReportStatus(id); checkReportStatus(id);
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); String content = getContent(id, ReportKeys.ResponseTimeChart);
String content = loadTestReport.getContent(); return JSON.parseArray(content, ChartsData.class);
List<ChartsData> chartsDataList = GenerateReport.getResponseTimeChartData(content);
return chartsDataList;
} }
public void checkReportStatus(String reportId) { public void checkReportStatus(String reportId) {
......
...@@ -71,6 +71,19 @@ CREATE TABLE IF NOT EXISTS `load_test_report_detail` ( ...@@ -71,6 +71,19 @@ CREATE TABLE IF NOT EXISTS `load_test_report_detail` (
DEFAULT CHARSET=utf8mb4 DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_bin; COLLATE=utf8mb4_bin;
CREATE TABLE IF NOT EXISTS `load_test_report_result` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`report_id` varchar(50) NOT NULL,
`report_key` varchar(64) DEFAULT NULL,
`report_value` text,
PRIMARY KEY (`id`),
KEY `load_test_report_result_report_id_report_key_index` (`report_id`,`report_key`)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_bin;
CREATE TABLE IF NOT EXISTS `organization` ( CREATE TABLE IF NOT EXISTS `organization` (
`id` varchar(50) NOT NULL COMMENT 'Organization ID', `id` varchar(50) NOT NULL COMMENT 'Organization ID',
`name` varchar(64) NOT NULL COMMENT 'Organization name', `name` varchar(64) NOT NULL COMMENT 'Organization name',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册