+优化sql

This commit is contained in:
wuyu 2023-12-05 10:12:13 +08:00
parent 275fce053b
commit d232d8fd85

View File

@ -3,14 +3,14 @@
<mapper namespace="cn.axzo.msg.center.dal.mapper.PendingMessageRecordMapper">
<select id="queryByTemplateCodes" resultType="cn.axzo.msg.center.domain.entity.PendingMessageRecord">
SELECT
*
select * from pending_message_record where id in(SELECT
id
FROM
(
<if test="isNowDay">
SELECT (@i:=@i+1) mi,aa.* FROM
(SELECT
old_undo.*,1 AS flag
old_undo.id,1 AS flag
FROM
(SELECT
*
@ -27,7 +27,7 @@
</if>
SELECT (@i:=@i+1) mi,aa.* FROM
(SELECT
new_todo.*,2 AS flag
new_todo.id,2 AS flag
FROM
(SELECT
*
@ -43,7 +43,7 @@
ALL
SELECT (@i:=@i+1) mi,aa.* FROM
(SELECT
new_todo_3.*,3 AS flag
new_todo_3.id,3 AS flag
FROM
(SELECT
*
@ -59,7 +59,7 @@
ALL
SELECT (@i:=@i+1) mi,aa.* FROM
(SELECT
new_todo_4.*,4 AS flag
new_todo_4.id,4 AS flag
FROM
(SELECT
*
@ -75,7 +75,7 @@
ALL
SELECT (@i:=@i+1) mi,aa.* FROM
(SELECT
all_new_do.*,5 AS flag
all_new_do.id,5 AS flag
FROM
(SELECT
*
@ -84,12 +84,12 @@
WHERE (DATE(create_at) = DATE(#{selectDate}) <if test="isNowDay">
OR (DATE(create_at) <![CDATA[<]]> DATE(#{selectDate}) AND state = ('COMPLETED') AND DATE(update_at) = DATE(#{selectDate})
AND template_code IN <foreach collection="pendingCalendarCodeDTO.constructionCodes" index="index" item="item" open="(" separator="," close=")">#{item}</foreach>)
</if>)
</if>)
AND state = 'COMPLETED'
AND is_delete = 0
AND executor_person_id = #{personId}
AND template_code IN <foreach collection="pendingCalendarCodeDTO.allCodes" index="index" item="item" open="(" separator="," close=")">#{item}</foreach>
ORDER BY create_at DESC) all_new_do) aa,(SELECT (@i:=0))tt
) ccc ORDER BY flag ASC,mi asc
) ccc ORDER BY flag ASC,mi asc)
</select>
</mapper>