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

    <select id="listQuarterRatio" resultType="StatHarmonicOrgVO">
        SELECT
        r.`org_no` `id`,
        r.over_limit_measurement_ratio_average `ratio`,
        r.over_limit_measurement_average `count`
        FROM
        r_stat_harmonic_org_q r
        where 1=1
        and org_no in
        <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
            #{item.id}
        </foreach>
        <if test="startTime!=null and endTime!=null">
            and DATE_FORMAT(data_date,'%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
    </select>
    <select id="selectInfoList" resultType="com.njcn.harmonic.pojo.vo.RStatHarmonicVO">
        SELECT
        harmonic_type,
        sum(over_limit_measurement_average)/count(*) as overLimitMeasurementAverage ,
        sum(over_limit_measurement_accrued) as overLimitMeasurementAccrued,
        sum(average_over_day)/count(*) as averageOverDay,
        sum(over_limit_measurement_ratio_average)/count(*) as overLimitMeasurementRatioAverage,
        sum(over_limit_measurement_ratio_accrued) as overLimitMeasurementRatioAccrued
        FROM
        r_stat_harmonic_org_q
        <where>
            and data_Type=#{dataType}
            <if test="param != null and  param.ids != null and param.ids.size > 0">
                AND org_no IN
                <foreach collection='param.ids' item='item' index="index" open='(' separator=',' close=')'>
                    #{item}
                </foreach>
            </if>
            <if test="ids != null and ids.size > 0">
                AND harmonic_type IN
                <foreach collection='ids' item='item' index="index" open='(' separator=',' close=')'>
                    #{item}
                </foreach>
            </if>
            <if test="param!=null and param.startTime != null and param.startTime !=''">
                AND  data_date >= #{param.startTime}
            </if>
            <if test="param!=null and param.endTime != null and param.endTime != ''">
                AND  data_date &lt;= #{param.endTime}
            </if>
        </where>
        GROUP BY
        harmonic_type
    </select>

</mapper>
