<?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.mapper.data.IntegrityMapper'>
    <select id="selectIntegralityByLineIndexAndTime" resultType="simpleValue">
        SELECT
        SUM (T1.real) countOnline,
        SUM (T1.due) countAll
        FROM
        PQS_Integrity T1
        WHERE
        T1.Line_index in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        AND
        T1.TIMEID BETWEEN #{startTime} AND #{endTime}
    </select>

    <select id="selectGwIntegralityByLineIndexAndTime" resultType="simpleValue">
        SELECT
        SUM (T1.real) countOnline,
        SUM (T1.due) countAll
        FROM
        PQS_Integrity T1
        WHERE
        T1.Line_index in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        AND
        T1.TIMEID BETWEEN #{startTime} AND #{endTime}
    </select>

    <select id="selectGistIntegrality" resultType="simpleValue">
        SELECT
        t1.integrality,
        t2. NAME,
        T3.NAME devName,
        t3.ip,
        t4.name gdName,
        t5.name subName
        FROM
             (
             SELECT
                T .*, ROWNUM row_num
            FROM
              (
                SELECT
                    LINE_INDEX,
                    ROUND ( SUM (REAL) / SUM (DUE),4) * 100 integrality
                FROM
                    PQS_INTEGRITY
                WHERE
                    LINE_INDEX IN <foreach collection="list" item="item" open="(" close=")" separator=",">#{item}</foreach>
                   AND TIMEID BETWEEN #{startTime} AND #{endTime}
                   GROUP BY
                        LINE_INDEX
                   ORDER BY
                        integrality ASC
                ) T
            ) t1
        LEFT JOIN PQ_LINE t2 ON t1.LINE_INDEX = t2.LINE_INDEX
        LEFT JOIN PQ_DEVICE t3 ON t2.dev_index = t3.dev_index
        LEFT JOIN PQ_GDINFORMATION t4 ON t2.GD_INDEX = t4.GD_INDEX
        LEFT JOIN PQ_SUBSTATION t5 ON T2.SUB_INDEX = T5.SUB_INDEX
              WHERE t1.row_num &lt; 20
    </select>

    <select id="selectIntegrityData" resultType="intergralityTable" >
      SELECT
        T6. NAME powerCompany,
        T7. NAME substation,
        T3. NAME device,
        T3.IP deviceIp,
        T3.UpdateTime updateTime,
        T3.dev_index devId,
        T3.Status status,
        T3.DevFlag devFlag,
        T5.DIC_NAME company,
        T8.DIC_NAME voltage,
        T2.NAME lineName,
        T2.line_index lineId,
        T1.integrity integrity,
        T9.dic_name devType
    FROM
        (
            SELECT
                T1.LINE_INDEX,
                ROUND (
                    SUM (T1.REAL) / (
                        SUM (T1.DUE)
                    ),
                    4
                ) * 100 integrity
            FROM
                PQS_Integrity T1
            WHERE
                T1.LINE_INDEX IN  <foreach collection="list" item="item" open="(" close=")" separator=",">#{item}</foreach>
            AND t1.TIMEID BETWEEN #{startTime} AND #{endTime}
            GROUP BY
                T1.LINE_INDEX
        ) T1,
        PQ_LINE T2,
        PQ_DEVICE T3,
        PQ_DEVICEDETAIL T4,
        PQS_DICDATA T5,
        PQ_GDINFORMATION T6,
        PQ_SUBSTATION T7,
        PQS_DICDATA T8,
        PQS_DICDATA T9
    WHERE
        T1.LINE_INDEX = T2.LINE_INDEX
    AND T2.DEV_INDEX = T3.DEV_INDEX
    AND T3.DEV_INDEX =T4.DEV_INDEX
    AND T4.MANUFACTURER=T5.DIC_INDEX
    AND T2.GD_INDEX=T6.GD_INDEX
    AND T2.SUB_INDEX=T7.SUB_INDEX
    AND T2.SCALE=T8.DIC_INDEX
    AND T9.DIC_INDEX = T3.DEVTYPE
    </select>

    <select id="selectGWIntegrityData" resultType="intergralityTable" >
        SELECT
        T6. NAME powerCompany,
        T7. NAME substation,
        T3. NAME device,
        T3.IP deviceIp,
        T3.UpdateTime updateTime,
        T3.dev_index devId,
        T3.Status status,
        T3.DevFlag devFlag,
        T5.DIC_NAME company,
        T8.DIC_NAME voltage,
        T2.NAME lineName,
        T2.line_index lineId,
        T1.integrity integrity,
        T9.dic_name devType
        FROM
        (
        SELECT
        T1.LINE_INDEX,
        ROUND (
        SUM (T1.REAL) / (
        SUM (T1.DUE)
        ),
        4
        ) * 100 integrity
        FROM
        PQS_Integrity T1
        WHERE
        T1.LINE_INDEX IN  <foreach collection="list" item="item" open="(" close=")" separator=",">#{item}</foreach>
        AND t1.TIMEID BETWEEN #{startTime} AND #{endTime}
        GROUP BY
        T1.LINE_INDEX
        ) T1,
        PQ_LINE T2,
        PQ_DEVICE T3,
        PQ_DEVICEDETAIL T4,
        PQS_DICDATA T5,
        PQ_GDINFORMATION T6,
        PQ_SUBSTATION T7,
        PQS_DICDATA T8,
        PQS_DICDATA T9
        WHERE
        T1.LINE_INDEX = T2.LINE_INDEX
        AND T2.DEV_INDEX = T3.DEV_INDEX
        AND T3.DEV_INDEX =T4.DEV_INDEX
        AND T4.MANUFACTURER=T5.DIC_INDEX
        AND T2.GD_INDEX=T6.GD_INDEX
        AND T2.SUB_INDEX=T7.SUB_INDEX
        AND T2.SCALE=T8.DIC_INDEX
        AND T9.DIC_INDEX = T3.DEVTYPE
    </select>

</mapper>
