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

    <resultMap type="DmsAccommodations" id="DmsAccommodationsResult">
        <result property="id"    column="id"    />
        <result property="stuNo"    column="stu_no"    />
        <result property="stuName"    column="stu_name"    />
        <result property="birthday"    column="birthday"    />
        <result property="gender"    column="gender"    />
        <result property="className"    column="class_name"    />
        <result property="stuPhone"    column="stu_phone"    />
        <result property="sfzh"    column="sfzh"    />
        <result property="deptName"    column="dept_name"    />
        <result property="majorName"    column="major_name"    />
        <result property="gradeName"    column="grade_name"    />
        <result property="roomNo"    column="room_no"    />
        <result property="isCharge"    column="isCharge"    />
        <result property="sleepOutRemark"    column="sleep_out_remark"    />
        <result property="address"    column="address"    />
        <result property="emergencyContact"    column="emergency_contact"    />
        <result property="parentComment"    column="parent_comment"    />
        <result property="parentTel"    column="parent_tel"    />
        <result property="parentAddress"    column="parent_address"    />
        <result property="reviewerStatus"    column="reviewer_status"    />
        <result property="applySign"    column="apply_sign"    />
        <result property="applyDate"    column="apply_date"    />
        <result property="applySign2"    column="apply_sign2"    />
        <result property="applyDate2"    column="apply_date2"    />
        <result property="fdyCmt"    column="fdy_cmt"    />
        <result property="fdySign"    column="fdy_sign"    />
        <result property="fdyDate"    column="fdy_date"    />
        <result property="fdyNo"    column="fdy_no"    />
        <result property="deptCmt"    column="dept_cmt"    />
        <result property="deptSign"    column="dept_sign"    />
        <result property="deptDate"    column="dept_date"    />
        <result property="deptNo"    column="dept_no"    />
        <result property="xgCmt"    column="xg_cmt"    />
        <result property="xgSign"    column="xg_sign"    />
        <result property="xgDate"    column="xg_date"    />
        <result property="xgNo"    column="xg_no"    />
        <result property="leaderCmt"    column="leader_cmt"    />
        <result property="leaderSign"    column="leader_sign"    />
        <result property="leaderDate"    column="leader_date"    />
        <result property="leaderNo"    column="leader_no"    />
        <result property="stuYearName"    column="stu_year_name"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectDmsAccommodationsVo">
        select id, stu_no, stu_name, birthday, gender, class_name, stu_phone, sfzh, dept_name, major_name, grade_name, room_no, isCharge, sleep_out_remark, address, emergency_contact, parent_comment, parent_tel, parent_address, reviewer_status, apply_sign, apply_date, apply_sign2, apply_date2,fdy_cmt, fdy_sign, fdy_date, fdy_no, dept_cmt, dept_sign, dept_date, dept_no, xg_cmt, xg_sign, xg_date, xg_no, leader_cmt, leader_sign, leader_date, leader_no, stu_year_name, create_time, create_by, update_time, update_by from dms_accommodations
    </sql>

    <select id="selectDmsAccommodationsList" parameterType="DmsAccommodations" resultMap="DmsAccommodationsResult">
        <include refid="selectDmsAccommodationsVo"/>
        <where>
            <if test="stuNo != null  and stuNo != ''"> and stu_no = #{stuNo}</if>
            <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="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="majorName != null  and majorName != ''"> and major_name like concat('%', #{majorName}, '%')</if>
            <if test="gradeName != null  and gradeName != ''"> and grade_name like concat('%', #{gradeName}, '%')</if>
            <if test="roomNo != null  and roomNo != ''"> and room_no = #{roomNo}</if>
        </where>
    </select>

    <select id="selectDmsAccommodationsById" parameterType="Long" resultMap="DmsAccommodationsResult">
        <include refid="selectDmsAccommodationsVo"/>
        where id = #{id}
    </select>
    <select id="getStuDormitory" resultType="com.srs.dormitory.domain.DmsAccommodations" parameterType="String">
        select e.name,a.room_no,b.`status`,a.charge_standard,f.signature from dms_dormitory a
        left join srs_dormitory_student  b on a.id=b.dormitory_id
        left join dms_dormitory_floor c  on c.id=a.floor_id
        left join dms_dormitory_building d on d.id=c.building_id
        left join dms_dormitory_park e on e.id=d.park_id
        left join sys_user f on f.user_name=b.stu_no
        where b.stu_no=#{stuNo}
    </select>

    <insert id="insertDmsAccommodations" parameterType="DmsAccommodations" useGeneratedKeys="true" keyProperty="id">
        insert into dms_accommodations
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">stu_no,</if>
            <if test="stuName != null">stu_name,</if>
            <if test="birthday != null">birthday,</if>
            <if test="gender != null">gender,</if>
            <if test="className != null">class_name,</if>
            <if test="stuPhone != null">stu_phone,</if>
            <if test="sfzh != null">sfzh,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="majorName != null">major_name,</if>
            <if test="gradeName != null">grade_name,</if>
            <if test="roomNo != null">room_no,</if>
            <if test="isCharge != null">isCharge,</if>
            <if test="sleepOutRemark != null">sleep_out_remark,</if>
            <if test="address != null">address,</if>
            <if test="emergencyContact != null">emergency_contact,</if>
            <if test="parentComment != null">parent_comment,</if>
            <if test="parentTel != null">parent_tel,</if>
            <if test="parentAddress != null">parent_address,</if>
            <if test="reviewerStatus != null">reviewer_status,</if>
            <if test="applySign != null">apply_sign,</if>
            <if test="applyDate != null">apply_date,</if>
            <if test="applySign2 != null">apply_sign2,</if>
            <if test="applyDate2 != null">apply_date2,</if>
            <if test="fdyCmt != null">fdy_cmt,</if>
            <if test="fdySign != null">fdy_sign,</if>
            <if test="fdyDate != null">fdy_date,</if>
            <if test="fdyNo != null">fdy_no,</if>
            <if test="deptCmt != null">dept_cmt,</if>
            <if test="deptSign != null">dept_sign,</if>
            <if test="deptDate != null">dept_date,</if>
            <if test="deptNo != null">dept_no,</if>
            <if test="xgCmt != null">xg_cmt,</if>
            <if test="xgSign != null">xg_sign,</if>
            <if test="xgDate != null">xg_date,</if>
            <if test="xgNo != null">xg_no,</if>
            <if test="leaderCmt != null">leader_cmt,</if>
            <if test="leaderSign != null">leader_sign,</if>
            <if test="leaderDate != null">leader_date,</if>
            <if test="leaderNo != null">leader_no,</if>
            <if test="stuYearName != null">stu_year_name,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">#{stuNo},</if>
            <if test="stuName != null">#{stuName},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="gender != null">#{gender},</if>
            <if test="className != null">#{className},</if>
            <if test="stuPhone != null">#{stuPhone},</if>
            <if test="sfzh != null">#{sfzh},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="majorName != null">#{majorName},</if>
            <if test="gradeName != null">#{gradeName},</if>
            <if test="roomNo != null">#{roomNo},</if>
            <if test="isCharge != null">#{isCharge},</if>
            <if test="sleepOutRemark != null">#{sleepOutRemark},</if>
            <if test="address != null">#{address},</if>
            <if test="emergencyContact != null">#{emergencyContact},</if>
            <if test="parentComment != null">#{parentComment},</if>
            <if test="parentTel != null">#{parentTel},</if>
            <if test="parentAddress != null">#{parentAddress},</if>
            <if test="reviewerStatus != null">#{reviewerStatus},</if>
            <if test="applySign != null">#{applySign},</if>
            <if test="applyDate != null">#{applyDate},</if>
            <if test="applySign2 != null">#{applySign2},</if>
            <if test="applyDate2 != null">#{applyDate2},</if>
            <if test="fdyCmt != null">#{fdyCmt},</if>
            <if test="fdySign != null">#{fdySign},</if>
            <if test="fdyDate != null">#{fdyDate},</if>
            <if test="fdyNo != null">#{fdyNo},</if>
            <if test="deptCmt != null">#{deptCmt},</if>
            <if test="deptSign != null">#{deptSign},</if>
            <if test="deptDate != null">#{deptDate},</if>
            <if test="deptNo != null">#{deptNo},</if>
            <if test="xgCmt != null">#{xgCmt},</if>
            <if test="xgSign != null">#{xgSign},</if>
            <if test="xgDate != null">#{xgDate},</if>
            <if test="xgNo != null">#{xgNo},</if>
            <if test="leaderCmt != null">#{leaderCmt},</if>
            <if test="leaderSign != null">#{leaderSign},</if>
            <if test="leaderDate != null">#{leaderDate},</if>
            <if test="leaderNo != null">#{leaderNo},</if>
            <if test="stuYearName != null">#{stuYearName},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateDmsAccommodations" parameterType="DmsAccommodations">
        update dms_accommodations
        <trim prefix="SET" suffixOverrides=",">
            <if test="stuNo != null">stu_no = #{stuNo},</if>
            <if test="stuName != null">stu_name = #{stuName},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="gender != null">gender = #{gender},</if>
            <if test="className != null">class_name = #{className},</if>
            <if test="stuPhone != null">stu_phone = #{stuPhone},</if>
            <if test="sfzh != null">sfzh = #{sfzh},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="majorName != null">major_name = #{majorName},</if>
            <if test="gradeName != null">grade_name = #{gradeName},</if>
            <if test="roomNo != null">room_no = #{roomNo},</if>
            <if test="isCharge != null">isCharge = #{isCharge},</if>
            <if test="sleepOutRemark != null">sleep_out_remark = #{sleepOutRemark},</if>
            <if test="address != null">address = #{address},</if>
            <if test="emergencyContact != null">emergency_contact = #{emergencyContact},</if>
            <if test="parentComment != null">parent_comment = #{parentComment},</if>
            <if test="parentTel != null">parent_tel = #{parentTel},</if>
            <if test="parentAddress != null">parent_address = #{parentAddress},</if>
            <if test="reviewerStatus != null">reviewer_status = #{reviewerStatus},</if>
            <if test="applySign != null">apply_sign = #{applySign},</if>
            <if test="applyDate != null">apply_date = #{applyDate},</if>
            <if test="applySign2 != null">apply_sign2 = #{applySign2},</if>
            <if test="applyDate2 != null">apply_date2 = #{applyDate2},</if>
            <if test="fdyCmt != null">fdy_cmt = #{fdyCmt},</if>
            <if test="fdySign != null">fdy_sign = #{fdySign},</if>
            <if test="fdyDate != null">fdy_date = #{fdyDate},</if>
            <if test="fdyNo != null">fdy_no = #{fdyNo},</if>
            <if test="deptCmt != null">dept_cmt = #{deptCmt},</if>
            <if test="deptSign != null">dept_sign = #{deptSign},</if>
            <if test="deptDate != null">dept_date = #{deptDate},</if>
            <if test="deptNo != null">dept_no = #{deptNo},</if>
            <if test="xgCmt != null">xg_cmt = #{xgCmt},</if>
            <if test="xgSign != null">xg_sign = #{xgSign},</if>
            <if test="xgDate != null">xg_date = #{xgDate},</if>
            <if test="xgNo != null">xg_no = #{xgNo},</if>
            <if test="leaderCmt != null">leader_cmt = #{leaderCmt},</if>
            <if test="leaderSign != null">leader_sign = #{leaderSign},</if>
            <if test="leaderDate != null">leader_date = #{leaderDate},</if>
            <if test="leaderNo != null">leader_no = #{leaderNo},</if>
            <if test="stuYearName != null">stu_year_name = #{stuYearName},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDmsAccommodationsById" parameterType="Long">
        delete from dms_accommodations where id = #{id}
    </delete>

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