fix(测试计划): 计划详情跨项目模块筛选问题

This commit is contained in:
song-cc-rock 2024-10-18 14:05:39 +08:00 committed by Craftsman
parent f713d8cf78
commit be6fe24b60
8 changed files with 211 additions and 59 deletions

View File

@ -604,10 +604,17 @@
</include> </include>
</foreach> </foreach>
<foreach collection="${combineSearch}.systemFieldConditions" item="condition"> <foreach collection="${combineSearch}.systemFieldConditions" item="condition">
<include refid="io.metersphere.system.mapper.BaseMapper.commonSystemFieldConditions"> <include refid="io.metersphere.system.mapper.BaseMapper.baseSystemFieldConditions">
<property name="condition" value="condition"/> <property name="condition" value="condition"/>
<property name="tablePrefix" value="atc"/> <property name="tablePrefix" value="atc"/>
</include> </include>
<!-- 模块ID -->
<if test="condition.name == 'moduleId'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="a.module_id"/>
</include>
</if>
<!-- 协议 --> <!-- 协议 -->
<if test="condition.name == 'protocol'"> <if test="condition.name == 'protocol'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition"> <include refid="io.metersphere.system.mapper.BaseMapper.condition">

View File

@ -3,6 +3,16 @@
<mapper namespace="io.metersphere.system.mapper.BaseMapper"> <mapper namespace="io.metersphere.system.mapper.BaseMapper">
<sql id="commonSystemFieldConditions"> <sql id="commonSystemFieldConditions">
<include refid="io.metersphere.system.mapper.BaseMapper.baseSystemFieldConditions" />
<if test="condition.name == 'moduleId'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="${tablePrefix}.module_id"/>
</include>
</if>
</sql>
<sql id="baseSystemFieldConditions">
<if test="condition.name == 'name'"> <if test="condition.name == 'name'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition"> <include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/> <property name="condition" value="condition"/>
@ -15,12 +25,6 @@
<property name="column" value="${tablePrefix}.num"/> <property name="column" value="${tablePrefix}.num"/>
</include> </include>
</if> </if>
<if test="condition.name == 'moduleId'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="${tablePrefix}.module_id"/>
</include>
</if>
<if test="condition.name == 'createUser'"> <if test="condition.name == 'createUser'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition"> <include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/> <property name="condition" value="condition"/>

View File

