<?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.TourismProjectMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourismProject">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="project_title" jdbcType="VARCHAR" property="projectTitle"/>
        <result column="remarks" jdbcType="VARCHAR" property="remarks"/>
        <result column="is_hotspot" jdbcType="TINYINT" property="isHotspot"/>
        <result column="project_label" jdbcType="VARCHAR" property="projectLabel"/>
        <result column="show_order" jdbcType="TINYINT" property="showOrder"/>
        <result column="enable" jdbcType="TINYINT" property="enable"/>
        <result column="belong_tab" jdbcType="BIGINT" property="belongTab"/>
        <result column="start_place" jdbcType="VARCHAR" property="startPlace"/>
        <result column="end_place" jdbcType="VARCHAR" property="endPlace"/>
        <result column="count_times" jdbcType="VARCHAR" property="countTimes"/>
        <result column="price" jdbcType="VARCHAR" property="price"/>
        <result column="tourism_url" jdbcType="VARCHAR" property="tourismUrl"/>
        <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>

    <insert id="insertList">
        INSERT INTO tour_tourism_project
            (id,
            project_title,
            remarks,
            is_hotspot,
            project_label,
            show_order,
            enable,
            belong_tab,
            start_place,
            end_place,
            count_times,
            price,
            tourism_url,
            create_user_id,
            create_time,
            update_user_id,
            update_time,
            data_state)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.projectTitle},
            #{item.remarks},
            #{item.isHotspot},
            #{item.projectLabel},
            #{item.showOrder},
            #{item.enable},
            #{item.belongTab},
            #{item.startPlace},
            #{item.endPlace},
            #{item.countTimes},
            #{item.price},
            #{item.tourismUrl},
            #{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.TourismProjectMapper.inputFilterRef"/>
        AND tour_tourism_project.data_state = ${@com.tourism.common.core.constant.GlobalDeletedFlag@NORMAL}
    </sql>

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tourismProjectFilter != null">
            <if test="tourismProjectFilter.belongTab != null and tourismProjectFilter.belongTab != ''">
                AND belong_tab = #{tourismProjectFilter.belongTab}
            </if>
            <if test="tourismProjectFilter.isHotspot != null and tourismProjectFilter.isHotspot != ''">
                AND is_hotspot = #{tourismProjectFilter.isHotspot}
            </if>
            <if test="tourismProjectFilter.projectTitle != null and tourismProjectFilter.projectTitle != ''">
                <bind name = "safeTourismProjectProjectTitle" value = "'%' + tourismProjectFilter.projectTitle + '%'" />
                AND tour_tourism_project.project_title LIKE #{safeTourismProjectProjectTitle}
            </if>
            <if test="tourismProjectFilter.searchString != null and tourismProjectFilter.searchString != ''">
                <bind name = "safeTourismProjectSearchString" value = "'%' + tourismProjectFilter.searchString + '%'" />
                AND IFNULL(tour_tourism_project.project_title,'') LIKE #{safeTourismProjectSearchString}
            </if>
        </if>
    </sql>

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