<?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.yfd.platform.modules.basedata.mapper.SubstationBayMapper">

    <select id="getSubstationBayInfo" resultType="java.util.Map">
            SELECT
            sb.area_id,
            sb.area_name,
            sb.bay_id,
            sb.bay_name name,
            sb.station_code,
            s.station_id,
            sb.station_name,
            sb.custom1,(
            SELECT
                COUNT(*)
            FROM
                iis_substation_device sd
            WHERE
                sd.bay_id = sb.bay_id
            ) deviceCount ,
            (
            SELECT
                COUNT(*)
            FROM
                iis_substation_maindevice sm
            WHERE
                sm.bay_id = sb.bay_id
            ) count
        FROM
            iis_substation_bay sb INNER JOIN iis_substation s ON s.station_code=sb.station_code WHERE sb.datastatus= '1'
            <if test="stationId != null and stationId != ''">
                AND s.station_id = #{stationId}
            </if>
        ORDER BY custom1
    </select>
</mapper>
