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

    <resultMap id="BaseResultMap" type="com.hdkj.lt.bf.entity.SjztPwwyyqxtPrmPdrOutageMvDs">
            <result property="id" column="id" jdbcType="VARCHAR"/>
            <result property="eventNo" column="event_no" jdbcType="VARCHAR"/>
            <result property="provinceOrganisationCode" column="province_organisation_code" jdbcType="VARCHAR"/>
            <result property="reliabilityOrganisation" column="reliability_organisation" jdbcType="VARCHAR"/>
            <result property="dutyOrgId" column="duty_org_id" jdbcType="VARCHAR"/>
            <result property="outageStime" column="outage_stime" jdbcType="TIMESTAMP"/>
            <result property="outageEtime" column="outage_etime" jdbcType="TIMESTAMP"/>
            <result property="outageDuration" column="outage_duration" jdbcType="DECIMAL"/>
            <result property="outageHcNum" column="outage_hc_num" jdbcType="DECIMAL"/>
            <result property="anes" column="anes" jdbcType="DECIMAL"/>
            <result property="outageFeederCnt" column="outage_feeder_cnt" jdbcType="DECIMAL"/>
            <result property="outageZonefeederCnt" column="outage_zonefeeder_cnt" jdbcType="DECIMAL"/>
            <result property="outageMvconsCnt" column="outage_mvcons_cnt" jdbcType="DECIMAL"/>
            <result property="outageLvconsCnt" column="outage_lvcons_cnt" jdbcType="DECIMAL"/>
            <result property="outageLvHcnum" column="outage_lv_hcnum" jdbcType="DECIMAL"/>
            <result property="outageCap" column="outage_cap" jdbcType="DECIMAL"/>
            <result property="orgNatureCode" column="org_nature_code" jdbcType="VARCHAR"/>
            <result property="outageNatureCode" column="outage_nature_code" jdbcType="VARCHAR"/>
            <result property="outageResponCode" column="outage_respon_code" jdbcType="VARCHAR"/>
            <result property="outgEquipmentReasonCode" column="outg_equipment_reason_code" jdbcType="VARCHAR"/>
            <result property="outageTechnicalCode" column="outage_technical_code" jdbcType="VARCHAR"/>
            <result property="specialAnalysisCode" column="special_analysis_code" jdbcType="VARCHAR"/>
            <result property="supplyArea" column="supply_area" jdbcType="VARCHAR"/>
            <result property="areaCode" column="area_code" jdbcType="VARCHAR"/>
            <result property="outageSource" column="outage_source" jdbcType="VARCHAR"/>
            <result property="remark" column="remark" jdbcType="VARCHAR"/>
            <result property="operateFlag" column="operate_flag" jdbcType="VARCHAR"/>
            <result property="provinceAuditTime" column="province_audit_time" jdbcType="TIMESTAMP"/>
            <result property="headquartersAuditTime" column="headquarters_audit_time" jdbcType="TIMESTAMP"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
            <result property="reportStatus" column="report_status" jdbcType="VARCHAR"/>
            <result property="reportTime" column="report_time" jdbcType="TIMESTAMP"/>
            <result property="isSyncEs" column="is_sync_es" jdbcType="VARCHAR"/>
            <result property="isConfirmed" column="is_confirmed" jdbcType="VARCHAR"/>
            <result property="confirmTime" column="confirm_time" jdbcType="TIMESTAMP"/>
            <result property="outageMainEquipmentType" column="outage_main_equipment_type" jdbcType="VARCHAR"/>
            <result property="isIgnored" column="is_ignored" jdbcType="VARCHAR"/>
            <result property="outageType" column="outage_type" jdbcType="VARCHAR"/>
            <result property="modifyReason" column="modify_reason" jdbcType="VARCHAR"/>
            <result property="isUpdated" column="is_updated" jdbcType="VARCHAR"/>
            <result property="provinceAuditStatus" column="province_audit_status" jdbcType="VARCHAR"/>
            <result property="firstConfirmTime" column="first_confirm_time" jdbcType="TIMESTAMP"/>
            <result property="dataVersion" column="data_version" jdbcType="DECIMAL"/>
            <result property="ignoreTime" column="ignore_time" jdbcType="TIMESTAMP"/>
            <result property="headquartersAuditStatus" column="headquarters_audit_status" jdbcType="VARCHAR"/>
            <result property="checkStatus" column="check_status" jdbcType="VARCHAR"/>
            <result property="voltageLevel" column="voltage_level" jdbcType="VARCHAR"/>
            <result property="procInstId" column="proc_inst_id" jdbcType="VARCHAR"/>
            <result property="auditStatus" column="audit_status" jdbcType="VARCHAR"/>
            <result property="checkTime" column="check_time" jdbcType="TIMESTAMP"/>
            <result property="txhash" column="txhash" jdbcType="VARCHAR"/>
            <result property="outageMainEquipmentName" column="outage_main_equipment_name" jdbcType="VARCHAR"/>
            <result property="outageFeederName" column="outage_feeder_name" jdbcType="VARCHAR"/>
            <result property="isException" column="is_exception" jdbcType="VARCHAR"/>
            <result property="provinceAuditRemark" column="province_audit_remark" jdbcType="VARCHAR"/>
            <result property="headquartersAuditRemark" column="headquarters_audit_remark" jdbcType="VARCHAR"/>
            <result property="dataConfidence" column="data_confidence" jdbcType="VARCHAR"/>
            <result property="hasAttachment" column="has_attachment" jdbcType="VARCHAR"/>
            <result property="isMajorFault" column="is_major_fault" jdbcType="VARCHAR"/>
            <result property="isAttachmentValid" column="is_attachment_valid" jdbcType="VARCHAR"/>
            <result property="operator" column="operator" jdbcType="VARCHAR"/>
            <result property="operationTime" column="operation_time" jdbcType="TIMESTAMP"/>
            <result property="countyAuditor" column="county_auditor" jdbcType="VARCHAR"/>
            <result property="countyAuditTime" column="county_audit_time" jdbcType="TIMESTAMP"/>
            <result property="cityAuditor" column="city_auditor" jdbcType="VARCHAR"/>
            <result property="cityAuditorTime" column="city_auditor_time" jdbcType="TIMESTAMP"/>
            <result property="provinceAuditor" column="province_auditor" jdbcType="VARCHAR"/>
            <result property="headquartersAuditor" column="headquarters_auditor" jdbcType="VARCHAR"/>
            <result property="changeHcNum" column="change_hc_num" jdbcType="DECIMAL"/>
            <result property="lockedStatus" column="locked_status" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,event_no,province_organisation_code,
        reliability_organisation,duty_org_id,outage_stime,
        outage_etime,outage_duration,outage_hc_num,
        anes,outage_feeder_cnt,outage_zonefeeder_cnt,
        outage_mvcons_cnt,outage_lvcons_cnt,outage_lv_hcnum,
        outage_cap,org_nature_code,outage_nature_code,
        outage_respon_code,outg_equipment_reason_code,outage_technical_code,
        special_analysis_code,supply_area,area_code,
        outage_source,remark,operate_flag,
        province_audit_time,headquarters_audit_time,create_time,
        update_time,report_status,report_time,
        is_sync_es,is_confirmed,confirm_time,
        outage_main_equipment_type,is_ignored,outage_type,
        modify_reason,is_updated,province_audit_status,
        first_confirm_time,data_version,ignore_time,
        headquarters_audit_status,check_status,voltage_level,
        proc_inst_id,audit_status,check_time,
        txhash,outage_main_equipment_name,outage_feeder_name,
        is_exception,province_audit_remark,headquarters_audit_remark,
        data_confidence,has_attachment,is_major_fault,
        is_attachment_valid,operator,operation_time,
        county_auditor,county_audit_time,city_auditor,
        city_auditor_time,province_auditor,headquarters_auditor,
        change_hc_num,locked_status
    </sql>

    <select id="selectStaticOutageDurationHoursHouseholds" resultType="BigDecimal">
        select SUM(td.outage_hc_num)
        from sjzt_pwwyyqxt_prm_pdr_outage_mv_ds td
        inner join(
            <foreach collection="feederNameList" item="line" separator="UNION ALL">
                select #{line} AS c
            </foreach>
        ) AS tmp ON td.outage_feeder_name = tmp.c
        where td.outage_stime &gt; #{startOfMonth}
        and td.outage_stime &lt; #{endOfToday}
    </select>
    <select id="selectOutageAggregation" resultType="com.hdkj.lt.bf.entity.dto.OutageAggregationDTO">
        SELECT
            COALESCE(SUM(td.outage_hc_num), 0) AS totalHouseholds,
            COALESCE(SUM(COALESCE(td.outage_mvcons_cnt, 0) + COALESCE(td.outage_lvcons_cnt, 0)), 0) AS totalAffectedUsers
        FROM sjzt_pwwyyqxt_prm_pdr_outage_mv_ds td
        INNER JOIN(
            <foreach collection="feederNameList" item="line" separator="UNION ALL">
                select #{line} AS c
            </foreach>
        ) AS tmp ON td.outage_feeder_name = tmp.c
        where td.outage_stime &gt;= #{startTime}
        and td.outage_stime &lt; #{endTime}
    </select>
</mapper>
