From fa8dfcee06b130aec5803a12a513fe264029c04c Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Wed, 19 Oct 2022 16:13:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E6=8A=A5=E5=91=8A=E5=88=86?= =?UTF-8?q?=E4=BA=AB=E6=94=AF=E6=8C=81=E8=AE=BF=E9=97=AE=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E6=8A=A5=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1018368 --user=陈建星 【测试跟踪】测试计划-查看测试报告-导出/分享-报告打开是空白 https://www.tapd.cn/55049933/s/1267815 --- .../plan/TestPlanApiCaseController.java | 6 +- .../plan/TestPlanScenarioCaseController.java | 5 + .../service/plan/TestPlanApiCaseService.java | 22 +-- .../plan/TestPlanScenarioCaseService.java | 78 +++------ .../commons/utils/HttpHeaderUtils.java | 6 + .../metersphere/commons/utils/ShiroUtils.java | 2 +- .../controller/ShareController.java | 4 +- .../controller/ShareReportController.java | 17 +- .../plan/service/TestPlanMessageService.java | 2 +- .../plan/service/TestPlanReportService.java | 154 +++++++++++------- .../plan/service/TestPlanService.java | 42 +++++ .../api/PlanTestPlanApiCaseService.java | 6 +- .../api/PlanTestPlanScenarioCaseService.java | 6 +- .../remote/gateway/GatewayService.java | 16 ++ test-track/frontend/src/api/share.js | 2 +- .../template/report/plan/planReportUse.js | 22 --- .../report/plan/share/share-plan-report.html | 14 ++ 17 files changed, 237 insertions(+), 167 deletions(-) create mode 100644 test-track/backend/src/main/java/io/metersphere/plan/service/remote/gateway/GatewayService.java diff --git a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java index db0a24aab4..c813e96e90 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java @@ -136,9 +136,9 @@ public class TestPlanApiCaseController { return testPlanApiCaseService.selectStatusForPlanReport(planId); } - @PostMapping("/get/plan/env/map/{resourceType}") - public Map> getPlanProjectEnvMap(@RequestBody List resourceIds, @PathVariable("resourceType") String resourceType) { - return testPlanApiCaseService.getPlanProjectEnvMap(resourceIds, resourceType); + @PostMapping("/get/plan/env/map") + public Map> getPlanProjectEnvMap(@RequestBody List resourceIds) { + return testPlanApiCaseService.getPlanProjectEnvMap(resourceIds); } @PostMapping("/set/env/{planId}") diff --git a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java index 8745928472..28189c128e 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java @@ -225,4 +225,9 @@ public class TestPlanScenarioCaseController { testPlanScenarioCaseService.buildScenarioResponse(cases); return cases; } + + @PostMapping("/get/plan/env/map") + public Map> getPlanProjectEnvMap(@RequestBody List resourceIds) { + return testPlanScenarioCaseService.getPlanProjectEnvMap(resourceIds); + } } diff --git a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java index 62b11fb54d..6166db7309 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java @@ -25,7 +25,6 @@ import io.metersphere.base.mapper.plan.TestPlanApiCaseMapper; import io.metersphere.base.mapper.plan.ext.ExtTestPlanApiCaseMapper; import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.constants.CommonConstants; -import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.TriggerMode; import io.metersphere.commons.enums.ApiReportStatus; import io.metersphere.commons.exception.MSException; @@ -521,26 +520,21 @@ public class TestPlanApiCaseService { return extTestPlanApiCaseMapper.selectForPlanReport(planId); } - public Map> getPlanProjectEnvMap(List resourceIds, String resourceType) { + public Map> getPlanProjectEnvMap(List resourceIds) { Map> result = new LinkedHashMap<>(); if (!CollectionUtils.isEmpty(resourceIds)) { - if (StringUtils.equalsIgnoreCase("ApiCase", resourceType)) { - List execResults = apiDefinitionExecResultService.selectByResourceIdsAndMaxCreateTime(resourceIds); - execResults.forEach(item -> { - String envConf = item.getEnvConfig(); - String projectId = item.getProjectId(); - Map> projectEnvMap = apiDefinitionService.getProjectEnvNameByEnvConfig(projectId, envConf); - this.setProjectEnvMap(result, projectEnvMap); - }); - } else if (StringUtils.equalsIgnoreCase(ElementConstants.SCENARIO, resourceType)) { - Map> projectEnvMap = apiScenarioEnvService.selectProjectEnvMapByTestPlanScenarioIds(resourceIds); + List execResults = apiDefinitionExecResultService.selectByResourceIdsAndMaxCreateTime(resourceIds); + execResults.forEach(item -> { + String envConf = item.getEnvConfig(); + String projectId = item.getProjectId(); + Map> projectEnvMap = apiDefinitionService.getProjectEnvNameByEnvConfig(projectId, envConf); this.setProjectEnvMap(result, projectEnvMap); - } + }); } return result; } - private void setProjectEnvMap(Map> result, Map> projectEnvMap) { + public void setProjectEnvMap(Map> result, Map> projectEnvMap) { if (MapUtils.isNotEmpty(projectEnvMap)) { for (Map.Entry> entry : projectEnvMap.entrySet()) { String projectName = entry.getKey(); diff --git a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java index be66ec90d4..f2cdca276a 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java @@ -6,51 +6,17 @@ import io.metersphere.api.dto.ApiCaseRelevanceRequest; import io.metersphere.api.dto.EnvironmentType; import io.metersphere.api.dto.RelevanceScenarioRequest; import io.metersphere.api.dto.ScenarioEnv; -import io.metersphere.api.dto.automation.ApiScenarioDTO; -import io.metersphere.api.dto.automation.ApiScenarioModuleDTO; import io.metersphere.api.dto.automation.ApiScenarioReportResult; -import io.metersphere.api.dto.automation.ApiScenarioRequest; -import io.metersphere.api.dto.automation.ExecuteType; -import io.metersphere.api.dto.automation.RunScenarioRequest; -import io.metersphere.api.dto.automation.RunTestPlanScenarioRequest; -import io.metersphere.api.dto.automation.TestPlanFailureApiDTO; -import io.metersphere.api.dto.automation.TestPlanFailureScenarioDTO; -import io.metersphere.api.dto.automation.TestPlanScenarioRequest; -import io.metersphere.api.dto.plan.ApiPlanReportDTO; -import io.metersphere.api.dto.plan.ApiPlanReportRequest; -import io.metersphere.api.dto.plan.TestPlanApiCaseInfoDTO; -import io.metersphere.api.dto.plan.TestPlanApiReportInfoDTO; -import io.metersphere.api.dto.plan.TestPlanApiScenarioInfoDTO; -import io.metersphere.api.dto.plan.TestPlanEnvInfoDTO; -import io.metersphere.api.dto.plan.TestPlanExecuteReportDTO; -import io.metersphere.api.dto.plan.TestPlanReportRunInfoDTO; -import io.metersphere.api.dto.plan.TestPlanScenarioCaseBatchRequest; -import io.metersphere.api.dto.plan.TestPlanScenarioStepCountDTO; -import io.metersphere.api.dto.plan.TestPlanScenarioStepCountSimpleDTO; -import io.metersphere.service.scenario.ApiScenarioService; -import io.metersphere.service.definition.ApiDefinitionExecResultService; -import io.metersphere.service.definition.ApiDefinitionService; -import io.metersphere.service.scenario.ApiScenarioModuleService; -import io.metersphere.service.scenario.ApiScenarioReportService; -import io.metersphere.base.domain.ApiDefinitionExecResult; -import io.metersphere.base.domain.ApiDefinitionExecResultExample; -import io.metersphere.base.domain.ApiDefinitionExecResultWithBLOBs; -import io.metersphere.base.domain.ApiScenario; -import io.metersphere.base.domain.ApiScenarioExample; -import io.metersphere.base.domain.ApiScenarioWithBLOBs; -import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; -import io.metersphere.base.domain.EnvironmentGroup; -import io.metersphere.base.domain.Project; -import io.metersphere.base.domain.TestPlanApiScenario; -import io.metersphere.base.domain.TestPlanApiScenarioExample; -import io.metersphere.base.domain.TestPlanReport; -import io.metersphere.base.domain.User; +import io.metersphere.api.dto.automation.*; +import io.metersphere.api.dto.plan.*; +import io.metersphere.api.exec.scenario.ApiScenarioEnvService; +import io.metersphere.base.domain.*; import io.metersphere.base.mapper.ApiDefinitionExecResultMapper; import io.metersphere.base.mapper.ApiScenarioMapper; import io.metersphere.base.mapper.ApiTestEnvironmentMapper; -import io.metersphere.base.mapper.plan.TestPlanApiScenarioMapper; import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper; import io.metersphere.base.mapper.ext.ExtApiScenarioModuleMapper; +import io.metersphere.base.mapper.plan.TestPlanApiScenarioMapper; import io.metersphere.base.mapper.plan.ext.ExtTestPlanApiCaseMapper; import io.metersphere.base.mapper.plan.ext.ExtTestPlanApiScenarioMapper; import io.metersphere.base.mapper.plan.ext.ExtTestPlanScenarioCaseMapper; @@ -59,11 +25,7 @@ import io.metersphere.commons.constants.CommonConstants; import io.metersphere.commons.constants.ProjectApplicationType; import io.metersphere.commons.enums.ApiReportStatus; import io.metersphere.commons.exception.MSException; -import io.metersphere.commons.utils.JSON; -import io.metersphere.commons.utils.LogUtil; -import io.metersphere.commons.utils.PageUtils; -import io.metersphere.commons.utils.Pager; -import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.commons.utils.*; import io.metersphere.dto.MsExecResponseDTO; import io.metersphere.dto.PlanReportCaseDTO; import io.metersphere.dto.ProjectConfig; @@ -77,6 +39,10 @@ import io.metersphere.service.BaseProjectApplicationService; import io.metersphere.service.BaseProjectService; import io.metersphere.service.BaseUserService; import io.metersphere.service.ServiceUtils; +import io.metersphere.service.definition.ApiDefinitionExecResultService; +import io.metersphere.service.scenario.ApiScenarioModuleService; +import io.metersphere.service.scenario.ApiScenarioReportService; +import io.metersphere.service.scenario.ApiScenarioService; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -89,19 +55,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; @Service @@ -139,7 +93,7 @@ public class TestPlanScenarioCaseService { @Resource private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper; @Resource - private ApiDefinitionService apiDefinitionService; + private ApiScenarioEnvService apiScenarioEnvService; @Resource private ApiDefinitionExecResultService apiDefinitionExecResultService; @Resource @@ -1199,6 +1153,14 @@ public class TestPlanScenarioCaseService { return extTestPlanScenarioCaseMapper.selectForPlanReport(planId); } + public Map> getPlanProjectEnvMap(List resourceIds) { + Map> result = new LinkedHashMap<>(); + if (!com.alibaba.nacos.common.utils.CollectionUtils.isEmpty(resourceIds)) { + Map> projectEnvMap = apiScenarioEnvService.selectProjectEnvMapByTestPlanScenarioIds(resourceIds); + testPlanApiCaseService.setProjectEnvMap(result, projectEnvMap); + } + return result; + } public List getNodeByPlanId(List projectIds, String planId) { List list = new ArrayList<>(); diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/HttpHeaderUtils.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/HttpHeaderUtils.java index 53f454373a..25a65897c6 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/HttpHeaderUtils.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/HttpHeaderUtils.java @@ -5,6 +5,7 @@ import io.metersphere.base.domain.UserKey; import io.metersphere.commons.constants.ApiKeyConstants; import io.metersphere.commons.constants.SessionConstants; import io.metersphere.commons.exception.MSException; +import io.metersphere.service.BaseUserService; import io.metersphere.service.UserKeyService; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -93,6 +94,11 @@ public class HttpHeaderUtils { } } + public static void runAsUser(String userId) { + BaseUserService baseUserService = CommonBeanFactory.getBean(BaseUserService.class); + runAsUser(baseUserService.getUserDTO(userId)); + } + public static void clearUser() { sessionUserThreadLocal.remove(); } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/ShiroUtils.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/ShiroUtils.java index 7724fc11b9..41867b6806 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/ShiroUtils.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/ShiroUtils.java @@ -65,7 +65,7 @@ public class ShiroUtils { filterChainDefinitionMap.put("/document/**", "anon"); filterChainDefinitionMap.put("/chart-pic/**", "anon"); filterChainDefinitionMap.put("/share/**", "anon"); - filterChainDefinitionMap.put("/sharePlanReport", "anon"); + filterChainDefinitionMap.put("/share-plan-report", "anon"); filterChainDefinitionMap.put("/share-report", "anon"); filterChainDefinitionMap.put("/share-document", "anon"); filterChainDefinitionMap.put("/share-api-report", "anon"); diff --git a/test-track/backend/src/main/java/io/metersphere/controller/ShareController.java b/test-track/backend/src/main/java/io/metersphere/controller/ShareController.java index a412ec707d..a2577aae7b 100644 --- a/test-track/backend/src/main/java/io/metersphere/controller/ShareController.java +++ b/test-track/backend/src/main/java/io/metersphere/controller/ShareController.java @@ -39,7 +39,7 @@ public class ShareController { @GetMapping("/test/plan/report/{shareId}/{planId}") public TestPlanSimpleReportDTO getReport(@PathVariable String shareId, @PathVariable String planId) { baseShareInfoService.validate(shareId, planId); - return testPlanService.getReport(planId, null); + return testPlanService.getShareReport(baseShareInfoService.get(shareId), planId); } @GetMapping("/report/export/{shareId}/{planId}/{lang}") @@ -59,6 +59,6 @@ public class ShareController { @GetMapping("/test/plan/report/db/{shareId}/{reportId}") public TestPlanSimpleReportDTO getTestPlanDbReport(@PathVariable String shareId, @PathVariable String reportId) { baseShareInfoService.validate(shareId, reportId); - return testPlanReportService.getReport(reportId); + return testPlanReportService.getShareDbReport(baseShareInfoService.get(shareId), reportId); } } diff --git a/test-track/backend/src/main/java/io/metersphere/controller/ShareReportController.java b/test-track/backend/src/main/java/io/metersphere/controller/ShareReportController.java index ff74d1541c..7ac4f34143 100644 --- a/test-track/backend/src/main/java/io/metersphere/controller/ShareReportController.java +++ b/test-track/backend/src/main/java/io/metersphere/controller/ShareReportController.java @@ -1,13 +1,22 @@ package io.metersphere.controller; -import org.springframework.stereotype.Controller; +import io.metersphere.controller.handler.annotation.NoResultHolder; +import io.metersphere.plan.service.TestPlanService; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; -@Controller +import javax.annotation.Resource; + +@RestController public class ShareReportController { - @GetMapping(value = "/sharePlanReport") + @Resource + TestPlanService testPlanService; + + + @NoResultHolder + @GetMapping(value = "/share-plan-report") public String shareRedirect() { - return "share-plan-report.html"; + return testPlanService.getShareReport(); } } diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanMessageService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanMessageService.java index 4aca77c385..6383f65d0e 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanMessageService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanMessageService.java @@ -166,7 +166,7 @@ public class TestPlanMessageService { paramMap.putAll(new BeanMap(testPlanDTOWithMetric)); String testPlanShareUrl = getTestPlanShareUrl(testPlanReport.getId(), creator); - paramMap.put("planShareUrl", baseSystemConfigDTO.getUrl() + "/sharePlanReport" + testPlanShareUrl); + paramMap.put("planShareUrl", baseSystemConfigDTO.getUrl() + "/share-plan-report" + testPlanShareUrl); /** * 测试计划的消息通知配置包括 完成、成功、失败 diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index b27162b5e3..56836407de 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -939,6 +939,15 @@ public class TestPlanReportService { this.delete(testPlanReportIdList); } + public TestPlanSimpleReportDTO getShareDbReport(ShareInfo shareInfo, String reportId) { + HttpHeaderUtils.runAsUser(shareInfo.getCreateUserId()); + try { + return getReport(reportId); + } finally { + HttpHeaderUtils.clearUser(); + } + } + public TestPlanSimpleReportDTO getReport(String reportId) { TestPlanReportContentExample example = new TestPlanReportContentExample(); example.createCriteria().andTestPlanReportIdEqualTo(reportId); @@ -956,66 +965,101 @@ public class TestPlanReportService { TestPlanSimpleReportDTO testPlanReportDTO = new TestPlanSimpleReportDTO(); BeanUtils.copyBean(testPlanReportDTO, testPlanReportContent); this.generateEnvironmentInfo(testPlanReportDTO, reportId); - if (StringUtils.isNotBlank(testPlanReportContent.getFunctionResult())) { - testPlanReportDTO.setFunctionResult(JSON.parseObject(testPlanReportContent.getFunctionResult(), TestPlanFunctionResultReportDTO.class)); - } - if (StringUtils.isNotBlank(testPlanReportContent.getApiResult())) { - testPlanReportDTO.setApiResult(JSON.parseObject(testPlanReportContent.getApiResult(), TestPlanApiResultReportDTO.class)); - } - if (StringUtils.isNotBlank(testPlanReportContent.getLoadResult())) { - testPlanReportDTO.setLoadResult(JSON.parseObject(testPlanReportContent.getLoadResult(), TestPlanLoadResultReportDTO.class)); - } - if (StringUtils.isNotBlank(testPlanReportContent.getFunctionAllCases())) { - testPlanReportDTO.setFunctionAllCases(JSON.parseArray(testPlanReportContent.getFunctionAllCases(), TestPlanCaseDTO.class)); - } - if (StringUtils.isNotBlank(testPlanReportContent.getIssueList())) { - testPlanReportDTO.setIssueList(JSON.parseArray(testPlanReportContent.getIssueList(), IssuesDao.class)); - } - if (StringUtils.isNotBlank(testPlanReportContent.getApiAllCases())) { - testPlanReportDTO.setApiAllCases(JSON.parseArray(testPlanReportContent.getApiAllCases(), TestPlanFailureApiDTO.class)); - } - if (StringUtils.isNotBlank(testPlanReportContent.getApiFailureCases())) { - testPlanReportDTO.setApiFailureCases(JSON.parseArray(testPlanReportContent.getApiFailureCases(), TestPlanFailureApiDTO.class)); - } - if (StringUtils.isNotBlank(testPlanReportContent.getScenarioAllCases())) { - testPlanReportDTO.setScenarioAllCases(JSON.parseArray(testPlanReportContent.getScenarioAllCases(), TestPlanFailureScenarioDTO.class)); - } - if (StringUtils.isNotBlank(testPlanReportContent.getScenarioFailureCases())) { - testPlanReportDTO.setScenarioFailureCases(JSON.parseArray(testPlanReportContent.getScenarioFailureCases(), TestPlanFailureScenarioDTO.class)); - } - if (StringUtils.isNotBlank(testPlanReportContent.getLoadAllCases())) { - testPlanReportDTO.setLoadAllCases(JSON.parseArray(testPlanReportContent.getLoadAllCases(), TestPlanLoadCaseDTO.class)); - } - if (StringUtils.isNotBlank(testPlanReportContent.getLoadFailureCases())) { - testPlanReportDTO.setLoadFailureCases(JSON.parseArray(testPlanReportContent.getLoadFailureCases(), TestPlanLoadCaseDTO.class)); - } - if (StringUtils.isNotBlank(testPlanReportContent.getErrorReportCases())) { - testPlanReportDTO.setErrorReportCases(JSON.parseArray(testPlanReportContent.getErrorReportCases(), TestPlanFailureApiDTO.class)); - } - if (StringUtils.isNotBlank(testPlanReportContent.getErrorReportScenarios())) { - testPlanReportDTO.setErrorReportScenarios(JSON.parseArray(testPlanReportContent.getErrorReportScenarios(), TestPlanFailureScenarioDTO.class)); - } - if (StringUtils.isNotBlank(testPlanReportContent.getUnExecuteCases())) { - testPlanReportDTO.setUnExecuteCases(JSON.parseArray(testPlanReportContent.getUnExecuteCases(), TestPlanFailureApiDTO.class)); - } - if (StringUtils.isNotBlank(testPlanReportContent.getUnExecuteScenarios())) { - testPlanReportDTO.setUnExecuteScenarios(JSON.parseArray(testPlanReportContent.getUnExecuteScenarios(), TestPlanFailureScenarioDTO.class)); - } - if (StringUtils.isNotBlank(testPlanReportContent.getUiResult())) { - testPlanReportDTO.setUiResult(JSON.parseObject(testPlanReportContent.getUiResult(), TestPlanUiResultReportDTO.class)); - } - if (StringUtils.isNotBlank(testPlanReportContent.getUiAllCases())) { - testPlanReportDTO.setUiAllCases(JSON.parseArray(testPlanReportContent.getUiAllCases(), TestPlanUiScenarioDTO.class)); - } - if (StringUtils.isNotBlank(testPlanReportContent.getUiFailureCases())) { - testPlanReportDTO.setUiFailureCases(JSON.parseArray(testPlanReportContent.getUiFailureCases(), TestPlanUiScenarioDTO.class)); - } + + testPlanReportDTO.setFunctionResult( + getReportContentResultObject(testPlanReportContent.getFunctionResult(), TestPlanFunctionResultReportDTO.class) + ); + + testPlanReportDTO.setApiResult( + getReportContentResultObject(testPlanReportContent.getApiResult(), TestPlanApiResultReportDTO.class) + ); + + testPlanReportDTO.setLoadResult( + getReportContentResultObject(testPlanReportContent.getLoadResult(), TestPlanLoadResultReportDTO.class) + ); + + testPlanReportDTO.setFunctionAllCases( + getReportContentResultArray(testPlanReportContent.getFunctionAllCases(), TestPlanCaseDTO.class) + ); + + testPlanReportDTO.setIssueList( + getReportContentResultArray(testPlanReportContent.getIssueList(), IssuesDao.class) + ); + + testPlanReportDTO.setApiAllCases( + getReportContentResultArray(testPlanReportContent.getApiAllCases(), TestPlanFailureApiDTO.class) + ); + + testPlanReportDTO.setApiFailureCases( + getReportContentResultArray(testPlanReportContent.getApiFailureCases(), TestPlanFailureApiDTO.class) + ); + + testPlanReportDTO.setScenarioAllCases( + getReportContentResultArray(testPlanReportContent.getScenarioAllCases(), TestPlanFailureScenarioDTO.class) + ); + + testPlanReportDTO.setScenarioFailureCases( + getReportContentResultArray(testPlanReportContent.getScenarioFailureCases(), TestPlanFailureScenarioDTO.class) + ); + + testPlanReportDTO.setLoadAllCases( + getReportContentResultArray(testPlanReportContent.getLoadAllCases(), TestPlanLoadCaseDTO.class) + ); + + testPlanReportDTO.setLoadFailureCases( + getReportContentResultArray(testPlanReportContent.getLoadFailureCases(), TestPlanLoadCaseDTO.class) + ); + + testPlanReportDTO.setErrorReportCases( + getReportContentResultArray(testPlanReportContent.getErrorReportCases(), TestPlanFailureApiDTO.class) + ); + + testPlanReportDTO.setErrorReportScenarios( + getReportContentResultArray(testPlanReportContent.getErrorReportScenarios(), TestPlanFailureScenarioDTO.class) + ); + + testPlanReportDTO.setUnExecuteCases( + getReportContentResultArray(testPlanReportContent.getUnExecuteCases(), TestPlanFailureApiDTO.class) + ); + + testPlanReportDTO.setUnExecuteScenarios( + getReportContentResultArray(testPlanReportContent.getUnExecuteScenarios(), TestPlanFailureScenarioDTO.class) + ); + + testPlanReportDTO.setUiResult( + getReportContentResultObject(testPlanReportContent.getUiResult(), TestPlanUiResultReportDTO.class) + ); + + testPlanReportDTO.setUiAllCases( + getReportContentResultArray(testPlanReportContent.getUiAllCases(), TestPlanUiScenarioDTO.class) + ); + + testPlanReportDTO.setUiFailureCases( + getReportContentResultArray(testPlanReportContent.getUiFailureCases(), TestPlanUiScenarioDTO.class) + ); + testPlanReportDTO.setId(reportId); TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(testPlanReportContent.getTestPlanReportId()); testPlanReportDTO.setName(testPlanReport.getName()); return testPlanReportDTO; } + private T getReportContentResultObject(String contentStr, Class clazz) { + if (StringUtils.isNotBlank(contentStr)) { + return JSON.parseObject(contentStr, clazz); + } + return null; + + } + + private List getReportContentResultArray(String contentStr, Class clazz) { + if (StringUtils.isNotBlank(contentStr)) { + return JSON.parseArray(contentStr, clazz); + } + return null; + } + + private void generateEnvironmentInfo(TestPlanSimpleReportDTO testPlanReportDTO, String reportId) { TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(reportId); try { @@ -1266,7 +1310,7 @@ public class TestPlanReportService { } }); String defaultStatus = "Fail"; - Map reportStatus = planUiScenarioReportService.getReportStatusByReportIds(reportIdList); + Map reportStatus = planUiScenarioReportService.getReportStatusByReportIds(reportIdList); for (TestPlanUiScenarioDTO dto : scenarioCases) { String reportId = dto.getReportId(); diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java index a65c5bbe05..bf76d1b5aa 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -33,6 +33,7 @@ import io.metersphere.plan.reuest.ui.RunUiScenarioRequest; import io.metersphere.plan.service.remote.api.PlanApiAutomationService; import io.metersphere.plan.service.remote.api.PlanTestPlanApiCaseService; import io.metersphere.plan.service.remote.api.PlanTestPlanScenarioCaseService; +import io.metersphere.plan.service.remote.gateway.GatewayService; import io.metersphere.plan.service.remote.performance.PerfExecService; import io.metersphere.plan.service.remote.performance.PlanTestPlanLoadCaseService; import io.metersphere.plan.service.remote.ui.PlanTestPlanUiScenarioCaseService; @@ -139,6 +140,8 @@ public class TestPlanService { private TestPlanExecutionQueueService testPlanExecutionQueueService; @Resource private KafkaTemplate kafkaTemplate; + @Resource + private GatewayService gatewayService; public synchronized TestPlan addTestPlan(AddTestPlanRequest testPlan) { if (getTestPlanByName(testPlan.getName()).size() > 0) { @@ -1072,6 +1075,36 @@ public class TestPlanService { } } + public String getShareReport() { + Object microServices = gatewayService.getMicroServices(); + return replaceSharReport(microServices); + } + + + /** + * 获取微服务信息,替换前端变量 + * 实现跨服务访问报告 + */ + public String replaceSharReport(Object microServices) { + try (InputStreamReader isr = new InputStreamReader(getClass().getResourceAsStream("/public/share-plan-report.html"), StandardCharsets.UTF_8);) { + BufferedReader bufferedReader = new BufferedReader(isr); + StringBuilder reportStr = new StringBuilder(); + String line; + while (null != (line = bufferedReader.readLine())) { + if (line.contains("\"#microService\"")) { + line = line.replace("\"#microService\"", new Gson().toJson(microServices)); + } + line += StringUtils.LF; + reportStr.append(line); + } + return reportStr.toString(); + } catch (Throwable e) { + LogUtil.error(e); + MSException.throwException(e); + } + return null; + } + public Map> getApiCaseEnv(List planApiCaseIds) { return planTestPlanApiCaseService.getApiCaseEnv(planApiCaseIds); } @@ -1330,6 +1363,15 @@ public class TestPlanService { } } + public TestPlanSimpleReportDTO getShareReport(ShareInfo shareInfo, String planId) { + HttpHeaderUtils.runAsUser(shareInfo.getCreateUserId()); + try { + return getReport(planId, null); + } finally { + HttpHeaderUtils.clearUser(); + } + } + /** * 生成测试计划报告并进行统计 * diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanApiCaseService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanApiCaseService.java index 9f56dbfec2..66720342e4 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanApiCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanApiCaseService.java @@ -36,7 +36,7 @@ public class PlanTestPlanApiCaseService extends ApiTestService { calculatePlanReport(report, planReportCaseDTOS); //记录接口用例的运行环境信息 List idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList()); - report.setProjectEnvMap(getPlanProjectEnvMap(idList, "ApiCase")); + report.setProjectEnvMap(getPlanProjectEnvMap(idList)); } catch (MSException e) { LogUtil.error(e); } @@ -76,8 +76,8 @@ public class PlanTestPlanApiCaseService extends ApiTestService { return microService.getForDataArray(serviceName, BASE_UEL + "/get/report/status/" + planId, PlanReportCaseDTO.class); } - public Map> getPlanProjectEnvMap(List resourceIds, String resourceType) { - return (Map>) microService.postForData(serviceName, BASE_UEL + "/get/plan/env/map/" + resourceType, resourceIds); + public Map> getPlanProjectEnvMap(List resourceIds) { + return (Map>) microService.postForData(serviceName, BASE_UEL + "/get/plan/env/map", resourceIds); } public List run(BatchRunDefinitionRequest request) { diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanScenarioCaseService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanScenarioCaseService.java index 950585b2cd..7d6cb9ea47 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanScenarioCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanScenarioCaseService.java @@ -29,7 +29,7 @@ public class PlanTestPlanScenarioCaseService extends ApiTestService { calculatePlanReport(report, planReportCaseDTOS); //记录接口用例的运行环境信息 List idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList()); - report.setProjectEnvMap(getPlanProjectEnvMap(idList, "Scenario")); + report.setProjectEnvMap(getPlanProjectEnvMap(idList)); } catch (MSException e) { LogUtil.error(e); } @@ -90,8 +90,8 @@ public class PlanTestPlanScenarioCaseService extends ApiTestService { return microService.getForDataArray(serviceName, BASE_UEL + "/get/report/status/" + planId, PlanReportCaseDTO.class); } - public Map> getPlanProjectEnvMap(List resourceIds, String resourceType) { - return (Map>) microService.postForData(serviceName, BASE_UEL + "/get/plan/env/map/" + resourceType, resourceIds); + public Map> getPlanProjectEnvMap(List resourceIds) { + return (Map>) microService.postForData(serviceName, BASE_UEL + "/get/plan/env/map", resourceIds); } public List getExecResultByPlanId(String planId) { diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/gateway/GatewayService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/gateway/GatewayService.java new file mode 100644 index 0000000000..54546f67f9 --- /dev/null +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/gateway/GatewayService.java @@ -0,0 +1,16 @@ +package io.metersphere.plan.service.remote.gateway; + +import io.metersphere.commons.constants.MicroServiceName; +import io.metersphere.service.RemoteService; +import org.springframework.stereotype.Service; + +@Service +public class GatewayService extends RemoteService { + public GatewayService() { + super(MicroServiceName.GATEWAY); + } + + public Object getMicroServices() { + return microService.getForData(serviceName, "/services"); + } +} diff --git a/test-track/frontend/src/api/share.js b/test-track/frontend/src/api/share.js index a56beeb5b3..f98fd12190 100644 --- a/test-track/frontend/src/api/share.js +++ b/test-track/frontend/src/api/share.js @@ -52,6 +52,6 @@ export function getShareId() { } export function getShareRedirectUrl(data) { - let name = '/sharePlanReport'; + let name = '/share-plan-report'; return generateShareUrl(name, data.shareUrl); } diff --git a/test-track/frontend/src/business/template/report/plan/planReportUse.js b/test-track/frontend/src/business/template/report/plan/planReportUse.js index de27edda02..ba56d49599 100644 --- a/test-track/frontend/src/business/template/report/plan/planReportUse.js +++ b/test-track/frontend/src/business/template/report/plan/planReportUse.js @@ -12,30 +12,8 @@ import plugins from "metersphere-frontend/src/plugins"; import mavonEditor from "mavon-editor"; import {createPinia, PiniaVuePlugin} from 'pinia' import PersistedState from "pinia-plugin-persistedstate"; -import {TokenKey} from "metersphere-frontend/src/utils/constants"; -import axios from 'axios'; function planReportUse(id, template) { - // 获取gateway路由 - let user = JSON.parse(localStorage.getItem(TokenKey)); - axios({ - method: 'get', - url: '/services', - headers: { - 'CSRF-TOKEN': user.csrfToken, - 'X-AUTH-TOKEN': user.sessionId - }, - }).then((res)=>{ - let modules = {}, microPorts = {}; - res.data.data.forEach(svc => { - let name = svc.serviceId; - modules[name] = true; - microPorts[name] = svc.port; - }) - sessionStorage.setItem("micro_apps", JSON.stringify(modules)); - sessionStorage.setItem("micro_ports", JSON.stringify(microPorts)); - }) - const pinia = createPinia() pinia.use(PersistedState)//开启缓存,存储在localstorage diff --git a/test-track/frontend/src/business/template/report/plan/share/share-plan-report.html b/test-track/frontend/src/business/template/report/plan/share/share-plan-report.html index 24f1065927..7bcb05af33 100644 --- a/test-track/frontend/src/business/template/report/plan/share/share-plan-report.html +++ b/test-track/frontend/src/business/template/report/plan/share/share-plan-report.html @@ -10,4 +10,18 @@
+ +