<?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.dormitory.mapper.DmsNewRangeMapper">
    
    <resultMap type="DmsNewRange" id="DmsNewRangeResult">
        <result property="id"    column="id"    />
        <result property="rangeName"    column="range_name"    />
        <result property="startDate"    column="start_date"    />
        <result property="endDate"    column="end_date"    />
        <result property="rangeStatus"    column="range_status"    />
        <result property="xndm"    column="xndm"    />
        <result property="rangeCode"    column="range_code"    />
    </resultMap>

    <sql id="selectDmsNewRangeVo">
        select id, range_name, start_date, end_date, range_status, xndm, range_code from dms_new_range
    </sql>

    <select id="selectDmsNewRangeList" parameterType="DmsNewRange" resultMap="DmsNewRangeResult">
        <include refid="selectDmsNewRangeVo"/>
        <where>  
            <if test="rangeName != null  and rangeName != ''"> and range_name like concat('%', #{rangeName}, '%')</if>
            <if test="startDate != null "> and start_date = #{startDate}</if>
            <if test="endDate != null "> and end_date = #{endDate}</if>
            <if test="rangeStatus != null  and rangeStatus != ''"> and range_status = #{rangeStatus}</if>
            <if test="xndm != null  and xndm != ''"> and xndm = #{xndm}</if>
            <if test="rangeCode != null  and rangeCode != ''"> and range_code = #{rangeCode}</if>
        </where>
    </select>
    
    <select id="selectDmsNewRangeById" parameterType="Long" resultMap="DmsNewRangeResult">
        <include refid="selectDmsNewRangeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertDmsNewRange" parameterType="DmsNewRange">
        insert into dms_new_range
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="rangeName != null">range_name,</if>
            <if test="startDate != null">start_date,</if>
            <if test="endDate != null">end_date,</if>
            <if test="rangeStatus != null">range_status,</if>
            <if test="xndm != null">xndm,</if>
            <if test="rangeCode != null">range_code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="rangeName != null">#{rangeName},</if>
            <if test="startDate != null">#{startDate},</if>
            <if test="endDate != null">#{endDate},</if>
            <if test="rangeStatus != null">#{rangeStatus},</if>
            <if test="xndm != null">#{xndm},</if>
            <if test="rangeCode != null">#{rangeCode},</if>
         </trim>
    </insert>

    <update id="updateDmsNewRange" parameterType="DmsNewRange">
        update dms_new_range
        <trim prefix="SET" suffixOverrides=",">
            <if test="rangeName != null">range_name = #{rangeName},</if>
            <if test="startDate != null">start_date = #{startDate},</if>
            <if test="endDate != null">end_date = #{endDate},</if>
            <if test="rangeStatus != null">range_status = #{rangeStatus},</if>
            <if test="xndm != null">xndm = #{xndm},</if>
            <if test="rangeCode != null">range_code = #{rangeCode},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDmsNewRangeById" parameterType="Long">
        delete from dms_new_range where id = #{id}
    </delete>

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