<?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.TourVisaOrderMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourVisaOrder">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="file" jdbcType="LONGVARCHAR" property="file"/>
        <result column="order_name" jdbcType="VARCHAR" property="orderName"/>
        <result column="order_phone" jdbcType="VARCHAR" property="orderPhone"/>
        <result column="order_id_card" jdbcType="VARCHAR" property="orderIdCard"/>
        <result column="visa_id" jdbcType="BIGINT" property="visaId"/>
        <result column="state" jdbcType="INTEGER" property="state"/>
        <result column="pay_state" jdbcType="INTEGER" property="payState"/>
        <result column="delete_flag" jdbcType="INTEGER" property="deleteFlag"/>
        <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="order_price" jdbcType="VARCHAR" property="orderPrice"/>
        <result column="counselor_id" jdbcType="BIGINT" property="counselorId"/>
        <result column="order_address" jdbcType="VARCHAR" property="orderAddress"/>
        <result column="service_price" jdbcType="VARCHAR" property="servicePrice"/>
        <result column="price" jdbcType="VARCHAR" property="price"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_visa_order
            (id,
            file,
            order_name,
            order_phone,
            order_id_card,
            visa_id,
            state,
            pay_state,
            delete_flag,
            create_user_id,
            create_time,
            update_user_id,
            update_time,
            order_price,
            counselor_id,
            order_address,
            service_price,
            price)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.file},
            #{item.orderName},
            #{item.orderPhone},
            #{item.orderIdCard},
            #{item.visaId},
            #{item.state},
            #{item.payState},
            #{item.deleteFlag},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.orderPrice},
            #{item.counselorId},
            #{item.orderAddress},
            #{item.servicePrice},
            #{item.price})
        </foreach>
    </insert>

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

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tourVisaOrderFilter != null">
            <if test="tourVisaOrderFilter.orderName != null and tourVisaOrderFilter.orderName != ''">
                <bind name = "safeTourVisaOrderOrderName" value = "'%' + tourVisaOrderFilter.orderName + '%'" />
                AND tour_visa_order.order_name LIKE #{safeTourVisaOrderOrderName}
            </if>
            <if test="tourVisaOrderFilter.orderPhone != null and tourVisaOrderFilter.orderPhone != ''">
                <bind name = "safeTourVisaOrderOrderPhone" value = "'%' + tourVisaOrderFilter.orderPhone + '%'" />
                AND tour_visa_order.order_phone LIKE #{safeTourVisaOrderOrderPhone}
            </if>
            <if test="tourVisaOrderFilter.orderIdCard != null and tourVisaOrderFilter.orderIdCard != ''">
                <bind name = "safeTourVisaOrderOrderIdCard" value = "'%' + tourVisaOrderFilter.orderIdCard + '%'" />
                AND tour_visa_order.order_id_card LIKE #{safeTourVisaOrderOrderIdCard}
            </if>
            <if test="tourVisaOrderFilter.state != null">
                AND tour_visa_order.state = #{tourVisaOrderFilter.state}
            </if>
            <if test="tourVisaOrderFilter.payState != null">
                AND tour_visa_order.pay_state = #{tourVisaOrderFilter.payState}
            </if>
            <if test="tourVisaOrderFilter.counselorId != null">
                AND tour_visa_order.counselor_id = #{tourVisaOrderFilter.counselorId}
            </if>
            <if test="tourVisaOrderFilter.searchString != null and tourVisaOrderFilter.searchString != ''">
                <bind name = "safeTourVisaOrderSearchString" value = "'%' + tourVisaOrderFilter.searchString + '%'" />
                AND CONCAT(IFNULL(tour_visa_order.order_name,''), IFNULL(tour_visa_order.order_phone,''), IFNULL(tour_visa_order.order_id_card,'')) LIKE #{safeTourVisaOrderSearchString}
            </if>
        </if>
    </sql>

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