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

    <resultMap id="facListMap" type="org.dromara.system.domain.vo.FacilitiesVo">
        <id column="facilities_id" property="facilities_id" jdbcType="VARCHAR"/>
        <result column="facilities_name" property="facilities_name" jdbcType="VARCHAR"/>
        <result column="facilities_title" property="facilities_title" jdbcType="VARCHAR"/>
        <result column="facilities_desc" property="facilities_desc" jdbcType="VARCHAR"/>
        <result column="facilities_type" property="facilities_type" jdbcType="VARCHAR"/>
    </resultMap>

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

    <select id="selectByRegionId" parameterType="list" resultType="org.dromara.system.domain.vo.FacilitiesVo">
        select * FROM region_facilities rr
            LEFT JOIN facilities fa on fa.facilities_id = rr.facilities_id
        WHERE rr.region_id IN
        <foreach item="item" collection="list" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <select id="selectByRegionId"  resultMap="facListMap">
        SELECT DISTINCT
            fa.*
        FROM
            region r
                LEFT JOIN region_facilities rr ON r.region_id = rr.region_id
                LEFT JOIN facilities fa on fa.facilities_id = rr.facilities_id

        where r.region_type = #{regionType}

    </select>

</mapper>
