<?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.device.pq.mapper.RStatOnlinerateDMapper">
    <select id="getOnlineRateByDevIds" resultType="com.njcn.device.pq.pojo.vo.RStatOnlinerateVO">
        select
        dev_index,
        ROUND( sum(online_min)/(sum(online_min) + sum(offline_min))*100,2) as online_rate
        from r_stat_onlinerate_d
        <where>
            <if test="param!=null and param.ids != null and param.ids.size > 0">
                AND dev_index IN
                <foreach collection='param.ids' item='item' index="index" open='(' separator=',' close=')'>
                    #{item}
                </foreach>
            </if>
            <if test=" param.startTime != null and param.startTime !=''">
                AND  time_id >= #{param.startTime}
            </if>
            <if test="param.endTime != null and param.endTime != ''">
                AND  time_id &lt;= #{param.endTime}
            </if>
        </where>
        group by dev_index ;
    </select>
    <select id="getTotalOnlineRates" resultType="java.lang.Float">
        select
        ROUND( sum(online_min)/(sum(online_min) + sum(offline_min))*100,2) as online_rate
        from r_stat_onlinerate_d
        <where>
            <if test="param!=null and param.ids != null and param.ids.size > 0">
                AND dev_index IN
                <foreach collection='param.ids' item='item' index="index" open='(' separator=',' close=')'>
                    #{item}
                </foreach>
            </if>
            <if test=" param.startTime != null and param.startTime !=''">
                AND  time_id >= #{param.startTime}
            </if>
            <if test="param.endTime != null and param.endTime != ''">
                AND  time_id &lt;= #{param.endTime}
            </if>
        </where>

    </select>
</mapper>
