<?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.distribution.PwRStatOrgMapper">


    <select id="selectListY" resultType="com.njcn.harmonic.pojo.vo.RStatOrgVO$PwRStatOrgVO">
       select
               org_no,
               data_date,
               measurement_type_class as monitorSort,
               all_count,
               effective_measurement_average,
               effective_measurement_accrued,
               over_limit_measurement_average,
               over_limit_measurement_accrued,
               harmonic_measurement_ratio_average,
               TRUNCATE(over_limit_measurement_accrued / effective_measurement_accrued ,2) as harmonicMeasurementRatioAccrued,
               average_over_day
        from r_stat_org_y
        <where>
            data_type = #{dataType}
            <if test="deptIds != null and  deptIds.size > 0">
                AND org_no IN
                <foreach collection='deptIds' item='item' index="index" open='(' separator=',' close=')'>
                    #{item}
                </foreach>
            </if>
            <if test="param != null and  param.ids != null and param.ids.size > 0">
                AND measurement_type_class IN
                <foreach collection='param.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>
    </select>
    <select id="selectListQ" resultType="com.njcn.harmonic.pojo.vo.RStatOrgVO$PwRStatOrgVO">
        select
            org_no,
            data_date,
            measurement_type_class as monitorSort,
            all_count,
            effective_measurement_average,
            effective_measurement_accrued,
            harmonic_measurement_average as overLimitMeasurementAverage,
            harmonic_measurement_accrued as overLimitMeasurementAccrued,
            harmonic_measurement_ratio_average,
            TRUNCATE(harmonic_measurement_accrued / effective_measurement_accrued ,2) as harmonicMeasurementRatioAccrued,
            average_over_day
        from r_stat_org_q
        <where>
            data_type = #{dataType}
            <if test="deptIds != null and  deptIds.size > 0">
                AND org_no IN
                <foreach collection='deptIds' item='item' index="index" open='(' separator=',' close=')'>
                    #{item}
                </foreach>
            </if>
            <if test="param != null and  param.ids != null and param.ids.size > 0">
                AND measurement_type_class IN
                <foreach collection='param.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>
    </select>
    <select id="selectListM" resultType="com.njcn.harmonic.pojo.vo.RStatOrgVO$PwRStatOrgVO">
        select
                org_no,
                data_date,
                measurement_type_class as monitorSort,
                all_count,
                effective_measurement_average,
                effective_measurement_accrued,
                harmonic_measurement_average as overLimitMeasurementAverage,
                harmonic_measurement_accrued as overLimitMeasurementAccrued,
                harmonic_measurement_ratio_average,
                TRUNCATE(harmonic_measurement_accrued / effective_measurement_accrued ,2) as harmonicMeasurementRatioAccrued,
                TRUNCATE(over_day_accrued / effective_measurement_accrued ,2) as averageOverDay
        from r_stat_org_m
        <where>
            data_type = #{dataType}
            <if test="deptIds != null and  deptIds.size > 0">
                AND org_no IN
                <foreach collection='deptIds' item='item' index="index" open='(' separator=',' close=')'>
                    #{item}
                </foreach>
            </if>
            <if test="param != null and  param.ids != null and param.ids.size > 0">
                AND measurement_type_class IN
                <foreach collection='param.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>
    </select>
</mapper>
