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

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

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.gear.oa.mapper.OaReportSummaryMapper">
<resultMap type="com.gear.oa.domain.OaReportSummary" id="OaReportSummaryResult">
@@ -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}, '%')
@@ -48,12 +54,11 @@
<if test="bo.type != null">
AND s.type = #{bo.type}
</if>
AND s.del_flag = 0
AND s.del_flag = 0
</where>
ORDER BY
COALESCE(d.latest_create_time, s.report_date) DESC,
s.report_date DESC
</select>
</mapper>