diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index 088a466246..d3294297eb 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -33,6 +33,7 @@ import io.metersphere.service.UserService; import io.metersphere.track.dto.PlanReportCaseDTO; import io.metersphere.track.dto.UiRunModeConfigDTO; import io.metersphere.utils.LoggerUtil; +import io.metersphere.utils.RetryResultUtil; import io.metersphere.xmind.utils.FileUtil; import org.apache.commons.beanutils.BeanMap; import org.apache.commons.collections4.CollectionUtils; @@ -543,7 +544,7 @@ public class ApiScenarioReportService { String custom = "customCommand"; if (report.getExecuteType().equals(ExecuteType.Debug.name()) && report.getReportType().equals(ReportTypeConstants.UI_INDEPENDENT.name()) && - !StringUtils.equalsIgnoreCase(scenario.getScenarioType(), custom) + !StringUtils.equalsIgnoreCase(scenario.getScenarioType(), custom) ) { return false; } @@ -948,6 +949,29 @@ public class ApiScenarioReportService { return report; } + public List filterRetryResults(List results) { + List list = new LinkedList<>(); + if (CollectionUtils.isNotEmpty(results)) { + Map> resultMap = results.stream().collect(Collectors.groupingBy(RequestResult::getResourceId)); + resultMap.forEach((k, v) -> { + if (CollectionUtils.isNotEmpty(v)) { + // 校验是否含重试结果 + List isRetryResults = v + .stream() + .filter(c -> StringUtils.isNotEmpty(c.getName()) && c.getName().startsWith(RetryResultUtil.RETRY_CN)) + .collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(isRetryResults)) { + list.add(isRetryResults.get(isRetryResults.size() - 1)); + } else { + // 成功的结果 + list.addAll(v); + } + } + }); + } + return list; + } + /** * 返回正确的报告状态 * @@ -959,7 +983,9 @@ public class ApiScenarioReportService { // 资源池执行整体传输失败,单条传输内容,获取资源池执行统计的状态 return String.valueOf(dto.getArbitraryData().get("REPORT_STATUS")); } - long errorSize = dto.getRequestResults().stream().filter(requestResult -> + // 过滤掉重试结果后进行统计 + List requestResults = filterRetryResults(dto.getRequestResults()); + long errorSize = requestResults.stream().filter(requestResult -> StringUtils.equalsIgnoreCase(requestResult.getStatus(), ScenarioStatus.Error.name())).count(); long errorReportResultSize = dto.getRequestResults().stream().filter(requestResult ->