<?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.njcn.event.mapper.distribution.PwRStatOrgClassifiedMapper">

    <sql id="query_field">
        rso.org_no AS orgNo,
	    rso.data_date AS dataDate,
        rso.measurement_type_class AS measurementTypeClass,
	    rso.effective_measurement_average AS effectiveMeasurementAverage,
	    rso.effective_measurement_accrued AS effectiveMeasurementAccrued,
	    rso.event_measurement_average AS eventMeasurementAverage,
	    rso.event_measurement_accrued AS eventMeasurementAccrued,
        rso.event_freq AS eventFreq,
        rso.event_count AS eventCount,
	    rseo.event_type,
	    rseo.event_measurement_average AS eEventMeasurementAverage,
	    rseo.event_measurement_accrued AS eEventMeasurementAccrued,
	    rseo.event_measurement_ratio_average AS eEventMeasurementRatioAverage,
	    rseo.event_measurement_ratio_accrued AS eEventMeasurementRatioAccrued,
	    rseo.event_freq AS eEventFreq,
	    rseo.event_count AS eEventCount,
	    rseo.data_type AS dataType
    </sql>
    <sql id="query_where">
        rso.data_type = #{distributionPoint}
        AND rseo.data_type = #{distributionPoint}
        AND rso.org_no IN
        <foreach collection="deptIdList" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        <if test="startTime != null and startTime != ''">
            AND DATE_FORMAT(rso.data_date, '%Y-%m-%d') &gt;= DATE_FORMAT(#{startTime}, '%Y-%m-%d')
        </if>
        <if test="endTime != null and endTime != ''">
            AND DATE_FORMAT(rso.data_date, '%Y-%m-%d') &lt;= DATE_FORMAT(#{endTime}, '%Y-%m-%d')
        </if>
    </sql>


    <!--获取配网区域暂态事件分类统计（年）-->
    <select id="getYearInfo" resultType="com.njcn.event.pojo.po.RStatEventOrgPO">
        SELECT
        <include refid="query_field"></include>
        FROM
        r_stat_org_y AS rso
        LEFT JOIN r_stat_event_org_y AS rseo ON rso.org_no = rseo.org_no
        WHERE
        <include refid="query_where"></include>
    </select>

    <!--获取配网区域暂态事件分类统计（月）-->
    <select id="getQuarterInfo" resultType="com.njcn.event.pojo.po.RStatEventOrgPO">
        SELECT
        <include refid="query_field"></include>
        FROM
        r_stat_org_q AS rso
        LEFT JOIN r_stat_event_org_q AS rseo ON rso.org_no = rseo.org_no
        WHERE
        <include refid="query_where"></include>
    </select>

    <!--获取配网区域暂态事件分类统计（月）-->
    <select id="getMonthInfo" resultType="com.njcn.event.pojo.po.RStatEventOrgPO">
        SELECT
        <include refid="query_field"></include>
        FROM
        r_stat_org_m AS rso
        LEFT JOIN r_stat_event_org_m AS rseo ON rso.org_no = rseo.org_no
        WHERE
        <include refid="query_where"></include>
    </select>
</mapper>
