<?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.tourism.webadmin.back.dao.TourTravelNotesCommentMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourTravelNotesComment">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="comment_content" jdbcType="VARCHAR" property="commentContent"/>
        <result column="parent_id" jdbcType="BIGINT" property="parentId"/>
        <result column="travel_note_id" jdbcType="BIGINT" property="travelNoteId"/>
        <result column="reply_comment_id" jdbcType="BIGINT" property="replyCommentId"/>
        <result column="reply_user_id" jdbcType="BIGINT" property="replyUserId"/>
        <result column="comment_user_id" jdbcType="BIGINT" property="commentUserId"/>
        <result column="like_num" jdbcType="INTEGER" property="likeNum"/>
        <result column="floor" jdbcType="VARCHAR" property="floor"/>
        <result column="data_state" jdbcType="TINYINT" property="dataState"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_user_id" jdbcType="BIGINT" property="updateUserId"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_travel_notes_comment
            (id,
            comment_content,
            parent_id,
            travel_note_id,
            reply_comment_id,
            reply_user_id,
            like_num,
            floor,
            data_state,
            create_user_id,
            create_time,
            update_user_id,
            update_time,
            comment_user_id)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.commentContent},
            #{item.parentId},
            #{item.travelNoteId},
            #{item.replyCommentId},
            #{item.replyUserId},
            #{item.likeNum},
            #{item.floor},
            #{item.dataState},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.commentUserId})
        </foreach>
    </insert>

    <!-- 如果有逻辑删除字段过滤，请写到这里 -->
    <sql id="filterRef">
        <!-- 这里必须加上全包名，否则当filterRef被其他Mapper.xml包含引用的时候，就会调用Mapper.xml中的该SQL片段 -->
        <include refid="com.tourism.webadmin.back.dao.TourTravelNotesCommentMapper.inputFilterRef"/>
        AND tour_travel_notes_comment.data_state = ${@com.tourism.common.core.constant.GlobalDeletedFlag@NORMAL}
    </sql>

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tourTravelNotesCommentFilter != null">
            <if test="tourTravelNotesCommentFilter.travelNoteId != null and tourTravelNotesCommentFilter.travelNoteId != ''">
                AND tour_travel_notes_comment.travel_note_id = #{tourTravelNotesCommentFilter.travelNoteId}
            </if>
        </if>
    </sql>

    <select id="getTourTravelNotesCommentList" resultMap="BaseResultMap" parameterType="com.tourism.webadmin.back.model.TourTravelNotesComment">
        SELECT * FROM tour_travel_notes_comment
        <where>
            <include refid="filterRef"/>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>

    <!-- 根据parent_id删除子评论 -->
    <delete id="deleteChildrenComment">
        DELETE FROM tour_travel_notes_comment WHERE parent_id = #{parentId}
    </delete>
</mapper>
