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

    <select id="getHomeostasisArea" resultType="java.util.Map">
        select
        rshom.org_no "id",
        round(avg(rshom.over_limit_measurement_ratio_accrued),2) avg
        from r_stat_harmonic_org_m rshom
        left join sys_dict_data sdd on rshom.data_type = sdd.Id and sdd.`Code` = 'Mainnet_Point'
        WHERE
        rshom.org_no IN
        <foreach collection="indexIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        <if test="startTime != null and startTime != ''">
            and date_format(rshom.data_date,'%y%m%d') &gt;= date_format(#{startTime},'%y%m%d')
        </if>
        <if test="endTime != null and endTime != ''">
            and date_format(rshom.data_date,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
        </if>
        group by rshom.org_no
    </select>

    <select id="getHomeostasisLoad" resultType="java.util.Map">
        select
        rshom.measurement_type_class "id",
        round(avg(rshom.over_limit_measurement_ratio_accrued),2) avg
        from r_stat_harmonic_m rshom
        left join sys_dict_data sdd on rshom.data_type = sdd.Id and sdd.`Code` = 'Mainnet_Point'
        WHERE
        rshom.measurement_type_class IN
        <foreach collection="indexIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        <if test="startTime != null and startTime != ''">
            and date_format(rshom.data_date,'%y%m%d') &gt;= date_format(#{startTime},'%y%m%d')
        </if>
        <if test="endTime != null and endTime != ''">
            and date_format(rshom.data_date,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
        </if>
        group by rshom.measurement_type_class
    </select>

    <select id="getPowerOrder" resultType="com.njcn.device.pq.pojo.vo.PowerOrderVO">
        select t.*, pl.`Name` "name"
        from (
        SELECT rsdhpd.line_id "id", round(max(rsdhpd.p), 0) "max"
        FROM r_stat_data_harmpower_p_d rsdhpd
        <where>
        rsdhpd.line_id in
        <foreach collection="lineIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and rsdhpd.value_type = 'MAX'
        AND rsdhpd.time BETWEEN date_format(#{largeScreenParam.searchBeginTime}, '%y%m%d')
        AND date_format(#{largeScreenParam.searchEndTime}, '%y%m%d')
        </where>
        group by rsdhpd.line_id
        ) t
        left join pq_line pl on pl.Id = t.id
        ORDER BY t.max desc limit #{largeScreenParam.limit}
    </select>

</mapper>
