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


    <select id="getFhzgPlanTransferSchemeUsersByIdPage"
            resultType="com.hdkj.lt.bf.entity.dto.FhzgPlanTransferSchemeUsersDTO">
        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_plan_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="getSum" resultType="com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanTransferSchemeUsers">
        SELECT
            sum( su.loss_cust_hours ) totalLossCustHours,
            sum( su.loss_powers ) totalLossPowers
        FROM
            fhzg_plan_transfer_scheme_users su
        WHERE
            su.scheme_id =#{id}
    </select>

    <select id="getUserSum" resultType="java.math.BigDecimal">
        SELECT
        sum( su.loss_cust_hours ) totalLossCustHours
        FROM
        fhzg_plan_transfer_scheme_users su
        <where>
            <if test=" params.id != null and params.id != '' ">
                su.scheme_id = #{params.id}
            </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>
        </where>
    </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_plan_transfer_scheme_users u on s.psr_id = u.start_switch_id
        WHERE
            u.data_type = 1 and u.scheme_id = #{schemeId} and s.obj_id = CONCAT(#{schemeId})
        GROUP BY
            s.load_switch_id,s.load_switch_name

    </select>
    <select id="getDistributionTransformerLowVoltage"
            resultType="com.hdkj.lt.bf.entity.dto.FhzgPlanTransferSchemeUsersDTO">
        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_plan_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>
