From e4d1cfa9a2c08752fff505fbe2431522a04d32c5 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Thu, 14 Jul 2022 14:26:02 +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=E5=AE=9E=E6=97=B6=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=E6=98=BE=E7=A4=BA=E6=89=A7=E8=A1=8C=E4=BA=86=E7=9A=84?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E7=9A=84=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 测试计划实时报告显示执行了的用例的环境 --- .../exec/scenario/ApiScenarioEnvService.java | 72 ++ .../ApiDefinitionExecResultService.java | 8 + .../api/service/ApiDefinitionService.java | 24 + .../ApiScenarioReportStructureService.java | 52 +- .../mapper/TestPlanApiScenarioMapper.java | 5 +- .../base/mapper/TestPlanApiScenarioMapper.xml | 800 +++++++++--------- .../ext/ExtApiDefinitionExecResultMapper.java | 2 + .../ext/ExtApiDefinitionExecResultMapper.xml | 26 +- .../track/service/TestPlanApiCaseService.java | 67 +- .../service/TestPlanScenarioCaseService.java | 15 +- .../scenario/component/ApiComponent.vue | 7 +- .../component/ApiScenarioComponent.vue | 28 +- .../report/detail/TestPlanOverviewReport.vue | 23 +- 13 files changed, 659 insertions(+), 470 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java index ab240f8d1e..c723b20099 100644 --- a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java +++ b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.parser.Feature; import io.metersphere.api.dto.EnvironmentType; +import io.metersphere.api.dto.RunModeConfigWithEnvironmentDTO; import io.metersphere.api.dto.ScenarioEnv; import io.metersphere.api.dto.automation.ApiScenarioDTO; import io.metersphere.api.dto.automation.RunScenarioRequest; @@ -22,6 +23,7 @@ import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; +import io.metersphere.dto.RunModeConfigDTO; import io.metersphere.plugin.core.MsTestElement; import io.metersphere.service.EnvironmentGroupProjectService; import io.metersphere.service.ProjectService; @@ -471,4 +473,74 @@ public class ApiScenarioEnvService { } return returnMap; } + + public Map> selectProjectEnvMapByTestPlanScenarioIds(List resourceIds) { + Map> returnMap = new LinkedHashMap<>(); + if (CollectionUtils.isNotEmpty(resourceIds)) { + List reportEnvConfList = testPlanApiScenarioMapper.selectReportEnvConfByResourceIds(resourceIds); + reportEnvConfList.forEach(envConf -> { + LinkedHashMap> projectEnvMap = this.getProjectEnvMapByEnvConfig(envConf); + for (Map.Entry> entry : projectEnvMap.entrySet()) { + String projectName = entry.getKey(); + List envNameList = entry.getValue(); + if (StringUtils.isEmpty(projectName) || CollectionUtils.isEmpty(envNameList)) { + continue; + } + if (returnMap.containsKey(projectName)) { + envNameList.forEach(envName -> { + if (!returnMap.get(projectName).contains(envName)) { + returnMap.get(projectName).add(envName); + } + }); + } else { + returnMap.put(projectName, envNameList); + } + } + }); + } + return returnMap; + } + + public LinkedHashMap> getProjectEnvMapByEnvConfig(String envConfig) { + LinkedHashMap> returnMap = new LinkedHashMap<>(); + //运行设置中选择的环境信息(批量执行时在前台选择了执行信息) + Map envMapByRunConfig = null; + //执行时选择的环境信息 (一般在集合报告中会记录) + Map> envMapByExecution = null; + + try { + JSONObject jsonObject = JSONObject.parseObject(envConfig); + if (jsonObject.containsKey("executionEnvironmentMap")) { + RunModeConfigWithEnvironmentDTO configWithEnvironment = JSONObject.parseObject(envConfig, RunModeConfigWithEnvironmentDTO.class); + if (MapUtils.isNotEmpty(configWithEnvironment.getExecutionEnvironmentMap())) { + envMapByExecution = configWithEnvironment.getExecutionEnvironmentMap(); + } else { + envMapByRunConfig = configWithEnvironment.getEnvMap(); + } + } else { + RunModeConfigDTO config = JSONObject.parseObject(envConfig, RunModeConfigDTO.class); + envMapByRunConfig = config.getEnvMap(); + } + } catch (Exception e) { + LogUtil.error("解析RunModeConfig失败!参数:" + envConfig, e); + } + returnMap.putAll(this.selectProjectNameAndEnvName(envMapByExecution)); + + if (MapUtils.isNotEmpty(envMapByRunConfig)) { + for (Map.Entry entry : envMapByRunConfig.entrySet()) { + String projectId = entry.getKey(); + String envId = entry.getValue(); + String projectName = projectService.selectNameById(projectId); + String envName = apiTestEnvironmentService.selectNameById(envId); + if (StringUtils.isNoneEmpty(projectName, envName)) { + returnMap.put(projectName, new ArrayList<>() {{ + this.add(envName); + }}); + } + } + + } + + return returnMap; + } } 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 6d2247fa07..41a3add056 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java @@ -523,4 +523,12 @@ public class ApiDefinitionExecResultService { }); return list; } + + public List selectByResourceIdsAndMaxCreateTime(List resourceIds) { + if (CollectionUtils.isNotEmpty(resourceIds)) { + return extApiDefinitionExecResultMapper.selectByResourceIdsAndMaxCreateTime(resourceIds); + } else { + return new ArrayList<>(); + } + } } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index d0e82c0d76..51d0548e6f 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -156,6 +156,9 @@ public class ApiDefinitionService { private ApiModuleService apiModuleService; @Resource private ApiTestEnvironmentService apiTestEnvironmentService; + @Lazy + @Resource + private ProjectService projectService; private ThreadLocal currentApiOrder = new ThreadLocal<>(); private ThreadLocal currentApiCaseOrder = new ThreadLocal<>(); @@ -1344,6 +1347,27 @@ public class ApiDefinitionService { return reportResult; } + public Map> getProjectEnvNameByEnvConfig(String projectId, String envConfig) { + Map> returnMap = new HashMap<>(); + RunModeConfigDTO runModeConfigDTO = null; + try { + runModeConfigDTO = JSONObject.parseObject(envConfig, RunModeConfigDTO.class); + } catch (Exception e) { + LogUtil.error("解析" + envConfig + "为RunModeConfigDTO时失败!", e); + } + if (StringUtils.isNotEmpty(projectId) && runModeConfigDTO != null && MapUtils.isNotEmpty(runModeConfigDTO.getEnvMap())) { + String envId = runModeConfigDTO.getEnvMap().get(projectId); + String envName = apiTestEnvironmentService.selectNameById(envId); + String projectName = projectService.selectNameById(projectId); + if (StringUtils.isNoneEmpty(envName, projectName)) { + returnMap.put(projectName, new ArrayList<>() {{ + this.add(envName); + }}); + } + } + return returnMap; + } + public String getEnvNameByEnvConfig(String projectId, String envConfig) { String envName = null; RunModeConfigDTO runModeConfigDTO = null; 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 c559fcca5a..4c75463a51 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java @@ -4,7 +4,10 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.parser.Feature; -import io.metersphere.api.dto.*; +import io.metersphere.api.dto.ApiScenarioReportBaseInfoDTO; +import io.metersphere.api.dto.ApiScenarioReportDTO; +import io.metersphere.api.dto.RequestResultExpandDTO; +import io.metersphere.api.dto.StepTreeDTO; import io.metersphere.api.exec.scenario.ApiScenarioEnvService; import io.metersphere.api.exec.utils.ResultParseUtil; import io.metersphere.api.service.vo.ApiDefinitionExecResultVo; @@ -20,7 +23,6 @@ import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; import io.metersphere.constants.RunModeConstants; import io.metersphere.dto.RequestResult; -import io.metersphere.dto.RunModeConfigDTO; import io.metersphere.service.ProjectService; import io.metersphere.utils.LoggerUtil; import org.apache.commons.collections.CollectionUtils; @@ -398,8 +400,8 @@ public class ApiScenarioReportStructureService { } // 非正常执行结束的请求结果 List unList = dtoList.stream().filter(e -> e.getValue() != null - && ((StringUtils.equalsIgnoreCase(e.getType(), "DubboSampler") && e.getValue().getStartTime() == 0) - || StringUtils.equalsIgnoreCase(e.getTotalStatus(), ExecuteResult.UN_EXECUTE.toString()))) + && ((StringUtils.equalsIgnoreCase(e.getType(), "DubboSampler") && e.getValue().getStartTime() == 0) + || StringUtils.equalsIgnoreCase(e.getTotalStatus(), ExecuteResult.UN_EXECUTE.toString()))) .collect(Collectors.toList()); // 有效数据按照时间排序 @@ -545,45 +547,9 @@ public class ApiScenarioReportStructureService { public void initProjectEnvironmentByEnvConfig(ApiScenarioReportDTO dto, String envConfig) { if (StringUtils.isNotEmpty(envConfig)) { - //运行设置中选择的环境信息(批量执行时在前台选择了执行信息) - Map envMapByRunConfig = null; - //执行时选择的环境信息 (一般在集合报告中会记录) - Map> envMapByExecution = null; - - try { - JSONObject jsonObject = JSONObject.parseObject(envConfig); - if (jsonObject.containsKey("executionEnvironmentMap")) { - RunModeConfigWithEnvironmentDTO configWithEnvironment = JSONObject.parseObject(envConfig, RunModeConfigWithEnvironmentDTO.class); - if (MapUtils.isNotEmpty(configWithEnvironment.getExecutionEnvironmentMap())) { - envMapByExecution = configWithEnvironment.getExecutionEnvironmentMap(); - } else { - envMapByRunConfig = configWithEnvironment.getEnvMap(); - } - } else { - RunModeConfigDTO config = JSONObject.parseObject(envConfig, RunModeConfigDTO.class); - envMapByRunConfig = config.getEnvMap(); - } - } catch (Exception e) { - LogUtil.error("解析RunModeConfig失败!参数:" + envConfig, e); - } - - LinkedHashMap> projectEnvMap = apiScenarioEnvService.selectProjectNameAndEnvName(envMapByExecution); - - if (MapUtils.isNotEmpty(envMapByRunConfig)) { - for (Map.Entry entry : envMapByRunConfig.entrySet()) { - String projectId = entry.getKey(); - String envId = entry.getValue(); - String projectName = projectService.selectNameById(projectId); - String envName = apiTestEnvironmentService.selectNameById(envId); - if (StringUtils.isNoneEmpty(projectName, envName)) { - projectEnvMap.put(projectName, new ArrayList<>() {{ - this.add(envName); - }}); - } - } - if (MapUtils.isNotEmpty(projectEnvMap)) { - dto.setProjectEnvMap(projectEnvMap); - } + LinkedHashMap> projectEnvMap = apiScenarioEnvService.getProjectEnvMapByEnvConfig(envConfig); + if (MapUtils.isNotEmpty(projectEnvMap)) { + dto.setProjectEnvMap(projectEnvMap); } } } diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestPlanApiScenarioMapper.java b/backend/src/main/java/io/metersphere/base/mapper/TestPlanApiScenarioMapper.java index 017d3a112e..1cda49bd82 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/TestPlanApiScenarioMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/TestPlanApiScenarioMapper.java @@ -2,9 +2,10 @@ package io.metersphere.base.mapper; import io.metersphere.base.domain.TestPlanApiScenario; import io.metersphere.base.domain.TestPlanApiScenarioExample; -import java.util.List; import org.apache.ibatis.annotations.Param; +import java.util.List; + public interface TestPlanApiScenarioMapper { long countByExample(TestPlanApiScenarioExample example); @@ -33,4 +34,6 @@ public interface TestPlanApiScenarioMapper { int updateByPrimaryKeyWithBLOBs(TestPlanApiScenario record); int updateByPrimaryKey(TestPlanApiScenario record); + + List selectReportEnvConfByResourceIds(@Param("ids") List resourceIds); } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestPlanApiScenarioMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/TestPlanApiScenarioMapper.xml index feed2b3997..90f6fde0df 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/TestPlanApiScenarioMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/TestPlanApiScenarioMapper.xml @@ -1,411 +1,427 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + - - - - - - - id, test_plan_id, api_scenario_id, `status`, create_time, update_time, pass_rate, + + + + id + , test_plan_id, api_scenario_id, `status`, create_time, update_time, pass_rate, last_result, report_id, create_user, `order`, environment_type, environment_group_id - - - environment - - - - - - delete from test_plan_api_scenario - where id = #{id,jdbcType=VARCHAR} - - - delete from test_plan_api_scenario - - - - - - insert into test_plan_api_scenario (id, test_plan_id, api_scenario_id, - `status`, create_time, update_time, - pass_rate, last_result, report_id, - create_user, `order`, environment_type, - environment_group_id, environment) - values (#{id,jdbcType=VARCHAR}, #{testPlanId,jdbcType=VARCHAR}, #{apiScenarioId,jdbcType=VARCHAR}, - #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, - #{passRate,jdbcType=VARCHAR}, #{lastResult,jdbcType=VARCHAR}, #{reportId,jdbcType=VARCHAR}, - #{createUser,jdbcType=VARCHAR}, #{order,jdbcType=BIGINT}, #{environmentType,jdbcType=VARCHAR}, - #{environmentGroupId,jdbcType=VARCHAR}, #{environment,jdbcType=LONGVARCHAR}) - - - insert into test_plan_api_scenario - - - id, - - - test_plan_id, - - - api_scenario_id, - - - `status`, - - - create_time, - - - update_time, - - - pass_rate, - - - last_result, - - - report_id, - - - create_user, - - - `order`, - - - environment_type, - - - environment_group_id, - - - environment, - - - - - #{id,jdbcType=VARCHAR}, - - - #{testPlanId,jdbcType=VARCHAR}, - - - #{apiScenarioId,jdbcType=VARCHAR}, - - - #{status,jdbcType=VARCHAR}, - - - #{createTime,jdbcType=BIGINT}, - - - #{updateTime,jdbcType=BIGINT}, - - - #{passRate,jdbcType=VARCHAR}, - - - #{lastResult,jdbcType=VARCHAR}, - - - #{reportId,jdbcType=VARCHAR}, - - - #{createUser,jdbcType=VARCHAR}, - - - #{order,jdbcType=BIGINT}, - - - #{environmentType,jdbcType=VARCHAR}, - - - #{environmentGroupId,jdbcType=VARCHAR}, - - - #{environment,jdbcType=LONGVARCHAR}, - - - - - - update test_plan_api_scenario - - - id = #{record.id,jdbcType=VARCHAR}, - - + + + environment + + + + + + delete + from test_plan_api_scenario + where id = #{id,jdbcType=VARCHAR} + + + delete from test_plan_api_scenario + + + + + + insert into test_plan_api_scenario (id, test_plan_id, api_scenario_id, + `status`, create_time, update_time, + pass_rate, last_result, report_id, + create_user, `order`, environment_type, + environment_group_id, environment) + values (#{id,jdbcType=VARCHAR}, #{testPlanId,jdbcType=VARCHAR}, #{apiScenarioId,jdbcType=VARCHAR}, + #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, + #{passRate,jdbcType=VARCHAR}, #{lastResult,jdbcType=VARCHAR}, #{reportId,jdbcType=VARCHAR}, + #{createUser,jdbcType=VARCHAR}, #{order,jdbcType=BIGINT}, #{environmentType,jdbcType=VARCHAR}, + #{environmentGroupId,jdbcType=VARCHAR}, #{environment,jdbcType=LONGVARCHAR}) + + + insert into test_plan_api_scenario + + + id, + + + test_plan_id, + + + api_scenario_id, + + + `status`, + + + create_time, + + + update_time, + + + pass_rate, + + + last_result, + + + report_id, + + + create_user, + + + `order`, + + + environment_type, + + + environment_group_id, + + + environment, + + + + + #{id,jdbcType=VARCHAR}, + + + #{testPlanId,jdbcType=VARCHAR}, + + + #{apiScenarioId,jdbcType=VARCHAR}, + + + #{status,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=BIGINT}, + + + #{updateTime,jdbcType=BIGINT}, + + + #{passRate,jdbcType=VARCHAR}, + + + #{lastResult,jdbcType=VARCHAR}, + + + #{reportId,jdbcType=VARCHAR}, + + + #{createUser,jdbcType=VARCHAR}, + + + #{order,jdbcType=BIGINT}, + + + #{environmentType,jdbcType=VARCHAR}, + + + #{environmentGroupId,jdbcType=VARCHAR}, + + + #{environment,jdbcType=LONGVARCHAR}, + + + + + + + + update test_plan_api_scenario + + + id = #{record.id,jdbcType=VARCHAR}, + + + test_plan_id = #{record.testPlanId,jdbcType=VARCHAR}, + + + api_scenario_id = #{record.apiScenarioId,jdbcType=VARCHAR}, + + + `status` = #{record.status,jdbcType=VARCHAR}, + + + create_time = #{record.createTime,jdbcType=BIGINT}, + + + update_time = #{record.updateTime,jdbcType=BIGINT}, + + + pass_rate = #{record.passRate,jdbcType=VARCHAR}, + + + last_result = #{record.lastResult,jdbcType=VARCHAR}, + + + report_id = #{record.reportId,jdbcType=VARCHAR}, + + + create_user = #{record.createUser,jdbcType=VARCHAR}, + + + `order` = #{record.order,jdbcType=BIGINT}, + + + environment_type = #{record.environmentType,jdbcType=VARCHAR}, + + + environment_group_id = #{record.environmentGroupId,jdbcType=VARCHAR}, + + + environment = #{record.environment,jdbcType=LONGVARCHAR}, + + + + + + + + update test_plan_api_scenario + set id = #{record.id,jdbcType=VARCHAR}, test_plan_id = #{record.testPlanId,jdbcType=VARCHAR}, - - api_scenario_id = #{record.apiScenarioId,jdbcType=VARCHAR}, - - `status` = #{record.status,jdbcType=VARCHAR}, - - create_time = #{record.createTime,jdbcType=BIGINT}, - - update_time = #{record.updateTime,jdbcType=BIGINT}, - - pass_rate = #{record.passRate,jdbcType=VARCHAR}, - - last_result = #{record.lastResult,jdbcType=VARCHAR}, - - report_id = #{record.reportId,jdbcType=VARCHAR}, - - create_user = #{record.createUser,jdbcType=VARCHAR}, - - `order` = #{record.order,jdbcType=BIGINT}, - - environment_type = #{record.environmentType,jdbcType=VARCHAR}, - - environment_group_id = #{record.environmentGroupId,jdbcType=VARCHAR}, - - - environment = #{record.environment,jdbcType=LONGVARCHAR}, - - - - - - - - update test_plan_api_scenario - set id = #{record.id,jdbcType=VARCHAR}, - test_plan_id = #{record.testPlanId,jdbcType=VARCHAR}, - api_scenario_id = #{record.apiScenarioId,jdbcType=VARCHAR}, - `status` = #{record.status,jdbcType=VARCHAR}, - create_time = #{record.createTime,jdbcType=BIGINT}, - update_time = #{record.updateTime,jdbcType=BIGINT}, - pass_rate = #{record.passRate,jdbcType=VARCHAR}, - last_result = #{record.lastResult,jdbcType=VARCHAR}, - report_id = #{record.reportId,jdbcType=VARCHAR}, - create_user = #{record.createUser,jdbcType=VARCHAR}, - `order` = #{record.order,jdbcType=BIGINT}, - environment_type = #{record.environmentType,jdbcType=VARCHAR}, - environment_group_id = #{record.environmentGroupId,jdbcType=VARCHAR}, - environment = #{record.environment,jdbcType=LONGVARCHAR} - - - - - - update test_plan_api_scenario - set id = #{record.id,jdbcType=VARCHAR}, - test_plan_id = #{record.testPlanId,jdbcType=VARCHAR}, - api_scenario_id = #{record.apiScenarioId,jdbcType=VARCHAR}, - `status` = #{record.status,jdbcType=VARCHAR}, - create_time = #{record.createTime,jdbcType=BIGINT}, - update_time = #{record.updateTime,jdbcType=BIGINT}, - pass_rate = #{record.passRate,jdbcType=VARCHAR}, - last_result = #{record.lastResult,jdbcType=VARCHAR}, - report_id = #{record.reportId,jdbcType=VARCHAR}, - create_user = #{record.createUser,jdbcType=VARCHAR}, - `order` = #{record.order,jdbcType=BIGINT}, - environment_type = #{record.environmentType,jdbcType=VARCHAR}, - environment_group_id = #{record.environmentGroupId,jdbcType=VARCHAR} - - - - - - update test_plan_api_scenario - - - test_plan_id = #{testPlanId,jdbcType=VARCHAR}, - - - api_scenario_id = #{apiScenarioId,jdbcType=VARCHAR}, - - - `status` = #{status,jdbcType=VARCHAR}, - - - create_time = #{createTime,jdbcType=BIGINT}, - - - update_time = #{updateTime,jdbcType=BIGINT}, - - - pass_rate = #{passRate,jdbcType=VARCHAR}, - - - last_result = #{lastResult,jdbcType=VARCHAR}, - - - report_id = #{reportId,jdbcType=VARCHAR}, - - - create_user = #{createUser,jdbcType=VARCHAR}, - - - `order` = #{order,jdbcType=BIGINT}, - - - environment_type = #{environmentType,jdbcType=VARCHAR}, - - - environment_group_id = #{environmentGroupId,jdbcType=VARCHAR}, - - - environment = #{environment,jdbcType=LONGVARCHAR}, - - - where id = #{id,jdbcType=VARCHAR} - - - update test_plan_api_scenario - set test_plan_id = #{testPlanId,jdbcType=VARCHAR}, - api_scenario_id = #{apiScenarioId,jdbcType=VARCHAR}, - `status` = #{status,jdbcType=VARCHAR}, - create_time = #{createTime,jdbcType=BIGINT}, - update_time = #{updateTime,jdbcType=BIGINT}, - pass_rate = #{passRate,jdbcType=VARCHAR}, - last_result = #{lastResult,jdbcType=VARCHAR}, - report_id = #{reportId,jdbcType=VARCHAR}, - create_user = #{createUser,jdbcType=VARCHAR}, - `order` = #{order,jdbcType=BIGINT}, - environment_type = #{environmentType,jdbcType=VARCHAR}, - environment_group_id = #{environmentGroupId,jdbcType=VARCHAR}, - environment = #{environment,jdbcType=LONGVARCHAR} - where id = #{id,jdbcType=VARCHAR} - - - update test_plan_api_scenario - set test_plan_id = #{testPlanId,jdbcType=VARCHAR}, - api_scenario_id = #{apiScenarioId,jdbcType=VARCHAR}, - `status` = #{status,jdbcType=VARCHAR}, - create_time = #{createTime,jdbcType=BIGINT}, - update_time = #{updateTime,jdbcType=BIGINT}, - pass_rate = #{passRate,jdbcType=VARCHAR}, - last_result = #{lastResult,jdbcType=VARCHAR}, - report_id = #{reportId,jdbcType=VARCHAR}, - create_user = #{createUser,jdbcType=VARCHAR}, - `order` = #{order,jdbcType=BIGINT}, - environment_type = #{environmentType,jdbcType=VARCHAR}, - environment_group_id = #{environmentGroupId,jdbcType=VARCHAR} - where id = #{id,jdbcType=VARCHAR} - + environment = #{record.environment,jdbcType=LONGVARCHAR} + + + + + + update test_plan_api_scenario + set id = #{record.id,jdbcType=VARCHAR}, + test_plan_id = #{record.testPlanId,jdbcType=VARCHAR}, + api_scenario_id = #{record.apiScenarioId,jdbcType=VARCHAR}, + `status` = #{record.status,jdbcType=VARCHAR}, + create_time = #{record.createTime,jdbcType=BIGINT}, + update_time = #{record.updateTime,jdbcType=BIGINT}, + pass_rate = #{record.passRate,jdbcType=VARCHAR}, + last_result = #{record.lastResult,jdbcType=VARCHAR}, + report_id = #{record.reportId,jdbcType=VARCHAR}, + create_user = #{record.createUser,jdbcType=VARCHAR}, + `order` = #{record.order,jdbcType=BIGINT}, + environment_type = #{record.environmentType,jdbcType=VARCHAR}, + environment_group_id = #{record.environmentGroupId,jdbcType=VARCHAR} + + + + + + update test_plan_api_scenario + + + test_plan_id = #{testPlanId,jdbcType=VARCHAR}, + + + api_scenario_id = #{apiScenarioId,jdbcType=VARCHAR}, + + + `status` = #{status,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=BIGINT}, + + + update_time = #{updateTime,jdbcType=BIGINT}, + + + pass_rate = #{passRate,jdbcType=VARCHAR}, + + + last_result = #{lastResult,jdbcType=VARCHAR}, + + + report_id = #{reportId,jdbcType=VARCHAR}, + + + create_user = #{createUser,jdbcType=VARCHAR}, + + + `order` = #{order,jdbcType=BIGINT}, + + + environment_type = #{environmentType,jdbcType=VARCHAR}, + + + environment_group_id = #{environmentGroupId,jdbcType=VARCHAR}, + + + environment = #{environment,jdbcType=LONGVARCHAR}, + + + where id = #{id,jdbcType=VARCHAR} + + + update test_plan_api_scenario + set test_plan_id = #{testPlanId,jdbcType=VARCHAR}, + api_scenario_id = #{apiScenarioId,jdbcType=VARCHAR}, + `status` = #{status,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=BIGINT}, + update_time = #{updateTime,jdbcType=BIGINT}, + pass_rate = #{passRate,jdbcType=VARCHAR}, + last_result = #{lastResult,jdbcType=VARCHAR}, + report_id = #{reportId,jdbcType=VARCHAR}, + create_user = #{createUser,jdbcType=VARCHAR}, + `order` = #{order,jdbcType=BIGINT}, + environment_type = #{environmentType,jdbcType=VARCHAR}, + environment_group_id = #{environmentGroupId,jdbcType=VARCHAR}, + environment = #{environment,jdbcType=LONGVARCHAR} + where id = #{id,jdbcType=VARCHAR} + + + update test_plan_api_scenario + set test_plan_id = #{testPlanId,jdbcType=VARCHAR}, + api_scenario_id = #{apiScenarioId,jdbcType=VARCHAR}, + `status` = #{status,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=BIGINT}, + update_time = #{updateTime,jdbcType=BIGINT}, + pass_rate = #{passRate,jdbcType=VARCHAR}, + last_result = #{lastResult,jdbcType=VARCHAR}, + report_id = #{reportId,jdbcType=VARCHAR}, + create_user = #{createUser,jdbcType=VARCHAR}, + `order` = #{order,jdbcType=BIGINT}, + environment_type = #{environmentType,jdbcType=VARCHAR}, + environment_group_id = #{environmentGroupId,jdbcType=VARCHAR} + where id = #{id,jdbcType=VARCHAR} + \ No newline at end of file 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 bc9529fdee..9ef9816eb3 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 @@ -56,4 +56,6 @@ public interface ExtApiDefinitionExecResultMapper { List selectRerunResult(@Param("reportId") String reportId); List selectByProjectIdAndLessThanTime(@Param("projectId") String projectId, @Param("time") long time); + + List selectByResourceIdsAndMaxCreateTime(@Param("ids") List resourceIds); } 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 9cad13b048..9d482e0fcb 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 @@ -416,6 +416,17 @@ + + 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 397b19e316..46db17b83b 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java @@ -10,7 +10,9 @@ import io.metersphere.api.dto.definition.ApiTestCaseRequest; import io.metersphere.api.dto.definition.BatchRunDefinitionRequest; import io.metersphere.api.dto.definition.TestPlanApiCaseDTO; import io.metersphere.api.exec.api.ApiCaseExecuteService; +import io.metersphere.api.exec.scenario.ApiScenarioEnvService; import io.metersphere.api.service.ApiDefinitionExecResultService; +import io.metersphere.api.service.ApiDefinitionService; import io.metersphere.api.service.ApiTestCaseService; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.ApiTestCaseMapper; @@ -29,6 +31,7 @@ import io.metersphere.track.dto.TestCaseReportStatusResultDTO; import io.metersphere.track.dto.TestPlanApiResultReportDTO; import io.metersphere.track.dto.TestPlanSimpleReportDTO; import io.metersphere.track.request.testcase.TestPlanApiCaseBatchRequest; +import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; @@ -69,6 +72,11 @@ public class TestPlanApiCaseService { private TestPlanService testPlanService; @Resource private EnvironmentGroupProjectService environmentGroupProjectService; + @Resource + private ApiDefinitionService apiDefinitionService; + @Resource + private ApiScenarioEnvService apiScenarioEnvService; + public TestPlanApiCase getInfo(String caseId, String testPlanId) { TestPlanApiCaseExample example = new TestPlanApiCaseExample(); @@ -135,7 +143,7 @@ public class TestPlanApiCaseService { } public int deleteByCaseId(String caseId) { - return this.deleteByCaseIds(Arrays.asList(caseId)); + return this.deleteByCaseIds(Arrays.asList(caseId)); } public int deleteByCaseIds(List caseIds) { @@ -368,9 +376,66 @@ public class TestPlanApiCaseService { return extTestPlanApiCaseMapper.getApiTestCaseById(testPlanApiCaseId); } + /** + * 计算测试计划中接口用例的相关数据 + * + * @param planId + * @param report + * @return 接口用例的最新执行报告 + */ public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) { List planReportCaseDTOS = extTestPlanApiCaseMapper.selectForPlanReport(planId); + //计算测试计划中接口用例的相关数据 calculatePlanReport(report, planReportCaseDTOS); + //记录接口用例的运行环境信息 + List idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList()); + this.initProjectEnvironment(report, idList, "ApiCase"); + } + + /** + * 初始化项目环境信息 + * + * @param report + * @param resourceIds 资源ID + * @param resourceType 资源类型 ApiCase/Scenario + */ + public void initProjectEnvironment(TestPlanSimpleReportDTO report, List resourceIds, String resourceType) { + 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(report, projectEnvMap); + }); + } else if (StringUtils.equalsIgnoreCase("Scenario", resourceType)) { + Map> projectEnvMap = apiScenarioEnvService.selectProjectEnvMapByTestPlanScenarioIds(resourceIds); + this.setProjectEnvMap(report, projectEnvMap); + } + } + + } + + private void setProjectEnvMap(TestPlanSimpleReportDTO report, Map> projectEnvMap) { + if (report != null && MapUtils.isNotEmpty(projectEnvMap)) { + if (report.getProjectEnvMap() == null) { + report.setProjectEnvMap(new LinkedHashMap<>()); + } + for (Map.Entry> entry : projectEnvMap.entrySet()) { + String projectName = entry.getKey(); + List envNameList = entry.getValue(); + if (report.getProjectEnvMap().containsKey(projectName)) { + envNameList.forEach(envName -> { + if (!report.getProjectEnvMap().get(projectName).contains(envName)) { + report.getProjectEnvMap().get(projectName).add(envName); + } + }); + } else { + report.getProjectEnvMap().put(projectName, envNameList); + } + } + } } public void calculatePlanReport(List apiReportIds, TestPlanSimpleReportDTO report) { 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 0505c752fd..bc2ed3718e 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java @@ -72,6 +72,8 @@ public class TestPlanScenarioCaseService { private TestPlanService testPlanService; @Resource private ProjectApplicationService projectApplicationService; + @Resource + private TestPlanApiCaseService testPlanApiCaseService; public List list(TestPlanScenarioRequest request) { request.setProjectId(null); @@ -96,15 +98,15 @@ public class TestPlanScenarioCaseService { apiTestCases.forEach(item -> { Project project = projectMap.get(item.getProjectId()); - if(project != null){ + if (project != null) { ProjectConfig config = projectApplicationService.getSpecificTypeValue(project.getId(), ProjectApplicationType.SCENARIO_CUSTOM_NUM.name()); boolean custom = config.getScenarioCustomNum(); if (custom) { item.setCustomNum(item.getCustomNum()); - }else { + } else { item.setCustomNum(item.getNum().toString()); } - }else { + } else { item.setCustomNum(item.getNum().toString()); } }); @@ -492,6 +494,9 @@ public class TestPlanScenarioCaseService { public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) { List planReportCaseDTOS = extTestPlanScenarioCaseMapper.selectForPlanReport(planId); calculatePlanReport(report, planReportCaseDTOS); + //记录接口用例的运行环境信息 + List idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList()); + testPlanApiCaseService.initProjectEnvironment(report, idList, "Scenario"); } public void calculatePlanReport(List reportIds, TestPlanSimpleReportDTO report) { @@ -499,7 +504,7 @@ public class TestPlanScenarioCaseService { calculatePlanReport(report, planReportCaseDTOS); } - public void calculatePlanReportByScenarioList(List scenarioList,TestPlanSimpleReportDTO report){ + public void calculatePlanReportByScenarioList(List scenarioList, TestPlanSimpleReportDTO report) { List planReportCaseDTOS = new ArrayList<>(); for (TestPlanFailureScenarioDTO scenario : scenarioList) { PlanReportCaseDTO dto = new PlanReportCaseDTO(); @@ -545,7 +550,7 @@ public class TestPlanScenarioCaseService { private void calculateScenarioResultDTO(PlanReportCaseDTO item, TestPlanScenarioStepCountDTO stepCount) { if (StringUtils.isNotBlank(item.getReportId())) { - APIScenarioReportResult apiScenarioReportResult = apiScenarioReportService.get(item.getReportId(),false); + APIScenarioReportResult apiScenarioReportResult = apiScenarioReportService.get(item.getReportId(), false); if (apiScenarioReportResult != null) { String content = apiScenarioReportResult.getContent(); if (StringUtils.isNotBlank(content)) { diff --git a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue index e87316827a..aab842c56f 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue @@ -60,7 +60,8 @@