<?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.SrsDormSelectMapper">
    
    <resultMap type="SrsDormSelect" id="SrsDormSelectResult">
        <result property="id"    column="id"    />
        <result property="dorms"    column="dorms"    />
        <result property="className"    column="class_name"    />
        <result property="classCode"    column="class_code"    />
    </resultMap>

    <sql id="selectSrsDormSelectVo">
        select id, dorms, class_name, class_code from srs_dorm_select
    </sql>

    <select id="selectSrsDormSelectList" parameterType="SrsDormSelect" resultMap="SrsDormSelectResult">
        <include refid="selectSrsDormSelectVo"/>
        <where>  
            <if test="dorms != null  and dorms != ''"> and dorms = #{dorms}</if>
            <if test="className != null  and className != ''"> and class_name like concat('%', #{className}, '%')</if>
            <if test="classCode != null  and classCode != ''"> and class_code = #{classCode}</if>
        </where>
    </select>
    
    <select id="selectSrsDormSelectById" parameterType="Long" resultMap="SrsDormSelectResult">
        <include refid="selectSrsDormSelectVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSrsDormSelect" parameterType="SrsDormSelect" useGeneratedKeys="true" keyProperty="id">
        insert into srs_dorm_select
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dorms != null">dorms,</if>
            <if test="className != null">class_name,</if>
            <if test="classCode != null">class_code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dorms != null">#{dorms},</if>
            <if test="className != null">#{className},</if>
            <if test="classCode != null">#{classCode},</if>
         </trim>
    </insert>

    <update id="updateSrsDormSelect" parameterType="SrsDormSelect">
        update srs_dorm_select
        <trim prefix="SET" suffixOverrides=",">
            <if test="dorms != null">dorms = #{dorms},</if>
            <if test="className != null">class_name = #{className},</if>
            <if test="classCode != null">class_code = #{classCode},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSrsDormSelectById" parameterType="Long">
        delete from srs_dorm_select where id = #{id}
    </delete>

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