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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.srs.dormitory.domain.DmsOffcampusApplication">
        <id column="id" property="id" />
        <result column="stu_no" property="stuNo" />
        <result column="current_dorm_id" property="currentDormId" />
        <result column="current_bed_id" property="currentBedId" />
        <result column="reason" property="reason" />
        <result column="create_time" property="createTime" />
        <result column="create_by" property="createBy" />
        <result column="update_time" property="updateTime" />
        <result column="update_by" property="updateBy" />
        <result column="status" property="status" />
        <result column="del_flag" property="delFlag" />
    </resultMap>
    <select id="getDmsOffcampusApplication" resultType="java.util.Map">
        SELECT a.id,s.`name` stuName,bed.bed_code bedCode,
               b.`name` buildingName,d.room_no roomNo,
               a.reason,a.create_time createTime,a.create_by createBy,a.update_time updateTime,
               a.update_by updateBy,a.`status`
        FROM dms_offcampus_application a
                 LEFT JOIN srs_student s ON a.stu_no = s.stu_no
                 LEFT JOIN dms_dormitory_bed bed ON a.current_bed_id = bed.id
                 LEFT JOIN dms_dormitory d ON d.id = a.current_dorm_id
                 LEFT JOIN dms_dormitory_floor f ON f.id = d.floor_id
                 LEFT JOIN dms_dormitory_building b ON b.id = f.building_id
        WHERE  a.id = #{id}
    </select>
    <select id="getDmsOffcampusApplicationList" resultType="java.util.Map">
        SELECT a.id,s.stu_no stuNo,s.`name` stuName,bed.bed_code bedCode,
               b.`name` buildingName,d.room_no roomNo,
               a.reason,a.create_time createTime,a.create_by createBy,a.update_time updateTime,
               a.update_by updateBy,a.`status`
        FROM dms_offcampus_application a
                 LEFT JOIN srs_student s ON a.stu_no = s.stu_no
                 LEFT JOIN dms_dormitory_bed bed ON a.current_bed_id = bed.id
                 LEFT JOIN dms_dormitory d ON d.id = a.current_dorm_id
                 LEFT JOIN dms_dormitory_floor f ON f.id = d.floor_id
                 LEFT JOIN dms_dormitory_building b ON b.id = f.building_id
        <where>
            <if test="buildingId != null">and b.id = #{buildingId}</if>
            <if test="floorId != null">and f.id = #{floorId}</if>
            <if test="dormitoryId != null">and d.id = #{dormitoryId}</if>
            <if test="studentId != null">and s.stu_id = #{studentId}</if>
        </where>
    </select>
</mapper>
