<?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.DmsDormitoryRecordsMapper">

    <resultMap type="DmsDormitoryRecords" id="DmsDormitoryRecordsResult">
        <result property="id"    column="id"    />
        <result property="stuName"    column="stu_name"    />
        <result property="className"    column="class_name"    />
        <result property="dormitoryHead"    column="dormitory_head"    />
        <result property="stuNo"    column="stu_no"    />
        <result property="roomNo1"    column="roomNo1"    />
        <result property="standardCapacity"    column="standard_capacity"    />
        <result property="actualOccupancy"    column="actual_occupancy"    />
        <result property="accommodationDuration1"    column="accommodation_duration1"    />
        <result property="equivalentMonths1"    column="equivalent_months1"    />
        <result property="chargeStandard1"    column="charge_standard1"    />
        <result property="amountDue1"    column="amount_due1"    />
        <result property="roomNo2"    column="roomNo2"    />
        <result property="standardCapacity2"    column="standard_capacity2"    />
        <result property="actualOccupancy2"    column="actual_occupancy2"    />
        <result property="accommodationDuration2"    column="accommodation_duration2"    />
        <result property="equivalentMonths2"    column="equivalent_months2"    />
        <result property="chargeStandard2"    column="charge_standard2"    />
        <result property="amountDue2"    column="amount_due2"    />
        <result property="annualAccommodationFee"    column="annual_accommodation_fee"    />
        <result property="bankAccount"    column="bank_account"    />
        <result property="phone"    column="phone"    />
        <result property="teacher"    column="teacher"    />
        <result property="teacherPhone"    column="teacher_phone"    />
        <result property="remark1"    column="remark1"    />
        <result property="remark2"    column="remark2"    />
    </resultMap>

    <sql id="selectDmsDormitoryRecordsVo">
        select id, stu_name, class_name, dormitory_head, stu_no, roomNo1, standard_capacity, actual_occupancy, accommodation_duration1, equivalent_months1, charge_standard1, amount_due1, roomNo2, standard_capacity2, actual_occupancy2, accommodation_duration2, equivalent_months2, charge_standard2, amount_due2, annual_accommodation_fee, bank_account, phone, teacher, teacher_phone, remark1, remark2 from dms_dormitory_records
    </sql>

    <select id="selectDmsDormitoryRecordsList" parameterType="DmsDormitoryRecords" resultMap="DmsDormitoryRecordsResult">
        <include refid="selectDmsDormitoryRecordsVo"/>
        <where>
            <if test="stuName != null  and stuName != ''"> and stu_name like concat('%', #{stuName}, '%')</if>
            <if test="className != null  and className != ''"> and class_name like concat('%',#{className},'%')</if>
            <if test="dormitoryHead != null  and dormitoryHead != ''"> and dormitory_head = #{dormitoryHead}</if>
            <if test="stuNo != null  and stuNo != ''"> and stu_no = #{stuNo}</if>
            <if test="roomNo1 != null  and roomNo1 != ''"> and roomNo1 = #{roomNo1}</if>
            <if test="standardCapacity != null "> and standard_capacity = #{standardCapacity}</if>
            <if test="actualOccupancy != null "> and actual_occupancy = #{actualOccupancy}</if>
            <if test="accommodationDuration1 != null  and accommodationDuration1 != ''"> and accommodation_duration1 = #{accommodationDuration1}</if>
            <if test="equivalentMonths1 != null "> and equivalent_months1 = #{equivalentMonths1}</if>
            <if test="chargeStandard1 != null "> and charge_standard1 = #{chargeStandard1}</if>
            <if test="amountDue1 != null "> and amount_due1 = #{amountDue1}</if>
            <if test="roomNo2 != null  and roomNo2 != ''"> and roomNo2 = #{roomNo2}</if>
            <if test="standardCapacity2 != null "> and standard_capacity2 = #{standardCapacity2}</if>
            <if test="actualOccupancy2 != null "> and actual_occupancy2 = #{actualOccupancy2}</if>
            <if test="accommodationDuration2 != null  and accommodationDuration2 != ''"> and accommodation_duration2 = #{accommodationDuration2}</if>
            <if test="equivalentMonths2 != null "> and equivalent_months2 = #{equivalentMonths2}</if>
            <if test="chargeStandard2 != null "> and charge_standard2 = #{chargeStandard2}</if>
            <if test="amountDue2 != null "> and amount_due2 = #{amountDue2}</if>
            <if test="annualAccommodationFee != null "> and annual_accommodation_fee = #{annualAccommodationFee}</if>
            <if test="bankAccount != null  and bankAccount != ''"> and bank_account = #{bankAccount}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="teacher != null  and teacher != ''"> and teacher = #{teacher}</if>
            <if test="teacherPhone != null  and teacherPhone != ''"> and teacher_phone = #{teacherPhone}</if>
            <if test="remark1 != null  and remark1 != ''"> and remark1 = #{remark1}</if>
            <if test="remark2 != null  and remark2 != ''"> and remark2 = #{remark2}</if>
        </where>
    </select>

    <select id="selectDmsDormitoryRecordsById" parameterType="Long" resultMap="DmsDormitoryRecordsResult">
        <include refid="selectDmsDormitoryRecordsVo"/>
        where id = #{id}
    </select>

    <insert id="insertDmsDormitoryRecords" parameterType="DmsDormitoryRecords" useGeneratedKeys="true" keyProperty="id">
        insert into dms_dormitory_records
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stuName != null and stuName != ''">stu_name,</if>
            <if test="className != null and class != ''">class_name,</if>
            <if test="dormitoryHead != null">dormitory_head,</if>
            <if test="stuNo != null and stuNo != ''">stu_no,</if>
            <if test="roomNo1 != null">roomNo1,</if>
            <if test="standardCapacity != null">standard_capacity,</if>
            <if test="actualOccupancy != null">actual_occupancy,</if>
            <if test="accommodationDuration1 != null">accommodation_duration1,</if>
            <if test="equivalentMonths1 != null">equivalent_months1,</if>
            <if test="chargeStandard1 != null">charge_standard1,</if>
            <if test="amountDue1 != null">amount_due1,</if>
            <if test="roomNo2 != null">roomNo2,</if>
            <if test="standardCapacity2 != null">standard_capacity2,</if>
            <if test="actualOccupancy2 != null">actual_occupancy2,</if>
            <if test="accommodationDuration2 != null">accommodation_duration2,</if>
            <if test="equivalentMonths2 != null">equivalent_months2,</if>
            <if test="chargeStandard2 != null">charge_standard2,</if>
            <if test="amountDue2 != null">amount_due2,</if>
            <if test="annualAccommodationFee != null">annual_accommodation_fee,</if>
            <if test="bankAccount != null">bank_account,</if>
            <if test="phone != null">phone,</if>
            <if test="teacher != null">teacher,</if>
            <if test="teacherPhone != null">teacher_phone,</if>
            <if test="remark1 != null">remark1,</if>
            <if test="remark2 != null">remark2,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stuName != null and stuName != ''">#{stuName},</if>
            <if test="className != null and className != ''">#{className},</if>
            <if test="dormitoryHead != null">#{dormitoryHead},</if>
            <if test="stuNo != null and stuNo != ''">#{stuNo},</if>
            <if test="roomNo1 != null">#{roomNo1},</if>
            <if test="standardCapacity != null">#{standardCapacity},</if>
            <if test="actualOccupancy != null">#{actualOccupancy},</if>
            <if test="accommodationDuration1 != null">#{accommodationDuration1},</if>
            <if test="equivalentMonths1 != null">#{equivalentMonths1},</if>
            <if test="chargeStandard1 != null">#{chargeStandard1},</if>
            <if test="amountDue1 != null">#{amountDue1},</if>
            <if test="roomNo2 != null">#{roomNo2},</if>
            <if test="standardCapacity2 != null">#{standardCapacity2},</if>
            <if test="actualOccupancy2 != null">#{actualOccupancy2},</if>
            <if test="accommodationDuration2 != null">#{accommodationDuration2},</if>
            <if test="equivalentMonths2 != null">#{equivalentMonths2},</if>
            <if test="chargeStandard2 != null">#{chargeStandard2},</if>
            <if test="amountDue2 != null">#{amountDue2},</if>
            <if test="annualAccommodationFee != null">#{annualAccommodationFee},</if>
            <if test="bankAccount != null">#{bankAccount},</if>
            <if test="phone != null">#{phone},</if>
            <if test="teacher != null">#{teacher},</if>
            <if test="teacherPhone != null">#{teacherPhone},</if>
            <if test="remark1 != null">#{remark1},</if>
            <if test="remark2 != null">#{remark2},</if>
        </trim>
    </insert>

    <update id="updateDmsDormitoryRecords" parameterType="DmsDormitoryRecords">
        update dms_dormitory_records
        <trim prefix="SET" suffixOverrides=",">
            <if test="stuName != null and stuName != ''">stu_name = #{stuName},</if>
            <if test="className != null and className != ''">class = #{className},</if>
            <if test="dormitoryHead != null">dormitory_head = #{dormitoryHead},</if>
            <if test="stuNo != null and stuNo != ''">stu_no = #{stuNo},</if>
            <if test="roomNo1 != null">roomNo1 = #{roomNo1},</if>
            <if test="standardCapacity != null">standard_capacity = #{standardCapacity},</if>
            <if test="actualOccupancy != null">actual_occupancy = #{actualOccupancy},</if>
            <if test="accommodationDuration1 != null">accommodation_duration1 = #{accommodationDuration1},</if>
            <if test="equivalentMonths1 != null">equivalent_months1 = #{equivalentMonths1},</if>
            <if test="chargeStandard1 != null">charge_standard1 = #{chargeStandard1},</if>
            <if test="amountDue1 != null">amount_due1 = #{amountDue1},</if>
            <if test="roomNo2 != null">roomNo2 = #{roomNo2},</if>
            <if test="standardCapacity2 != null">standard_capacity2 = #{standardCapacity2},</if>
            <if test="actualOccupancy2 != null">actual_occupancy2 = #{actualOccupancy2},</if>
            <if test="accommodationDuration2 != null">accommodation_duration2 = #{accommodationDuration2},</if>
            <if test="equivalentMonths2 != null">equivalent_months2 = #{equivalentMonths2},</if>
            <if test="chargeStandard2 != null">charge_standard2 = #{chargeStandard2},</if>
            <if test="amountDue2 != null">amount_due2 = #{amountDue2},</if>
            <if test="annualAccommodationFee != null">annual_accommodation_fee = #{annualAccommodationFee},</if>
            <if test="bankAccount != null">bank_account = #{bankAccount},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="teacher != null">teacher = #{teacher},</if>
            <if test="teacherPhone != null">teacher_phone = #{teacherPhone},</if>
            <if test="remark1 != null">remark1 = #{remark1},</if>
            <if test="remark2 != null">remark2 = #{remark2},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDmsDormitoryRecordsById" parameterType="Long">
        delete from dms_dormitory_records where id = #{id}
    </delete>

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