<?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.younike.system.mapper.ServerTimeBookMapper">
    
    <resultMap type="ServerTimeBook" id="ServerTimeBookResult">
        <result property="id"    column="id"    />
        <result property="serverId"    column="server_id"    />
        <result property="serverDate"    column="server_date"    />
        <result property="week"    column="week"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="booked"    column="booked"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectServerTimeBookVo">
        select id, server_id, server_date, week, start_time, end_time, booked, create_by, create_time from server_time_book
    </sql>

    <select id="selectServerTimeBookList" parameterType="ServerTimeBook" resultMap="ServerTimeBookResult">
        <include refid="selectServerTimeBookVo"/>
        <where>  
            <if test="serverId != null "> and server_id = #{serverId}</if>
            <if test="serverDate != null "> and server_date = #{serverDate}</if>
            <if test="week != null "> and week = #{week}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="booked != null "> and booked = #{booked}</if>
        </where>
    </select>
    
    <select id="selectServerTimeBookById" parameterType="Long" resultMap="ServerTimeBookResult">
        <include refid="selectServerTimeBookVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertServerTimeBook" parameterType="ServerTimeBook" useGeneratedKeys="true" keyProperty="id">
        insert into server_time_book
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="serverId != null">server_id,</if>
            <if test="serverDate != null">server_date,</if>
            <if test="week != null">week,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="booked != null">booked,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="serverId != null">#{serverId},</if>
            <if test="serverDate != null">#{serverDate},</if>
            <if test="week != null">#{week},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="booked != null">#{booked},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateServerTimeBook" parameterType="ServerTimeBook">
        update server_time_book
        <trim prefix="SET" suffixOverrides=",">
            <if test="serverId != null">server_id = #{serverId},</if>
            <if test="serverDate != null">server_date = #{serverDate},</if>
            <if test="week != null">week = #{week},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="booked != null">booked = #{booked},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteServerTimeBookById" parameterType="Long">
        delete from server_time_book where id = #{id}
    </delete>

    <delete id="deleteServerTimeBookByIds" parameterType="String">
        delete from server_time_book where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>