<?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.TourOrderPassenageMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourOrderPassenage">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="chinese_name" jdbcType="VARCHAR" property="chineseName"/>
        <result column="english_name" jdbcType="VARCHAR" property="englishName"/>
        <result column="nationality" jdbcType="VARCHAR" property="nationality"/>
        <result column="birthday" jdbcType="DATE" property="birthday"/>
        <result column="mobile" jdbcType="VARCHAR" property="mobile"/>
        <result column="order_id" jdbcType="BIGINT" property="orderId"/>
        <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_order_passenger
            (id,
            chinese_name,
            english_name,
            nationality,
            birthday,
            mobile,
            order_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.chineseName},
            #{item.englishName},
            #{item.nationality},
            #{item.birthday},
            #{item.mobile},
            #{item.orderId},
            #{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.TourOrderPassenageMapper.inputFilterRef"/>
        AND tour_order_passenger.data_state = ${@com.tourism.common.core.constant.GlobalDeletedFlag@NORMAL}
    </sql>

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tourOrderPassenageFilter != null">
            <if test="tourOrderPassenageFilter.chineseName != null and tourOrderPassenageFilter.chineseName != ''">
                <bind name = "safeTourOrderPassenageChineseName" value = "'%' + tourOrderPassenageFilter.chineseName + '%'" />
                AND tour_order_passenger.chinese_name LIKE #{safeTourOrderPassenageChineseName}
            </if>
            <if test="tourOrderPassenageFilter.englishName != null and tourOrderPassenageFilter.englishName != ''">
                <bind name = "safeTourOrderPassenageEnglishName" value = "'%' + tourOrderPassenageFilter.englishName + '%'" />
                AND tour_order_passenger.english_name LIKE #{safeTourOrderPassenageEnglishName}
            </if>
            <if test="tourOrderPassenageFilter.nationality != null">
                AND tour_order_passenger.nationality = #{tourOrderPassenageFilter.nationality}
            </if>
            <if test="tourOrderPassenageFilter.mobile != null and tourOrderPassenageFilter.mobile != ''">
                <bind name = "safeTourOrderPassenageMobile" value = "'%' + tourOrderPassenageFilter.mobile + '%'" />
                AND tour_order_passenger.mobile LIKE #{safeTourOrderPassenageMobile}
            </if>
            <if test="tourOrderPassenageFilter.orderId != null">
                AND tour_order_passenger.order_id = #{tourOrderPassenageFilter.orderId}
            </if>
            <if test="tourOrderPassenageFilter.searchString != null and tourOrderPassenageFilter.searchString != ''">
                <bind name = "safeTourOrderPassenageSearchString" value = "'%' + tourOrderPassenageFilter.searchString + '%'" />
                AND CONCAT(IFNULL(tour_order_passenger.chinese_name,''), IFNULL(tour_order_passenger.english_name,''), IFNULL(tour_order_passenger.mobile,'')) LIKE #{safeTourOrderPassenageSearchString}
            </if>
        </if>
    </sql>

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