<?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.device.pms.mapper.majornetwork.RStatSubstationMapper">

    <!--根据部门id查询监测点id-->
    <select id="getMonitorInfo" resultType="com.njcn.device.pms.pojo.po.PmsMonitorPO">
        SELECT
        id,
        `Name`,
        Org_Name AS orgName,
        Org_Id AS orgId,
        Operation_Name AS operationName,
        Operation_Id AS operationId,
        Powerr_Name AS powerrName,
        Powerr_Id AS powerrId,
        Generatrix_Name AS generatrixName,
        Generatrix_Id AS generatrixId
        FROM
        pms_monitor
        WHERE
        Org_Id IN ()
        <foreach collection="deptIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>


    <sql id="query_field">
        substation_id AS substationId,
        data_date AS dataDate,
        effective_measurement_average AS effectiveMeasurementAverage,
        effective_measurement_accrued AS effectiveMeasurementAccrued,
        event_count AS eventCount,
        event_freq AS eventFreq,
        interrupt_count AS interruptCount,
        interrupt_freq AS interruptFreq,
        swell_count AS swellCount,
        swell_freq AS swellFreq,
        sag_count AS sagCount,
        sag_freq AS sagFreq
    </sql>
    <sql id="query_where">
        substation_id IN
        <foreach collection="powerrIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        <if test="startTime != null and startTime != ''">
            AND DATE_FORMAT( data_date,'%Y-%m-%d') &gt;= DATE_FORMAT(#{startTime},'%Y-%m-%d')
        </if>
        <if test="endTime != null and endTime != ''">
            AND DATE_FORMAT( data_date,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endTime},'%Y-%m-%d')
        </if>
    </sql>

    <!--获取年变电站暂态指标分类统计表-->
    <select id="getYearInfo" resultType="com.njcn.device.pms.pojo.vo.RStatSubstationVO">
        SELECT
        <include refid="query_field"></include>
        FROM
        r_stat_substation_y
        WHERE
        <include refid="query_where"></include>
    </select>

    <!--获取季变电站暂态指标分类统计表-->
    <select id="getQuarterInfo" resultType="com.njcn.device.pms.pojo.vo.RStatSubstationVO">
        SELECT
        <include refid="query_field"></include>
        FROM
        r_stat_substation_q
        WHERE
        <include refid="query_where"></include>
    </select>

    <!--获取月变电站暂态指标分类统计表-->
    <select id="getMonthInfo" resultType="com.njcn.device.pms.pojo.vo.RStatSubstationVO">
        SELECT
        <include refid="query_field"></include>
        FROM
        r_stat_substation_m
        WHERE
        <include refid="query_where"></include>
    </select>
</mapper>