<?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.mmc.csf.release.dao.CommentDAO">
    <insert id="insertComment" parameterType="com.mmc.csf.release.forum.vo.CommentVO">
        INSERT INTO forum_comment(user_id, dynamic_id, content)
        VALUES (#{userId}, #{dynamicId}, #{content})
    </insert>

    <insert id="insertReplyComment">
        INSERT INTO forum_comment(user_id, dynamic_id, content,parent_id)
        VALUES (#{userId}, #{dynamicId}, #{content},#{parentId})
    </insert>

    <update id="deleteComment" parameterType="int">
        update forum_comment
        set is_deleted = 1
        where id = #{id}
    </update>

    <delete id="deleteCommentsByDynamic" parameterType="int">
        DELETE FROM forum_comment WHERE dynamic_id = #{dynamicId}
    </delete>
    <select id="selectCommentList" resultType="com.mmc.csf.release.forum.vo.CommentAndReplyVO">
        select id,
               parent_id,
               user_id,
               dynamic_id,
               content,
               likes_count
        from forum_comment
        where dynamic_id = #{dynamicId} and is_deleted = 0
    </select>
    <select id="selectSubCommentList" resultType="com.mmc.csf.release.forum.vo.CommentVO">
        select  id,
                parent_id,
                user_id,
                dynamic_id,
                content,
                likes_count
        from forum_comment
        where parent_id in
        <foreach collection="list" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
</mapper>