diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/TestPlanFailureApiDTO.java b/backend/src/main/java/io/metersphere/api/dto/automation/TestPlanFailureApiDTO.java index 807496c340..28e79f2e4b 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/TestPlanFailureApiDTO.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/TestPlanFailureApiDTO.java @@ -10,4 +10,5 @@ import lombok.Setter; @JsonInclude(JsonInclude.Include.NON_NULL) public class TestPlanFailureApiDTO extends TestPlanApiCaseDTO { private String response; + private String reportId; } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 5b66dc50da..673868266c 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -1204,8 +1204,6 @@ public class ApiAutomationService { String scenarioId = entry.getValue(); ApiScenarioWithBLOBs scenario = scenarioMap.get(scenarioId); -// } -// for (ApiScenarioWithBLOBs scenario : apiScenarios) { if (scenario.getStepTotal() == null || scenario.getStepTotal() == 0) { continue; } @@ -1213,16 +1211,12 @@ public class ApiAutomationService { Map planEnvMap = new HashMap<>(); //测试计划页面触发的执行方式,生成报告时createScenarioReport第二个参数需要特殊处理 -// String testPlanScenarioId = scenario.getId(); -// if (request.getScenarioTestPlanIdMap() != null && request.getScenarioTestPlanIdMap().containsKey(item.getId())) { -// testPlanScenarioId = request.getScenarioTestPlanIdMap().get(item.getId()); - // 获取场景用例单独的执行环境 - TestPlanApiScenario planApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(testPlanScenarioId); - String environment = planApiScenario.getEnvironment(); - if (StringUtils.isNotBlank(environment)) { - planEnvMap = JSON.parseObject(environment, Map.class); - } -// } + // 获取场景用例单独的执行环境 + TestPlanApiScenario planApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(testPlanScenarioId); + String environment = planApiScenario.getEnvironment(); + if (StringUtils.isNotBlank(environment)) { + planEnvMap = JSON.parseObject(environment, Map.class); + } if(StringUtils.isEmpty(projectId)){ projectId = testPlanScenarioCaseService.getProjectIdById(testPlanScenarioId); } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java index 02c6c7e365..fcf29c6843 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java @@ -423,4 +423,19 @@ public class ApiDefinitionExecResultService { return returnList; } } + + public Map selectReportResultByReportIds(Collection values) { + if(CollectionUtils.isEmpty(values)){ + return new HashMap<>(); + }else { + Map returnMap = new HashMap<>(); + List idStatusList = extApiDefinitionExecResultMapper.selectStatusByIdList(values); + for (ApiDefinitionExecResult model: idStatusList){ + String id = model.getId(); + String status = model.getStatus(); + returnMap.put(id,status); + } + return returnMap; + } + } } 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 0cf4e9556f..a9033ea186 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -863,4 +863,15 @@ public class ApiScenarioReportService { return count; } + public Map getReportStatusByReportIds(Collection values) { + if(CollectionUtils.isEmpty(values)){ + return new HashMap<>(); + } + Map map = new HashMap<>(); + List reportList = extApiScenarioReportMapper.selectStatusByIds(values); + for (ApiScenarioReport report : reportList) { + map.put(report.getId(),report.getStatus()); + } + return map; + } } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultMapper.java index 38f4841e8b..fa3d030d85 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultMapper.java @@ -4,6 +4,7 @@ import io.metersphere.api.dto.datacount.ExecutedCaseInfoResult; import io.metersphere.base.domain.ApiDefinitionExecResult; import org.apache.ibatis.annotations.Param; +import java.util.Collection; import java.util.List; public interface ExtApiDefinitionExecResultMapper { @@ -24,4 +25,6 @@ public interface ExtApiDefinitionExecResultMapper { String selectExecResult(String resourceId); ApiDefinitionExecResult selectPlanApiMaxResultByTestIdAndType(String resourceId, String type); + + List selectStatusByIdList(@Param("ids")Collection values); } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultMapper.xml index 99ee9a98bd..8abf019d6d 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultMapper.xml @@ -92,4 +92,14 @@ where resource_id = #{resourceId,jdbcType=VARCHAR} and `type` = #{type, jdbcType=VARCHAR} ORDER BY start_time DESC LIMIT 1 + + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.java index 4a3cd2a159..8dcca9fa9b 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.java @@ -7,6 +7,7 @@ import io.metersphere.base.domain.ApiScenarioReport; import io.metersphere.dto.ApiReportCountDTO; import org.apache.ibatis.annotations.Param; +import java.util.Collection; import java.util.List; public interface ExtApiScenarioReportMapper { @@ -29,4 +30,6 @@ public interface ExtApiScenarioReportMapper { List idList(@Param("request") QueryAPIReportRequest request); List countByApiScenarioId(); + + List selectStatusByIds(@Param("ids") Collection values); } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.xml index ca1e3360dc..be041d4abe 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.xml @@ -285,4 +285,11 @@ WHERE scenario_id is not null GROUP BY scenario_id; + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/track/dto/TestPlanLoadCaseDTO.java b/backend/src/main/java/io/metersphere/track/dto/TestPlanLoadCaseDTO.java index 98e275b03b..d343dba55f 100644 --- a/backend/src/main/java/io/metersphere/track/dto/TestPlanLoadCaseDTO.java +++ b/backend/src/main/java/io/metersphere/track/dto/TestPlanLoadCaseDTO.java @@ -23,6 +23,7 @@ public class TestPlanLoadCaseDTO extends TestPlanLoadCase { private String num; private String name; private ResponseDTO response; + private String reportId; @Getter @Setter diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java index d5cd6c4fee..6620cc67bd 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java @@ -419,10 +419,23 @@ public class TestPlanApiCaseService { // 开始选择执行模式 if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) { Map executeQueue = new HashMap<>(); + + //记录案例线程结果以及执行失败的案例ID + Map executeThreadIdMap = new HashMap<>(); + planApiCases.forEach(testPlanApiCase -> { ApiDefinitionExecResult report = addResult(request, testPlanApiCase, APITestStatus.Waiting.name(), batchMapper); executeQueue.put(testPlanApiCase, report); + executeThreadIdMap.put(testPlanApiCase.getId(),report.getId()); }); + + //如果是测试计划生成报告的执行,则更新执行信息、执行线程信息。 + if(TestPlanReportExecuteCatch.containsReport(request.getPlanReportId())){ + if (!executeThreadIdMap.isEmpty()) { + TestPlanReportExecuteCatch.updateTestPlanThreadInfo(request.getPlanReportId(), executeThreadIdMap,null, null); + } + } + sqlSession.commit(); List reportIds = new LinkedList<>(); // 开始串行执行 @@ -433,8 +446,6 @@ public class TestPlanApiCaseService { try { Thread.currentThread().setName("TestPlanCase串行执行线程"); - //记录案例线程结果以及执行失败的案例ID - Map executeThreadIdMap = new HashMap<>(); List executeErrorList = new ArrayList<>(); for (TestPlanApiCase testPlanApiCase : executeQueue.keySet()) { @@ -479,7 +490,7 @@ public class TestPlanApiCaseService { break; } } - executeThreadIdMap.put(testPlanApiCase.getId(),randomUUID); + } catch (Exception e) { executeErrorList.add(testPlanApiCase.getId()); reportIds.remove(executeQueue.get(testPlanApiCase).getId()); @@ -507,9 +518,6 @@ public class TestPlanApiCaseService { } TestPlanReportExecuteCatch.updateApiTestPlanExecuteInfo(request.getPlanReportId(), executeErrorMap, null, null); } - if (!executeThreadIdMap.isEmpty()) { - TestPlanReportExecuteCatch.updateTestPlanThreadInfo(request.getPlanReportId(), executeThreadIdMap,null, null); - } } } catch (Exception e) { @@ -522,17 +530,23 @@ public class TestPlanApiCaseService { thread.start(); } else { Map executeQueue = new HashMap<>(); + //记录案例线程结果以及执行失败的案例ID + Map executeThreadIdMap = new HashMap<>(); planApiCases.forEach(testPlanApiCase -> { ApiDefinitionExecResult report = addResult(request, testPlanApiCase, APITestStatus.Running.name(), batchMapper); executeQueue.put(report.getId(), testPlanApiCase); + executeThreadIdMap.put(testPlanApiCase.getId(),report.getId()); MessageCache.caseExecResourceLock.put(report.getId(), report); }); sqlSession.commit(); + //如果是测试计划生成报告的执行,则更新执行信息、执行线程信息。 + if(TestPlanReportExecuteCatch.containsReport(request.getPlanReportId())){ + if (!executeThreadIdMap.isEmpty()) { + TestPlanReportExecuteCatch.updateTestPlanThreadInfo(request.getPlanReportId(), executeThreadIdMap,null, null); + } + } // 开始并发执行 - - //记录案例线程结果以及执行失败的案例ID - Map executeThreadIdMap = new HashMap<>(); List executeErrorList = new ArrayList<>(); for (String reportId : executeQueue.keySet()) { @@ -542,7 +556,6 @@ public class TestPlanApiCaseService { if (request.getConfig() != null && StringUtils.isNotEmpty(request.getConfig().getResourcePoolId())) { String testId = testPlanApiCase.getId()+":"+ request.getPlanReportId() + ":" +reportId; jMeterService.runTest(testId, reportId, request.getTriggerMode(), request.getPlanReportId(), request.getConfig()); - executeThreadIdMap.put(testPlanApiCase.getApiCaseId(),testPlanApiCase.getId()); } else { HashTree hashTree = generateHashTree(testPlanApiCase.getId()); if(StringUtils.isEmpty(debugId)){ @@ -550,7 +563,6 @@ public class TestPlanApiCaseService { } String testId = reportId+":"+ request.getPlanReportId(); jMeterService.runLocal(testId,request.getConfig(), hashTree, debugId, request.getTriggerMode()); - executeThreadIdMap.put(testPlanApiCase.getId(),reportId); } }catch (Exception e){ executeErrorList.add(testPlanApiCase.getId()); @@ -567,9 +579,6 @@ public class TestPlanApiCaseService { } TestPlanReportExecuteCatch.updateApiTestPlanExecuteInfo(request.getPlanReportId(), executeErrorMap, null, null); } - if (!executeThreadIdMap.isEmpty()) { - TestPlanReportExecuteCatch.updateTestPlanThreadInfo(request.getPlanReportId(), executeThreadIdMap,null, null); - } } } return request.getId(); @@ -678,14 +687,6 @@ public class TestPlanApiCaseService { return buildCases(apiTestCases); } - public List getAllCases(Collection caseIdList,String status) { - if (caseIdList.isEmpty()) { - return new ArrayList<>(); - } - List apiTestCases = extTestPlanApiCaseMapper.getFailureListByIds(caseIdList, status); - return buildCases(apiTestCases); - } - public List buildCases(List apiTestCases) { if (CollectionUtils.isEmpty(apiTestCases)) { return apiTestCases; @@ -713,4 +714,30 @@ public class TestPlanApiCaseService { testPlanApiCaseMapper::updateByPrimaryKeySelective); } + public List getByApiExecReportIds(Map testPlanApiCaseReportMap,boolean isFinish) { + if (testPlanApiCaseReportMap.isEmpty()) { + return new ArrayList<>(); + } + String defaultStatus = "Running"; + if(isFinish){ + defaultStatus = "error"; + } + List apiTestCases = extTestPlanApiCaseMapper.getFailureListByIds(testPlanApiCaseReportMap.keySet(),null); + Map reportResult = apiDefinitionExecResultService.selectReportResultByReportIds(testPlanApiCaseReportMap.values()); + for (TestPlanFailureApiDTO dto : apiTestCases) { + String testPlanApiCaseId = dto.getId(); + String reportId = testPlanApiCaseReportMap.get(testPlanApiCaseId); + dto.setReportId(reportId); + if(StringUtils.isEmpty(reportId)){ + dto.setStatus(defaultStatus); + }else { + String status = reportResult.get(reportId); + if(status == null){ + status = defaultStatus; + } + dto.setStatus(status); + } + } + return buildCases(apiTestCases); + } } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java index 1d95f0f898..1365c72ccc 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java @@ -107,19 +107,6 @@ public class TestPlanReportService { return list; } -// private void checkReport(List list) { -// if(CollectionUtils.isNotEmpty(list)){ -// for (TestPlanReportDTO dto : list){ -// if(StringUtils.equalsIgnoreCase(dto.getStatus(),TestPlanApiExecuteStatus.RUNNING.name())){ -// TestPlanReport model = this.updateTestPlanReportById(dto.getId()); -// if(model != null && model.getStatus() != null){ -// dto.setStatus(model.getStatus()); -// } -// } -// } -// } -// } - public TestPlanScheduleReportInfoDTO genTestPlanReportBySchedule(String projectID, String planId, String userId, String triggerMode) { Map> apiTestCaseIdMap = new LinkedHashMap<>(); @@ -274,7 +261,6 @@ public class TestPlanReportService { TestPlanReportExecuteCatch.addApiTestPlanExecuteInfo(testPlanReportID, saveRequest.getUserId(), apiCaseInfoMap, scenarioInfoMap, performanceInfoMap); -// testPlanReport.setPrincipal(testPlan.getPrincipal()); if (testPlanReport.getIsScenarioExecuting() || testPlanReport.getIsApiCaseExecuting() || testPlanReport.getIsPerformanceExecuting()) { testPlanReport.setStatus(APITestStatus.Running.name()); } else { @@ -583,16 +569,12 @@ public class TestPlanReportService { int[] componentIndexArr = new int[]{1, 3, 4}; testPlanReport.setComponents(JSONArray.toJSONString(componentIndexArr)); -// QueryTestPlanRequest queryTestPlanRequest = new QueryTestPlanRequest(); -// queryTestPlanRequest.setId(testPlanReport.getTestPlanId()); -// TestPlanDTO testPlan = extTestPlanMapper.list(queryTestPlanRequest).get(0); - TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class); Map> testPlanExecuteResult = executeInfo.getExecutedResult(); testPlanLog.info("ReportId[" + testPlanReport.getId() + "] COUNT OVER. COUNT RESULT :" + JSONObject.toJSONString(testPlanExecuteResult)); - TestPlanSimpleReportDTO reportDTO = testPlanService.buildPlanReport(executeInfo, testPlanReport.getTestPlanId(), false); + TestPlanSimpleReportDTO reportDTO = testPlanService.buildPlanReport(executeInfo, testPlanReport.getTestPlanId(), apiCaseIsOk && scenarioIsOk && performanceIsOk); reportDTO.setStartTime(testPlanReport.getStartTime()); long endTime = System.currentTimeMillis(); //全部结束时,更新时间 @@ -620,17 +602,6 @@ public class TestPlanReportService { return testPlanReport; } -// public void checkTestPlanStatus(String planReportId) { -// try { -// TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(planReportId); -// -// TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class); -// testPlanService.checkStatus(testPlanReport.getTestPlanId()); -// } catch (Exception e) { -// LogUtil.error(e.getMessage(), e); -// } -// } - /** * @param planReportId 测试计划报告ID * @param resourceRunMode 资源的运行模式,triggerMode非Scedule可以为null @@ -813,8 +784,6 @@ public class TestPlanReportService { TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(report.getTestPlanId()); if (testPlan != null) { testPlanService.checkStatus(testPlan); -// testPlan.setStatus(TestPlanStatus.Completed.name()); -// testPlanMapper.updateByPrimaryKeySelective(testPlan); } if (testPlan != null && StringUtils.equalsAny(report.getTriggerMode(), ReportTriggerMode.MANUAL.name(), @@ -1005,9 +974,6 @@ public class TestPlanReportService { TestPlanReportContentExample contentExample = new TestPlanReportContentExample(); contentExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId); testPlanReportContentMapper.deleteByExample(contentExample); -// TestPlanReportResourceExample resourceExample = new TestPlanReportResourceExample(); -// resourceExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId); -// testPlanReportResourceService.deleteByExample(resourceExample); } } @@ -1036,9 +1002,6 @@ public class TestPlanReportService { contentExample.createCriteria().andTestPlanReportIdIn(deleteReportIds); testPlanReportContentMapper.deleteByExample(contentExample); -// TestPlanReportResourceExample resourceExample = new TestPlanReportResourceExample(); -// resourceExample.createCriteria().andTestPlanReportIdIn(deleteReportIds); -// testPlanReportResourceService.deleteByExample(resourceExample); } } @@ -1123,7 +1086,7 @@ public class TestPlanReportService { //如果间隔超过5分钟没有案例执行完成,则把执行结果变成false long lastCountTime = executeInfo.getLastFinishedNumCountTime(); long nowTime = System.currentTimeMillis(); - if (nowTime - lastCountTime > 300000) { + if (nowTime - lastCountTime > 1800000) { TestPlanReportExecuteCatch.finishAllTask(planReportId); } } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java index a4651d56ce..c8c882a2a4 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java @@ -450,9 +450,27 @@ public class TestPlanScenarioCaseService { return buildCases(apiTestCases); } - public List getAllCases(Collection ids, String status) { + public List getAllCases(Map idMap, boolean isFinish) { List apiTestCases = - extTestPlanScenarioCaseMapper.getFailureListByIds(ids, status); + extTestPlanScenarioCaseMapper.getFailureListByIds(idMap.keySet(), null); + + String defaultStatus = "Running"; + if(isFinish){ + defaultStatus = "Error"; + } + Map reportStatus = apiScenarioReportService.getReportStatusByReportIds(idMap.values()); + for (TestPlanFailureScenarioDTO dto: apiTestCases) { + String reportId = idMap.get(dto.getId()); + dto.setReportId(reportId); + if(reportId != null){ + String status = reportStatus.get(reportId); + if(status == null ){ + status = defaultStatus; + } + dto.setStatus(status); + } + + } return buildCases(apiTestCases); } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index 966c209881..b47c26f859 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -1114,7 +1114,7 @@ public class TestPlanService { //执行性能测试任务 Map performaneReportIDMap = new LinkedHashMap<>(); - + Map performaneThreadIDMap = new LinkedHashMap<>(); for (Map.Entry entry : performanceIdMap.entrySet()) { String id = entry.getKey(); String caseID = entry.getValue(); @@ -1148,12 +1148,14 @@ public class TestPlanService { } catch (Exception e) { e.printStackTrace(); } + performaneThreadIDMap.put(performanceRequest.getTestPlanLoadId(),reportId); if (StringUtils.isNotEmpty(reportId)) { executePerformanceIdMap.put(caseID, TestPlanApiExecuteStatus.RUNNING.name()); } else { executePerformanceIdMap.put(caseID, TestPlanApiExecuteStatus.PREPARE.name()); } } + TestPlanReportExecuteCatch.updateTestPlanThreadInfo(planReportId,null,null,performaneThreadIDMap); if (!performaneReportIDMap.isEmpty()) { //性能测试时保存性能测试报告ID,在结果返回时用于捕捉并进行 testPlanReportService.updatePerformanceInfo(testPlanReport, performaneReportIDMap, triggerMode); @@ -1700,7 +1702,7 @@ public class TestPlanService { } } - public void buildApiReport(TestPlanSimpleReportDTO report, JSONObject config, TestPlanExecuteInfo executeInfo, String planId, boolean saveResponse) { + public void buildApiReport(TestPlanSimpleReportDTO report, JSONObject config, TestPlanExecuteInfo executeInfo,boolean isFinish) { if (MapUtils.isEmpty(executeInfo.getApiCaseExecInfo()) && MapUtils.isEmpty(executeInfo.getApiScenarioCaseExecInfo())) { return; } @@ -1711,33 +1713,12 @@ public class TestPlanService { if (checkReportConfig(config, "api", "all")) { if (MapUtils.isNotEmpty(executeInfo.getApiCaseExecInfo())) { // 接口 - apiAllCases = testPlanApiCaseService.getAllCases(executeInfo.getApiCaseExecInfo().keySet(), null); - if (saveResponse) { - apiAllCases.forEach(item -> { - String apiReportid = executeInfo.getApiCaseReportMap().get(item.getId()); - ApiDefinitionExecResult result = apiDefinitionExecResultMapper.selectByPrimaryKey(apiReportid); - if (result != null) { - APIReportResult dbResult = apiDefinitionService.buildAPIReportResult(result); - if (dbResult != null && StringUtils.isNotBlank(dbResult.getContent())) { - item.setResponse(dbResult.getContent()); - } - } - }); - } + apiAllCases = testPlanApiCaseService.getByApiExecReportIds(executeInfo.getApiCaseExecuteThreadMap(),isFinish); report.setApiAllCases(apiAllCases); } if (MapUtils.isNotEmpty(executeInfo.getApiScenarioCaseExecInfo())) { //场景 - scenarioAllCases = testPlanScenarioCaseService.getAllCases(executeInfo.getApiScenarioCaseExecInfo().keySet(), null); - if (saveResponse) { - scenarioAllCases.forEach((item) -> { - String resultId = executeInfo.getApiScenarioReportMap().get(item.getId()); - APIScenarioReportResult result = apiScenarioReportService.get(resultId); - if (result != null) { - item.setResponse(result); - } - }); - } + scenarioAllCases = testPlanScenarioCaseService.getAllCases(executeInfo.getApiScenarioThreadMap(),isFinish); report.setScenarioAllCases(scenarioAllCases); } } @@ -1749,18 +1730,6 @@ public class TestPlanService { .filter(i -> StringUtils.isNotBlank(i.getExecResult()) && i.getExecResult().equals("error")) .collect(Collectors.toList()); - if (saveResponse) { - for (TestPlanFailureApiDTO item : apiFailureCases) { - String apiReportid = executeInfo.getApiCaseReportMap().get(item.getId()); - ApiDefinitionExecResult result = apiDefinitionExecResultMapper.selectByPrimaryKey(apiReportid); - if (result != null) { - APIReportResult dbResult = apiDefinitionService.buildAPIReportResult(result); - if (dbResult != null && StringUtils.isNotBlank(dbResult.getContent())) { - item.setResponse(dbResult.getContent()); - } - } - } - } } report.setApiFailureCases(apiFailureCases); @@ -1771,15 +1740,6 @@ public class TestPlanService { .filter(i -> StringUtils.isNotBlank(i.getLastResult()) && i.getLastResult().equals("Fail")) .collect(Collectors.toList()); - if (saveResponse) { - for (TestPlanFailureScenarioDTO item : scenarioFailureCases) { - String resultId = executeInfo.getApiScenarioReportMap().get(item.getId()); - APIScenarioReportResult result = apiScenarioReportService.get(resultId); - if (result != null) { - item.setResponse(result); - } - } - } } report.setScenarioFailureCases(scenarioFailureCases); } @@ -1794,6 +1754,11 @@ public class TestPlanService { List allCases = null; if (checkReportConfig(config, "load", "all")) { allCases = testPlanLoadCaseService.getAllCases(executeInfo.getLoadCaseExecInfo().keySet(), planId, null); + for (TestPlanLoadCaseDTO dto : + allCases) { + String reportId = executeInfo.getLoadCaseReportIdMap().get(dto.getId()); + dto.setReportId(reportId); + } if (saveResponse) { buildLoadResponse(allCases); } @@ -1812,7 +1777,7 @@ public class TestPlanService { } } - public TestPlanSimpleReportDTO buildPlanReport(TestPlanExecuteInfo executeInfo, String planId, boolean saveResponse) { + public TestPlanSimpleReportDTO buildPlanReport(TestPlanExecuteInfo executeInfo, String planId, boolean isFinish) { TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(planId); if (testPlan != null) { String reportConfig = testPlan.getReportConfig(); @@ -1822,8 +1787,8 @@ public class TestPlanService { } TestPlanSimpleReportDTO report = getReport(planId); buildFunctionalReport(report, config, planId); - buildApiReport(report, config, executeInfo, planId, true); - buildLoadReport(report, config, executeInfo, planId, saveResponse); + buildApiReport(report, config, executeInfo, isFinish); + buildLoadReport(report, config, executeInfo, planId, false); return report; } else { return null; diff --git a/frontend/src/business/components/track/plan/view/comonents/report/detail/component/ApiCaseFailureResult.vue b/frontend/src/business/components/track/plan/view/comonents/report/detail/component/ApiCaseFailureResult.vue index 009230c9b4..e28376011b 100644 --- a/frontend/src/business/components/track/plan/view/comonents/report/detail/component/ApiCaseFailureResult.vue +++ b/frontend/src/business/components/track/plan/view/comonents/report/detail/component/ApiCaseFailureResult.vue @@ -155,13 +155,25 @@ export default { } }); } else { - // todo - getApiReport(row.id, (data) => { - if (data && data.content) { - this.showResponse = true; - this.response = JSON.parse(data.content); - } - }); + if(row.reportId){ + let url = "/api/definition/report/get/" + row.reportId; + this.$get(url, response => { + if (response.data) { + let data = response.data; + if (data && data.content) { + this.showResponse = true; + this.response = JSON.parse(data.content); + } + } + }); + }else { + getApiReport(row.id, (data) => { + if (data && data.content) { + this.showResponse = true; + this.response = JSON.parse(data.content); + } + }); + } } } }