<?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.ics.admin.mapper.meeting.ReservationMapper">
    
    <resultMap type="com.ics.admin.domain.meeting.Reservation" id="ReservationResult">
        <result property="id"    column="id"    />
        <result property="roomContentId"    column="room_content_id"    />
        <result property="userId"    column="user_id"    />
        <result property="ticketId"    column="ticket_id"    />
        <result property="customerId"    column="customer_id"    />
        <result property="serveId"    column="serve_id"    />
        <result property="title"    column="title"    />
        <result property="stauts"    column="stauts"    />
        <result property="isAfterSale"    column="is_after_sale"    />
        <result property="oderNumber"    column="oder_number"    />
        <result property="orderMoney"    column="order_money"    />
        <result property="cancelTime"    column="cancel_time"    />
        <result property="orderTime"    column="order_time"    />
        <result property="cancelResaon"    column="cancel_resaon"    />
        <result property="visitType"    column="visit_type"    />
        <result property="prepayId"    column="prepay_id"    />
        <result property="reservationNumber"    column="reservation_number"    />
        <result property="explainNeedType"    column="explain_need_type"    />
        <result property="meetingNeedType"    column="meeting_need_type"    />
        <result property="photographType"    column="photograph_type"    />
        <result property="startTime"    column="start_time"    />
        <result property="endDate"    column="end_date"    />
        <result property="deleteFlag"    column="delete_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remake"    column="remake"    />
        <result property="personNum"    column="person_num"    />
    </resultMap>

    <sql id="selectReservationVo">
        SELECT id, room_content_id, user_id, ticket_id,
               customer_id, title, stauts,serve_id,end_date, is_after_sale,person_num,
               oder_number,reservation_number, order_money, cancel_time,prepay_id,
               cancel_resaon, visit_type, explain_need_type, meeting_need_type,  photograph_type, start_time,
               delete_flag, create_by, create_time, update_by, update_time, remake FROM tb_reservation
    </sql>

    <select id="selectReservationList" parameterType="Reservation" resultMap="ReservationResult">
        <include refid="selectReservationVo"/>
        <where>  
        </where>
    </select>
    
    <select id="selectReservationById" parameterType="Long" resultMap="ReservationResult">
        <include refid="selectReservationVo"/>
        WHERE id = #{id}
    </select>
    <select id="selectListByDate" resultType="java.util.Date">
        select  date_format(start_time, '%Y-%m-%d') from tb_reservation where `stauts` != 4 and start_time >= date_format(now(), '%Y-%m-%d')
        and room_content_id = #{roomContentId} group by date_format(start_time, '%Y-%m-%d');
    </select>
    <select id="todayMeeting" resultType="com.ics.admin.domain.meeting.Reservation">
        <include refid="selectReservationVo"/>
        WHERE
        (
        DATE_FORMAT( start_time, '%Y-%m-%d' ) =
        DATE_FORMAT( NOW(), '%Y-%m-%d' ))
        and
        ((DATE_FORMAT( start_time, '%Y-%m-%d %H:%i:%S' ) &lt;
            DATE_FORMAT( NOW(), '%Y-%m-%d %H:%i:%S' )
        and
        DATE_FORMAT( end_date, '%Y-%m-%d %H:%i:%S' ) >
        DATE_FORMAT( NOW(), '%Y-%m-%d %H:%i:%S' ))
        or
        (
        DATE_FORMAT( start_time, '%Y-%m-%d %H:%i:%S' ) >
        DATE_FORMAT( NOW(), '%Y-%m-%d %H:%i:%S' )))
        and room_content_id =#{id}
        and (`stauts` = 1 OR `stauts` = 2)
        ORDER BY start_time ASC

    </select>
    <select id="selectReservationListByDay" resultType="com.ics.admin.domain.meeting.Reservation">
        <include refid="selectReservationVo"/>
        WHERE
        DATE_FORMAT( start_time, '%Y-%m-%d' ) = DATE_FORMAT(now(), '%Y-%m-%d' )
            and `stauts` = 1 and `park_id` = '27'
    </select>

    <insert id="insertReservation" parameterType="Reservation">
        INSERT INTO tb_reservation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null ">id,</if>
            <if test="roomContentId != null ">room_content_id,</if>
            <if test="userId != null ">user_id,</if>
            <if test="ticketId != null ">ticket_id,</if>
            <if test="customerId != null ">customer_id,</if>
            <if test="serveId != null ">serve_id,</if>
            <if test="title != null  and title != ''">title,</if>
            <if test="stauts != null ">stauts,</if>
            <if test="isAfterSale != null  and isAfterSale != ''">is_after_sale,</if>
            <if test="oderNumber != null  and oderNumber != ''">oder_number,</if>
            <if test="orderMoney != null  and orderMoney != ''">order_money,</if>
            <if test="prepayId != null  and prepayId != ''">prepay_id,</if>
            <if test="cancelTime != null ">cancel_time,</if>
            <if test="orderTime != null ">order_time,</if>
            <if test="cancelResaon != null  and cancelResaon != ''">cancel_resaon,</if>
            <if test="visitType != null  and visitType != ''">visit_type,</if>
            <if test="explainNeedType != null  and explainNeedType != ''">explain_need_type,</if>
            <if test="meetingNeedType != null  and meetingNeedType != ''">meeting_need_type,</if>
            <if test="photographType != null  and photographType != ''">photograph_type,</if>
            <if test="startTime != null ">start_time,</if>
            <if test="endDate != null ">end_date,</if>
            <if test="reservationNumber != null ">reservation_number,</if>
            <if test="deleteFlag != null ">delete_flag,</if>
            <if test="createBy != null  and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="updateBy != null  and updateBy != ''">update_by,</if>
            <if test="updateTime != null ">update_time,</if>
            <if test="remake != null  and remake != ''">remake,</if>
            <if test="personNum != null  and personNum != ''">person_num,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null ">#{id},</if>
            <if test="roomContentId != null ">#{roomContentId},</if>
            <if test="userId != null ">#{userId},</if>
            <if test="ticketId != null ">#{ticketId},</if>
            <if test="customerId != null ">#{customerId},</if>
            <if test="serveId != null ">#{serveId},</if>
            <if test="title != null  and title != ''">#{title},</if>
            <if test="stauts != null ">#{stauts},</if>
            <if test="reservationNumber != null ">#{reservationNumber},</if>
            <if test="isAfterSale != null  and isAfterSale != ''">#{isAfterSale},</if>
            <if test="oderNumber != null  and oderNumber != ''">#{oderNumber},</if>
            <if test="orderMoney != null  and orderMoney != ''">#{orderMoney},</if>
            <if test="prepayId != null  and prepayId != ''">#{prepayId},</if>
            <if test="cancelTime != null ">#{cancelTime},</if>
            <if test="orderTime != null ">#{orderTime},</if>
            <if test="cancelResaon != null  and cancelResaon != ''">#{cancelResaon},</if>
            <if test="visitType != null  and visitType != ''">#{visitType},</if>
            <if test="explainNeedType != null  and explainNeedType != ''">#{explainNeedType},</if>
            <if test="meetingNeedType != null  and meetingNeedType != ''">#{meetingNeedType},</if>
            <if test="photographType != null  and photographType != ''">#{photographType},</if>
            <if test="startTime != null ">#{startTime},</if>
            <if test="endDate != null ">#{endDate},</if>
            <if test="deleteFlag != null ">#{deleteFlag},</if>
            <if test="createBy != null  and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null ">#{updateTime},</if>
            <if test="remake != null  and remake != ''">#{remake},</if>
            <if test="personNum != null  and personNum != ''">#{personNum},</if>
         </trim>
    </insert>

    <update id="updateReservation" parameterType="Reservation">
        UPDATE tb_reservation
        <trim prefix="SET" suffixOverrides=",">
            <if test="roomContentId != null ">room_content_id = #{roomContentId},</if>
            <if test="userId != null ">user_id = #{userId},</if>
            <if test="ticketId != null ">ticket_id = #{ticketId},</if>
            <if test="customerId != null ">customer_id = #{customerId},</if>
            <if test="serveId != null ">serve_id = #{serveId},</if>
            <if test="title != null  and title != ''">title = #{title},</if>
            <if test="stauts != null ">stauts = #{stauts},</if>
            <if test="isAfterSale != null  and isAfterSale != ''">is_after_sale = #{isAfterSale},</if>
            <if test="oderNumber != null  and oderNumber != ''">oder_number = #{oderNumber},</if>
            <if test="orderMoney != null  and orderMoney != ''">order_money = #{orderMoney},</if>
            <if test="prepayId != null  and prepayId != ''">prepay_id = #{prepayId},</if>
            <if test="cancelTime != null ">cancel_time = #{cancelTime},</if>
            <if test="reservationNumber != null ">reservation_number = #{reservationNumber},</if>
            <if test="cancelResaon != null  and cancelResaon != ''">cancel_resaon = #{cancelResaon},</if>
            <if test="visitType != null  and visitType != ''">visit_type = #{visitType},</if>
            <if test="explainNeedType != null  and explainNeedType != ''">explain_need_type = #{explainNeedType},</if>
            <if test="meetingNeedType != null  and meetingNeedType != ''">meeting_need_type = #{meetingNeedType},</if>
            <if test="photographType != null  and photographType != ''">photograph_type = #{photographType},</if>
            <if test="startTime != null ">start_time = #{startTime},</if>
            <if test="endDate != null ">end_date = #{endDate},</if>
            <if test="orderTime != null ">order_time = #{orderTime},</if>
            <if test="deleteFlag != null ">delete_flag = #{deleteFlag},</if>
            <if test="createBy != null  and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null ">update_time = #{updateTime},</if>
            <if test="remake != null  and remake != ''">remake = #{remake},</if>
            <if test="personNum != null  and personNum != ''">person_num = #{personNum},</if>
        </trim>
        WHERE id = #{id}
    </update>

    <delete id="deleteReservationById" parameterType="Long">
        DELETE FROM tb_reservation WHERE id = #{id}
    </delete>

    <delete id="deleteReservationByIds" parameterType="String">
        DELETE FROM tb_reservation where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
</mapper>