<?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.utic.center.utic.traf.server.dao.mapper.utic.LinkCollectMoctMapper">

    <select id="findAllLinkTrafMOCT" resultType="com.utic.center.utic.traf.server.dto.LinkCollectDto" parameterType="com.utic.center.utic.traf.server.dto.LinkCollectParam" fetchSize="2000" timeout="90">
        <![CDATA[
        SELECT A.STD_LINK_ID AS linkId,
               1             AS crtPriority,
               'R'           AS missValueYn,
               'S'           AS dataResType,
               'C00'         AS centerId,
               A.SPEED       AS speed
        FROM (
                 SELECT STD_LINK_ID, SPEED, REG_DATE
                 FROM CURLINKST_MOCT_PRIVATE_LOG@PTDBSDB
                 WHERE REG_DATE >= TO_CHAR(SYSDATE - INTERVAL '6' MINUTE, 'YYYYMMDDHH24MISS')
                   AND SPEED BETWEEN 1 AND 149
             ) A
             JOIN LINK B ON A.STD_LINK_ID = B.LINKID
        WHERE B.LINKLEVEL = '1'
        ORDER BY A.STD_LINK_ID, A.REG_DATE ASC
        ]]>
    </select>

    <select id="findAllLinkTrafMOCTx" resultType="com.utic.center.utic.traf.server.dto.LinkCollectDto" parameterType="com.utic.center.utic.traf.server.dto.LinkCollectParam" fetchSize="2000" timeout="90">
        <![CDATA[
        SELECT A.STD_LINK_ID AS linkId,
               1             AS crtPriority,
               'R'           AS missValueYn,
               'S'           AS dataResType,
               'C00'         AS centerId,
               A.SPEED       AS speed
        FROM CURLINKST_MOCT_PRIVATE_LOG@PTDBSDB A, LINK B
        WHERE A.REG_DATE >= TO_CHAR(SYSDATE - INTERVAL '6' MINUTE, 'YYYYMMDDHH24MISS')
          AND A.STD_LINK_ID = B.LINKID
          AND B.LINKLEVEL = '1'
          AND A.SPEED BETWEEN 1 AND 149
        ORDER BY A.STD_LINK_ID, A.REG_DATE ASC
        ]]>
    </select>

    <select id="findAllLinkTrafMOCTxxx" resultType="com.utic.center.utic.traf.server.dto.LinkCollectDto" parameterType="com.utic.center.utic.traf.server.dto.LinkCollectParam" fetchSize="2000" timeout="90">
        <![CDATA[
        SELECT
            T.STD_LINK_ID AS linkId,
            1             AS crtPriority,
            'R'           AS missValueYn,
            'S'           AS dataResType,
            'C00'         AS centerId,
            T.SPEED       AS speed
        FROM (
                 SELECT
                     T.STD_LINK_ID,
                     MAX(T.REG_DATE) AS MAX_REGDATE
                 FROM CURLINKST_MOCT_PRIVATE_LOG@PTDBSDB T
           INNER JOIN LINK C
                   ON T.STD_LINK_ID = C.LINKID
                WHERE C.LINKLEVEL = '1'
                  AND T.REG_DATE >= TO_CHAR(SYSDATE - INTERVAL '6' MINUTE, 'YYYYMMDDHH24MISS')
                GROUP BY T.STD_LINK_ID
             ) latest
      INNER JOIN CURLINKST_MOCT_PRIVATE_LOG@PTDBSDB T
              ON T.STD_LINK_ID = latest.STD_LINK_ID
             AND T.REG_DATE    = latest.MAX_REGDATE
        WHERE T.REG_DATE >= TO_CHAR(SYSDATE - INTERVAL '6' MINUTE, 'YYYYMMDDHH24MISS')
          AND T.SPEED BETWEEN 1 AND 149
        ]]>
    </select>

    <select id="findAllLinkTrafMoctPrivate" resultType="com.utic.center.utic.traf.server.dto.LinkCollectDto" fetchSize="2000" timeout="90">
        <![CDATA[
        SELECT
            T.STD_LINK_ID AS linkId,
            1             AS crtPriority,
            'R'           AS missValueYn,
            'S'           AS dataResType,
            'C00'         AS centerId,
            T.SPEED       AS speed
        FROM (
                 SELECT
                     T.STD_LINK_ID,
                     MAX(T.REG_DATE) AS MAX_REGDATE
                 FROM CURLINKST_MOCT_PRIVATE_LOG@PTDBSDB T
                          INNER JOIN LINK@PTDBSDB C
                                     ON T.STD_LINK_ID = C.LINKID
                 WHERE C.LINKLEVEL = '1'
                   AND T.REG_DATE >= TO_CHAR(SYSDATE - INTERVAL '2' MINUTE, 'YYYYMMDDHH24MISS')
                 GROUP BY T.STD_LINK_ID
             ) latest
                 INNER JOIN CURLINKST_MOCT_PRIVATE_LOG@PTDBSDB T
                            ON T.STD_LINK_ID = latest.STD_LINK_ID
                                AND T.REG_DATE    = latest.MAX_REGDATE
        WHERE T.REG_DATE >= TO_CHAR(SYSDATE - INTERVAL '2' MINUTE, 'YYYYMMDDHH24MISS')
          AND T.SPEED BETWEEN 1 AND 149
        ]]>
    </select>

    <select id="findAllLinkTrafMOCT2" resultType="com.utic.center.utic.traf.server.dto.LinkCollectDto" parameterType="com.utic.center.utic.traf.server.dto.LinkCollectParam" fetchSize="2000" timeout="90">
        <![CDATA[
        SELECT A.STD_LINK_ID AS linkId,
               1             AS crtPriority,
               'R'           AS missValueYn,
               'S'           AS dataResType,
               'C00'         AS centerId,
               A.SPEED       AS speed
        FROM CURLINKST_MOCT_PRIVATE_LOG@PTDBSDB A, LINK B
        WHERE A.REG_DATE >= TO_CHAR(SYSDATE - 6/1440, 'YYYYMMDDHH24MISS')
          AND A.STD_LINK_ID = B.LINKID
          AND B.LINKLEVEL = '1'
          AND A.SPEED BETWEEN 1 AND 149
        ORDER BY A.STD_LINK_ID, A.REG_DATE ASC
        ]]>
    </select>

    <!--    WHERE A.REG_DATE >= TO_CHAR(SYSDATE - INTERVAL '6' MINUTE, 'YYYYMMDDHH24MISS')-->
</mapper>
