<?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="org.dromara.system.mapper.RegionMapper">

    <resultMap id="RegionListMap" type="org.dromara.system.domain.vo.RegionVo">
        <id column="region_id" property="region_id" jdbcType="VARCHAR"/>
        <result column="region_name" property="region_name" jdbcType="VARCHAR"/>
        <result column="region_title" property="region_title" jdbcType="VARCHAR"/>
        <result column="region_desc" property="region_desc" jdbcType="VARCHAR"/>
        <result column="region_type" property="region_type" jdbcType="VARCHAR"/>
    </resultMap>

    <resultMap id="facListMap" type="org.dromara.system.domain.vo.FacilitiesVo">
        <id column="facilities_id" property="facilitiesId" jdbcType="VARCHAR"/>
    </resultMap>

    <select id="selectByRegionId" parameterType="list" resultType="org.dromara.system.domain.vo.RegionVo">
        select * FROM region WHERE region_id IN
        <foreach item="item" collection="list" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <select id="selectByRoomId"  resultMap="RegionListMap">
        SELECT DISTINCT
            rg.region_id as regionId,
            rg.region_name as regionName,
            rg.region_title as regionTitle,
            rg.region_desc as regionDesc,
            rg.region_type as regionType

        FROM
            room r
                LEFT JOIN room_region rr ON r.room_id = rr.room_id
                LEFT JOIN region rg ON rr.region_id = rg.region_id

        WHERE
            r.room_id = #{roomId}

    </select>


    <select id="selectByRegionType"  resultType="string">
        SELECT
            r.facilities_id
        FROM
            region rg
            left join region_facilities r on rg.region_id = r.region_id
        WHERE
            rg.region_type = #{regionType}

    </select>

</mapper>
