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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.njcn.harmonic.pojo.po.RStatLoadTypeY">
        <id column="org_no" property="orgNo" />
        <result column="data_date" property="dataDate" />
        <result column="load_type" property="loadType" />
        <result column="effective_measurement" property="effectiveMeasurement" />
        <result column="v_average" property="vAverage" />
        <result column="v_count" property="vCount" />
        <result column="i_average" property="iAverage" />
        <result column="i_count" property="iCount" />
        <result column="unbalance_average" property="unbalanceAverage" />
        <result column="unbalance_count" property="unbalanceCount" />
        <result column="i_neg_average" property="iNegAverage" />
        <result column="i_neg_count" property="iNegCount" />
        <result column="flicker_average" property="flickerAverage" />
        <result column="flicker_count" property="flickerCount" />
    </resultMap>
    <select id="getYearStatLoadType" resultType="com.njcn.harmonic.pojo.vo.RStatLoadTypeVO">
        select
            org_no,
            load_type,
            v_average,
            ROUND( v_count / effective_measurement, 2 ) AS vAccrued,
            i_average,
            ROUND( i_count / effective_measurement, 2 ) AS iAccrued,
            unbalance_average,
            ROUND( unbalance_count / effective_measurement, 2 ) AS unbalanceAccrued,
            i_neg_average,
            ROUND( i_neg_count / effective_measurement, 2 ) AS iNegAccrued,
            flicker_average,
            ROUND( flicker_count / effective_measurement, 2 ) AS flickerAccrued
        from
            r_stat_load_type_y
        <where>
            <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>
    </select>

</mapper>
