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

    <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="countCriticalAndSensitiveUsers"
            resultType="com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanTransferSchemeUsers">
        SELECT count(case when su.is_critical_user = '1' then 1 end)  criticalUsercount,
               count(case when su.is_sensitive_user = '1' then 1 end) sensitiveUsercount,
               count(case when su.is_protect_power = '1' then 1 end)  protectUserCount
        FROM fhzg_plan_transfer_scheme_users su
        WHERE su.scheme_id = #{schemeId}
          and su.data_type = 1

    </select>
    <select id="getLowVoltageNum" resultType="java.lang.Integer">
        SELECT count(*)
        FROM fhzg_plan_transferable_scheme_users su
        where su.scheme_id = #{schemeId}
          and cust_type = '公变'
          and 9.3 > user_voltage
          and user_voltage is not null
        ORDER BY su.id DESC
    </select>
</mapper>
