refactor(测试计划): 优化测试计划报告保留时间清理查询逻辑

--bug=1044722 --user=宋昌昌 【测试计划】github#32364测试计划报告保留时间范围未生效 https://www.tapd.cn/55049933/s/1560377
This commit is contained in:
song-cc-rock 2024-08-09 10:44:42 +08:00 committed by Craftsman
parent 3d095f7cc5
commit cf3ca1e567
1 changed files with 29 additions and 24 deletions

View File

@ -45,10 +45,11 @@
</select> </select>
<select id="selectReportIdByProjectIdAndTime" resultType="java.lang.String"> <select id="selectReportIdByProjectIdAndTime" resultType="java.lang.String">
select report.id select report.id
from test_plan_report report left join test_plan_report_summary summary from test_plan_report report
on report.id = summary.test_plan_report_id left join test_plan_report_summary summary
on report.id = summary.test_plan_report_id
where report.project_id = #{projectId} where report.project_id = #{projectId}
and report.start_time &lt;= #{time} and report.create_time &lt;= #{time}
</select> </select>
<select id="selectReportIdTestPlanIds" resultType="java.lang.String"> <select id="selectReportIdTestPlanIds" resultType="java.lang.String">
select report.id select report.id
@ -119,7 +120,7 @@
inner join test_plan tp ON tpr.test_plan_id = tp.id inner join test_plan tp ON tpr.test_plan_id = tp.id
left join project on tpr.project_id = project.id left join project on tpr.project_id = project.id
where where
tpr.id != tpr.parent_id tpr.id != tpr.parent_id
<if test="ids != null and ids.size() > 0"> <if test="ids != null and ids.size() > 0">
and tpr.parent_id in and tpr.parent_id in
<foreach collection="ids" item="id" separator="," open="(" close=")"> <foreach collection="ids" item="id" separator="," open="(" close=")">
@ -131,17 +132,17 @@
<select id="getPlanReportListById" <select id="getPlanReportListById"
resultType="io.metersphere.plan.dto.response.TestPlanReportDetailResponse"> resultType="io.metersphere.plan.dto.response.TestPlanReportDetailResponse">
SELECT tpr.id, SELECT tpr.id,
tpr.test_plan_name, tpr.test_plan_name,
tpr.result_status, tpr.result_status,
tpr.pass_rate, tpr.pass_rate,
tpr.pass_threshold, tpr.pass_threshold,
(tprs.functional_case_count + tprs.api_case_count + tprs.api_scenario_count + tprs.bug_count) as caseTotal, (tprs.functional_case_count + tprs.api_case_count + tprs.api_scenario_count + tprs.bug_count) as caseTotal,
tpr.create_time, tpr.create_time,
tpr.deleted tpr.deleted
from test_plan_report tpr from test_plan_report tpr
LEFT JOIN test_plan_report_summary tprs on tpr.id = tprs.test_plan_report_id LEFT JOIN test_plan_report_summary tprs on tpr.id = tprs.test_plan_report_id
<include refid="queryWhereConditionByParentId"/> <include refid="queryWhereConditionByParentId"/>
</select> </select>
<select id="getReports" resultType="io.metersphere.api.dto.report.ReportDTO"> <select id="getReports" resultType="io.metersphere.api.dto.report.ReportDTO">
@ -157,7 +158,7 @@
left join project on tpr.project_id = project.id left join project on tpr.project_id = project.id
where where
tpr.start_time BETWEEN #{startTime} AND #{endTime} tpr.start_time BETWEEN #{startTime} AND #{endTime}
and tpr.exec_status in ('PENDING', 'RUNNING', 'RERUNNING') and tpr.exec_status in ('PENDING', 'RUNNING', 'RERUNNING')
<if test="ids != null and ids.size() > 0"> <if test="ids != null and ids.size() > 0">
and tpr.id in and tpr.id in
<foreach collection="ids" item="id" open="(" separator="," close=")"> <foreach collection="ids" item="id" open="(" separator="," close=")">
@ -180,7 +181,8 @@
<include refid="filterByCondition"/> <include refid="filterByCondition"/>
</select> </select>
<select id="getHistoryDeleted" resultType="io.metersphere.api.dto.definition.ExecuteReportDTO"> <select id="getHistoryDeleted" resultType="io.metersphere.api.dto.definition.ExecuteReportDTO">
select distinct tpr.* from test_plan_report tpr INNER JOIN test_plan_report_summary tprs on tpr.id = tprs.test_plan_report_id select distinct tpr.* from test_plan_report tpr INNER JOIN test_plan_report_summary tprs on tpr.id =
tprs.test_plan_report_id
<if test="ids != null and ids.size() > 0"> <if test="ids != null and ids.size() > 0">
where tpr.id in where tpr.id in
<foreach collection="ids" item="id" open="(" separator="," close=")"> <foreach collection="ids" item="id" open="(" separator="," close=")">
@ -228,19 +230,19 @@
</select> </select>
<select id="getScenarioReports" resultType="io.metersphere.api.dto.report.ReportDTO"> <select id="getScenarioReports" resultType="io.metersphere.api.dto.report.ReportDTO">
SELECT DISTINCT SELECT DISTINCT
asr.*, asr.*,
project.organization_id, project.organization_id,
asr.test_plan_scenario_id AS testPlanId, asr.test_plan_scenario_id AS testPlanId,
asr.test_plan_scenario_id AS resourceId asr.test_plan_scenario_id AS resourceId
FROM FROM
api_scenario_report asr api_scenario_report asr
LEFT JOIN test_plan_report_api_scenario tpras ON asr.id = tpras.api_scenario_execute_report_id LEFT JOIN test_plan_report_api_scenario tpras ON asr.id = tpras.api_scenario_execute_report_id
LEFT JOIN project ON asr.project_id = project.id LEFT JOIN project ON asr.project_id = project.id
WHERE WHERE
asr.deleted = FALSE asr.deleted = FALSE
AND asr.plan = 1 AND asr.plan = 1
AND asr.exec_status IN ( 'PENDING', 'RUNNING', 'RERUNNING' ) AND asr.exec_status IN ( 'PENDING', 'RUNNING', 'RERUNNING' )
AND tpras.test_plan_report_id IN AND tpras.test_plan_report_id IN
<foreach collection="ids" item="id" open="(" close=")" separator=","> <foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id} #{id}
</foreach> </foreach>
@ -259,7 +261,10 @@
</select> </select>
<delete id="deleteGroupReport" parameterType="java.lang.String"> <delete id="deleteGroupReport" parameterType="java.lang.String">
delete from test_plan_report where id = #{id} or parent_id = #{id} delete
from test_plan_report
where id = #{id}
or parent_id = #{id}
</delete> </delete>
<update id="batchUpdateExecuteTimeAndStatus" parameterType="java.lang.String"> <update id="batchUpdateExecuteTimeAndStatus" parameterType="java.lang.String">