<?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.TourUserLikeTopicMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourUserLikeTopic">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="tour_user_id" jdbcType="BIGINT" property="tourUserId"/>
        <result column="tour_travel_notes_topic_id" jdbcType="BIGINT" property="tourTravelNotesTopicId"/>
        <result column="tour_travel_notes_topic_name" jdbcType="VARCHAR" property="tourTravelNotesTopicName"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_user_like_topic
            (id,
            tour_user_id,
            tour_travel_notes_topic_id,
            tour_travel_notes_topic_name)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.tourUserId},
            #{item.tourTravelNotesTopicId},
            #{item.tourTravelNotesTopicName})
        </foreach>
    </insert>

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

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tourUserLikeTopicFilter != null">
            <if test="tourUserLikeTopicFilter.tourUserId != null">
                AND tour_user_like_topic.tour_user_id = #{tourUserLikeTopicFilter.tourUserId}
            </if>
            <if test="tourUserLikeTopicFilter.tourTravelNotesTopicId != null">
                AND tour_user_like_topic.tour_travel_notes_topic_id = #{tourUserLikeTopicFilter.tourTravelNotesTopicId}
            </if>
            <if test="tourUserLikeTopicFilter.tourTravelNotesTopicName != null and tourUserLikeTopicFilter.tourTravelNotesTopicName != ''">
                AND tour_user_like_topic.tour_travel_notes_topic_name = #{tourUserLikeTopicFilter.tourTravelNotesTopicName}
            </if>
        </if>
    </sql>

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

    <select id="getSpecialCollection" resultType="com.tourism.webadmin.app.website.vo.SpecialCollectionVo">
        SELECT
            t1.id,
            t1.name,
            t1.hot_value
        FROM
            tour_travel_notes_topic as t1
        INNER JOIN
            tour_user_like_topic as t2
        ON t1.id = t2.tour_travel_notes_topic_id
        where  t2.tour_user_id=#{userId}
        ORDER BY t2.creat_time DESC
    </select>
</mapper>
