<?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.yida.data.school.facility.mapper.EduDormitoryRoomMapper">
  <select id="listDormRoomPage" resultType="com.yida.data.school.vo.index.DormRoomInfoVO">
    select id dormRoomId,name dormRoomName,floor,bed_num,check_in_num
    from edu_dormitory_room
    where del_flag=0
    and dorm_id=#{dto.dormId}
    <if test="dto.floor != null">
      and floor=#{dto.floor}
    </if>
    <if test="dto.name != null and dto.name != ''">
      and name like concat('%',#{dto.name},'%')
    </if>
    order by name
  </select>

  <select id="listDormRoom" resultType="com.yida.data.common.core.entity.school.EduDormitoryRoom">
    select a.*,b.name dormName
    from edu_dormitory_room a left join edu_dormitory b on a.dorm_id=b.id
    where a.del_flag=0 and b.del_flag=0
    <if test="dto.schoolId != null">
      and b.school_id=#{dto.schoolId}
    </if>
    <if test="dto.dormIds != null and dto.dormIds.size() != 0">
      and b.id in
      <foreach collection="dto.dormIds" separator="," open="(" close=")"
        item="item">
        #{item}
      </foreach>
    </if>
    <if test="dto.floor != null">
      and a.floor=#{dto.floor}
    </if>
    <if test="dto.masterId != null">
      and b.master_id=#{dto.masterId}
    </if>
    order by b.create_date desc,a.name
  </select>

  <select id="getDormRoom" resultType="com.yida.data.common.core.entity.school.EduDormitoryRoom">
    select a.*,b.name dormName
    from edu_dormitory_room a left join edu_dormitory b on a.dorm_id=b.id
    where a.del_flag=0 and b.del_flag=0
    and a.id=#{id}
  </select>

  <select id="listExistRoom" resultType="com.yida.data.common.core.entity.school.EduDormitoryRoom">
    select *
    from edu_dormitory_room
    where del_flag=0
    and dorm_id=#{dormId}
    and name in
    <foreach collection="list" separator="," open="(" item="item" close=")">
      #{item}
    </foreach>
  </select>
</mapper>
