You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
43 lines
1.3 KiB
|
1 month ago
|
<?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">
|
||
|
|
|
||
|
|
<mapper namespace="com.youlai.boot.mini.mapper.MiniStrayAnimalNoteCommentMapper">
|
||
|
|
|
||
|
|
<update id="incrementCommentCount">
|
||
|
|
UPDATE mini_stray_animal_note
|
||
|
|
SET comment_count = comment_count + 1
|
||
|
|
WHERE id = #{noteId}
|
||
|
|
</update>
|
||
|
|
|
||
|
|
<!-- 一次性校准所有笔记的评论数 -->
|
||
|
|
<update id="batchCalibrateAllCommentCounts">
|
||
|
|
UPDATE mini_stray_animal_note n
|
||
|
|
SET n.comment_count = (
|
||
|
|
SELECT COUNT(1)
|
||
|
|
FROM mini_stray_animal_note_comment c
|
||
|
|
WHERE c.note_id = n.id
|
||
|
|
AND c.flag = 0
|
||
|
|
)
|
||
|
|
WHERE 1 = 1
|
||
|
|
</update>
|
||
|
|
|
||
|
|
<!-- 只校准最近有变动的笔记(24小时内有过评论的) -->
|
||
|
|
<update id="batchCalibrateRecentNotes">
|
||
|
|
UPDATE mini_stray_animal_note n
|
||
|
|
INNER JOIN (
|
||
|
|
SELECT note_id, MAX(create_time) as last_comment_time
|
||
|
|
FROM mini_stray_animal_note_comment
|
||
|
|
WHERE create_time >= DATE_SUB(NOW(), INTERVAL 1 DAY)
|
||
|
|
GROUP BY note_id
|
||
|
|
) c ON n.id = c.note_id
|
||
|
|
SET n.comment_count = (
|
||
|
|
SELECT COUNT(1)
|
||
|
|
FROM mini_stray_animal_note_comment c2
|
||
|
|
WHERE c2.note_id = n.id AND c2.flag = 0
|
||
|
|
)
|
||
|
|
</update>
|
||
|
|
|
||
|
|
</mapper>
|