fix comment page
This commit is contained in:
@@ -2,101 +2,7 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.imyeyu.api.modules.common.mapper.CommentMapper">
|
||||
<sql id="table">comment</sql>
|
||||
<!-- 主评论 -->
|
||||
<select id="selectByPage" resultMap="selectResult">
|
||||
SELECT
|
||||
-- 主评论
|
||||
comment.id,
|
||||
comment.biz_type,
|
||||
comment.biz_id,
|
||||
comment.user_id,
|
||||
comment.nick,
|
||||
comment.content,
|
||||
comment.created_at,
|
||||
|
||||
-- 回复数量
|
||||
reply_count.reply_length,
|
||||
|
||||
-- 回复
|
||||
reply.id AS reply_id,
|
||||
reply.comment_id,
|
||||
reply.sender_id,
|
||||
reply.sender_nick,
|
||||
reply.receiver_id,
|
||||
reply.receiver_nick,
|
||||
reply.content AS reply_content,
|
||||
reply.created_at AS reply_created_at
|
||||
FROM (
|
||||
-- 查询主评论
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
<include refid="table" />
|
||||
WHERE
|
||||
biz_type = #{bizType}
|
||||
AND biz_id = #{bizId}
|
||||
AND deleted_at IS NULL
|
||||
ORDER BY
|
||||
created_at ${orderMap.createdAt}
|
||||
LIMIT
|
||||
#{offset}, #{limit}
|
||||
) AS comment
|
||||
LEFT JOIN (
|
||||
-- 查询前 6 条回复(时间升序)
|
||||
SELECT
|
||||
*
|
||||
FROM (
|
||||
SELECT
|
||||
comment_reply.*,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY comment_id
|
||||
ORDER BY created_at ASC
|
||||
) AS seq
|
||||
FROM
|
||||
comment_reply
|
||||
WHERE
|
||||
deleted_at IS NULL
|
||||
) AS reply
|
||||
WHERE
|
||||
seq < 7
|
||||
) AS reply
|
||||
ON
|
||||
reply.comment_id = comment.id
|
||||
LEFT JOIN(
|
||||
-- 统计回复总数
|
||||
SELECT
|
||||
comment_id AS id,
|
||||
COUNT(*) AS reply_length
|
||||
FROM
|
||||
comment_reply
|
||||
WHERE
|
||||
deleted_at IS NULL
|
||||
GROUP BY
|
||||
comment_id
|
||||
) AS reply_count
|
||||
ON
|
||||
reply_count.id = comment.id
|
||||
</select>
|
||||
<resultMap id="selectResult" type="com.imyeyu.api.modules.common.vo.comment.CommentView">
|
||||
<id property="id" column="id" />
|
||||
<result property="userId" column="user_id" />
|
||||
<result property="nick" column="nick" />
|
||||
<result property="content" column="content" />
|
||||
<result property="repliesLength" column="reply_length" />
|
||||
<result property="createdAt" column="created_at" />
|
||||
<!-- 关联回复 -->
|
||||
<collection property="replies" ofType="com.imyeyu.api.modules.common.vo.comment.CommentReplyView">
|
||||
<id property="id" column="reply_id" />
|
||||
<result property="commentId" column="comment_id" />
|
||||
<result property="senderId" column="sender_id" />
|
||||
<result property="senderNick" column="sender_nick" />
|
||||
<result property="receiverId" column="receiver_id" />
|
||||
<result property="receiverNick" column="receiver_nick" />
|
||||
<result property="content" column="reply_content" />
|
||||
<result property="createdAt" column="reply_created_at" />
|
||||
</collection>
|
||||
</resultMap>
|
||||
<select id="countByPage" resultType="long">
|
||||
<select id="countAll" resultType="long">
|
||||
SELECT
|
||||
SUM(result.total_comment + result.total_reply)
|
||||
FROM (
|
||||
@@ -116,28 +22,4 @@
|
||||
AND comment_reply.deleted_at IS NULL
|
||||
) AS result
|
||||
</select>
|
||||
|
||||
<sql id="byUserIdCondition">
|
||||
FROM
|
||||
<include refid="table" />
|
||||
WHERE
|
||||
user_id = #{userId}
|
||||
AND deleted_at IS NULL
|
||||
</sql>
|
||||
<select id="countByUserId" resultType="long">
|
||||
SELECT COUNT(1) <include refid="byUserIdCondition" />
|
||||
</select>
|
||||
<select id="listByUserId" resultType="com.imyeyu.api.modules.common.vo.comment.CommentView">
|
||||
SELECT
|
||||
id,
|
||||
biz_type,
|
||||
biz_id,
|
||||
content,
|
||||
created_at
|
||||
<include refid="byUserIdCondition" />
|
||||
ORDER BY
|
||||
created_at ${orderMap.createdAt}
|
||||
LIMIT
|
||||
#{offset}, #{limit}
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user