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.
 
 

42 lines
1.7 KiB

<?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.MiniStrayAnimalNoteCollectMapper">
<!-- 查询用户是否收藏该笔记 -->
<select id="selectUserCollectCount" resultType="java.lang.Integer">
SELECT COUNT(1)
FROM mini_stray_animal_note_collect
WHERE note_id = #{noteId}
AND mini_user_id = #{userId}
AND is_deleted = 0
</select>
<!-- 新增或更新收藏记录(原子操作,依赖note_id和mini_user_id联合唯一索引) -->
<insert id="insertOrUpdateCollect" parameterType="com.youlai.boot.mini.model.entity.MiniStrayAnimalNoteCollect">
INSERT INTO mini_stray_animal_note_collect
(uuid, note_id, mini_user_id, create_time, create_timestamp, create_by, update_time, update_timestamp, update_by, is_deleted)
VALUES
(#{uuid}, #{noteId}, #{miniUserId}, #{createTime}, #{createTimestamp}, #{createBy}, #{updateTime}, #{updateTimestamp}, #{updateBy}, #{deleted})
ON DUPLICATE KEY UPDATE
is_deleted = 0,
update_time = VALUES(update_time),
update_timestamp = VALUES(update_timestamp),
update_by = VALUES(update_by)
</insert>
<!-- 逻辑删除收藏记录(取消收藏) -->
<update id="deleteCollect">
UPDATE mini_stray_animal_note_collect
SET is_deleted = 1,
update_time = NOW(),
update_timestamp = #{currentTime},
update_by = #{userId}
WHERE note_id = #{noteId}
AND mini_user_id = #{userId}
AND is_deleted = 0
</update>
</mapper>