<?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.TourBookInfoMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourBookInfo">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="book_mobile" jdbcType="VARCHAR" property="bookMobile"/>
        <result column="book_name" jdbcType="VARCHAR" property="bookName"/>
        <result column="book_ip" jdbcType="VARCHAR" property="bookIp"/>
        <result column="book_time" jdbcType="TIMESTAMP" property="bookTime"/>
        <result column="is_handle" jdbcType="TINYINT" property="isHandle"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <result column="type" jdbcType="TINYINT" property="type"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="project_id" jdbcType="BIGINT" property="projectId"/>
        <result column="update_user_id" jdbcType="BIGINT" property="updateUserId"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="deleted_flag" jdbcType="INTEGER" property="deletedFlag"/>
        <result column="adult_price" jdbcType="DECIMAL" property="adultPrice"/>
        <result column="children_price" jdbcType="DECIMAL" property="childrenPrice"/>
        <result column="adult_number" jdbcType="INTEGER" property="adultNumber"/>
        <result column="children_number" jdbcType="INTEGER" property="childrenNumber"/>
        <result column="total_price" jdbcType="DECIMAL" property="totalPrice"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_book_info
            (id,
            book_mobile,
            book_name,
            book_ip,
            book_time,
            is_handle,
            create_user_id,
            type,
            create_time,
            project_id,
            update_user_id,
            update_time,
            deleted_flag,
            adult_price,
            children_price,
            adult_number,
            children_number,
            total_price)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.bookMobile},
            #{item.bookName},
            #{item.bookIp},
            #{item.bookTime},
            #{item.isHandle},
            #{item.createUserId},
            #{item.type},
            #{item.createTime},
            #{item.projectId},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.deletedFlag},
            #{item.adultPrice},
            #{item.childrenPrice},
            #{item.adultNumber},
            #{item.childrenNumber},
            #{item.totalPrice})
        </foreach>
    </insert>

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

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tourBookInfoFilter != null">
            <if test="tourBookInfoFilter.bookMobile != null and tourBookInfoFilter.bookMobile != ''">
                <bind name = "safeTourBookInfoBookMobile" value = "'%' + tourBookInfoFilter.bookMobile + '%'" />
                AND tour_book_info.book_mobile LIKE #{safeTourBookInfoBookMobile}
            </if>
            <if test="tourBookInfoFilter.bookName != null and tourBookInfoFilter.bookName != ''">
                <bind name = "safeTourBookInfoBookName" value = "'%' + tourBookInfoFilter.bookName + '%'" />
                AND tour_book_info.book_name LIKE #{safeTourBookInfoBookName}
            </if>
            <if test="tourBookInfoFilter.bookIp != null and tourBookInfoFilter.bookIp != ''">
                AND tour_book_info.book_ip = #{tourBookInfoFilter.bookIp}
            </if>
            <if test="tourBookInfoFilter.bookTime != null">
                AND tour_book_info.book_time = #{tourBookInfoFilter.bookTime}
            </if>
            <if test="tourBookInfoFilter.isHandle != null">
                AND tour_book_info.is_handle = #{tourBookInfoFilter.isHandle}
            </if>
            <if test="tourBookInfoFilter.searchString != null and tourBookInfoFilter.searchString != ''">
                <bind name = "safeTourBookInfoSearchString" value = "'%' + tourBookInfoFilter.searchString + '%'" />
                AND CONCAT(IFNULL(tour_book_info.book_mobile,''), IFNULL(tour_book_info.book_name,'')) LIKE #{safeTourBookInfoSearchString}
            </if>
            <if test="tourBookInfoFilter.startTime != null and tourBookInfoFilter.endTime != null">
                AND tour_book_info.book_time between #{tourBookInfoFilter.startTime} and #{tourBookInfoFilter.endTime}
            </if>
            <if test="tourBookInfoFilter.type != null">
                AND tour_book_info.type = #{tourBookInfoFilter.type}
            </if>
            <if test="tourBookInfoFilter.projectId != null">
                AND tour_book_info.project_id = #{tourBookInfoFilter.projectId}
            </if>
        </if>
    </sql>

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