<?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.DirectoryInfoMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.DirectoryInfo">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="parent_id" jdbcType="BIGINT" property="parentId"/>
        <result column="menu_name" jdbcType="VARCHAR" property="menuName"/>
        <result column="show_order" jdbcType="TINYINT" property="showOrder"/>
        <result column="enable" jdbcType="TINYINT" property="enable"/>
        <result column="directory_type" jdbcType="TINYINT" property="directoryType"/>
        <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"/>
        <result column="is_hotspot" jdbcType="TINYINT" property="isHotspot"/>
        <result column="hot_order" jdbcType="TINYINT" property="hotOrder"/>
        <result column="hot_picture_url" jdbcType="VARCHAR" property="hotPictureUrl"/>
<!--        <result column="is_winnow_destination" jdbcType="TINYINT" property="isWinnowDestination"/>-->
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_directory_info
            (id,
            parent_id,
            menu_name,
            show_order,
            enable,
            directory_type,
            create_user_id,
            create_time,
            update_user_id,
            update_time,
            data_state,
            is_hotspot,
            hot_order,
            hot_picture_url,
--         is_winnow_destination
        )

        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.parentId},
            #{item.menuName},
            #{item.showOrder},
            #{item.enable},
            #{item.directoryType},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.dataState},
            #{item.isHotspot},
            #{item.hotOrder},
            #{item.hotPictureUrl},
            #{item.isWinnowDestination}
            )
        </foreach>
    </insert>

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

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="directoryInfoFilter != null">
            <if test="directoryInfoFilter.menuName != null and directoryInfoFilter.menuName != ''">
                <bind name = "safeDirectoryInfoMenuName" value = "'%' + directoryInfoFilter.menuName + '%'" />
                AND tour_directory_info.menu_name LIKE #{safeDirectoryInfoMenuName}
            </if>
            <if test="directoryInfoFilter.searchString != null and directoryInfoFilter.searchString != ''">
                <bind name = "safeDirectoryInfoSearchString" value = "'%' + directoryInfoFilter.searchString + '%'" />
                AND IFNULL(tour_directory_info.menu_name,'') LIKE #{safeDirectoryInfoSearchString}
            </if>
            <if test="directoryInfoFilter.parentId != null">
                AND tour_directory_info.parent_id = #{directoryInfoFilter.parentId}
            </if>
            <if test="directoryInfoFilter.isHotspot != null">
                AND tour_directory_info.is_hotspot = #{directoryInfoFilter.isHotspot}
            </if>
            <if test="directoryInfoFilter.directoryType != null">
                AND tour_directory_info.directory_type = #{directoryInfoFilter.directoryType}
            </if>
            <if test="directoryInfoFilter.enable != null">
                AND tour_directory_info.enable = #{directoryInfoFilter.enable}
            </if>
            <if test="directoryInfoFilter.directoryId != null">
                AND tour_directory_info.id &gt;= #{directoryInfoFilter.directoryId}
            </if>
<!--            <if test="directoryInfoFilter.isWinnowDestination != null">-->
<!--                AND tour_directory_info.is_winnow_destination = #{directoryInfoFilter.isWinnowDestination}-->
<!--            </if>-->
        </if>
    </sql>

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

    <select id="queryDirectoryNameSub" resultMap="BaseResultMap" parameterType="com.tourism.webadmin.back.model.DirectoryInfo">
        SELECT * FROM tour_directory_info WHERE id IN (11, 12, 13, 14, 15, 17) order by show_order;
    </select>

</mapper>
