<?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.harmonic.mapper.specialanalysis.WindFarmIndexOverviewMapper">
    <!--电流指标-->
    <resultMap id="HarmonicCurrentMap" type="com.njcn.harmonic.pojo.po.WindFarmIndexOverviewPO">
        <id property="orgNo" column="org_no"/>
        <id property="dataDate" column="data_date"/>
        <id property="monitorTag" column="monitor_tag"/>
        <result property="monitorNum" column="monitor_harmonic_electric_exceeds_num"/>
        <result property="proportionOfExcessPoints" column="monitor_harmonic_electric_exceeds_proportion"/>
        <result property="avgExcessiveDays" column="monitor_harmonic_electric_exceeds_avg_days"/>
    </resultMap>

    <!--电压指标-->
    <resultMap id="HarmonicVoltageMap" type="com.njcn.harmonic.pojo.po.WindFarmIndexOverviewPO">
        <id property="orgNo" column="org_no"/>
        <id property="dataDate" column="data_date"/>
        <id property="monitorTag" column="monitor_tag"/>
        <result property="monitorNum" column="monitor_harmonic_voltage_content_exceeds_num"/>
        <result property="proportionOfExcessPoints" column="monitor_harmonic_voltage_content_exceeds_proportion"/>
        <result property="avgExcessiveDays" column="monitor_harmonic_voltage_content_exceeds_avg_days"/>
    </resultMap>

    <!--各单位电流-->
    <resultMap id="UnitCurrentMap" type="com.njcn.harmonic.pojo.po.WindFarmIndexOverviewPO">
        <id property="orgNo" column="org_no"/>
        <id property="dataDate" column="data_date"/>
        <id property="monitorTag" column="monitor_tag"/>
        <result property="monitorNum" column="electric_index_exceeds_num"/>
        <result property="proportionOfExcessPoints" column="electric_index_exceeds_proportion"/>
        <result property="avgExcessiveDays" column="electric_index_exceeds_avg_days"/>
    </resultMap>

    <!--各单位电压-->
    <resultMap id="UnitVoltageMap" type="com.njcn.harmonic.pojo.po.WindFarmIndexOverviewPO">
        <id property="orgNo" column="org_no"/>
        <id property="dataDate" column="data_date"/>
        <id property="monitorTag" column="monitor_tag"/>
        <result property="monitorNum" column="voltage_index_exceeds_num"/>
        <result property="proportionOfExcessPoints" column="voltage_index_exceeds_proportion"/>
        <result property="avgExcessiveDays" column="voltage_index_exceeds_avg_days"/>
    </resultMap>

    <sql id="conditions">
        s.org_no IN
        <foreach collection="deptCode" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        <if test="param.monitorTag != null and param.monitorTag != '' ">
            AND s.monitor_tag = #{param.monitorTag}
        </if>
        <if test="param.monitorTag != null and param.monitorTag != '' ">
            AND sd.monitor_tag = #{param.monitorTag}
        </if>
        <if test="param.startTime != null and param.startTime != ''">
            AND DATE_FORMAT(s.data_date, '%Y-%m-%d') &gt;= DATE_FORMAT(#{param.startTime}, '%Y-%m-%d')
        </if>
        <if test="param.endTime != null and param.endTime != ''">
            AND DATE_FORMAT(s.data_date, '%Y-%m-%d') &lt;= DATE_FORMAT(#{param.endTime}, '%Y-%m-%d')
        </if>
        <if test="param.startTime != null and param.startTime != ''">
            AND DATE_FORMAT(sd.data_date, '%Y-%m-%d') &gt;= DATE_FORMAT(#{param.startTime}, '%Y-%m-%d')
        </if>
        <if test="param.endTime != null and param.endTime != ''">
            AND DATE_FORMAT(sd.data_date, '%Y-%m-%d') &lt;= DATE_FORMAT(#{param.endTime}, '%Y-%m-%d')
        </if>
    </sql>

    <!--获取风电场指标总览-电流指标-->
    <select id="getWindFarmIndexOverviewHarmonicCurrent" resultMap="HarmonicCurrentMap">
        SELECT
        s.org_no,
        s.data_date,
        s.monitor_tag,
        s.monitor_harmonic_electric_exceeds_num,
        sd.monitor_harmonic_electric_exceeds_proportion,
        sd.monitor_harmonic_electric_exceeds_avg_days
        FROM special_analysis_index_overview AS s
        JOIN special_analysis_index_overview_detailed AS sd ON s.org_no = sd.org_no
        WHERE
        <include refid="conditions"></include>
    </select>

    <!--获取风电场指标总览-电压指标-->
    <select id="getWindFarmIndexOverviewHarmonicVoltage" resultMap="HarmonicVoltageMap">
        SELECT
        s.org_no,
        s.data_date,
        s.monitor_tag,
        s.monitor_harmonic_voltage_content_exceeds_num,
        sd.monitor_harmonic_voltage_content_exceeds_proportion,
        sd.monitor_harmonic_voltage_content_exceeds_avg_days
        FROM special_analysis_index_overview AS s
        JOIN special_analysis_index_overview_detailed AS sd ON s.org_no = sd.org_no
        WHERE
        <include refid="conditions"></include>
    </select>

    <!--获取风电场指标总览-各单位电流-->
    <select id="getWindFarmIndexOverviewUnitCurrent" resultMap="UnitCurrentMap">
        SELECT
        s.org_no,
        s.data_date,
        s.monitor_tag,
        s.electric_index_exceeds_num,
        sd.electric_index_exceeds_proportion,
        sd.electric_index_exceeds_avg_days
        FROM special_analysis_index_overview AS s
        JOIN special_analysis_index_overview_detailed AS sd ON s.org_no = sd.org_no
        WHERE
        <include refid="conditions"></include>
    </select>

    <!--获取风电场指标总览-各单位电压-->
    <select id="getWindFarmIndexOverviewUnitVoltage" resultMap="UnitVoltageMap">
        SELECT
        s.org_no,
        s.data_date,
        s.monitor_tag,
        s.voltage_index_exceeds_num,
        sd.voltage_index_exceeds_proportion,
        sd.voltage_index_exceeds_avg_days
        FROM special_analysis_index_overview AS s
        JOIN special_analysis_index_overview_detailed AS sd ON s.org_no = sd.org_no
        WHERE
        <include refid="conditions"></include>
    </select>
</mapper>