<?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.majornetwork.PVOverviewMapper">

    <select id="selectPVSynthesisCount" resultType="java.lang.Integer">
        SELECT
            count(*)
        FROM
            (
                SELECT
                    measurement_point_id,
                    sum( is_v_dev_warn + is_freq_warn + is_unbalance_warn + is_v_warn + is_flicker_warn + is_sag_warn + is_interrupt_warn + is_swell_warn ) AS num
                FROM
                    r_mp_target_warn_d rmtwd
                <where>
                    is_effective = 1 AND is_warn = 1
                    <if test="param!=null and param.startTime != null and param.startTime !=''">
                        AND  rmtwd.data_date >= #{param.startTime} AND rmtwd.data_date >= #{param.startTime}
                    </if>
                    <if test="param!=null and param.endTime != null and param.endTime != ''">
                        AND  rmtwd.data_date &lt;= #{param.endTime}  AND  rmtwd.data_date &lt;= #{param.endTime}
                    </if>
                    <if test="id != null and id.size > 0">
                        AND measurement_point_id IN
                        <foreach collection='id' item='item' index="index" open='(' separator=',' close=')'>
                            #{item}
                        </foreach>
                    </if>
                </where>
                GROUP BY
                    measurement_point_id
                HAVING
                    num > 0
            ) x UNION ALL
        SELECT
            count(*)
        FROM
            (
                SELECT
                    measurement_point_id,
                    sum( is_v_dev_warn + is_freq_warn + is_unbalance_warn + is_v_warn + is_flicker_warn + is_sag_warn + is_interrupt_warn + is_swell_warn ) AS num
                FROM
                    r_mp_target_warn_d rmtwd
                <where>
                    is_effective = 1 AND is_harmonic = 1
                    <if test="param!=null and param.startTime != null and param.startTime !=''">
                        AND  rmtwd.data_date >= #{param.startTime} AND rmtwd.data_date >= #{param.startTime}
                    </if>
                    <if test="param!=null and param.endTime != null and param.endTime != ''">
                        AND  rmtwd.data_date &lt;= #{param.endTime}  AND  rmtwd.data_date &lt;= #{param.endTime}
                    </if>
                    <if test="id != null and id.size > 0">
                        AND measurement_point_id IN
                        <foreach collection='id' item='item' index="index" open='(' separator=',' close=')'>
                            #{item}
                        </foreach>
                    </if>
                </where>
                GROUP BY
                    measurement_point_id
                HAVING
                    num > 0
            ) x
    </select>
</mapper>