@ -90,7 +90,7 @@
project_version.name as version_name project_version.name as version_name
from api_definition a left join project_version on project_version.id = a.version_id from api_definition a left join project_version on project_version.id = a.version_id
where a.deleted = false where a.deleted = false
<include refid="queryWhereCondition"/> <include refid="queryWhereApiDefinitionCondition"/>
and exists ( and exists (
select id select id
from api_test_case atc from api_test_case atc
@ -107,7 +107,7 @@
</select> </select>
<sql id="queryWhereCondition"> <sql id="queryWhereApiDefinitionCondition">
<if test="request.moduleIds != null and request.moduleIds.size() > 0"> <if test="request.moduleIds != null and request.moduleIds.size() > 0">
and a.module_id in and a.module_id in
<foreach collection="request.moduleIds" item="moduleId" separator="," open="(" close=")"> <foreach collection="request.moduleIds" item="moduleId" separator="," open="(" close=")">
@ -135,8 +135,10 @@
<property name="filter" value="request.filter"/> <property name="filter" value="request.filter"/>
</include> </include>
<include refid="combine"> <include refid="queryApiDefinitionCombine">
<property name="combineSearch" value="request.combineSearch"/> <property name="combineSearch" value="request.combineSearch"/>
<property name="projectId" value="${request.projectId}"/>
<property name="deleted" value="${request.deleted}"/>
</include> </include>
<include refid="queryVersionCondition"> <include refid="queryVersionCondition">
@ -383,6 +385,106 @@
</if> </if>
</sql> </sql>
<sql id="queryApiDefinitionCombine">
<trim prefix="AND">
<trim prefix="(" suffix=")" suffixOverrides="AND|OR">
<if test="${combineSearch} != null">
<foreach collection="${combineSearch}.userViewConditions" item="condition">
<if test="condition.name == 'createUser'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="a.create_user"/>
</include>
</if>
<include refid="io.metersphere.system.mapper.BaseMapper.queryType">
<property name="searchMode" value="${combineSearch}.searchMode"/>
</include>
</foreach>
<foreach collection="${combineSearch}.systemFieldConditions" item="condition">
<include refid="io.metersphere.system.mapper.BaseMapper.commonSystemFieldConditions">
<property name="condition" value="condition"/>
<property name="tablePrefix" value="a"/>
</include>
<if test="condition.name == 'protocol'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="a.protocol"/>
</include>
</if>
<if test="condition.name == 'status'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="a.status"/>
</include>
</if>
<if test="condition.name == 'method'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="a.method"/>
</include>
</if>
<if test="condition.name == 'path'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="a.path"/>
</include>
</if>
<if test="condition.name == 'caseTotal'">
<choose>
<when test="condition.operator == 'NOT_EMPTY'">
a.id in (
select api_definition_id from api_test_case where deleted = ${deleted}
and project_id = '${projectId}'
)
</when>
<when test="condition.operator == 'EMPTY'">
a.id not in (
select api_definition_id from api_test_case where deleted = ${deleted}
and project_id = '${projectId}'
)
</when>
<when test="(condition.operator == 'LT' and condition.value &lt; 1) or (condition.operator == 'EQUALS' and condition.value &lt; 0)">
1=2
</when>
<otherwise>
<if test="condition.operator == 'LT' or (condition.operator == 'EQUALS' and condition.value == 0)">
a.id not in (
select api_definition_id from api_test_case where deleted = ${deleted}
and project_id = '${projectId}'
)
<if test="condition.value &gt; 1">
OR
</if>
</if>
<if test="(condition.operator == 'EQUALS' and condition.value &gt; 0) or (condition.operator == 'LT' and condition.value &gt; 1) or condition.operator == 'GT'">
a.id in (
select api_definition_id from api_test_case where deleted = ${deleted}
and project_id = '${projectId}'
group by api_definition_id having
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="count(id)"/>
</include>
)
</if>
</otherwise>
</choose>
</if>
<include refid="io.metersphere.system.mapper.BaseMapper.queryType">
<property name="searchMode" value="${combineSearch}.searchMode"/>
</include>
</foreach>
<include refid="io.metersphere.system.mapper.BaseMapper.customFiledConditions">
<property name="mainIdColumn" value="a.id"/>
<property name="associationTable" value="api_definition_custom_field"/>
<property name="associationIdColumn" value="api_id"/>
<property name="combineSearch" value="${combineSearch}"/>
</include>
</if>
</trim>
</trim>
</sql>
<sql id="combine"> <sql id="combine">
<trim prefix="AND"> <trim prefix="AND">
<trim prefix="(" suffix=")" suffixOverrides="AND|OR"> <trim prefix="(" suffix=")" suffixOverrides="AND|OR">
@ -399,10 +501,27 @@
</include> </include>
</foreach> </foreach>
<foreach collection="${combineSearch}.systemFieldConditions" item="condition"> <foreach collection="${combineSearch}.systemFieldConditions" item="condition">
<include refid="io.metersphere.system.mapper.BaseMapper.commonSystemFieldConditions"> <include refid="io.metersphere.system.mapper.BaseMapper.baseSystemFieldConditions">
<property name="condition" value="condition"/> <property name="condition" value="condition"/>
<property name="tablePrefix" value="atc"/> <property name="tablePrefix" value="atc"/>
</include> </include>
<!-- 所属模块(项目ID_模块ID 组合查询) -->
<if test="condition.name == 'moduleId'">
<choose>
<when test="condition.operator == 'IN'">
concat(a.project_id, '_', a.module_id) in
<foreach collection="condition.value" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</when>
<when test="condition.operator == 'NOT_IN'">
concat(a.project_id, '_', a.module_id) not in
<foreach collection="condition.value" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</when>
</choose>
</if>
<!-- 测试点 --> <!-- 测试点 -->
<if test="condition.name == 'testPlanCollectionId'"> <if test="condition.name == 'testPlanCollectionId'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition"> <include refid="io.metersphere.system.mapper.BaseMapper.condition">
@ -561,8 +680,7 @@
</sql> </sql>
<select id="countModuleIdByRequest" resultType="io.metersphere.functional.dto.FunctionalCaseModuleCountDTO"> <select id="countModuleIdByRequest" resultType="io.metersphere.functional.dto.FunctionalCaseModuleCountDTO">
SELECT CASE WHEN a.module_id = 'root' THEN CONCAT(atc.project_id, '_', a.module_id) ELSE a.module_id END AS SELECT concat(atc.project_id, '_', a.module_id) as moduleId,
moduleId,
count(atc.id) AS dataCount, atc.project_id AS projectId, project.name AS projectName count(atc.id) AS dataCount, atc.project_id AS projectId, project.name AS projectName
FROM test_plan_api_case t FROM test_plan_api_case t
INNER JOIN api_test_case atc ON t.api_case_id = atc.id INNER JOIN api_test_case atc ON t.api_case_id = atc.id

View File

@ -265,10 +265,27 @@
</include> </include>
</foreach> </foreach>
<foreach collection="${combineSearch}.systemFieldConditions" item="condition"> <foreach collection="${combineSearch}.systemFieldConditions" item="condition">
<include refid="io.metersphere.system.mapper.BaseMapper.commonSystemFieldConditions"> <include refid="io.metersphere.system.mapper.BaseMapper.baseSystemFieldConditions">
<property name="condition" value="condition"/> <property name="condition" value="condition"/>
<property name="tablePrefix" value="api_scenario"/> <property name="tablePrefix" value="api_scenario"/>
</include> </include>
<!-- 所属模块(项目ID_模块ID 组合查询) -->
<if test="condition.name == 'moduleId'">
<choose>
<when test="condition.operator == 'IN'">
concat(api_scenario.project_id, '_', api_scenario.module_id) in
<foreach collection="condition.value" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</when>
<when test="condition.operator == 'NOT_IN'">
concat(api_scenario.project_id, '_', api_scenario.module_id) not in
<foreach collection="condition.value" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</when>
</choose>
</if>
<!-- 测试点 --> <!-- 测试点 -->
<if test="condition.name == 'testPlanCollectionId'"> <if test="condition.name == 'testPlanCollectionId'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition"> <include refid="io.metersphere.system.mapper.BaseMapper.condition">
@ -409,8 +426,7 @@
<select id="countModuleIdByRequest" resultType="io.metersphere.functional.dto.FunctionalCaseModuleCountDTO"> <select id="countModuleIdByRequest" resultType="io.metersphere.functional.dto.FunctionalCaseModuleCountDTO">
SELECT CASE WHEN api_scenario.module_id = 'root' THEN CONCAT(api_scenario.project_id, '_', SELECT concat(api_scenario.project_id, '_', api_scenario.module_id) as moduleId,
api_scenario.module_id) ELSE api_scenario.module_id END AS moduleId,
count(api_scenario.id) AS dataCount, api_scenario.project_id AS projectId, project.name AS projectName count(api_scenario.id) AS dataCount, api_scenario.project_id AS projectId, project.name AS projectName
FROM test_plan_api_scenario FROM test_plan_api_scenario
INNER JOIN api_scenario on api_scenario.id = test_plan_api_scenario.api_scenario_id INNER JOIN api_scenario on api_scenario.id = test_plan_api_scenario.api_scenario_id

View File

@ -310,10 +310,27 @@
</include> </include>
</foreach> </foreach>
<foreach collection="${combineSearch}.systemFieldConditions" item="condition"> <foreach collection="${combineSearch}.systemFieldConditions" item="condition">
<include refid="io.metersphere.system.mapper.BaseMapper.commonSystemFieldConditions"> <include refid="io.metersphere.system.mapper.BaseMapper.baseSystemFieldConditions">
<property name="condition" value="condition"/> <property name="condition" value="condition"/>
<property name="tablePrefix" value="functional_case"/> <property name="tablePrefix" value="functional_case"/>
</include> </include>
<!-- 所属模块(项目ID_模块ID 组合查询) -->
<if test="condition.name == 'moduleId'">
<choose>
<when test="condition.operator == 'IN'">
concat(functional_case.project_id, '_', functional_case.module_id) in
<foreach collection="condition.value" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</when>
<when test="condition.operator == 'NOT_IN'">
concat(functional_case.project_id, '_', functional_case.module_id) not in
<foreach collection="condition.value" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</when>
</choose>
</if>
<!-- 测试点 --> <!-- 测试点 -->
<if test="condition.name == 'testPlanCollectionId'"> <if test="condition.name == 'testPlanCollectionId'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition"> <include refid="io.metersphere.system.mapper.BaseMapper.condition">
@ -552,8 +569,7 @@
</select> </select>
<select id="countModuleIdByRequest" resultType="io.metersphere.functional.dto.FunctionalCaseModuleCountDTO"> <select id="countModuleIdByRequest" resultType="io.metersphere.functional.dto.FunctionalCaseModuleCountDTO">
SELECT CASE WHEN functional_case.module_id = 'root' THEN concat(functional_case.project_id, '_', SELECT concat(functional_case.project_id, '_', functional_case.module_id) AS moduleId,
functional_case.module_id) ElSE functional_case.module_id END AS moduleId,
count(functional_case.id) As dataCount, functional_case.project_id As projectId, project.name As projectName count(functional_case.id) As dataCount, functional_case.project_id As projectId, project.name As projectName
FROM test_plan_functional_case FROM test_plan_functional_case
LEFT JOIN functional_case ON test_plan_functional_case.functional_case_id = functional_case.id LEFT JOIN functional_case ON test_plan_functional_case.functional_case_id = functional_case.id

View File

@ -513,10 +513,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
} }
List<BaseTreeNode> baseTreeNodes = apiDefinitionModuleService.buildTreeAndCountResource(nodeByNodeIds, needCreateRoot, Translator.get("api_unplanned_request")); List<BaseTreeNode> baseTreeNodes = apiDefinitionModuleService.buildTreeAndCountResource(nodeByNodeIds, needCreateRoot, Translator.get("api_unplanned_request"));
for (BaseTreeNode baseTreeNode : baseTreeNodes) { for (BaseTreeNode baseTreeNode : baseTreeNodes) {
if (StringUtils.equals(baseTreeNode.getId(), ModuleConstants.DEFAULT_NODE_ID)) { baseTreeNode.setId(projectId + "_" + baseTreeNode.getId());
// 默认拼项目id
baseTreeNode.setId(projectId + "_" + ModuleConstants.DEFAULT_NODE_ID);
}
projectNode.addChild(baseTreeNode); projectNode.addChild(baseTreeNode);
} }
}); });

