refactor(oa): 优化报告摘要查询 SQL

- 重构了查询最新详情时间的子查询,提高了查询效率
- 调整了 SQL 结构,增强了可读性
- 移除了冗余的空行和缩进,统一了代码格式
This commit is contained in:
2025-08-08 17:59:50 +08:00
parent 4ec4c9d173
commit 10812ab53a

View File

@@ -30,11 +30,17 @@
FROM oa_report_summary s
LEFT JOIN (
SELECT
d1.summary_id,
d1.create_time AS latest_create_time
FROM oa_report_detail d1
INNER JOIN (
SELECT
summary_id,
create_time AS latest_create_time,
ROW_NUMBER() OVER (PARTITION BY summary_id ORDER BY create_time DESC) AS rn
MAX(create_time) AS max_time
FROM oa_report_detail
) d ON s.summary_id = d.summary_id AND d.rn = 1
GROUP BY summary_id
) d2 ON d1.summary_id = d2.summary_id AND d1.create_time = d2.max_time
) d ON s.summary_id = d.summary_id
<where>
<if test="bo.reportTitle != null and bo.reportTitle != ''">
AND s.report_title LIKE CONCAT('%', #{bo.reportTitle}, '%')
@@ -55,5 +61,4 @@
s.report_date DESC
</select>
</mapper>