From c3f773ba90090e7805fad089862646127514237a Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 10 Jan 2022 13:00:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8A=A5=E5=91=8A=E5=9C=BA=E6=99=AF=E6=AD=A5?= =?UTF-8?q?=E9=AA=A4=E7=BB=9F=E8=AE=A1=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiScenarioReportStructureService.java | 71 ++++++++++++------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java index b5e353ab25..b8340dc711 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java @@ -139,28 +139,23 @@ public class ApiScenarioReportStructureService { } } - private void scenarioCalculate(List dtoList, AtomicLong isError, AtomicLong isErrorReport) { + private void scenarioCalculate(List dtoList, AtomicLong isErrorReport) { for (StepTreeDTO step : dtoList) { - if(step.getValue() != null && StringUtils.isNotEmpty(step.getErrorCode())){ + if (step.getValue() != null && StringUtils.isNotEmpty(step.getErrorCode())) { isErrorReport.set(isErrorReport.longValue() + 1); break; - }else if (step.getValue() != null && step.getValue().getError() > 0) { - isError.set(isError.longValue() + 1); - break; - } else if (CollectionUtils.isNotEmpty(step.getChildren())) { - scenarioCalculate(step.getChildren(), isError,isErrorReport); } } } - private void calculate(List dtoList, AtomicLong totalScenario, AtomicLong scenarioError, AtomicLong totalTime,AtomicLong errorReport) { + private void calculate(List dtoList, AtomicLong totalScenario, AtomicLong scenarioError, AtomicLong totalTime, AtomicLong errorReport) { for (StepTreeDTO step : dtoList) { if (StringUtils.equals(step.getType(), "scenario")) { totalScenario.set((totalScenario.longValue() + 1)); // 失败结果数量 AtomicLong error = new AtomicLong(); AtomicLong errorCode = new AtomicLong(); - scenarioCalculate(step.getChildren(), error,errorCode); + scenarioCalculate(step.getChildren(), errorCode); if (error.longValue() > 0) { scenarioError.set((scenarioError.longValue() + 1)); } @@ -175,20 +170,18 @@ public class ApiScenarioReportStructureService { } } if (CollectionUtils.isNotEmpty(step.getChildren())) { - calculate(step.getChildren(), totalScenario, scenarioError, totalTime,errorReport); + calculate(step.getChildren(), totalScenario, scenarioError, totalTime, errorReport); } } } - private void calculateStep(List dtoList, AtomicLong stepError, AtomicLong stepTotal,AtomicLong stepErrorCode) { + private void calculateStep(List dtoList, AtomicLong stepError, AtomicLong stepTotal, AtomicLong stepErrorCode) { for (StepTreeDTO step : dtoList) { // 失败结果数量 - AtomicLong error = new AtomicLong(); + stepErrorCalculate(step.getChildren(), stepError); + AtomicLong errorReport = new AtomicLong(); - scenarioCalculate(step.getChildren(), error,errorReport); - if (error.longValue() > 0) { - stepError.set((stepError.longValue() + 1)); - } + scenarioCalculate(step.getChildren(), errorReport); if (errorReport.longValue() > 0) { stepErrorCode.set((stepErrorCode.longValue() + 1)); } @@ -224,16 +217,16 @@ public class ApiScenarioReportStructureService { } if (CollectionUtils.isNotEmpty(dto.getChildren())) { reportFormatting(dto.getChildren(), maps); - if(StringUtils.isEmpty(dto.getErrorCode())){ + if (StringUtils.isEmpty(dto.getErrorCode())) { //统计child的errorCode List childErrorCodeList = new ArrayList<>(); for (StepTreeDTO child : dto.getChildren()) { - if(StringUtils.isNotEmpty(child.getErrorCode()) && !childErrorCodeList.contains(child.getErrorCode())){ + if (StringUtils.isNotEmpty(child.getErrorCode()) && !childErrorCodeList.contains(child.getErrorCode())) { childErrorCodeList.add(child.getErrorCode()); } } - if(CollectionUtils.isNotEmpty(childErrorCodeList)){ - dto.setErrorCode(StringUtils.join(childErrorCodeList,",")); + if (CollectionUtils.isNotEmpty(childErrorCodeList)) { + dto.setErrorCode(StringUtils.join(childErrorCodeList, ",")); } } @@ -278,24 +271,50 @@ public class ApiScenarioReportStructureService { AtomicLong scenarioError = new AtomicLong(); AtomicLong totalTime = new AtomicLong(); AtomicLong errorReport = new AtomicLong(); - calculate(stepList, totalScenario, scenarioError, totalTime,errorReport); + AtomicLong stepError = new AtomicLong(); + AtomicLong stepTotal = new AtomicLong(); + + calculate(stepList, totalScenario, scenarioError, totalTime, errorReport); reportDTO.setTotalTime(totalTime.longValue()); reportDTO.setScenarioTotal(totalScenario.longValue()); reportDTO.setScenarioError(scenarioError.longValue()); reportDTO.setScenarioErrorReport(errorReport.longValue()); - reportDTO.setScenarioSuccess((totalScenario.longValue() - scenarioError.longValue() -errorReport.longValue())); //统计步骤数据 - AtomicLong stepError = new AtomicLong(); AtomicLong stepErrorCode = new AtomicLong(); - AtomicLong stepTotal = new AtomicLong(); - calculateStep(stepList, stepError, stepTotal,stepErrorCode); + calculateStep(stepList, stepError, stepTotal, stepErrorCode); + + reportDTO.setScenarioStepSuccess((stepTotal.longValue() - stepError.longValue())); reportDTO.setScenarioStepTotal(stepTotal.longValue()); reportDTO.setScenarioStepError(stepError.longValue()); reportDTO.setScenarioStepErrorReport(stepErrorCode.longValue()); - reportDTO.setScenarioStepSuccess((stepList.size() - stepError.longValue() - stepErrorCode.longValue())); reportDTO.setConsole(scenarioReportStructure.getConsole()); reportDTO.setSteps(stepList); } return reportDTO; } + + private void stepErrorCalculate(List dtoList, AtomicLong isError) { + for (StepTreeDTO step : dtoList) { + if (step.getValue() != null && step.getValue().getError() > 0) { + isError.set(isError.longValue() + 1); + } else if (CollectionUtils.isNotEmpty(step.getChildren())) { + AtomicLong isChildrenError = new AtomicLong(); + stepChildrenErrorCalculate(step.getChildren(), isChildrenError); + if (isChildrenError.longValue() > 0) { + isError.set(isError.longValue() + 1); + } + } + } + } + + private void stepChildrenErrorCalculate(List dtoList, AtomicLong isError) { + for (StepTreeDTO step : dtoList) { + if (step.getValue() != null && step.getValue().getError() > 0) { + isError.set(isError.longValue() + 1); + break; + } else if (CollectionUtils.isNotEmpty(step.getChildren())) { + stepChildrenErrorCalculate(step.getChildren(), isError); + } + } + } }