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

    <select id="getLineIntegrityRate" resultType="LineDataIntegrity">
        select  line_index lineId,
                avg(real_time/due_time)*100 integrityData,
                sum(real_time) `real`,
                sum(due_time) due
        from r_stat_integrity_d
        where line_index in
        <foreach collection="lineIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and time_id between #{startTime} and #{endTime}
        group by line_index
    </select>

    <select id="getOnIntegrityByIds" resultType="com.njcn.device.pq.pojo.vo.RStatIntegrityVO">
        SELECT
        line_index AS lineIndex,
        sum( real_time )/ sum( due_time )* 100 AS integrityRate
        FROM
        r_stat_integrity_d
        <where>
            <if test="param!=null and param.ids != null and param.ids.size > 0">
                AND line_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 line_index ;
    </select>



    <select id="getOnIntegrityByIdsAndTime" resultType="com.njcn.device.pq.pojo.vo.RStatIntegrityVO">
        SELECT
        line_index AS lineIndex,
        sum( real_time )/ sum( due_time )* 100 AS integrityRate
        FROM
        r_stat_integrity_d
        <where>
            <if test="list.size > 0">
                AND line_index IN
                <foreach collection='list' item='item' index="index" open='(' separator=',' close=')'>
                    #{item}
                </foreach>
            </if>
            <if test="startTime != null and startTime !=''">
                AND  time_id >= #{startTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND  time_id &lt;= #{endTime}
            </if>
        </where>
        group by line_index ;
    </select>
    <select id="selectTotalIntegrityByLineIds" resultType="java.lang.Float">
        select
        ROUND( sum(real_time)/sum(due_time)*100,2) as integrityRate
        from
            r_stat_integrity_d
        <where>
            <if test="param!=null and param.lineIds != null and param.ids.lineIds > 0">
                AND line_index IN
                <foreach collection='param.lineIds' 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>
