- 新增 Category、Collection、Comment 等实体类 - 实现笔记查询、分类、收藏、评论等功能 - 添加 Markdown 解析工具类 - 新增用户点赞和收藏功能 - 实现问题查询和统计功能
95 lines
3.6 KiB
XML
95 lines
3.6 KiB
XML
<?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.example.copykamanotes.mapper.CommentMapper">
|
|
<!-- 评论结果映射 -->
|
|
<resultMap id="commentMap" type="com.example.copykamanotes.model.entity.Comment">
|
|
<id property="commentId" column="comment_id"/>
|
|
<result property="noteId" column="note_id"/>
|
|
<result property="authorId" column="author_id"/>
|
|
<result property="parentId" column="parent_id"/>
|
|
<result property="content" column="content"/>
|
|
<result property="likeCount" column="like_count"/>
|
|
<result property="replyCount" column="reply_count"/>
|
|
<result property="createdAt" column="created_at"/>
|
|
<result property="updatedAt" column="updated_at"/>
|
|
</resultMap>
|
|
|
|
<!-- 插入评论 -->
|
|
<insert id="insert" useGeneratedKeys="true" keyProperty="commentId">
|
|
INSERT INTO comment (
|
|
note_id, author_id, parent_id, content,
|
|
like_count, reply_count, created_at, updated_at
|
|
) VALUES (
|
|
#{noteId}, #{authorId}, #{parentId}, #{content},
|
|
#{likeCount}, #{replyCount}, #{createdAt}, #{updatedAt}
|
|
)
|
|
</insert>
|
|
|
|
<!-- 更新评论 -->
|
|
<update id="update">
|
|
UPDATE comment
|
|
<set>
|
|
<if test="content != null">content = #{content},</if>
|
|
<if test="likeCount != null">like_count = #{likeCount},</if>
|
|
<if test="replyCount != null">reply_count = #{replyCount},</if>
|
|
updated_at = CURRENT_TIMESTAMP
|
|
</set>
|
|
WHERE comment_id = #{commentId}
|
|
</update>
|
|
|
|
<!-- 删除评论 -->
|
|
<delete id="deleteById">
|
|
DELETE FROM comment WHERE comment_id = #{commentId}
|
|
</delete>
|
|
|
|
<!-- 根据ID查询评论 -->
|
|
<select id="findById" resultMap="commentMap">
|
|
SELECT * FROM comment WHERE comment_id = #{commentId}
|
|
</select>
|
|
|
|
<!-- 查询评论列表 -->
|
|
<select id="findByQueryParam" resultMap="commentMap">
|
|
SELECT * FROM comment
|
|
<where>
|
|
<if test="params.noteId != null">AND note_id = #{params.noteId}</if>
|
|
<if test="params.parentId != null">AND parent_id = #{params.parentId}</if>
|
|
<if test="params.authorId != null">AND author_id = #{params.authorId}</if>
|
|
</where>
|
|
ORDER BY created_at DESC
|
|
LIMIT #{pageSize} OFFSET #{offset}
|
|
</select>
|
|
|
|
<!-- 统计评论数量 -->
|
|
<select id="countByQueryParam" resultType="int">
|
|
SELECT COUNT(*) FROM comment
|
|
<where>
|
|
<if test="params.noteId != null">AND note_id = #{params.noteId}</if>
|
|
<if test="params.parentId != null">AND parent_id = #{params.parentId}</if>
|
|
<if test="params.authorId != null">AND author_id = #{params.authorId}</if>
|
|
</where>
|
|
</select>
|
|
|
|
<!-- 增加评论点赞数 -->
|
|
<update id="incrementLikeCount">
|
|
UPDATE comment SET like_count = like_count + 1
|
|
WHERE comment_id = #{commentId}
|
|
</update>
|
|
|
|
<!-- 减少评论点赞数 -->
|
|
<update id="decrementLikeCount">
|
|
UPDATE comment SET like_count = like_count - 1
|
|
WHERE comment_id = #{commentId} AND like_count > 0
|
|
</update>
|
|
|
|
<!-- 增加评论回复数 -->
|
|
<update id="incrementReplyCount">
|
|
UPDATE comment SET reply_count = reply_count + 1
|
|
WHERE comment_id = #{commentId}
|
|
</update>
|
|
|
|
<!-- 减少评论回复数 -->
|
|
<update id="decrementReplyCount">
|
|
UPDATE comment SET reply_count = reply_count - 1
|
|
WHERE comment_id = #{commentId} AND reply_count > 0
|
|
</update>
|
|
</mapper> |