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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.srs.dormitory.domain.DmsForeignDormitory">
        <id column="id" property="id" />
        <result column="dormitory_id" property="dormitoryId" />
        <result column="bed_id" property="bedId" />
        <result column="application_id" property="applicationId" />
    </resultMap>
    <select id="getForeignDormitoryList" resultType="java.util.Map">
        SELECT fd.id,building.`name` buildingName,d.room_no roomNo,b.bed_code bedCode,
               a.applicant_name applicantName,er.nick_name contactName
        FROM dms_foreign_dormitory fd
                 LEFT JOIN dms_dormitory d ON fd.dormitory_id = d.id
                 LEFT JOIN dms_dormitory_bed b ON fd.bed_id = b.id
                 LEFT JOIN dms_dormitory_floor f ON f.id = d.floor_id
                 LEFT JOIN dms_dormitory_building building ON building.id = f.building_id
                 LEFT JOIN dms_foreign_application a ON fd.application_id = a.id
                 LEFT JOIN sys_user er ON a.campus_contact_id = er.user_id
        <where>
            <if test="buildingName != null">and building.name = #{buildingName}</if>
            <if test="applicationName != null">and a.applicant_name = #{applicationName}</if>
            <if test="contactName != null">and er.nick_name = #{contactName}</if>
        </where>
    </select>

</mapper>
