<?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.srs.stureg.mapper.CheckRoomMapper">
    
    <resultMap type="CheckRoom" id="CheckRoomResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="studentId"    column="student_id"    />
        <result property="lodging"    column="lodging"    />
        <result property="dormitory"    column="dormitory"    />
        <result property="room"    column="room"    />
        <result property="bed"    column="bed"    />
        <result property="roomLevel"    column="room_level"    />
        <result property="roomImg"    column="room_img"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_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"    />
    </resultMap>

    <sql id="selectCheckRoomVo">
        select id, name, student_id, lodging, dormitory, room, bed, room_level, room_img,status, del_flag, create_by, create_time, update_by, update_time from srs_check
    </sql>

    <select id="selectCheckRoomList" parameterType="CheckRoom" resultMap="CheckRoomResult">
        <include refid="selectCheckRoomVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="studentId != null "> and student_id = #{studentId}</if>
            <if test="lodging != null  and lodging != ''"> and lodging = #{lodging}</if>
            <if test="dormitory != null  and dormitory != ''"> and dormitory = #{dormitory}</if>
            <if test="room != null  and room != ''"> and room = #{room}</if>
            <if test="bed != null  and bed != ''"> and bed = #{bed}</if>
            <if test="roomLevel != null "> and room_level = #{roomLevel}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectCheckRoomById" parameterType="Long" resultMap="CheckRoomResult">
        <include refid="selectCheckRoomVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCheckRoom" parameterType="CheckRoom" useGeneratedKeys="true" keyProperty="id">
        insert into srs_check
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="studentId != null">student_id,</if>
            <if test="lodging != null">lodging,</if>
            <if test="dormitory != null">dormitory,</if>
            <if test="room != null">room,</if>
            <if test="bed != null">bed,</if>
            <if test="roomLevel != null">room_level,</if>
            <if test="roomImg != null">room_img,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="studentId != null">#{studentId},</if>
            <if test="lodging != null">#{lodging},</if>
            <if test="dormitory != null">#{dormitory},</if>
            <if test="room != null">#{room},</if>
            <if test="bed != null">#{bed},</if>
            <if test="roomLevel != null">#{roomLevel},</if>
            <if test="roomImg != null">room_img,</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateCheckRoom" parameterType="CheckRoom">
        update srs_check
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="studentId != null">student_id = #{studentId},</if>
            <if test="lodging != null">lodging = #{lodging},</if>
            <if test="dormitory != null">dormitory = #{dormitory},</if>
            <if test="room != null">room = #{room},</if>
            <if test="bed != null">bed = #{bed},</if>
            <if test="roomLevel != null">room_level = #{roomLevel},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCheckRoomById" parameterType="Long">
        delete from srs_check where id = #{id}
    </delete>

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