<?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.hdkj.lt.bf.mapper.FaultTransferSchemeUsersMapper">

    <select id="getFhzgFaultTransferSchemeUsersByIdPage"
            resultType="com.hdkj.lt.bf.entity.dto.FhzgFaultTransferSchemeUsersDTO">
        SELECT
        su.id id,
        su.scheme_id schemeId,
        su.transformer_no transformerNo,
        su.transformer_name transformerName,
        su.cust_type custType,
        su.cold_loss_times coldLossTimes,
        su.repair_times repairTimes,
        su.active_power activePower,
        su.loss_powers lossPowers,
        su.loss_cust_hours lossCustHours,
        su.is_critical_user isCriticalUser,
        su.is_sensitive_user isSensitiveUser,
        su.is_protect_power isProtectPower
        FROM
        fhzg_fault_transfer_scheme_users su
        <where>
            <if test=" params.id != null and params.id != '' ">
                su.scheme_id = #{params.id}
            </if>
            -- 损失用户
            <if test=" params.queryType == 1 ">
                and su.data_type = 1
            </if>
            -- 失电用户
            <if test=" params.queryType == 2 ">
                and su.data_type = 2
            </if>
            -- 重要用户 失电
<!--            <if test=" params.queryType == 3 ">-->
<!--                and su.is_critical_user = 1-->
<!--            </if>-->
            -- 敏感用户 失电
<!--            <if test=" params.queryType == 4 ">-->
<!--                and su.is_sensitive_user = 1-->
<!--            </if>-->
<!--            <if test=" params.queryType == 5 ">-->
<!--                and su.is_protect_power = 1-->
<!--            </if>-->
        </where>
        ORDER BY
        su.id DESC
    </select>

    <select id="countLoadSwitchLoseUsersByScheme"
            resultType="com.hdkj.lt.bf.entity.dto.LoadSwitchLoseUsersDTO">
        SELECT s.show_switch_id   loadSwitchId,
               s.show_switch_name loadSwitchName,
               count(*)           loseUsers
        FROM fhzg_dist_line_switch_section_show s
        INNER JOIN fhzg_fault_transfer_scheme_users u on s.psr_id = u.start_switch_id
        WHERE u.data_type = 1 AND s.obj_id = CONCAT(#{schemeId})
          AND u.scheme_id = #{schemeId}
        GROUP BY s.show_switch_id, s.show_switch_name
    </select>

    <select id="getDistributionTransformerLowVoltage"
            resultType="com.hdkj.lt.bf.entity.dto.FhzgFaultTransferSchemeUsersDTO">
        SELECT
        su.id id,
        su.scheme_id schemeId,
        su.transformer_no transformerNo,
        su.transformer_name transformerName,
        su.cust_type custType,
        su.user_voltage afterTransferVoltage
        FROM
        fhzg_fault_transferable_scheme_users su
        <where>
            <if test=" params.id != null and params.id != '' ">
                su.scheme_id = #{params.id}
            </if>
            and cust_type = '公变' and 9.3 > user_voltage and user_voltage is not null
        </where>
        ORDER BY
        su.id DESC
    </select>
</mapper>