View File

@ -67,7 +67,6 @@ import org.springframework.validation.annotation.Validated;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@ -671,10 +670,7 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
} }
List<BaseTreeNode> baseTreeNodes = apiScenarioModuleService.buildTreeAndCountResource(nodeByNodeIds, needCreateRoot, Translator.get("api_unplanned_scenario")); List<BaseTreeNode> baseTreeNodes = apiScenarioModuleService.buildTreeAndCountResource(nodeByNodeIds, needCreateRoot, Translator.get("api_unplanned_scenario"));
for (BaseTreeNode baseTreeNode : baseTreeNodes) { for (BaseTreeNode baseTreeNode : baseTreeNodes) {
if (StringUtils.equals(baseTreeNode.getId(), ModuleConstants.DEFAULT_NODE_ID)) { baseTreeNode.setId(projectId + "_" + baseTreeNode.getId());
// 默认拼项目id
baseTreeNode.setId(projectId + "_" + ModuleConstants.DEFAULT_NODE_ID);
}
projectNode.addChild(baseTreeNode); projectNode.addChild(baseTreeNode);
} }
}); });

View File

@ -358,10 +358,8 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
} }
List<BaseTreeNode> baseTreeNodes = functionalCaseModuleService.buildTreeAndCountResource(nodeByNodeIds, needCreatRoot, Translator.get("functional_case.module.default.name")); List<BaseTreeNode> baseTreeNodes = functionalCaseModuleService.buildTreeAndCountResource(nodeByNodeIds, needCreatRoot, Translator.get("functional_case.module.default.name"));
for (BaseTreeNode baseTreeNode : baseTreeNodes) { for (BaseTreeNode baseTreeNode : baseTreeNodes) {
if (StringUtils.equals(baseTreeNode.getId(), ModuleConstants.DEFAULT_NODE_ID)) { // 节点ID, 拼接项目ID
// 默认拼项目id baseTreeNode.setId(projectId + "_" + baseTreeNode.getId());
baseTreeNode.setId(projectId + "_" + ModuleConstants.DEFAULT_NODE_ID);
}
projectNode.addChild(baseTreeNode); projectNode.addChild(baseTreeNode);
} }
}); });