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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.srs.dormitory.domain.DmsDormitoryBed">
        <id column="id" property="id" />
        <result column="dormitory_id" property="dormitoryId" />
        <result column="bed_code" property="bedCode" />
        <result column="create_by" property="createBy" />
        <result column="create_time" property="createTime" />
        <result column="update_by" property="updateBy" />
        <result column="update_time" property="updateTime" />
        <result column="del_flag" property="delFlag" />
        <result column="remark" property="remark" />
    </resultMap>

    <select id="getDmsDormitoryByDormitoryId" resultType="java.util.Map">
        SELECT bed.id bedId,bed.bed_code bedCode, CASE WHEN st.bed_id IS NULL THEN 0 ELSE 1 END AS hasStudent,
               ss.name stuName
        FROM `dms_dormitory_bed` bed
        LEFT JOIN srs_dormitory_student st ON bed.id = st.bed_id
        LEFT JOIN srs_student ss on st.stu_no = ss.stu_no
        <where>
            <if test="id != null">and bed.dormitory_id = #{id}</if>
        </where>
    </select>

</mapper>
