<?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.amms.mapper.ReservationTimeSlotMapper">

    <resultMap type="com.amms.domain.ReservationTimeSlot" id="ReservationTimeSlotResult">
        <result property="id"    column="id"    />
        <result property="date"    column="date"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="maxPeople"    column="max_people"    />
        <result property="currentPeople"    column="current_people"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="creator"    column="creator"    />
    </resultMap>

    <sql id="selectReservationTimeSlotVo">
        select id, date, start_time, end_time, max_people, current_people, status, create_time, creator from reservation_time_slot
    </sql>

    <select id="selectReservationTimeSlotList" parameterType="com.amms.domain.ReservationTimeSlot" resultMap="ReservationTimeSlotResult">
        <include refid="selectReservationTimeSlotVo"/>
        <where>
            <if test="date != null "> and date = #{date}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="maxPeople != null "> and max_people = #{maxPeople}</if>
            <if test="currentPeople != null "> and current_people = #{currentPeople}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="creator != null "> and creator = #{creator}</if>
        </where>
    </select>

    <select id="selectReservationTimeSlotById" parameterType="Long" resultMap="ReservationTimeSlotResult">
        <include refid="selectReservationTimeSlotVo"/>
        where id = #{id}
    </select>

    <insert id="insertReservationTimeSlot" parameterType="com.amms.domain.ReservationTimeSlot" useGeneratedKeys="true" keyProperty="id">
        insert into reservation_time_slot
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="date != null">date,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="maxPeople != null">max_people,</if>
            <if test="currentPeople != null">current_people,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="creator != null">creator,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="date != null">#{date},</if>
            <if test="startTime != null">#{startTime,jdbcType=TIME},</if>
            <if test="endTime != null">#{endTime,jdbcType=TIME},</if>
            <if test="maxPeople != null">#{maxPeople},</if>
            <if test="currentPeople != null">#{currentPeople},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="creator != null">#{creator},</if>
         </trim>
    </insert>

    <insert id="batchInsertReservationTimeSlots" parameterType="java.util.List">
        insert into reservation_time_slot (date, start_time, end_time, max_people, current_people, status, create_time, creator)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.date,jdbcType=DATE}, #{item.startTime,jdbcType=TIME}, #{item.endTime,jdbcType=TIME}, #{item.maxPeople}, #{item.currentPeople}, #{item.status}, #{item.createTime,jdbcType=TIMESTAMP}, #{item.creator})
        </foreach>
    </insert>

    <update id="updateReservationTimeSlot" parameterType="com.amms.domain.ReservationTimeSlot">
        update reservation_time_slot
        <trim prefix="SET" suffixOverrides=",">
            <if test="date != null">date = #{date},</if>
            <if test="startTime != null">start_time = #{startTime,jdbcType=TIME},</if>
            <if test="endTime != null">end_time = #{endTime,jdbcType=TIME},</if>
            <if test="maxPeople != null">max_people = #{maxPeople},</if>
            <if test="currentPeople != null">current_people = #{currentPeople},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="creator != null">creator = #{creator},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteReservationTimeSlotById" parameterType="Long">
        delete from reservation_time_slot where id = #{id}
    </delete>
</mapper>
