fix(测试跟踪): 测试跟踪首页关联用例数量统计忽略掉回收站中的接口和场景

--bug=1015414 --user=宋天阳 【测试跟踪】首页-关联用例数量统计,统计了回收站中的接口用例和场景
https://www.tapd.cn/55049933/s/1212890
This commit is contained in:
song-tianyang 2022-07-26 23:23:38 +08:00 committed by 建国
parent 41fa8c8839
commit 35d78b367f
1 changed files with 223 additions and 138 deletions

View File

@ -138,7 +138,10 @@
</if> </if>
</sql> </sql>
<update id="updateTestCaseCustomNumByProjectId"> <update id="updateTestCaseCustomNumByProjectId">
update test_case set custom_num = num where (custom_num is null or custom_num = '') and project_id = #{projectId} update test_case
set custom_num = num
where (custom_num is null or custom_num = '')
and project_id = #{projectId}
</update> </update>
<select id="getTestCaseByNotInReview" resultType="io.metersphere.track.dto.TestCaseDTO"> <select id="getTestCaseByNotInReview" resultType="io.metersphere.track.dto.TestCaseDTO">
select select
@ -151,7 +154,8 @@
project_version.id as versionId project_version.id as versionId
from test_case from test_case
left join test_case_review_test_case as T2 on test_case.id=T2.case_id and T2.review_id =#{request.reviewId} left join test_case_review_test_case as T2 on test_case.id=T2.case_id and T2.review_id =#{request.reviewId}
left join project_version on test_case.version_id = project_version.id and test_case.project_id = project_version.project_id left join project_version on test_case.version_id = project_version.id and test_case.project_id =
project_version.project_id
<include refid="notInQueryWhereCondition"/> <include refid="notInQueryWhereCondition"/>
and T2.case_id is null and T2.case_id is null
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/> <include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
@ -214,7 +218,8 @@
</select> </select>
<select id="getTestCaseNames" resultType="io.metersphere.base.domain.TestCase"> <select id="getTestCaseNames" resultType="io.metersphere.base.domain.TestCase">
select test_case.id, test_case.name, test_case.priority, test_case.type, test_case.review_status,test_case.num,test_case.custom_num select test_case.id, test_case.name, test_case.priority, test_case.type,
test_case.review_status,test_case.num,test_case.custom_num
from test_case from test_case
<where> <where>
<if test="request.combine != null"> <if test="request.combine != null">
@ -276,7 +281,8 @@
</foreach> </foreach>
</if> </if>
<if test="request.selectFields == null or request.selectFields.size() == 0"> <if test="request.selectFields == null or request.selectFields.size() == 0">
test_case.id, test_case.node_id, test_case.node_path, test_case.project_id, test_case.`name`, test_case.version_id, test_case.id, test_case.node_id, test_case.node_path, test_case.project_id, test_case.`name`,
test_case.version_id,
test_case.`type`, test_case.maintainer, test_case.priority, test_case.`method`, test_case.`type`, test_case.maintainer, test_case.priority, test_case.`method`,
test_case.create_time, test_case.update_time, test_case.test_id, test_case.sort, test_case.num, test_case.create_time, test_case.update_time, test_case.test_id, test_case.sort, test_case.num,
test_case.other_test_name, test_case.review_status, test_case.tags, test_case.other_test_name, test_case.review_status, test_case.tags,
@ -325,7 +331,8 @@
<select id="getTestReviewRelateCountNodes" resultType="io.metersphere.track.dto.TestCaseNodeDTO"> <select id="getTestReviewRelateCountNodes" resultType="io.metersphere.track.dto.TestCaseNodeDTO">
select tcn.id, count(*) as caseNum, test_case.project_id select tcn.id, count(*) as caseNum, test_case.project_id
from test_case from test_case
left join test_case_review_test_case tcrtc on tcrtc.case_id = test_case.id and tcrtc.review_id = #{request.reviewId} left join test_case_review_test_case tcrtc on tcrtc.case_id = test_case.id and tcrtc.review_id =
#{request.reviewId}
left join test_case_node tcn on test_case.node_id = tcn.id left join test_case_node tcn on test_case.node_id = tcn.id
<include refid="queryWhereCondition"/> <include refid="queryWhereCondition"/>
and tcrtc.case_id is null and tcrtc.case_id is null
@ -333,15 +340,18 @@
</select> </select>
<select id="listByMethod" resultType="io.metersphere.track.dto.TestCaseDTO"> <select id="listByMethod" resultType="io.metersphere.track.dto.TestCaseDTO">
select load_test.id, load_test.name, load_test.project_id,'性能测试' as type, project_version.name as version_name select load_test.id, load_test.name, load_test.project_id,'性能测试' as type, project_version.name as version_name
from load_test inner join project_version on project_version.project_id = load_test.project_id and project_version.id = load_test.version_id from load_test inner join project_version on project_version.project_id = load_test.project_id and
project_version.id = load_test.version_id
<where> <where>
<if test="request.projectId!=null"> <if test="request.projectId!=null">
and load_test.project_id= #{request.projectId} and load_test.project_id= #{request.projectId}
</if> </if>
</where> </where>
UNION ALL UNION ALL
select api_scenario.id, api_scenario.name, api_scenario.project_id,'接口场景' as type, project_version.name as version_name select api_scenario.id, api_scenario.name, api_scenario.project_id,'接口场景' as type, project_version.name as
from api_scenario inner join project_version on project_version.project_id = api_scenario.project_id and project_version.id = api_scenario.version_id version_name
from api_scenario inner join project_version on project_version.project_id = api_scenario.project_id and
project_version.id = api_scenario.version_id
<where> <where>
<if test="request.projectId!=null"> <if test="request.projectId!=null">
and api_scenario.project_id= #{request.projectId} and api_scenario.project_id= #{request.projectId}
@ -384,8 +394,7 @@
SELECT * SELECT *
FROM test_case FROM test_case
WHERE test_case.project_id = #{projectId} WHERE test_case.project_id = #{projectId}
ORDER BY num DESC ORDER BY num DESC LIMIT 1;
LIMIT 1;
</select> </select>
<select id="checkIsHave" resultType="int"> <select id="checkIsHave" resultType="int">
@ -657,10 +666,28 @@
</if> </if>
<include refid="filters"/> <include refid="filters"/>
<if test="request.caseCoverage == 'uncoverage' "> <if test="request.caseCoverage == 'uncoverage' ">
and test_case.id not in (select distinct test_case_test.test_case_id from test_case_test) and test_case.id not in (
SELECT test_case_id FROM test_case_test WHERE test_type = 'testCase' and test_id IN (select id FROM
api_test_case WHERE `STATUS` is null or status != 'Trash')
UNION
SELECT test_case_id FROM test_case_test WHERE test_type = 'performance' and test_id IN (select id from
load_test)
UNION
SELECT test_case_id FROM test_case_test WHERE test_type = 'automation' and test_id IN (select id FROM
api_scenario WHERE `STATUS` != 'Trash')
)
</if> </if>
<if test="request.caseCoverage == 'coverage' "> <if test="request.caseCoverage == 'coverage' ">
and test_case.id in (select distinct test_case_test.test_case_id from test_case_test) and test_case.id in (
SELECT test_case_id FROM test_case_test WHERE test_type = 'testCase' and test_id IN (select id FROM
api_test_case WHERE `STATUS` is null or status != 'Trash')
UNION
SELECT test_case_id FROM test_case_test WHERE test_type = 'performance' and test_id IN (select id from
load_test)
UNION
SELECT test_case_id FROM test_case_test WHERE test_type = 'automation' and test_id IN (select id FROM
api_scenario WHERE `STATUS` != 'Trash')
)
</if> </if>
<include refid="queryVersionCondition"> <include refid="queryVersionCondition">
<property name="versionTable" value="test_case"/> <property name="versionTable" value="test_case"/>
@ -739,38 +766,88 @@
</select> </select>
<select id="countCreatedThisWeek" resultType="java.lang.Long"> <select id="countCreatedThisWeek" resultType="java.lang.Long">
SELECT count(DISTINCT ref_id) AS countNumber FROM test_case WHERE test_case.project_id = #{projectId} and test_case.status != 'Trash' and latest = 1 SELECT count(DISTINCT ref_id) AS countNumber
AND create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp} FROM test_case
WHERE test_case.project_id = #{projectId}
and test_case.status != 'Trash' and latest = 1
AND create_time BETWEEN #{firstDayTimestamp}
AND #{lastDayTimestamp}
</select> </select>
<select id="countStatus" resultType="io.metersphere.track.response.TrackCountResult"> <select id="countStatus" resultType="io.metersphere.track.response.TrackCountResult">
SELECT review_status AS groupField,count(id) AS countNumber FROM test_case SELECT review_status AS groupField, count(id) AS countNumber
WHERE project_id = #{projectId} and test_case.status != 'Trash' and latest = 1 FROM test_case
WHERE project_id = #{projectId}
and test_case.status != 'Trash' and latest = 1
GROUP BY test_case.review_status GROUP BY test_case.review_status
</select> </select>
<select id="countRelevance" resultType="io.metersphere.track.response.TrackCountResult"> <select id="countRelevance" resultType="io.metersphere.track.response.TrackCountResult">
SELECT test_case_test.test_type AS groupField, count(test_case_test.test_case_id) AS countNumber SELECT test_case_test.test_type AS groupField,
FROM test_case join test_case_test on test_case.id = test_case_test.test_case_id count(test_case_test.test_case_id) AS countNumber
WHERE test_case.project_id = #{projectId} and test_case.status != 'Trash' and latest = 1 GROUP BY test_case_test.test_type FROM test_case
INNER JOIN (SELECT test_case_id, test_id, test_type
FROM test_case_test
WHERE test_type = 'testCase'
and test_id IN (select id FROM api_test_case WHERE `STATUS` is null or status != 'Trash')
UNION
SELECT test_case_id, test_id, test_type
FROM test_case_test
WHERE test_type = 'performance'
and test_id IN (select id from load_test)
UNION
SELECT test_case_id, test_id, test_type
FROM test_case_test
WHERE test_type = 'automation'
and test_id IN (select id FROM api_scenario WHERE `STATUS` != 'Trash')
)
test_case_test
ON test_case.id = test_case_test.test_case_id
WHERE
test_case.project_id = #{projectId}
AND test_case.STATUS != 'Trash'
AND latest = 1
GROUP BY
test_case_test.test_type
</select> </select>
<select id="countRelevanceCreatedThisWeek" resultType="java.lang.Long"> <select id="countRelevanceCreatedThisWeek" resultType="java.lang.Long">
SELECT count(distinct test_case.ref_id) AS countNumber FROM test_case join test_case_test on test_case.id = test_case_test.test_case_id SELECT count(distinct test_case.ref_id) AS countNumber
WHERE test_case.project_id = #{projectId} and test_case.status != 'Trash' and latest = 1 FROM test_case
AND test_case_test.create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp} join test_case_test on test_case.id = test_case_test.test_case_id
WHERE test_case.project_id = #{projectId}
and test_case.status != 'Trash' and latest = 1
AND test_case_test.create_time BETWEEN #{firstDayTimestamp}
AND #{lastDayTimestamp}
</select> </select>
<select id="countCoverage" resultType="int"> <select id="countCoverage" resultType="int">
select count(test_case.id) from test_case where test_case.project_id = #{projectId} and test_case.status != 'Trash' and latest = 1 select count(test_case.id)
and test_case.id in (select distinct test_case_test.test_case_id from test_case_test) from test_case
where test_case.project_id = #{projectId}
and test_case.status != 'Trash' and latest = 1
and test_case.id in (
SELECT test_case_id FROM test_case_test WHERE test_type = 'testCase' and test_id IN (select id FROM
api_test_case WHERE `STATUS` is null or status != 'Trash')
UNION
SELECT test_case_id FROM test_case_test WHERE test_type = 'performance' and test_id IN (select id from load_test)
UNION
SELECT test_case_id FROM test_case_test WHERE test_type = 'automation' and test_id IN (select id FROM
api_scenario WHERE `STATUS` != 'Trash')
)
</select> </select>
<select id="countFuncMaintainer" resultType="io.metersphere.track.response.TrackCountResult"> <select id="countFuncMaintainer" resultType="io.metersphere.track.response.TrackCountResult">
select count(tc.id) as countNumber, user.name as groupField from test_case tc right join user on tc.maintainer = user.id select count(tc.id) as countNumber, user.name as groupField
where tc.project_id = #{projectId} and tc.status != 'Trash' and tc.latest = 1 from test_case tc
right join user on tc.maintainer = user.id
where tc.project_id = #{projectId}
and tc.status != 'Trash' and tc.latest = 1
group by tc.maintainer group by tc.maintainer
</select> </select>
<select id="countRelevanceMaintainer" resultType="io.metersphere.track.response.TrackCountResult"> <select id="countRelevanceMaintainer" resultType="io.metersphere.track.response.TrackCountResult">
select count(tc.id) as countNumber, user.name as groupField from test_case tc right join user on tc.maintainer = user.id select count(tc.id) as countNumber, user.name as groupField
where tc.project_id = #{projectId} and tc.status != 'Trash' and tc.latest = 1 and tc.id in (select distinct test_case_test.test_case_id from test_case_test) from test_case tc
right join user on tc.maintainer = user.id
where tc.project_id = #{projectId}
and tc.status != 'Trash' and tc.latest = 1 and tc.id in (select distinct test_case_test.test_case_id from test_case_test)
group by tc.maintainer group by tc.maintainer
</select> </select>
<select id="getTestPlanBug" resultType="int"> <select id="getTestPlanBug" resultType="int">
@ -788,50 +865,57 @@
</select> </select>
<select id="getTestPlanCase" resultType="int"> <select id="getTestPlanCase" resultType="int">
select count(s) select count(s)
from ( from (select tptc.id as s
select tptc.id as s from test_plan_test_case tptc
from test_plan_test_case tptc join test_case on tptc.case_id = test_case.id join test_case on tptc.case_id = test_case.id
where tptc.plan_id = #{planId} and (test_case.status != 'Trash' or test_case.status is null) where tptc.plan_id = #{planId}
and (test_case.status != 'Trash' or test_case.status is null)
union all union all
select tpas.id as s select tpas.id as s
from test_plan_api_scenario tpas join api_scenario on tpas.api_scenario_id = api_scenario.id from test_plan_api_scenario tpas
where tpas.test_plan_id = #{planId} and (api_scenario.status != 'Trash' or api_scenario.status is null) join api_scenario on tpas.api_scenario_id = api_scenario.id
where tpas.test_plan_id = #{planId}
and (api_scenario.status != 'Trash' or api_scenario.status is null)
union all union all
select tpac.id as s select tpac.id as s
from test_plan_api_case tpac join api_test_case on tpac.api_case_id = api_test_case.id from test_plan_api_case tpac
join api_test_case on tpac.api_case_id = api_test_case.id
join api_definition on api_test_case.api_definition_id = api_definition.id join api_definition on api_test_case.api_definition_id = api_definition.id
where tpac.test_plan_id = #{planId} and (api_definition.status != 'Trash' or api_definition.status is null) where tpac.test_plan_id = #{planId}
and (api_definition.status != 'Trash' or api_definition.status is null)
union all union all
select tplc.id as s select tplc.id as s
from test_plan_load_case tplc join load_test on tplc.load_case_id = load_test.id from test_plan_load_case tplc
where tplc.test_plan_id = #{planId} join load_test on tplc.load_case_id = load_test.id
) as temp where tplc.test_plan_id = #{planId}) as temp
</select> </select>
<select id="getTestPlanPassCase" resultType="int"> <select id="getTestPlanPassCase" resultType="int">
select count(s) select count(s)
from ( from (select id as s
select id as s
from test_plan_test_case tptc from test_plan_test_case tptc
where tptc.plan_id = #{planId} and tptc.status = 'Pass' where tptc.plan_id = #{planId}
and tptc.status = 'Pass'
union all union all
select id as s select id as s
from test_plan_api_scenario tpas from test_plan_api_scenario tpas
where tpas.test_plan_id = #{planId} and tpas.last_result = 'Success' where tpas.test_plan_id = #{planId}
and tpas.last_result = 'Success'
union all union all
select id as s select id as s
from test_plan_api_case tpac from test_plan_api_case tpac
where tpac.test_plan_id = #{planId} and tpac.status = 'success' where tpac.test_plan_id = #{planId}
and tpac.status = 'success'
union all union all
select id as s select id as s
from test_plan_load_case tplc from test_plan_load_case tplc
where tplc.test_plan_id = #{planId} and tplc.status = 'success' where tplc.test_plan_id = #{planId}
) as temp and tplc.status = 'success') as temp
</select> </select>
<select id="listForMinder" resultType="io.metersphere.track.dto.TestCaseDTO"> <select id="listForMinder" resultType="io.metersphere.track.dto.TestCaseDTO">
@ -894,13 +978,19 @@
</where> </where>
</select> </select>
<select id="getTestCaseStep" resultType="io.metersphere.base.domain.TestCaseWithBLOBs"> <select id="getTestCaseStep" resultType="io.metersphere.base.domain.TestCaseWithBLOBs">
select id, prerequisite, steps, step_description, expected_result, step_model from test_case where id = #{id} select id, prerequisite, steps, step_description, expected_result, step_model
from test_case
where id = #{id}
</select> </select>
<select id="selectProjectIds" resultType="java.lang.String"> <select id="selectProjectIds" resultType="java.lang.String">
select DISTINCT project_id from test_case; select DISTINCT project_id
from test_case;
</select> </select>
<select id="getIdsOrderByUpdateTime" resultType="java.lang.String"> <select id="getIdsOrderByUpdateTime" resultType="java.lang.String">
select id from test_case where project_id = #{projectId} order by update_time ASC; select id
from test_case
where project_id = #{projectId}
order by update_time ASC;
</select> </select>
<select id="getLastOrder" resultType="java.lang.Long"> <select id="getLastOrder" resultType="java.lang.Long">
@ -934,7 +1024,8 @@
project_version.id versionId project_version.id versionId
FROM FROM
test_case AS test_case test_case AS test_case
inner join project_version on project_version.project_id = test_case.project_id and project_version.id = test_case.version_id inner join project_version on project_version.project_id = test_case.project_id and project_version.id =
test_case.version_id
<include refid="notInQueryWhereCondition"></include> <include refid="notInQueryWhereCondition"></include>
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/> <include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
</select> </select>
@ -1027,8 +1118,7 @@
<select id="countByWorkSpaceId" resultType="java.lang.Integer"> <select id="countByWorkSpaceId" resultType="java.lang.Integer">
select count(distinct ref_id) select count(distinct ref_id)
from test_case from test_case
where project_id in ( where project_id in (select id
select id
from project from project
where workspace_id = #{workSpaceId}) where workspace_id = #{workSpaceId})
and case_public = true and case_public = true
@ -1036,12 +1126,9 @@
</select> </select>
<select id="trashCount" resultType="java.lang.Long"> <select id="trashCount" resultType="java.lang.Long">
SELECT SELECT count(DISTINCT ref_id)
count(DISTINCT ref_id) FROM test_case
FROM WHERE project_id = #{projectId}
test_case
WHERE
project_id = #{projectId}
AND STATUS = 'Trash' AND STATUS = 'Trash'
</select> </select>
@ -1060,12 +1147,10 @@
<select id="selectRefIdsForVersionChange" resultType="java.lang.String"> <select id="selectRefIdsForVersionChange" resultType="java.lang.String">
SELECT DISTINCT ref_id SELECT DISTINCT ref_id
FROM test_case FROM test_case
WHERE ref_id NOT IN ( WHERE ref_id NOT IN (SELECT DISTINCT ref_id
SELECT DISTINCT ref_id
FROM test_case FROM test_case
WHERE version_id = #{versionId} WHERE version_id = #{versionId}
AND project_id = #{projectId} AND project_id = #{projectId})
)
AND project_id = #{projectId} AND project_id = #{projectId}
</select> </select>
<select id="getMaintainerMap" resultType="io.metersphere.base.domain.TestCase"> <select id="getMaintainerMap" resultType="io.metersphere.base.domain.TestCase">
@ -1087,8 +1172,8 @@
<select id="getForCompatibleCustomField" resultType="io.metersphere.track.dto.CustomFieldResourceCompatibleDTO"> <select id="getForCompatibleCustomField" resultType="io.metersphere.track.dto.CustomFieldResourceCompatibleDTO">
select id, custom_fields select id, custom_fields
from test_case from test_case
where project_id = #{projectId} where project_id = #{projectId} limit #{offset}
limit #{offset},#{pageSize} , #{pageSize}
</select> </select>
<update id="addLatestVersion"> <update id="addLatestVersion">