<?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.TourUserLikeTravelNotesMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourUserLikeTravelNotes">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="user_id" jdbcType="BIGINT" property="userId"/>
        <result column="travel_notes_id" jdbcType="BIGINT" property="travelNotesId"/>
        <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"/>
        <result column="data_state" jdbcType="TINYINT" property="dataState"/>
    </resultMap>

    <resultMap id="TourismProjectTravelNotesWriteResultMap" type="com.tourism.webadmin.back.model.TourismProjectTravelNotesWrite">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="project_title" jdbcType="VARCHAR" property="projectTitle"/>
        <result column="departure_time" jdbcType="DATE" property="departureTime"/>
        <result column="count_times" jdbcType="VARCHAR" property="countTimes"/>
        <result column="role" jdbcType="VARCHAR" property="role"/>
        <result column="recommendation_rate" jdbcType="TINYINT" property="recommendationRate"/>
        <result column="average_cost" jdbcType="VARCHAR" property="averageCost"/>
        <result column="state" jdbcType="TINYINT" property="state"/>
        <result column="reason" jdbcType="VARCHAR" property="reason"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <result column="travel_notes_banner" jdbcType="VARCHAR" property="travelNotesBanner"/>
        <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"/>
        <result column="data_state" jdbcType="TINYINT" property="dataState"/>
        <result column="tourism_tavel_notes_url" jdbcType="VARCHAR" property="tourismTavelNotesUrl"/>
        <result column="unmount_state" jdbcType="TINYINT" property="unmountState"/>
        <result column="tourism_url" jdbcType="VARCHAR" property="tourismUrl"/>
        <result column="remarks" jdbcType="VARCHAR" property="remarks"/>
        <result column="is_hotspot" jdbcType="TINYINT" property="isHotspot"/>
        <result column="note_label" jdbcType="VARCHAR" property="noteLabel"/>
        <result column="like_count" jdbcType="INTEGER" property="likeCount"/>
        <result column="page_view_count" jdbcType="INTEGER" property="pageViewCount"/>
        <result column="hot_value" jdbcType="INTEGER" property="hotValue"/>
        <result column="is_original" jdbcType="TINYINT" property="isOriginal"/>
        <result column="end_place" jdbcType="BIGINT" property="endPlace"/>
        <result column="auto_audit_status" jdbcType="TINYINT" property="autoAuditStatus"/>
        <result column="auto_reject_reason" jdbcType="VARCHAR" property="autoRejectReason"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_user_like_travel_notes
            (id,
            user_id,
            travel_notes_id,
            create_user_id,
            create_time,
            update_user_id,
            update_time,
            data_state)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.userId},
            #{item.travelNotesId},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.dataState})
        </foreach>
    </insert>

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

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tourUserLikeTravelNotesFilter != null">
            <if test="tourUserLikeTravelNotesFilter.userId != null">
                AND tour_user_like_travel_notes.user_id = #{tourUserLikeTravelNotesFilter.userId}
            </if>
            <if test="tourUserLikeTravelNotesFilter.travelNotesId != null">
                AND tour_user_like_travel_notes.travel_notes_id = #{tourUserLikeTravelNotesFilter.travelNotesId}
            </if>
        </if>
    </sql>

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

    <select id="getTourUserLikeTravelNotesWithRelationWriteList" resultMap="TourismProjectTravelNotesWriteResultMap" parameterType="com.tourism.webadmin.back.model.TourismProjectTravelNotesWrite">
        SELECT
        a.*
        FROM
        tour_user_like_travel_notes
        inner JOIN (select * from tour_tourism_project_travel_notes_writer where tour_tourism_project_travel_notes_writer.unmount_state = ${unmountState}
        AND tour_tourism_project_travel_notes_writer.data_state = 1) a ON a.id = tour_user_like_travel_notes.travel_notes_id
        <where>
            <include refid="filterRef"/>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>
</mapper>
