<?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.yeejoin.amos.boot.module.jxiop.api.mapper.MonitorFanIndicatorMapper">
    <select id="getFanConfigPower" resultType="java.util.Map">
        select
            sequence_nbr as id,
            equipment_number as equipmentNumber,
            equipment_specific_name as equipmentSpecificName,
            gateway_id as gatewayId
        from fan_config_power
            <where>
                <if test="equipmentNum != null and equipmentNum != ''">
                    and equipment_number = #{equipmentNum}
                </if>
                <if test="gatewayId != null and gatewayId != ''">
                    and gateway_id = #{gatewayId}
                </if>
            </where>
    </select>

    <select id="getBoosterStationInfo" resultType="java.util.Map">
        select
            sequence_nbr as id,
            gateway_id as gatewayId,
            booster_name as text,
             booster_name  as boosterName,
            booster_code as boosterCode,
            sort as value
        from booster_station_info
        <where>
            <if test="gatewayId != null and gatewayId != ''">
                AND gateway_id = #{gatewayId}
            </if>
<!--            <if test="sort != null and sort != ''">-->
<!--                AND sort = #{sort}-->
<!--            </if>-->
<!--            <if test="boosterName != null and boosterName != '' and (sort = null or sort = '')">-->
<!--                AND booster_name = #{boosterName}-->
<!--            </if>-->
        </where>
        ORDER BY sort ASC
    </select>

    <select id="getBoosterStationInfo2" resultType="java.util.Map">
        select * from
        ((select
        sequence_nbr as id,
        gateway_id as gatewayId,
        booster_name as text,
        booster_name as boosterName,
        booster_code as boosterCode,
        sort as value
        from booster_station_info
        <where>
            sort != 2
            <if test="gatewayId != null and gatewayId != ''">
                AND gateway_id = #{gatewayId}
            </if>
            <!--            <if test="sort != null and sort != ''">-->
            <!--                AND sort = #{sort}-->
            <!--            </if>-->
            <!--            <if test="boosterName != null and boosterName != '' and (sort = null or sort = '')">-->
            <!--                AND booster_name = #{boosterName}-->
            <!--            </if>-->
        </where>)
        union all
        (select
        '99999' as id,
        gateway_id as gatewayId,
        '1主变' as text,
        '1主变' as boosterName,
        '2' as boosterCode,
         2 as value
        from booster_station_info
        <where>
            <if test="gatewayId != null and gatewayId != ''">
                AND gateway_id = #{gatewayId}
            </if>
        </where>
        limit 1)) a
        ORDER BY a.value ASC
    </select>


    <select id="getMajorBoosterStationInfo" resultType="java.util.Map">
        select
        sequence_nbr as id,
        gateway_id as gatewayId,
        booster_name as text,
        booster_name  as boosterName,
        booster_code as boosterCode,
        sort as value
        from booster_station_info
        <where>
            <if test="gatewayId != null and gatewayId != ''">
                AND gateway_id = #{gatewayId}
            </if>
        </where>
        ORDER BY major_sort ${sortType}
        limit #{size}
    </select>


    <select id="getMajorBoosterStationInfoBySort" resultType="java.util.Map">
        select
            sequence_nbr as id,
            gateway_id as gatewayId,
            booster_name as text,
            booster_name  as boosterName,
            booster_code as boosterCode,
            sort as value
        from booster_station_info
        where
            sort = #{sort}
          AND gateway_id = #{gatewayId}

            limit 1
    </select>

    <select id="getBoosterStationInfoNormal" resultType="java.util.Map">
        select
        sequence_nbr as id,
        gateway_id as gatewayId,
        booster_name as text,
        booster_name as boosterName,
        booster_code as boosterCode,
        sort as value
        from booster_station_info
        <where>
            <if test="gatewayId != null and gatewayId != ''">
                AND gateway_id = #{gatewayId}
            </if>
        </where>
    </select>
</mapper>
