<?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.ruoyi.post.frequency.postcomment.mapper.PostCommentMapper">

    <resultMap type="com.ruoyi.post.frequency.postcomment.entity.PostComment" id="PostCommentResult">
        <result property="id" column="id"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="userType" column="user_type"/>
        <result property="userId" column="user_id"/>
        <result property="postId" column="post_id"/>
        <result property="topId" column="top_id"/>
        <result property="parentId" column="parent_id"/>
        <result property="parentUserType" column="parent_user_type"/>
        <result property="parentUserId" column="parent_user_id"/>
        <result property="content" column="content"/>
        <result property="image" column="image"/>
        <result property="likeNum" column="like_num"/>
        <result property="commentNum" column="comment_num"/>
    </resultMap>

    <sql id="selectPostCommentVo">
        select id,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time,
               user_type,
               user_id,
               post_id,
               top_id,
               parent_id,
               parent_user_type,
               parent_user_id,
               content,
               image,
               like_num,
               comment_num
        from t_post_comment
    </sql>

    <select id="selectPostCommentList" parameterType="com.ruoyi.post.frequency.postcomment.entity.PostComment"
            resultMap="PostCommentResult">
        <include refid="selectPostCommentVo"/>
        <where>and del_flag != 2
            <if test="userType != null ">and user_type = #{userType}</if>
            <if test="userId != null ">and user_id = #{userId}</if>
            <if test="postId != null ">and post_id = #{postId}</if>
            <if test="topId != null ">and top_id = #{topId}</if>
            <if test="parentId != null ">and parent_id = #{parentId}</if>
            <if test="parentUserType != null ">and parent_user_type = #{parentUserType}</if>
            <if test="parentUserId != null ">and parent_user_id = #{parentUserId}</if>
            <if test="content != null  and content != ''">and content = #{content}</if>
            <if test="image != null  and image != ''">and image = #{image}</if>
            <if test="likeNum != null ">and like_num = #{likeNum}</if>
            <if test="commentNum != null ">and comment_num = #{commentNum}</if>
        </where>
        order by create_time asc
    </select>

    <select id="selectPostCommentById" parameterType="Long" resultMap="PostCommentResult">
        <include refid="selectPostCommentVo"/>
        where id = #{id}
    </select>

    <insert id="insertPostComment" parameterType="com.ruoyi.post.frequency.postcomment.entity.PostComment">
        insert into t_post_comment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="userType != null">user_type,</if>
            <if test="userId != null">user_id,</if>
            <if test="postId != null">post_id,</if>
            <if test="topId != null">top_id,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="parentUserType != null">parent_user_type,</if>
            <if test="parentUserId != null">parent_user_id,</if>
            <if test="content != null">content,</if>
            <if test="image != null">image,</if>
            <if test="likeNum != null">like_num,</if>
            <if test="commentNum != null">comment_num,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="userType != null">#{userType},</if>
            <if test="userId != null">#{userId},</if>
            <if test="postId != null">#{postId},</if>
            <if test="topId != null">#{topId},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="parentUserType != null">#{parentUserType},</if>
            <if test="parentUserId != null">#{parentUserId},</if>
            <if test="content != null">#{content},</if>
            <if test="image != null">#{image},</if>
            <if test="likeNum != null">#{likeNum},</if>
            <if test="commentNum != null">#{commentNum},</if>
        </trim>
    </insert>

    <update id="updatePostComment" parameterType="com.ruoyi.post.frequency.postcomment.entity.PostComment">
        update t_post_comment
        <trim prefix="SET" suffixOverrides=",">
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="userType != null">user_type = #{userType},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="postId != null">post_id = #{postId},</if>
            <if test="topId != null">top_id = #{topId},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="parentUserType != null">parent_user_type = #{parentUserType},</if>
            <if test="parentUserId != null">parent_user_id = #{parentUserId},</if>
            <if test="content != null">content = #{content},</if>
            <if test="image != null">image = #{image},</if>
            <if test="likeNum != null">like_num = like_num + #{likeNum},</if>
            <if test="commentNum != null">comment_num = comment_num + #{commentNum},</if>
        </trim>
        where id = #{id}
        <if test="likeNum != null">and like_num + #{likeNum}>=0</if>
        <if test="commentNum != null">and comment_num + #{commentNum} >= 0</if>
    </update>


    <update id="updatePostCommentNumBatch" parameterType="com.ruoyi.post.frequency.postcomment.entity.PostComment">
        <foreach item="item" index="index" collection="list" separator=";">
            update t_post_comment
            <trim prefix="SET" suffixOverrides=",">
                <if test="item.likeNum != null">like_num = like_num + #{item.likeNum},</if>
                <if test="item.commentNum != null">comment_num = comment_num + #{item.commentNum},</if>
            </trim>
            where id = #{item.id}
            <if test="item.likeNum != null">and like_num + #{item.likeNum}>=0</if>
            <if test="item.commentNum != null">and comment_num + #{item.commentNum} >= 0</if>
        </foreach>
    </update>

    <delete id="deletePostCommentById" parameterType="Long">
        delete
        from t_post_comment
        where id = #{id}
    </delete>

    <delete id="deletePostCommentByIds" parameterType="String">
        delete from t_post_comment where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="getPostCommentResp" resultType="com.ruoyi.post.controller.resp.PostCommentResp">
        SELECT t.id,
               t.top_id,
               t.create_time,
               t.user_type,
               t.user_id,
               t.parent_id,
               t.parent_user_type,
               t.parent_user_id,
               t.content,
               t.like_num,
               t.comment_num,
               CASE
                   WHEN (SELECT COUNT(1)
                         FROM t_post_like fl
                         WHERE fl.del_flag = 1
                           AND fl.type = 2
                           AND fl.user_id = #{userVo.userId}
                           AND fl.user_type = #{userVo.userType}
                           AND fl.object_id = t.id) = 0 THEN
                       1
                   ELSE 2
                   END isLike,
               CASE
                   WHEN #{userVo.userType} = t.user_type
                       AND #{userVo.userId} = t.user_id THEN
                       2
                   ELSE 1
                   END isSelf
        FROM t_post_comment AS t
        WHERE t.id = #{id}
    </select>

    <select id="postCommentPage" resultType="com.ruoyi.post.controller.resp.PostCommentPageResp">
        SELECT
        t.id,
        t.top_id,
        t.create_time,
        t.user_type,
        t.user_id,
        t.parent_id,
        t.parent_user_type,
        t.parent_user_id,
        t.image,
        t.content,
        t.like_num,
        t.comment_num,
        CASE
        WHEN (
        SELECT
        COUNT( 1 )
        FROM
        t_post_like fl
        WHERE
        fl.del_flag = 1
        AND fl.type = 2
        AND fl.user_id = #{userVo.userId}
        AND fl.user_type = #{userVo.userType}
        AND fl.object_id = t.id
        ) = 0 THEN
        1 ELSE 2
        END isLike,
        CASE
        WHEN #{userVo.userType} = t.user_type
        AND #{userVo.userId} = t.user_id THEN
        2 ELSE 1
        END isSelf,
        IF( p.comment_id is not null and t.id = p.comment_id ,2,1) isSelectedComment
        FROM
        t_post_comment AS t
        LEFT JOIN t_post_comment t4 ON t.parent_id = t4.id
        LEFT JOIN t_post p ON t.post_id = p.id
        WHERE
        t.del_flag = 1
        AND t.post_id = #{req.postId}
        <if test="req.parentId!=null and req.parentId!=''">
            AND t.parent_id != 0
            AND t.top_id = #{req.parentId}
        </if>
        <if test="req.parentId==null or req.parentId ==''">
            AND t.parent_id = 0
        </if>

        <if test="req.blockUserList!=null and req.blockUserList.size() > 0">
            AND (
            (t.user_type = 1 and t.user_id not in
            <foreach collection="req.blockUserList" item="userVo" open="(" close=")" separator=",">
                IF(#{userVo.userType} = 1,#{userVo.userId},'')
            </foreach>)
            or
            (t.user_type = 2 and t.user_id not in
            <foreach collection="req.blockUserList" item="userVo" open="(" close=")" separator=",">
                IF(#{userVo.userType} = 2,#{userVo.userId},'')
            </foreach>)
            or
            (t.user_type = 4 and t.user_id not in
            <foreach collection="req.blockUserList" item="userVo" open="(" close=")" separator=",">
                IF(#{userVo.userType} = 4,#{userVo.userId},'')
            </foreach>)
            )
        </if>
        <if test="req.shieldUserList!=null and req.shieldUserList.size() > 0">
            AND (
            (t.user_type = 1 and t.user_id not in
            <foreach collection="req.shieldUserList" item="userVo" open="(" close=")" separator=",">
                IF(#{userVo.userType} = 1,#{userVo.userId},'')
            </foreach>)
            or
            (t.user_type = 2 and t.user_id not in
            <foreach collection="req.shieldUserList" item="userVo" open="(" close=")" separator=",">
                IF(#{userVo.userType} = 2,#{userVo.userId},'')
            </foreach>)
            or
            (t.user_type = 4 and t.user_id not in
            <foreach collection="req.shieldUserList" item="userVo" open="(" close=")" separator=",">
                IF(#{userVo.userType} = 4,#{userVo.userId},'')
            </foreach>)
            )
        </if>
        ORDER BY
        <choose>
            <when test="req.sortType != null and req.sortType != ''">
                <if test="req.sortType == 1">
                    <if test="req.isAsc == 1">
                        t.create_time
                    </if>
                    <if test="req.isAsc == 2">
                        t.create_time DESC
                    </if>
                </if>
                <if test="req.sortType == 2">
                    <if test="req.isAsc == 1">
                        t.like_num
                    </if>
                    <if test="req.isAsc == 2">
                        t.like_num DESC
                    </if>
                </if>
            </when>
            <otherwise>
                t.like_num DESC ,t.create_time
            </otherwise>
        </choose>
    </select>

    <select id="selectCommentNumList" resultType="com.ruoyi.controller.resp.CommentNum">
        SELECT
        t.top_id post_id,
        COUNT(t.id) commentNum
        FROM
        t_post_comment AS t
        LEFT JOIN t_post_comment t4 ON t.parent_id = t4.id
        WHERE
        t.del_flag = 1
        AND t.parent_id != 0
        AND t.top_id in
        <foreach item="id" collection="commentIds" open="(" separator="," close=")">
            #{id}
        </foreach>
        AND (
        (t.user_type = 1 and t.user_id in
        <foreach collection="userVoList" item="userVo" open="(" close=")" separator=",">
            IF(#{userVo.userType} = 1,#{userVo.userId},'')
        </foreach>)
        or
        (t.user_type = 2 and t.user_id in
        <foreach collection="userVoList" item="userVo" open="(" close=")" separator=",">
            IF(#{userVo.userType} = 2,#{userVo.userId},'')
        </foreach>)
        or
        (t.user_type = 4 and t.user_id in
        <foreach collection="userVoList" item="userVo" open="(" close=")" separator=",">
            IF(#{userVo.userType} = 4,#{userVo.userId},'')
        </foreach>)
        )
        GROUP BY t.top_id
    </select>

    <select id="selectedNewCommentList" resultType="com.ruoyi.post.frequency.postcomment.entity.PostComment">
        SELECT
        tt2.*
        FROM
        (
        SELECT
        t.post_id,
        MAX( t.create_time ) create_time
        FROM
        t_post_comment AS t
        WHERE
        t.del_flag = 1
        AND t.parent_id = 0
        GROUP BY
        t.post_id
        ) tt
        LEFT JOIN t_post_comment tt2 ON tt2.create_time = tt.create_time
        AND tt2.post_id = tt.post_id
        AND tt2.parent_id = 0
        WHERE
        tt2.del_flag = 1
        AND tt2.post_id IN
        <foreach item="id" collection="postIds" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <select id="postCommentList" resultType="com.ruoyi.post.controller.resp.PostCommentPageResp">
        SELECT
        t.id,
        t.top_id,
        t.create_time,
        t.user_type,
        t.user_id,
        t.parent_id,
        t.parent_user_type,
        t.parent_user_id,
        t.image,
        t.content,
        t.like_num,
        t.comment_num,
        CASE
        WHEN (
        SELECT
        COUNT( 1 )
        FROM
        t_post_like fl
        WHERE
        fl.del_flag = 1
        AND fl.type = 2
        AND fl.user_id = #{userVo.userId}
        AND fl.user_type = #{userVo.userType}
        AND fl.object_id = t.id
        ) = 0 THEN
        1 ELSE 2
        END isLike,
        CASE
        WHEN #{userVo.userType} = t.user_type
        AND #{userVo.userId} = t.user_id THEN
        2 ELSE 1
        END isSelf,
        IF( p.comment_id is not null and t.id = p.comment_id ,2,1) isSelectedComment
        FROM
        t_post_comment AS t
        LEFT JOIN t_post_comment t4 ON t.parent_id = t4.id
        LEFT JOIN t_post p ON t.post_id = p.id
        WHERE
        t.del_flag = 1
        AND t.post_id = #{req.postId}
        <if test="req.parentId!=null and req.parentId!=''">
            AND t.parent_id != 0
            AND t.top_id = #{req.parentId}
        </if>
        <if test="req.parentId==null or req.parentId ==''">
            AND t.parent_id != 0
        </if>

        <if test="req.blockUserList!=null and req.blockUserList.size() > 0">
            AND (
            (t.user_type = 1 and t.user_id not in
            <foreach collection="req.blockUserList" item="userVo" open="(" close=")" separator=",">
                IF(#{userVo.userType} = 1,#{userVo.userId},'')
            </foreach>)
            or
            (t.user_type = 2 and t.user_id not in
            <foreach collection="req.blockUserList" item="userVo" open="(" close=")" separator=",">
                IF(#{userVo.userType} = 2,#{userVo.userId},'')
            </foreach>)
            or
            (t.user_type = 4 and t.user_id not in
            <foreach collection="req.blockUserList" item="userVo" open="(" close=")" separator=",">
                IF(#{userVo.userType} = 4,#{userVo.userId},'')
            </foreach>)
            )
        </if>
        <if test="req.shieldUserList!=null and req.shieldUserList.size() > 0">
            AND (
            (t.user_type = 1 and t.user_id not in
            <foreach collection="req.shieldUserList" item="userVo" open="(" close=")" separator=",">
                IF(#{userVo.userType} = 1,#{userVo.userId},'')
            </foreach>)
            or
            (t.user_type = 2 and t.user_id not in
            <foreach collection="req.shieldUserList" item="userVo" open="(" close=")" separator=",">
                IF(#{userVo.userType} = 2,#{userVo.userId},'')
            </foreach>)
            or
            (t.user_type = 4 and t.user_id not in
            <foreach collection="req.shieldUserList" item="userVo" open="(" close=")" separator=",">
                IF(#{userVo.userType} = 4,#{userVo.userId},'')
            </foreach>)
            )
        </if>
        AND ( SELECT COUNT(*) FROM t_post_comment AS sub WHERE sub.parent_id = t.parent_id AND sub.like_num >=
        t.like_num AND sub.create_time &lt;= t.create_time ) &lt;= 10
        AND t.parent_id in
        <foreach item="id" collection="list" open="(" separator="," close=")">
            #{id}
        </foreach>
        ORDER BY
        t.like_num DESC ,t.create_time
    </select>

    <!--    <select id="postCommentDialoguePage" resultType="com.ruoyi.post.controller.resp.PostCommentPageResp">-->

    <!--        (SELECT-->
    <!--        t.id,-->
    <!--        t.create_time,-->
    <!--        t.user_type,-->
    <!--        t.user_id,-->
    <!--        t.parent_id,-->
    <!--        t.parent_user_type,-->
    <!--        t.parent_user_id,-->
    <!--        t.image,-->
    <!--        t.content,-->
    <!--        t.like_num,-->
    <!--        t.comment_num,-->
    <!--        CASE-->
    <!--        WHEN (-->
    <!--        SELECT-->
    <!--        COUNT( 1 )-->
    <!--        FROM-->
    <!--        t_post_like fl-->
    <!--        WHERE-->
    <!--        fl.del_flag = 1-->
    <!--        AND fl.type = 2-->
    <!--        AND fl.user_id = #{userVo.userId}-->
    <!--        AND fl.user_type = #{userVo.userType}-->
    <!--        AND fl.object_id = t.id-->
    <!--        ) = 0 THEN-->
    <!--        1 ELSE 2-->
    <!--        END isLike,-->
    <!--        CASE-->
    <!--        WHEN #{userVo.userType} = t.user_type-->
    <!--        AND #{userVo.userId} = t.user_id THEN-->
    <!--        2 ELSE 1-->
    <!--        END isSelf,-->
    <!--        IF( p.comment_id is not null and t.id = p.comment_id ,2,1) isSelectedComment-->
    <!--        FROM-->
    <!--        t_post_comment AS t-->
    <!--        LEFT JOIN t_post_comment t4 ON t.parent_id = t4.id-->
    <!--        LEFT JOIN t_post p ON t.post_id = p.id-->
    <!--        WHERE-->
    <!--        t.id = #{req.commentId}-->
    <!--        )-->
    <!--        UNION ALL-->
    <!--        (-->
    <!--        SELECT-->
    <!--        t.id,-->
    <!--        t.create_time,-->
    <!--        t.user_type,-->
    <!--        t.user_id,-->
    <!--        t.parent_id,-->
    <!--        t.parent_user_type,-->
    <!--        t.parent_user_id,-->
    <!--        t.image,-->
    <!--        t.content,-->
    <!--        t.like_num,-->
    <!--        t.comment_num,-->
    <!--        CASE-->
    <!--        WHEN (-->
    <!--        SELECT-->
    <!--        COUNT( 1 )-->
    <!--        FROM-->
    <!--        t_post_like fl-->
    <!--        WHERE-->
    <!--        fl.del_flag = 1-->
    <!--        AND fl.type = 2-->
    <!--        AND fl.user_id = #{userVo.userId}-->
    <!--        AND fl.user_type = #{userVo.userType}-->
    <!--        AND fl.object_id = t.id-->
    <!--        ) = 0 THEN-->
    <!--        1 ELSE 2-->
    <!--        END isLike,-->
    <!--        CASE-->
    <!--        WHEN #{userVo.userType} = t.user_type-->
    <!--        AND #{userVo.userId} = t.user_id THEN-->
    <!--        2 ELSE 1-->
    <!--        END isSelf,-->
    <!--        IF( p.comment_id is not null and t.id = p.comment_id ,2,1) isSelectedComment-->
    <!--        FROM-->
    <!--        t_post_comment AS t-->
    <!--        LEFT JOIN t_post_comment t4 ON t.parent_id = t4.id-->
    <!--        LEFT JOIN t_post p ON t.post_id = p.id-->
    <!--        LEFT JOIN t_post_comment pc ON pc.id = #{req.commentId}-->
    <!--        WHERE-->
    <!--        t.del_flag = 1-->
    <!--        AND t.id != #{req.commentId}-->
    <!--        AND (-->
    <!--        (t.user_type = pc.user_type and t.user_id = pc.user_id )-->
    <!--        or-->
    <!--        (t.user_type = pc.parent_user_type and t.user_id = pc.parent_user_id )-->
    <!--        or-->
    <!--        (t.parent_user_type = pc.user_type and t.parent_user_id = pc.user_id )-->
    <!--        or-->
    <!--        (t.parent_user_type = pc.parent_user_type and t.parent_user_id = pc.parent_user_id )-->
    <!--        )-->
    <!--        <if test="req.parentId!=null and req.parentId!=''">-->
    <!--            AND t.parent_id != 0-->
    <!--            AND t.top_id = #{req.parentId}-->
    <!--        </if>-->
    <!--        ORDER BY-->
    <!--        <choose>-->
    <!--            <when test="req.sortType != null and req.sortType != ''">-->
    <!--                <if test="req.sortType == 1">-->
    <!--                    t.create_time DESC-->
    <!--                </if>-->
    <!--                <if test="req.sortType == 2">-->
    <!--                    <if test="req.isAse == 1">-->
    <!--                        t.like_num-->
    <!--                    </if>-->
    <!--                    <if test="req.isAse == 2">-->
    <!--                        t.like_num DESC-->
    <!--                    </if>-->
    <!--                </if>-->
    <!--            </when>-->
    <!--            <otherwise>-->
    <!--                t.like_num DESC ,t.create_time-->
    <!--            </otherwise>-->
    <!--        </choose>-->
    <!--        )-->
    <!--    </select>-->

    <select id="postCommentDialoguePage" resultType="com.ruoyi.post.controller.resp.PostCommentPageResp">
        (SELECT
        t.id,
        1 sort,
        t.create_time,
        t.user_type,
        t.user_id,
        t.parent_id,
        t.parent_user_type,
        t.parent_user_id,
        t.image,
        t.content,
        t.like_num,
        t.comment_num,
        CASE
        WHEN (
        SELECT
        COUNT( 1 )
        FROM
        t_post_like fl
        WHERE
        fl.del_flag = 1
        AND fl.type = 2
        AND fl.user_id = #{userVo.userId}
        AND fl.user_type = #{userVo.userType}
        AND fl.object_id = t.id
        ) = 0 THEN
        1 ELSE 2
        END isLike,
        CASE
        WHEN #{userVo.userType} = t.user_type
        AND #{userVo.userId} = t.user_id THEN
        2 ELSE 1
        END isSelf,
        IF( p.comment_id is not null and t.id = p.comment_id ,2,1) isSelectedComment
        FROM
        t_post_comment AS t
        LEFT JOIN t_post_comment t4 ON t.parent_id = t4.id
        LEFT JOIN t_post p ON t.post_id = p.id
        WHERE
        t.id = #{req.commentId}
        )
        UNION ALL
        (
        SELECT
        t.id,
        2 sort,
        t.create_time,
        t.user_type,
        t.user_id,
        t.parent_id,
        t.parent_user_type,
        t.parent_user_id,
        t.image,
        t.content,
        t.like_num,
        t.comment_num,
        CASE
        WHEN (
        SELECT
        COUNT( 1 )
        FROM
        t_post_like fl
        WHERE
        fl.del_flag = 1
        AND fl.type = 2
        AND fl.user_id = #{userVo.userId}
        AND fl.user_type = #{userVo.userType}
        AND fl.object_id = t.id
        ) = 0 THEN
        1 ELSE 2
        END isLike,
        CASE
        WHEN #{userVo.userType} = t.user_type
        AND #{userVo.userId} = t.user_id THEN
        2 ELSE 1
        END isSelf,
        IF( p.comment_id is not null and t.id = p.comment_id ,2,1) isSelectedComment
        FROM
        t_post_comment AS t
        LEFT JOIN t_post_comment t4 ON t.parent_id = t4.id
        LEFT JOIN t_post p ON t.post_id = p.id
        LEFT JOIN t_post_comment pc ON pc.id = #{req.commentId}
        WHERE
        t.del_flag = 1
        AND t.id != #{req.commentId}
        AND (
        (t.user_type = pc.user_type and t.user_id = pc.user_id )
        or
        (t.user_type = pc.parent_user_type and t.user_id = pc.parent_user_id )
        or
        (t.parent_user_type = pc.user_type and t.parent_user_id = pc.user_id )
        or
        (t.parent_user_type = pc.parent_user_type and t.parent_user_id = pc.parent_user_id )
        )
        <if test="req.parentId!=null and req.parentId!=''">
            AND t.parent_id != 0
            AND t.top_id = #{req.parentId}
        </if>
        )
        ORDER BY
        <choose>
            <when test="req.sortType != null and req.sortType != ''">
                <if test="req.sortType == 1">
                    sort,create_time DESC
                    <if test="req.isAsc == 1">
                        sort,create_time
                    </if>
                    <if test="req.isAsc == 2">
                        sort,create_time DESC
                    </if>
                </if>
                <if test="req.sortType == 2">
                    <if test="req.isAsc == 1">
                        sort,like_num
                    </if>
                    <if test="req.isAsc == 2">
                        sort, like_num DESC
                    </if>
                </if>
            </when>
            <otherwise>
                sort, like_num DESC ,create_time
            </otherwise>
        </choose>
    </select>
</mapper>
