fix(测试跟踪): 修复测试计划场景使用环境组时执行测试计划所选环境不对的问题

--bug=1015251 --user=宋天阳 【测试跟踪】多次切换环境后,在测试计划详情里和报告列表查看测试报告,显示的环境不一样
https://www.tapd.cn/55049933/s/1209606
This commit is contained in:
song-tianyang 2022-07-25 13:10:10 +08:00 committed by f2c-ci-robot[bot]
parent ff61886ea9
commit 50d33f9521
3 changed files with 345 additions and 305 deletions

View File

@ -5,19 +5,35 @@
<insert id="insertIfNotExists" parameterType="io.metersphere.base.domain.TestPlanApiScenario">
-- 查询没有数据再插入
INSERT INTO test_plan_api_scenario(id, test_plan_id, api_scenario_id, create_time, update_time, environment, `order`, environment_group_id, environment_type)
SELECT #{request.id}, #{request.testPlanId}, #{request.apiScenarioId}, #{request.createTime}, #{request.updateTime}, #{request.environment}, #{request.order}, #{request.environmentGroupId}, #{request.environmentType}
INSERT INTO test_plan_api_scenario(id, test_plan_id, api_scenario_id, create_time, update_time, environment,
`order`, environment_group_id, environment_type)
SELECT #{request.id},
#{request.testPlanId},
#{request.apiScenarioId},
#{request.createTime},
#{request.updateTime},
#{request.environment},
#{request.order},
#{request.environmentGroupId},
#{request.environmentType}
FROM DUAL
WHERE NOT EXISTS(
SELECT id FROM
test_plan_api_scenario
WHERE test_plan_id = #{request.testPlanId} and api_scenario_id = #{request.apiScenarioId}
SELECT id
FROM test_plan_api_scenario
WHERE test_plan_id = #{request.testPlanId}
and api_scenario_id = #{request.apiScenarioId}
)
</insert>
<select id="selectLegalDataByTestPlanId" resultType="io.metersphere.track.dto.testplan.TestPlanApiScenarioInfoDTO">
SELECT tpas.id, tpas.api_scenario_id,tpas.environment,apis.project_id FROM
test_plan_api_scenario tpas INNER JOIN api_scenario apis ON tpas.api_scenario_id = apis.id
SELECT tpas.id,
tpas.api_scenario_id,
tpas.environment,
tpas.environment_type,
tpas.environment_group_id,
apis.project_id
FROM test_plan_api_scenario tpas
INNER JOIN api_scenario apis ON tpas.api_scenario_id = apis.id
WHERE (apis.`status` IS NULL OR apis.`status` != 'Trash')
AND tpas.test_plan_id = #{0}
ORDER BY tpas.`order` DESC;
@ -117,7 +133,10 @@
</select>
<select id="selectByIds" resultType="io.metersphere.base.domain.TestPlanApiScenario">
select t.* from test_plan_api_scenario t where t.id in (${ids}) ORDER BY FIND_IN_SET(t.id,${oderId})
select t.*
from test_plan_api_scenario t
where t.id in (${ids})
ORDER BY FIND_IN_SET(t.id, ${oderId})
</select>
<select id="selectIds" resultType="java.lang.String">
select
@ -207,8 +226,7 @@
<select id="getExecResultByPlanId" resultType="java.lang.String">
select last_result
from
test_plan_api_scenario
from test_plan_api_scenario
where test_plan_id = #{planId}
AND api_scenario_id in (SELECT id FROM api_scenario WHERE (`status` is null or `status` != 'Trash'))
</select>
@ -232,9 +250,15 @@
where t.test_plan_id = #{planId}
</select>
<select id="selectForPlanReport" resultType="io.metersphere.track.dto.PlanReportCaseDTO">
select id,last_result as status, report_id, api_scenario_id as caseId from test_plan_api_scenario where test_plan_id = #{planId}
select id, last_result as status, report_id, api_scenario_id as caseId
from test_plan_api_scenario
where test_plan_id = #{planId}
and api_scenario_id IN (
SELECT id FROM api_scenario where status is null or status != 'Trash'
SELECT id
FROM api_scenario
where status is null
or status
!= 'Trash'
)
</select>
<select id="getFailureList" resultType="io.metersphere.api.dto.automation.TestPlanFailureScenarioDTO">
@ -290,16 +314,24 @@
</select>
<select id="getProjectIdById" resultType="java.lang.String">
SELECT project_id FROM test_plan WHERE id in (
SELECT test_plan_id FROM test_plan_api_scenario WHERE id = #{0}
SELECT project_id
FROM test_plan
WHERE id in (
SELECT test_plan_id
FROM test_plan_api_scenario
WHERE id = #{0}
)
</select>
<select id="selectPlanIds" resultType="java.lang.String">
select DISTINCT test_plan_id from test_plan_api_scenario;
select DISTINCT test_plan_id
from test_plan_api_scenario;
</select>
<select id="getIdsOrderByUpdateTime" resultType="java.lang.String">
select id from test_plan_api_scenario where test_plan_id = #{planId} order by update_time ASC;
select id
from test_plan_api_scenario
where test_plan_id = #{planId}
order by update_time ASC;
</select>
<select id="getLastOrder" resultType="java.lang.Long">

View File

@ -10,4 +10,6 @@ public class TestPlanApiScenarioInfoDTO {
private String apiScenarioId;
private String environment;
private String projectId;
private String environmentType;
private String environmentGroupId;
}

View File

@ -299,11 +299,20 @@ public class TestPlanReportService {
}
for (TestPlanApiScenarioInfoDTO model : testPlanApiScenarioList) {
Map<String, String> envMap = null;
if (StringUtils.equalsIgnoreCase("group", model.getEnvironmentType()) && StringUtils.isNotEmpty(model.getEnvironmentGroupId())) {
envMap = environmentGroupProjectService.getEnvMap(model.getEnvironmentGroupId());
} else {
if (MapUtils.isNotEmpty(selectEnvMap) && selectEnvMap.containsKey(model.getProjectId())) {
runInfoDTO.putScenarioRunInfo(model.getId(), model.getProjectId(), selectEnvMap.get(model.getProjectId()));
} else if (StringUtils.isNotEmpty(model.getEnvironment())) {
try {
Map<String, String> envMap = JSONObject.parseObject(model.getEnvironment(), Map.class);
envMap = JSONObject.parseObject(model.getEnvironment(), Map.class);
} catch (Exception e) {
LogUtil.error("解析场景环境失败!", e);
}
}
}
if (MapUtils.isNotEmpty(envMap)) {
for (Map.Entry<String, String> entry : envMap.entrySet()) {
String projectId = entry.getKey();
@ -311,9 +320,6 @@ public class TestPlanReportService {
runInfoDTO.putScenarioRunInfo(model.getId(), projectId, envIdStr);
}
}
} catch (Exception ignore) {
}
}
}
for (TestPlanApiCaseInfoDTO model : testPlanApiCaseList) {
if (MapUtils.isNotEmpty(selectEnvMap) && selectEnvMap.containsKey(model.getProjectId())) {