refactor(测试计划): 优化测试计划报告生成方法,考虑到测试计划可能会含有大批接口和场景,接口和场景的报告执行结果不再调用api服务查询

优化测试计划报告生成方法,考虑到测试计划可能会含有大批接口和场景,接口和场景的报告执行结果不再调用api服务查询
This commit is contained in:
song-tianyang 2023-03-10 12:41:01 +08:00 committed by 建国
parent d182c2fc76
commit 1d14afdb62
21 changed files with 165 additions and 100 deletions

View File

@ -1,11 +1,13 @@
package io.metersphere.commons.utils;
import io.metersphere.api.dto.definition.BatchDataCopyRequest;
import io.metersphere.base.domain.ApiScenarioReportResultWithBLOBs;
import org.apache.commons.collections.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
/**
* 批量处理工具
@ -14,6 +16,34 @@ public class BatchProcessingUtil {
private static final int BATCH_PROCESS_QUANTITY = 1000;
public static List<ApiScenarioReportResultWithBLOBs> selectScenarioReportResultByScenarioReportId(List<String> scenarioReportId, Function<List<String>, List<ApiScenarioReportResultWithBLOBs>> func) {
List<ApiScenarioReportResultWithBLOBs> returnList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(scenarioReportId)) {
int unProcessingCount = scenarioReportId.size();
while (scenarioReportId.size() > BATCH_PROCESS_QUANTITY) {
List<String> processingList = new ArrayList<>();
for (int i = 0; i < BATCH_PROCESS_QUANTITY; i++) {
processingList.add(scenarioReportId.get(i));
}
//函数处理
returnList.addAll(func.apply(processingList));
scenarioReportId.removeAll(processingList);
if (scenarioReportId.size() == unProcessingCount) {
//如果剩余数量没有发生变化则跳出循环防止出现死循环的情况
break;
} else {
unProcessingCount = scenarioReportId.size();
}
}
if (CollectionUtils.isNotEmpty(scenarioReportId)) {
//剩余待处理数据进行处理
returnList.addAll(func.apply(scenarioReportId));
}
}
return returnList;
}
public static void batchProcessingByDataCopy(BatchDataCopyRequest paramRequest, Consumer<BatchDataCopyRequest> func) {
List<String> paramList = paramRequest.getIds();
if (CollectionUtils.isNotEmpty(paramList)) {

View File

@ -687,7 +687,8 @@ public class TestPlanScenarioCaseService {
private void calculateScenarioResultDTO(List<String> scenarioReportIdList,
TestPlanScenarioStepCountDTO stepCount) {
if (CollectionUtils.isNotEmpty(scenarioReportIdList)) {
List<ApiScenarioReportResultWithBLOBs> resultList = extApiScenarioReportResultMapper.selectIdAndStatusByReportIdList(scenarioReportIdList);
List<ApiScenarioReportResultWithBLOBs> resultList = BatchProcessingUtil.selectScenarioReportResultByScenarioReportId(scenarioReportIdList, extApiScenarioReportResultMapper::selectIdAndStatusByReportIdList);
resultList = apiScenarioReportStructureService.filterProcessResult(resultList);
stepCount.setScenarioStepTotal(resultList.size());
int successStep = 0;

View File

@ -1,5 +1,6 @@
package io.metersphere.base.mapper.ext;
import io.metersphere.base.domain.ApiDefinitionExecResult;
import io.metersphere.base.domain.TestPlanApiCase;
import io.metersphere.plan.dto.CaseExecResult;
import io.metersphere.plan.dto.TestPlanApiCaseInfoDTO;
@ -15,5 +16,7 @@ public interface ExtTestPlanApiCaseMapper {
@Select("SELECT id,test_plan_id,api_case_id,status FROM test_plan_api_case WHERE id = #{0} ")
TestPlanApiCase selectBaseInfoById(String testId);
List<ApiDefinitionExecResult> selectReportStatusByReportIds(@Param("ids") List<String> apiReportIdList);
}

View File

@ -19,4 +19,13 @@
#{id}
</foreach>
</select>
<select id="selectReportStatusByReportIds"
resultType="io.metersphere.base.domain.ApiDefinitionExecResult">
select id,status from api_definition_exec_result
where id in
<foreach collection="ids" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</select>
</mapper>

View File

@ -1,5 +1,6 @@
package io.metersphere.base.mapper.ext;
import io.metersphere.base.domain.ApiScenarioReport;
import io.metersphere.base.domain.TestPlanApiScenario;
import io.metersphere.plan.dto.CaseExecResult;
import io.metersphere.plan.dto.TestPlanApiScenarioInfoDTO;
@ -17,4 +18,6 @@ public interface ExtTestPlanScenarioCaseMapper {
@Select("SELECT id,test_plan_id,api_scenario_id,last_result FROM test_plan_api_scenario WHERE id = #{0} ")
TestPlanApiScenario selectBaseInfoById(String testId);
List<ApiScenarioReport> selectReportStatusByReportIds(@Param("ids") List<String> scenarioReportIdList);
}

View File

@ -38,4 +38,12 @@
#{id}
</foreach>
</select>
<select id="selectReportStatusByReportIds" resultType="io.metersphere.base.domain.ApiScenarioReport">
select id,status from api_scenario_report
WHERE id IN
<foreach collection="ids" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</select>
</mapper>

View File

@ -5,7 +5,7 @@ import io.metersphere.commons.utils.HttpHeaderUtils;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.dto.TestPlanCaseDTO;
import io.metersphere.plan.dto.ExecutionModeDTO;
import io.metersphere.plan.dto.TestPlanSimpleReportDTO;
import io.metersphere.plan.dto.TestPlanReportDataStruct;
import io.metersphere.plan.service.TestPlanReportService;
import io.metersphere.plan.service.TestPlanService;
import io.metersphere.plan.service.TestPlanTestCaseService;
@ -41,7 +41,7 @@ public class ShareController {
}
@GetMapping("/test/plan/report/{shareId}/{planId}")
public TestPlanSimpleReportDTO getReport(@PathVariable String shareId, @PathVariable String planId) {
public TestPlanReportDataStruct getReport(@PathVariable String shareId, @PathVariable String planId) {
shareInfoService.validate(shareId, planId);
return testPlanService.getShareReport(shareInfoService.get(shareId), planId);
}
@ -61,7 +61,7 @@ public class ShareController {
}
@GetMapping("/test/plan/report/db/{shareId}/{reportId}")
public TestPlanSimpleReportDTO getTestPlanDbReport(@PathVariable String shareId, @PathVariable String reportId) {
public TestPlanReportDataStruct getTestPlanDbReport(@PathVariable String shareId, @PathVariable String reportId) {
shareInfoService.validate(shareId, reportId);
return testPlanReportService.getShareDbReport(shareInfoService.get(shareId), reportId);
}

View File

@ -17,7 +17,7 @@ import io.metersphere.notice.annotation.SendNotice;
import io.metersphere.plan.dto.ExecutionModeDTO;
import io.metersphere.plan.dto.TestCaseReportStatusResultDTO;
import io.metersphere.plan.dto.TestPlanDTO;
import io.metersphere.plan.dto.TestPlanSimpleReportDTO;
import io.metersphere.plan.dto.TestPlanReportDataStruct;
import io.metersphere.plan.request.AddTestPlanRequest;
import io.metersphere.plan.request.BatchOperateRequest;
import io.metersphere.plan.request.QueryTestPlanRequest;
@ -267,7 +267,7 @@ public class TestPlanController {
}
@GetMapping("/get/report/export/{planId}")
public TestPlanSimpleReportDTO getExportHtmlReport(@PathVariable String planId, HttpServletResponse response) throws UnsupportedEncodingException {
public TestPlanReportDataStruct getExportHtmlReport(@PathVariable String planId, HttpServletResponse response) throws UnsupportedEncodingException {
return testPlanService.buildPlanReport(planId, true);
}

View File

@ -14,7 +14,7 @@ import io.metersphere.dto.TestPlanReportDTO;
import io.metersphere.dto.TestPlanScheduleReportInfoDTO;
import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.notice.annotation.SendNotice;
import io.metersphere.plan.dto.TestPlanSimpleReportDTO;
import io.metersphere.plan.dto.TestPlanReportDataStruct;
import io.metersphere.plan.request.TestPlanReportSaveRequest;
import io.metersphere.plan.service.TestPlanReportService;
import io.metersphere.request.report.QueryTestPlanReportRequest;
@ -48,12 +48,12 @@ public class TestPlanReportController {
}
@GetMapping("/real-time/{planId}")
public TestPlanSimpleReportDTO getRealTimeReport(@PathVariable String planId) {
public TestPlanReportDataStruct getRealTimeReport(@PathVariable String planId) {
return testPlanReportService.getRealTimeReport(planId);
}
@GetMapping("/db/{reportId}")
public TestPlanSimpleReportDTO getReport(@PathVariable String reportId) {
public TestPlanReportDataStruct getReport(@PathVariable String reportId) {
return testPlanReportService.getReport(reportId);
}

View File

@ -1,11 +0,0 @@
package io.metersphere.dto;
import io.metersphere.plan.dto.TestPlanSimpleReportDTO;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class TestPlanReportBuildResultDTO {
private TestPlanSimpleReportDTO testPlanSimpleReportDTO;
}

View File

@ -13,7 +13,7 @@ import java.util.Map;
@Getter
@Setter
public class TestPlanSimpleReportDTO extends TestPlanReportContent {
public class TestPlanReportDataStruct extends TestPlanReportContent {
private String name;
private int executeCount;

View File

@ -10,7 +10,7 @@ import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.*;
import io.metersphere.notice.sender.NoticeModel;
import io.metersphere.notice.service.NoticeSendService;
import io.metersphere.plan.dto.TestPlanSimpleReportDTO;
import io.metersphere.plan.dto.TestPlanReportDataStruct;
import io.metersphere.service.BaseProjectService;
import io.metersphere.service.BaseShareInfoService;
import io.metersphere.service.BaseUserService;
@ -142,7 +142,7 @@ public class TestPlanMessageService {
UserDTO userDTO = baseUserService.getUserDTO(creator);
// 计算各种属性
HttpHeaderUtils.runAsUser(userDTO);
TestPlanSimpleReportDTO report = testPlanReportService.getReport(testPlanReport.getId());
TestPlanReportDataStruct report = testPlanReportService.getReport(testPlanReport.getId());
HttpHeaderUtils.clearUser();
Map<String, Long> caseCountMap = calculateCaseCount(report);
@ -219,7 +219,7 @@ public class TestPlanMessageService {
return baseShareInfoService.conversionShareInfoToDTO(shareInfo).getShareUrl();
}
private Map<String, Long> calculateCaseCount(TestPlanSimpleReportDTO report) {
private Map<String, Long> calculateCaseCount(TestPlanReportDataStruct report) {
Map<String, Long> result = new HashMap<>();
// 功能用例
result.put("functionAllCount", 0L);

View File

@ -537,7 +537,7 @@ public class TestPlanReportService {
}
//更新测试计划报告的数据结构
private void updateReportStructInfo(TestPlanReportContentWithBLOBs testPlanReportContentWithBLOBs, TestPlanSimpleReportDTO reportStruct) {
private void updateReportStructInfo(TestPlanReportContentWithBLOBs testPlanReportContentWithBLOBs, TestPlanReportDataStruct reportStruct) {
//更新BaseCount统计字段和通过率
testPlanReportContentWithBLOBs.setPassRate(reportStruct.getPassRate());
testPlanReportContentWithBLOBs.setApiBaseCount(JSON.toJSONString(reportStruct));
@ -607,9 +607,11 @@ public class TestPlanReportService {
if (!isRerunningTestPlan) {
content.setStartTime(testPlanReport.getStartTime());
content.setEndTime(endTime);
//重跑的报告要重新生成统计数据
content.setApiBaseCount(null);
}
TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(testPlanReport.getTestPlanId());
TestPlanSimpleReportDTO apiBaseCountStruct = this.initTestPlanReportStruct(testPlan, testPlanReport, content);
TestPlanReportDataStruct apiBaseCountStruct = this.generateTestPlanReportStruct(testPlan, testPlanReport, content);
if (apiBaseCountStruct.getPassRate() == 1) {
testPlanReport.setStatus(TestPlanReportStatus.SUCCESS.name());
} else if (apiBaseCountStruct.getPassRate() < 1) {
@ -664,19 +666,18 @@ public class TestPlanReportService {
}
//构建测试计划报告的数据结构
private TestPlanSimpleReportDTO initTestPlanReportStruct(TestPlanWithBLOBs testPlan, TestPlanReport testPlanReport, TestPlanReportContentWithBLOBs reportContent) {
TestPlanSimpleReportDTO returnDTO = null;
private TestPlanReportDataStruct generateTestPlanReportStruct(TestPlanWithBLOBs testPlan, TestPlanReport testPlanReport, TestPlanReportContentWithBLOBs reportContent) {
TestPlanReportDataStruct returnDTO = null;
if (testPlanReport != null && reportContent != null) {
try {
TestPlanReportBuildResultDTO reportBuildResultDTO = testPlanService.buildTestPlanReport(testPlan, testPlanReport, reportContent);
returnDTO = testPlanService.buildTestPlanReportStruct(testPlan, testPlanReport, reportContent);
//查找运行环境
this.selectEnvironmentByTestPlanReport(reportBuildResultDTO.getTestPlanSimpleReportDTO(), testPlanReport);
returnDTO = reportBuildResultDTO.getTestPlanSimpleReportDTO();
this.initRunInfomation(returnDTO, testPlanReport);
} catch (Exception e) {
LogUtil.error("计算测试计划报告信息出错!", e);
}
}
return returnDTO;
return returnDTO == null ? new TestPlanReportDataStruct() : returnDTO;
}
/**
@ -715,7 +716,7 @@ public class TestPlanReportService {
List<TestPlanReportContentWithBLOBs> testPlanReportContentList = testPlanReportContentMapper.selectByExampleWithBLOBs(example);
TestPlanReportContentWithBLOBs testPlanReportContent = null;
TestPlanSimpleReportDTO reportDTO = testPlanService.buildPlanReport(testPlan.getId(), false);
TestPlanReportDataStruct reportDTO = testPlanService.buildPlanReport(testPlan.getId(), false);
if (!testPlanReportContentList.isEmpty()) {
testPlanReportContent = parseReportDaoToReportContent(reportDTO, testPlanReportContentList.get(0));
testPlanReportContent.setStartTime(null);
@ -737,7 +738,7 @@ public class TestPlanReportService {
testPlanReportMapper.updateByPrimaryKey(testPlanReport);
}
public TestPlanReportContentWithBLOBs parseReportDaoToReportContent(TestPlanSimpleReportDTO reportDTO, TestPlanReportContentWithBLOBs testPlanReportContentWithBLOBs) {
public TestPlanReportContentWithBLOBs parseReportDaoToReportContent(TestPlanReportDataStruct reportDTO, TestPlanReportContentWithBLOBs testPlanReportContentWithBLOBs) {
String id = testPlanReportContentWithBLOBs.getId();
String testPlanReportId = testPlanReportContentWithBLOBs.getTestPlanReportId();
if (testPlanReportContentWithBLOBs.getEndTime() != null) {
@ -809,7 +810,7 @@ public class TestPlanReportService {
* @param testPlanReport
* @return
*/
private String getTestPlanReportStatus(TestPlanReport testPlanReport, TestPlanSimpleReportDTO reportDTO) {
private String getTestPlanReportStatus(TestPlanReport testPlanReport, TestPlanReportDataStruct reportDTO) {
String status = TestPlanReportStatus.COMPLETED.name();
if (testPlanReport != null) {
if (testPlanReport.getIsApiCaseExecuting() || testPlanReport.getIsPerformanceExecuting() || testPlanReport.getIsScenarioExecuting()) {
@ -1025,7 +1026,7 @@ public class TestPlanReportService {
this.delete(ids);
}
public TestPlanSimpleReportDTO getShareDbReport(ShareInfo shareInfo, String reportId) {
public TestPlanReportDataStruct getShareDbReport(ShareInfo shareInfo, String reportId) {
if (SessionUtils.getUser() == null) {
HttpHeaderUtils.runAsUser(shareInfo.getCreateUserId());
}
@ -1047,8 +1048,8 @@ public class TestPlanReportService {
}
}
public TestPlanSimpleReportDTO getReport(String reportId) {
TestPlanSimpleReportDTO testPlanReportDTO = new TestPlanSimpleReportDTO();
public TestPlanReportDataStruct getReport(String reportId) {
TestPlanReportDataStruct testPlanReportDTO = new TestPlanReportDataStruct();
TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(reportId);
TestPlanReportContentWithBLOBs testPlanReportContent = this.selectTestPlanReportContentByReportId(reportId);
if (ObjectUtils.anyNull(testPlanReport, testPlanReportContent)) {
@ -1056,7 +1057,7 @@ public class TestPlanReportService {
}
if (this.isDynamicallyGenerateReports(testPlanReportContent) || StringUtils.isNotEmpty(testPlanReportContent.getApiBaseCount())) {
TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(testPlanReport.getTestPlanId());
testPlanReportDTO = this.initTestPlanReportStruct(testPlan, testPlanReport, testPlanReportContent);
testPlanReportDTO = this.generateTestPlanReportStruct(testPlan, testPlanReport, testPlanReportContent);
}
testPlanReportDTO.setId(reportId);
testPlanReportDTO.setName(testPlanReport.getName());
@ -1069,9 +1070,9 @@ public class TestPlanReportService {
* @param planId
* @return
*/
public TestPlanSimpleReportDTO getRealTimeReport(String planId) {
public TestPlanReportDataStruct getRealTimeReport(String planId) {
TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(planId);
TestPlanSimpleReportDTO report = new TestPlanSimpleReportDTO();
TestPlanReportDataStruct report = new TestPlanReportDataStruct();
TestPlanFunctionResultReportDTO functionResult = new TestPlanFunctionResultReportDTO();
TestPlanApiResultReportDTO apiResult = new TestPlanApiResultReportDTO();
TestPlanUiResultReportDTO uiResult = new TestPlanUiResultReportDTO();
@ -1127,7 +1128,7 @@ public class TestPlanReportService {
return report;
}
public void selectEnvironmentByTestPlanReport(TestPlanSimpleReportDTO testPlanReportDTO, TestPlanReport testPlanReport) {
public void initRunInfomation(TestPlanReportDataStruct testPlanReportDTO, TestPlanReport testPlanReport) {
if (StringUtils.isNotEmpty(testPlanReport.getRunInfo())) {
try {
TestPlanReportRunInfoDTO runInfoDTO = JSON.parseObject(testPlanReport.getRunInfo(), TestPlanReportRunInfoDTO.class);
@ -1138,7 +1139,7 @@ public class TestPlanReportService {
}
}
public void setEnvironmentToDTO(TestPlanSimpleReportDTO testPlanReportDTO, TestPlanReportRunInfoDTO runInfoDTO) {
public void setEnvironmentToDTO(TestPlanReportDataStruct testPlanReportDTO, TestPlanReportRunInfoDTO runInfoDTO) {
if (ObjectUtils.allNotNull(testPlanReportDTO, runInfoDTO)) {
//查找资源池
if (CollectionUtils.isNotEmpty(runInfoDTO.getResourcePools())) {
@ -1289,7 +1290,7 @@ public class TestPlanReportService {
LogUtil.info("测试计划报告【" + testPlanReportContentWithBLOBs.getTestPlanReportId() + "】开始处理用例执行结果");
TestPlanCaseReportResultDTO reportDetailDTO = new TestPlanCaseReportResultDTO();
//查找api测试报告结果
if (DiscoveryUtil.hasService(MicroServiceName.API_TEST)) {
if (StringUtils.isNotEmpty(testPlanReportContentWithBLOBs.getPlanApiCaseReportStruct()) || StringUtils.isNotEmpty(testPlanReportContentWithBLOBs.getPlanScenarioReportStruct())) {
LogUtil.info("测试计划报告【" + testPlanReportContentWithBLOBs.getTestPlanReportId() + "】开始查找接口测试报告结果");
try {
Map<String, String> apiCaseReportMap = this.parseCaseReportMap(testPlanReportContentWithBLOBs.getPlanApiCaseReportStruct());
@ -1303,7 +1304,9 @@ public class TestPlanReportService {
if (MapUtils.isNotEmpty(scenarioReportMap)) {
request.setScenarioReportIdList(new ArrayList<>(scenarioReportMap.values()));
}
ApiReportResultDTO apiReportResult = planTestPlanScenarioCaseService.getApiExecuteReport(request);
ApiReportResultDTO apiReportResult = new ApiReportResultDTO();
apiReportResult.setApiReportResultMap(this.selectApiCaseRunResultByIds(request.getApiReportIdList()));
apiReportResult.setScenarioReportResultMap(this.selectScenarioRunResultByIds(request.getScenarioReportIdList()));
reportDetailDTO.setApiPlanReportDTO(this.getApiPlanReport(reportConfig, testPlanReportContentWithBLOBs, apiReportResult));
} catch (Exception e) {
LogUtil.error("连接Api-test查找报告结果信息失败!", e);
@ -1366,6 +1369,28 @@ public class TestPlanReportService {
return reportDetailDTO;
}
private Map<String, String> selectApiCaseRunResultByIds(List<String> apiReportIdList) {
Map<String, String> returnMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(apiReportIdList)) {
List<ApiDefinitionExecResult> apiDefinitionExecResultList = extTestPlanApiCaseMapper.selectReportStatusByReportIds(apiReportIdList);
if (CollectionUtils.isNotEmpty(apiDefinitionExecResultList)) {
returnMap = apiDefinitionExecResultList.stream().collect(Collectors.toMap(ApiDefinitionExecResult::getId, ApiDefinitionExecResult::getStatus, (k1, k2) -> k1));
}
}
return returnMap;
}
private Map<String, String> selectScenarioRunResultByIds(List<String> scenarioReportIdList) {
Map<String, String> returnMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(scenarioReportIdList)) {
List<ApiScenarioReport> apiDefinitionExecResultList = extTestPlanScenarioCaseMapper.selectReportStatusByReportIds(scenarioReportIdList);
if (CollectionUtils.isNotEmpty(apiDefinitionExecResultList)) {
returnMap = apiDefinitionExecResultList.stream().collect(Collectors.toMap(ApiScenarioReport::getId, ApiScenarioReport::getStatus, (k1, k2) -> k1));
}
}
return returnMap;
}
private List<TestPlanScenarioDTO> getByScenarioExecReportIds(String planScenarioReportStruct, Map<String, String> scenarioReportResultMap) {
if (MapUtils.isEmpty(scenarioReportResultMap) || StringUtils.isEmpty(planScenarioReportStruct)) {
return new ArrayList<>();

View File

@ -1276,7 +1276,7 @@ public class TestPlanService {
return planTestPlanScenarioCaseService.getApiCaseEnv(planApiScenarioIds);
}
public void buildFunctionalReport(TestPlanSimpleReportDTO report, Map config, String planId) {
public void buildFunctionalReport(TestPlanReportDataStruct report, Map config, String planId) {
if (checkReportConfig(config, "functional")) {
List<TestPlanCaseDTO> allCases = null;
List<String> statusList = getFunctionalReportStatusList(config);
@ -1293,7 +1293,7 @@ public class TestPlanService {
}
}
public void buildUiReport(TestPlanSimpleReportDTO report, Map config, String planId, TestPlanCaseReportResultDTO testPlanExecuteReportDTO, boolean saveResponse) {
public void buildUiReport(TestPlanReportDataStruct report, Map config, String planId, TestPlanCaseReportResultDTO testPlanExecuteReportDTO, boolean saveResponse) {
ApiPlanReportRequest request = new ApiPlanReportRequest();
request.setConfig(config);
request.setPlanId(planId);
@ -1330,7 +1330,7 @@ public class TestPlanService {
return statusList.size() > 0 ? statusList : null;
}
public void buildApiReport(TestPlanSimpleReportDTO report, Map config, String planId, boolean saveResponse) {
public void buildApiReport(TestPlanReportDataStruct report, Map config, String planId, boolean saveResponse) {
ApiPlanReportRequest request = new ApiPlanReportRequest();
request.setConfig(config);
request.setPlanId(planId);
@ -1341,7 +1341,7 @@ public class TestPlanService {
}
}
public void buildLoadReport(TestPlanSimpleReportDTO report, Map config, String planId, boolean saveResponse) {
public void buildLoadReport(TestPlanReportDataStruct report, Map config, String planId, boolean saveResponse) {
ApiPlanReportRequest request = new ApiPlanReportRequest();
request.setConfig(config);
request.setPlanId(planId);
@ -1357,36 +1357,33 @@ public class TestPlanService {
* @param testPlanReportContentWithBLOBs 测试计划报告内容
* @return
*/
public TestPlanReportBuildResultDTO buildTestPlanReport(TestPlanWithBLOBs testPlan, TestPlanReport testPlanReport, TestPlanReportContentWithBLOBs testPlanReportContentWithBLOBs) {
TestPlanReportBuildResultDTO returnDTO = new TestPlanReportBuildResultDTO();
public TestPlanReportDataStruct buildTestPlanReportStruct(TestPlanWithBLOBs testPlan, TestPlanReport testPlanReport, TestPlanReportContentWithBLOBs testPlanReportContentWithBLOBs) {
TestPlanReportDataStruct testPlanReportStruct = null;
if (ObjectUtils.allNotNull(testPlanReport, testPlanReportContentWithBLOBs)) {
Map config = null;
if (StringUtils.isNotBlank(testPlan.getReportConfig())) {
config = JSON.parseMap(testPlan.getReportConfig());
}
TestPlanSimpleReportDTO report = this.getTestPlanReportStructByCreated(testPlanReportContentWithBLOBs);
testPlanReportStruct = this.getTestPlanReportStructByCreated(testPlanReportContentWithBLOBs);
//检查是否有已经生成过的测试计划报告内容如若没有则进行动态计算
if (report == null) {
if (testPlanReportStruct == null) {
//查询测试计划内的用例信息然后进行测试计划报告的结果统计
TestPlanCaseReportResultDTO testPlanExecuteReportDTO = testPlanReportService.selectCaseDetailByTestPlanReport(config, testPlan.getId(), testPlanReportContentWithBLOBs);
report = generateTestPlanReport(
testPlanReportStruct = initTestPlanReportStructData(
config,
testPlanReport,
testPlan, testPlanExecuteReportDTO);
}
returnDTO.setTestPlanSimpleReportDTO(report);
} else {
returnDTO.setTestPlanSimpleReportDTO(new TestPlanSimpleReportDTO());
}
return returnDTO;
return testPlanReportStruct == null ? new TestPlanReportDataStruct() : testPlanReportStruct;
}
//获取已生成过的测试计划报告内容
private TestPlanSimpleReportDTO getTestPlanReportStructByCreated(TestPlanReportContentWithBLOBs testPlanReportContentWithBLOBs) {
TestPlanSimpleReportDTO reportStruct = null;
private TestPlanReportDataStruct getTestPlanReportStructByCreated(TestPlanReportContentWithBLOBs testPlanReportContentWithBLOBs) {
TestPlanReportDataStruct reportStruct = null;
try {
if (StringUtils.isNotEmpty(testPlanReportContentWithBLOBs.getApiBaseCount())) {
reportStruct = JSON.parseObject(testPlanReportContentWithBLOBs.getApiBaseCount(), TestPlanSimpleReportDTO.class);
reportStruct = JSON.parseObject(testPlanReportContentWithBLOBs.getApiBaseCount(), TestPlanReportDataStruct.class);
}
} catch (Exception e) {
LogUtil.info("解析接口统计数据出错!数据:" + testPlanReportContentWithBLOBs.getApiBaseCount(), e);
@ -1395,7 +1392,7 @@ public class TestPlanService {
}
public TestPlanSimpleReportDTO buildPlanReport(String planId, boolean saveResponse) {
public TestPlanReportDataStruct buildPlanReport(String planId, boolean saveResponse) {
TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(planId);
String reportConfig = testPlan.getReportConfig();
@ -1403,7 +1400,7 @@ public class TestPlanService {
if (StringUtils.isNotBlank(reportConfig)) {
config = JSON.parseMap(reportConfig);
}
TestPlanSimpleReportDTO report = testPlanReportService.getRealTimeReport(planId);
TestPlanReportDataStruct report = testPlanReportService.getRealTimeReport(planId);
buildFunctionalReport(report, config, planId);
buildApiReport(report, config, planId, saveResponse);
buildLoadReport(report, config, planId, saveResponse);
@ -1412,13 +1409,13 @@ public class TestPlanService {
}
public void exportPlanReport(String planId, String lang, HttpServletResponse response) throws UnsupportedEncodingException, JsonProcessingException {
TestPlanSimpleReportDTO report = buildPlanReport(planId, true);
TestPlanReportDataStruct report = buildPlanReport(planId, true);
report.setLang(lang);
render(report, response);
}
public void exportPlanDbReport(String reportId, String lang, HttpServletResponse response) throws UnsupportedEncodingException, JsonProcessingException {
TestPlanSimpleReportDTO report = testPlanReportService.getReport(reportId);
TestPlanReportDataStruct report = testPlanReportService.getReport(reportId);
Set<String> serviceIdSet = DiscoveryUtil.getServiceIdSet();
if (serviceIdSet.contains(MicroServiceName.API_TEST)) {
report.setApiAllCases(planTestPlanApiCaseService.buildResponse(report.getApiAllCases()));
@ -1444,7 +1441,7 @@ public class TestPlanService {
return ServiceUtils.checkConfigEnable(config, key);
}
public void render(TestPlanSimpleReportDTO report, HttpServletResponse response) throws UnsupportedEncodingException {
public void render(TestPlanReportDataStruct report, HttpServletResponse response) throws UnsupportedEncodingException {
response.reset();
response.setContentType("application/octet-stream");
response.addHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("test", StandardCharsets.UTF_8.name()));
@ -1476,7 +1473,7 @@ public class TestPlanService {
}
}
public TestPlanSimpleReportDTO getShareReport(ShareInfo shareInfo, String planId) {
public TestPlanReportDataStruct getShareReport(ShareInfo shareInfo, String planId) {
if (SessionUtils.getUser() == null) {
HttpHeaderUtils.runAsUser(shareInfo.getCreateUserId());
}
@ -1488,8 +1485,8 @@ public class TestPlanService {
}
//根据用例运行结果生成测试计划报告
public TestPlanSimpleReportDTO generateTestPlanReport(Map reportConfig, TestPlanReport testPlanReport, TestPlanWithBLOBs testPlan, TestPlanCaseReportResultDTO testPlanCaseReportResultDTO) {
TestPlanSimpleReportDTO report = new TestPlanSimpleReportDTO();
public TestPlanReportDataStruct initTestPlanReportStructData(Map reportConfig, TestPlanReport testPlanReport, TestPlanWithBLOBs testPlan, TestPlanCaseReportResultDTO testPlanCaseReportResultDTO) {
TestPlanReportDataStruct report = new TestPlanReportDataStruct();
if (ObjectUtils.anyNotNull(testPlan, testPlanReport, testPlanCaseReportResultDTO)) {
TestPlanFunctionResultReportDTO functionResult = new TestPlanFunctionResultReportDTO();
TestPlanApiResultReportDTO apiResult = new TestPlanApiResultReportDTO();

View File

@ -19,7 +19,7 @@ import io.metersphere.excel.constants.TestPlanTestCaseStatus;
import io.metersphere.log.vo.DetailColumn;
import io.metersphere.log.vo.OperatingLogDetails;
import io.metersphere.plan.dto.TestCaseReportStatusResultDTO;
import io.metersphere.plan.dto.TestPlanSimpleReportDTO;
import io.metersphere.plan.dto.TestPlanReportDataStruct;
import io.metersphere.plan.request.function.*;
import io.metersphere.plan.service.remote.api.PlanApiAutomationService;
import io.metersphere.plan.service.remote.api.PlanApiTestCaseService;
@ -521,7 +521,7 @@ public class TestPlanTestCaseService {
}
public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) {
public void calculatePlanReport(String planId, TestPlanReportDataStruct report) {
try {
List<PlanReportCaseDTO> planReportCaseDTOS = extTestPlanTestCaseMapper.selectForPlanReport(planId);
this.calculatePlanReport(planReportCaseDTOS, report);
@ -530,7 +530,7 @@ public class TestPlanTestCaseService {
}
}
public void calculateReportByTestCaseList(String operator, TestPlan testPlan, boolean isTestPlanExecuteOver, List<TestPlanCaseDTO> testPlanCaseList, TestPlanSimpleReportDTO report) {
public void calculateReportByTestCaseList(String operator, TestPlan testPlan, boolean isTestPlanExecuteOver, List<TestPlanCaseDTO> testPlanCaseList, TestPlanReportDataStruct report) {
try {
if (ObjectUtils.anyNotNull(testPlan, report) && CollectionUtils.isNotEmpty(testPlanCaseList)) {
List<PlanReportCaseDTO> planReportCaseDTOList = new ArrayList<>();
@ -557,7 +557,7 @@ public class TestPlanTestCaseService {
}
}
private void calculatePlanReport(List<PlanReportCaseDTO> planReportCaseDTOList, TestPlanSimpleReportDTO report) {
private void calculatePlanReport(List<PlanReportCaseDTO> planReportCaseDTOList, TestPlanReportDataStruct report) {
TestPlanFunctionResultReportDTO functionResult = report.getFunctionResult();
List<TestCaseReportStatusResultDTO> statusResult = new ArrayList<>();
Map<String, TestCaseReportStatusResultDTO> statusResultMap = new HashMap<>();

View File

@ -39,7 +39,7 @@ public class PlanTestPlanApiCaseService extends ApiTestService {
* @param report
* @return 接口用例的最新执行报告
*/
public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) {
public void calculatePlanReport(String planId, TestPlanReportDataStruct report) {
if (DiscoveryUtil.hasService(MicroServiceName.API_TEST)) {
List<PlanReportCaseDTO> planReportCaseDTOS = selectStatusForPlanReport(planId);
//计算测试计划中接口用例的相关数据
@ -55,7 +55,7 @@ public class PlanTestPlanApiCaseService extends ApiTestService {
}
public void calculateReportByApiCase(List<TestPlanApiDTO> testPlanApiDTOList, TestPlanSimpleReportDTO report) {
public void calculateReportByApiCase(List<TestPlanApiDTO> testPlanApiDTOList, TestPlanReportDataStruct report) {
try {
if (CollectionUtils.isNotEmpty(testPlanApiDTOList)) {
List<PlanReportCaseDTO> planReportCaseDTOList = new ArrayList<>();
@ -74,7 +74,7 @@ public class PlanTestPlanApiCaseService extends ApiTestService {
}
}
public void calculatePlanReport(List<String> apiReportIds, TestPlanSimpleReportDTO report) {
public void calculatePlanReport(List<String> apiReportIds, TestPlanReportDataStruct report) {
try {
List<PlanReportCaseDTO> planReportCaseDTOS = planApiDefinitionExecResultService.selectForPlanReport(apiReportIds);
calculatePlanReport(report, planReportCaseDTOS);
@ -84,7 +84,7 @@ public class PlanTestPlanApiCaseService extends ApiTestService {
}
public void calculatePlanReport(TestPlanSimpleReportDTO report, List<PlanReportCaseDTO> planReportCaseDTOS) {
public void calculatePlanReport(TestPlanReportDataStruct report, List<PlanReportCaseDTO> planReportCaseDTOS) {
TestPlanApiResultReportDTO apiResult = report.getApiResult();
List<TestCaseReportStatusResultDTO> statusResult = new ArrayList<>();
Map<String, TestCaseReportStatusResultDTO> statusResultMap = new HashMap<>();

View File

@ -34,7 +34,7 @@ public class PlanTestPlanScenarioCaseService extends ApiTestService {
@Resource
PlanApiScenarioReportService planApiScenarioReportService;
public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) {
public void calculatePlanReport(String planId, TestPlanReportDataStruct report) {
if (DiscoveryUtil.hasService(MicroServiceName.API_TEST)) {
List<PlanReportCaseDTO> planReportCaseDTOS = selectStatusForPlanReport(planId);
calculatePlanReport(report, planReportCaseDTOS);
@ -48,7 +48,7 @@ public class PlanTestPlanScenarioCaseService extends ApiTestService {
}
}
public void calculateReportByScenario(List<TestPlanScenarioDTO> testPlanScenarioDTOList, TestPlanSimpleReportDTO report) {
public void calculateReportByScenario(List<TestPlanScenarioDTO> testPlanScenarioDTOList, TestPlanReportDataStruct report) {
try {
List<PlanReportCaseDTO> planReportCaseDTOList = new ArrayList<>();
testPlanScenarioDTOList.forEach(item -> {
@ -65,7 +65,7 @@ public class PlanTestPlanScenarioCaseService extends ApiTestService {
}
}
public void calculatePlanReport(List<String> reportIds, TestPlanSimpleReportDTO report) {
public void calculatePlanReport(List<String> reportIds, TestPlanReportDataStruct report) {
try {
List<PlanReportCaseDTO> planReportCaseDTOS = planApiScenarioReportService.selectForPlanReport(reportIds);
calculatePlanReport(report, planReportCaseDTOS);
@ -74,7 +74,7 @@ public class PlanTestPlanScenarioCaseService extends ApiTestService {
}
}
public void calculatePlanReport(TestPlanSimpleReportDTO report, List<PlanReportCaseDTO> planReportCaseDTOS) {
public void calculatePlanReport(TestPlanReportDataStruct report, List<PlanReportCaseDTO> planReportCaseDTOS) {
TestPlanApiResultReportDTO apiResult = report.getApiResult();
List<TestCaseReportStatusResultDTO> statusResult = new ArrayList<>();
Map<String, TestCaseReportStatusResultDTO> statusResultMap = new HashMap<>();

View File

@ -8,7 +8,7 @@ import io.metersphere.dto.PlanReportCaseDTO;
import io.metersphere.dto.TestPlanLoadCaseDTO;
import io.metersphere.dto.TestPlanLoadResultReportDTO;
import io.metersphere.plan.dto.TestCaseReportStatusResultDTO;
import io.metersphere.plan.dto.TestPlanSimpleReportDTO;
import io.metersphere.plan.dto.TestPlanReportDataStruct;
import io.metersphere.plan.request.api.ApiPlanReportRequest;
import io.metersphere.plan.request.performance.LoadCaseRequest;
import io.metersphere.plan.request.performance.LoadPlanReportDTO;
@ -37,7 +37,7 @@ public class PlanTestPlanLoadCaseService extends LoadTestService {
@Lazy
private TestPlanService testPlanService;
public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) {
public void calculatePlanReport(String planId, TestPlanReportDataStruct report) {
if (DiscoveryUtil.hasService(MicroServiceName.PERFORMANCE_TEST)) {
List<PlanReportCaseDTO> planReportCaseDTOS = selectStatusForPlanReport(planId);
calculatePlanReport(report, planReportCaseDTOS);
@ -46,7 +46,7 @@ public class PlanTestPlanLoadCaseService extends LoadTestService {
}
}
public void calculateReportByLoadCaseList(List<TestPlanLoadCaseDTO> testPlanLoadCaseDTOList, TestPlanSimpleReportDTO report) {
public void calculateReportByLoadCaseList(List<TestPlanLoadCaseDTO> testPlanLoadCaseDTOList, TestPlanReportDataStruct report) {
try {
List<PlanReportCaseDTO> planReportCaseDTOList = new ArrayList<>();
testPlanLoadCaseDTOList.forEach(item -> {
@ -63,7 +63,7 @@ public class PlanTestPlanLoadCaseService extends LoadTestService {
}
}
private void calculatePlanReport(TestPlanSimpleReportDTO report, List<PlanReportCaseDTO> planReportCaseDTOS) {
private void calculatePlanReport(TestPlanReportDataStruct report, List<PlanReportCaseDTO> planReportCaseDTOS) {
TestPlanLoadResultReportDTO loadResult = new TestPlanLoadResultReportDTO();
report.setLoadResult(loadResult);
List<TestCaseReportStatusResultDTO> statusResult = new ArrayList<>();

View File

@ -49,7 +49,7 @@ public class PlanTestPlanUiScenarioCaseService extends UiTestService {
return microService.postForData(serviceName, BASE_URL + "/plan/report", request, UiPlanReportDTO.class);
}
public void calculateReportByUiScenarios(List<TestPlanUiScenarioDTO> uiScenarioDTOList, TestPlanSimpleReportDTO report) {
public void calculateReportByUiScenarios(List<TestPlanUiScenarioDTO> uiScenarioDTOList, TestPlanReportDataStruct report) {
try {
List<PlanReportCaseDTO> planReportCaseDTOList = new ArrayList<>();
uiScenarioDTOList.forEach(item -> {
@ -66,7 +66,7 @@ public class PlanTestPlanUiScenarioCaseService extends UiTestService {
}
}
public void calculatePlanReport(List<String> reportIds, TestPlanSimpleReportDTO report) {
public void calculatePlanReport(List<String> reportIds, TestPlanReportDataStruct report) {
try {
List<PlanReportCaseDTO> planReportCaseDTOS = planUiScenarioReportService.selectForPlanReport(reportIds);
calculatePlanReport(report, planReportCaseDTOS);
@ -75,12 +75,12 @@ public class PlanTestPlanUiScenarioCaseService extends UiTestService {
}
}
public void calculatePlanReport(TestPlanSimpleReportDTO report, List<PlanReportCaseDTO> planReportCaseDTOS) {
public void calculatePlanReport(TestPlanReportDataStruct report, List<PlanReportCaseDTO> planReportCaseDTOS) {
TestPlanUiResultReportDTO uiResult = getUiResult(report, planReportCaseDTOS);
report.setUiResult(uiResult);
}
public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) {
public void calculatePlanReport(String planId, TestPlanReportDataStruct report) {
if (DiscoveryUtil.hasService(MicroServiceName.UI_TEST)) {
List<PlanReportCaseDTO> planReportCaseDTOS = selectStatusForPlanReport(planId);
@ -98,7 +98,7 @@ public class PlanTestPlanUiScenarioCaseService extends UiTestService {
}
@NotNull
private TestPlanUiResultReportDTO getUiResult(TestPlanSimpleReportDTO report, List<PlanReportCaseDTO> planReportCaseDTOS) {
private TestPlanUiResultReportDTO getUiResult(TestPlanReportDataStruct report, List<PlanReportCaseDTO> planReportCaseDTOS) {
TestPlanUiResultReportDTO uiResult = report.getUiResult();
List<TestCaseReportStatusResultDTO> statusResult = new ArrayList<>();

View File

@ -1,11 +1,11 @@
package io.metersphere.plan.utils;
import io.metersphere.commons.constants.ExecuteResult;
import io.metersphere.dto.PlanReportCaseDTO;
import io.metersphere.excel.constants.TestPlanTestCaseStatus;
import io.metersphere.plan.constant.ApiReportStatus;
import io.metersphere.plan.dto.TestCaseReportStatusResultDTO;
import io.metersphere.dto.PlanReportCaseDTO;
import io.metersphere.plan.dto.TestPlanSimpleReportDTO;
import io.metersphere.excel.constants.TestPlanTestCaseStatus;
import io.metersphere.plan.dto.TestPlanReportDataStruct;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
@ -40,11 +40,12 @@ public class TestPlanStatusCalculator {
/**
* 将map转成前端需要的数组数据
*
* @param resultMap
* @param statusResult
*/
public static void addToReportCommonStatusResultList(Map<String, TestCaseReportStatusResultDTO> resultMap,
List<TestCaseReportStatusResultDTO> statusResult) {
List<TestCaseReportStatusResultDTO> statusResult) {
addToReportStatusResultList(resultMap, statusResult, TestPlanTestCaseStatus.Pass.name());
addToReportStatusResultList(resultMap, statusResult, TestPlanTestCaseStatus.Failure.name());
addToReportStatusResultList(resultMap, statusResult, "error");
@ -66,7 +67,7 @@ public class TestPlanStatusCalculator {
*/
public static void buildStatusResultMap(List<PlanReportCaseDTO> planReportCaseDTOS,
Map<String, TestCaseReportStatusResultDTO> statusResultMap,
TestPlanSimpleReportDTO report, String successStatus) {
TestPlanReportDataStruct report, String successStatus) {
planReportCaseDTOS.forEach(item -> {
report.setCaseCount((report.getCaseCount() == null ? 0 : report.getCaseCount()) + 1);
String status = item.getStatus();

View File

@ -32,7 +32,7 @@ import io.metersphere.log.vo.OperatingLogDetails;
import io.metersphere.log.vo.track.TestPlanReference;
import io.metersphere.plan.dto.PlanReportIssueDTO;
import io.metersphere.plan.dto.TestCaseReportStatusResultDTO;
import io.metersphere.plan.dto.TestPlanSimpleReportDTO;
import io.metersphere.plan.dto.TestPlanReportDataStruct;
import io.metersphere.plan.service.TestPlanService;
import io.metersphere.plan.service.TestPlanTestCaseService;
import io.metersphere.plan.utils.TestPlanStatusCalculator;
@ -53,7 +53,6 @@ import io.metersphere.service.remote.project.TrackIssueTemplateService;
import io.metersphere.service.wapper.TrackProjectService;
import io.metersphere.service.wapper.UserService;
import io.metersphere.utils.DistinctKeyUtil;
import io.metersphere.xpack.track.dto.AttachmentRequest;
import io.metersphere.xpack.track.dto.PlatformStatusDTO;
import io.metersphere.xpack.track.dto.PlatformUser;
import io.metersphere.xpack.track.dto.*;
@ -1226,7 +1225,7 @@ public class IssuesService {
}
public void calculateReportByIssueList(List<IssuesDao> issueList, TestPlanSimpleReportDTO report) {
public void calculateReportByIssueList(List<IssuesDao> issueList, TestPlanReportDataStruct report) {
if (CollectionUtils.isNotEmpty(issueList)) {
List<PlanReportIssueDTO> planReportIssueDTOList = new ArrayList<>();
issueList.forEach(issue -> {
@ -1241,12 +1240,12 @@ public class IssuesService {
}
}
public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) {
public void calculatePlanReport(String planId, TestPlanReportDataStruct report) {
List<PlanReportIssueDTO> planReportIssueDTOList = extIssuesMapper.selectForPlanReport(planId);
this.calculatePlanReport(planReportIssueDTOList, report);
}
public void calculatePlanReport(List<PlanReportIssueDTO> planReportIssueDTOList, TestPlanSimpleReportDTO report) {
public void calculatePlanReport(List<PlanReportIssueDTO> planReportIssueDTOList, TestPlanReportDataStruct report) {
planReportIssueDTOList = DistinctKeyUtil.distinctByKey(planReportIssueDTOList, PlanReportIssueDTO::getId);
TestPlanFunctionResultReportDTO functionResult = report.getFunctionResult();
List<TestCaseReportStatusResultDTO> statusResult = new ArrayList<>();