<?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.event.mapper.majornetwork.RStatEventQMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.njcn.event.pojo.po.RStatEventQ">
        <id column="org_no" property="orgNo" />
        <result column="data_date" property="dataDate" />
        <result column="measurement_type_class" property="measurementTypeClass" />
        <result column="event_type" property="eventType" />
        <result column="event_measurement_average" property="eventMeasurementAverage" />
        <result column="event_measurement_accrued" property="eventMeasurementAccrued" />
        <result column="event_freq" property="eventFreq" />
        <result column="event_count" property="eventCount" />
        <result column="event_measurement_ratio_average" property="eventMeasurementRatioAverage" />
        <result column="event_measurement_ratio_accrued" property="eventMeasurementRatioAccrued" />
        <result column="data_type" property="dataType" />
    </resultMap>
    <select id="selectInfoList" resultType="com.njcn.event.pojo.po.RStatEventQ">
        SELECT
            measurement_type_class,
            event_type,
            sum(event_measurement_average)/count(*) as eventMeasurementAverage ,
            sum(event_measurement_accrued) as eventMeasurementAccrued,
            sum(event_freq)/count(*) as eventFreq,
            sum(event_count) as eventCount,
            sum(event_measurement_ratio_average)/count(*) as eventMeasurementRatioAverage,
            sum(event_measurement_ratio_accrued) as eventMeasurementRatioAccrued
        FROM
             r_stat_event_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="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
        measurement_type_class,
        event_type
    </select>

</mapper>
