<?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.TourCarOrderMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourCarOrder">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
        <result column="category_id" jdbcType="BIGINT" property="categoryId"/>
        <result column="driver_id" jdbcType="BIGINT" property="driverId"/>
        <result column="start_time" jdbcType="TIMESTAMP" property="startTime"/>
        <result column="end_time" jdbcType="TIMESTAMP" property="endTime"/>
        <result column="days" jdbcType="INTEGER" property="days"/>
        <result column="start_place_id" jdbcType="BIGINT" property="startPlaceId"/>
        <result column="connect_phone" jdbcType="VARCHAR" property="connectPhone"/>
        <result column="connect_name" jdbcType="VARCHAR" property="connectName"/>
        <result column="connect_sex" jdbcType="TINYINT" property="connectSex"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
        <result column="state" jdbcType="TINYINT" property="state"/>
        <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="category_mark" jdbcType="TINYINT" property="categoryMark"/>
        <result column="drive_mark" jdbcType="TINYINT" property="driveMark"/>
        <result column="connect_wechat" jdbcType="VARCHAR" property="connectWechat"/>
        <result column="driver_name" jdbcType="VARCHAR" property="driverName"/>
        <result column="driver_sex" jdbcType="TINYINT" property="driverSex"/>
        <result column="driver_age" jdbcType="TINYINT" property="driverAge"/>
        <result column="driving_years" jdbcType="TINYINT" property="drivingYears"/>
        <result column="driver_mobile" jdbcType="VARCHAR" property="driverMobile"/>
        <result column="driver_image" jdbcType="VARCHAR" property="driverImage"/>
        <result column="car_model" jdbcType="BIGINT" property="carModel"/>
        <result column="car_name" jdbcType="VARCHAR" property="carName"/>
        <result column="car_seat_number" jdbcType="TINYINT" property="carSeatNumber"/>
        <result column="car_luggage_number" jdbcType="TINYINT" property="carLuggageNumber"/>
        <result column="car_image" jdbcType="VARCHAR" property="carImage"/>
        <result column="day_price" jdbcType="DECIMAL" property="dayPrice"/>
        <result column="day_price_unit" jdbcType="VARCHAR" property="dayPriceUnit"/>
        <result column="total_price" jdbcType="DECIMAL" property="totalPrice"/>
        <result column="total_price_unit" jdbcType="VARCHAR" property="totalPriceUnit"/>
        <result column="category_type" jdbcType="TINYINT" property="categoryType"/>
        <result column="driver_sys_id" jdbcType="BIGINT" property="driverSysId"/>
        <result column="driver_dept_id" jdbcType="BIGINT" property="driverDeptId"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_car_order
            (id,
            order_no,
            category_id,
            driver_id,
            start_time,
            end_time,
            days,
            start_place_id,
            connect_phone,
            connect_name,
            connect_sex,
            remark,
            state,
            create_user_id,
            create_time,
            update_user_id,
            update_time,
            data_state,
            category_mark,
            drive_mark,
            connect_wechat,
            driver_name,
            driver_sex,
            driver_age,
            driving_years,
            driver_mobile,
            driver_image,
            car_model,
            car_name,
            car_seat_number,
            car_luggage_number,
            car_image,
            day_price,
            day_price_unit,
            total_price,
            total_price_unit,
            category_type,
            marking,
            driver_sys_id,
            driver_dept_id)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.orderNo},
            #{item.categoryId},
            #{item.driverId},
            #{item.startTime},
            #{item.endTime},
            #{item.days},
            #{item.startPlaceId},
            #{item.connectPhone},
            #{item.connectName},
            #{item.connectSex},
            #{item.remark},
            #{item.state},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.dataState},
            #{item.categoryMark},
            #{item.driveMark},
            #{item.connectWechat},
            #{item.driverName},
            #{item.driverSex},
            #{item.driverAge},
            #{item.drivingYears},
            #{item.driverMobile},
            #{item.driverImage},
            #{item.carModel},
            #{item.carName},
            #{item.carSeatNumber},
            #{item.carLuggageNumber},
            #{item.carImage},
            #{item.dayPrice},
            #{item.dayPriceUnit},
            #{item.totalPrice},
            #{item.totalPriceUnit},
            #{item.categoryType},
            #{item.marking},
            #{item.driverSysId},
            #{item.driverDeptId})
        </foreach>
    </insert>

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

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tourCarOrderFilter != null">
            <if test="tourCarOrderFilter.orderNo != null and tourCarOrderFilter.orderNo != ''">
                AND tour_car_order.order_no = #{tourCarOrderFilter.orderNo}
            </if>
            <if test="tourCarOrderFilter.categoryId != null">
                AND tour_car_order.category_id = #{tourCarOrderFilter.categoryId}
            </if>
            <if test="tourCarOrderFilter.driverId != null">
                AND tour_car_order.driver_id = #{tourCarOrderFilter.driverId}
            </if>
            <if test="tourCarOrderFilter.startTimeStart != null and tourCarOrderFilter.startTimeStart != ''">
                AND tour_car_order.start_time &gt;= #{tourCarOrderFilter.startTimeStart}
            </if>
            <if test="tourCarOrderFilter.startTimeEnd != null and tourCarOrderFilter.startTimeEnd != ''">
                AND tour_car_order.start_time &lt;= #{tourCarOrderFilter.startTimeEnd}
            </if>
            <if test="tourCarOrderFilter.endTimeStart != null and tourCarOrderFilter.endTimeStart != ''">
                AND tour_car_order.end_time &gt;= #{tourCarOrderFilter.endTimeStart}
            </if>
            <if test="tourCarOrderFilter.endTimeEnd != null and tourCarOrderFilter.endTimeEnd != ''">
                AND tour_car_order.end_time &lt;= #{tourCarOrderFilter.endTimeEnd}
            </if>
            <if test="tourCarOrderFilter.days != null">
                AND tour_car_order.days = #{tourCarOrderFilter.days}
            </if>
            <if test="tourCarOrderFilter.startPlaceId != null">
                AND tour_car_order.start_place_id = #{tourCarOrderFilter.startPlaceId}
            </if>
            <if test="tourCarOrderFilter.connectPhone != null and tourCarOrderFilter.connectPhone != ''">
                <bind name = "safeTourCarOrderConnectPhone" value = "'%' + tourCarOrderFilter.connectPhone + '%'" />
                AND tour_car_order.connect_phone LIKE #{safeTourCarOrderConnectPhone}
            </if>
            <if test="tourCarOrderFilter.connectName != null and tourCarOrderFilter.connectName != ''">
                <bind name = "safeTourCarOrderConnectName" value = "'%' + tourCarOrderFilter.connectName + '%'" />
                AND tour_car_order.connect_name LIKE #{safeTourCarOrderConnectName}
            </if>
            <if test="tourCarOrderFilter.connectSex != null">
                AND tour_car_order.connect_sex = #{tourCarOrderFilter.connectSex}
            </if>
            <if test="tourCarOrderFilter.state != null">
                AND tour_car_order.state = #{tourCarOrderFilter.state}
            </if>
            <if test="tourCarOrderFilter.carModel != null">
                AND tour_car_order.car_model = #{tourCarOrderFilter.carModel}
            </if>
            <if test="tourCarOrderFilter.categoryType != null">
                AND tour_car_order.category_type = #{tourCarOrderFilter.categoryType}
            </if>
            <if test="tourCarOrderFilter.searchString != null and tourCarOrderFilter.searchString != ''">
                <bind name = "safeTourCarOrderSearchString" value = "'%' + tourCarOrderFilter.searchString + '%'" />
                AND CONCAT(IFNULL(tour_car_order.connect_phone,''), IFNULL(tour_car_order.connect_name,'')) LIKE #{safeTourCarOrderSearchString}
            </if>
            <if test="tourCarOrderFilter.createUserId != null">
                AND tour_car_order.create_user_id = #{tourCarOrderFilter.createUserId}
            </if>
        </if>
    </sql>

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

    <!-- 支持基于一对一或者一对多从表字段过滤的SQL_ID -->
    <select id="getTourCarOrderListEx" resultMap="BaseResultMap" >
        SELECT
            tour_car_order.*
        FROM
            tour_car_order
        <where>
            <include refid="filterRef"/>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>
</mapper>
