<?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="mapper.utic.collect.PRIOETC">

    <!--  우선순위가 높은 순서로 처리해야 함 팻치 순서에 따라 먼저 처리됨 -->
    <select id="findAllLinkTrafPRIOETC" resultType="com.utic.center.utic.traf.server.dto.LinkCollectDto" parameterType="com.utic.center.utic.traf.server.dto.LinkCollectParam" fetchSize="2000" timeout="60">
        <![CDATA[
        SELECT
            LINKID  AS linkId,
            1       AS crtPriority,
            'R'     AS missValueYn,
            'P'     AS dataResType,
            'L00'   AS centerId,
            SPEED   AS speed
        FROM (
                 SELECT
                     A.LINKID,
                     A.SPEED,
                     ROW_NUMBER() OVER (PARTITION BY A.LINKID ORDER BY A.LOGDATE DESC) AS rn
                 FROM TRAFFIC_LOC A
                 JOIN LINK B ON A.LINKID = B.LINKID
                 WHERE B.LINKLEVEL = '1'
                   AND A.LOGDATE   > TO_DATE(#{prcsTime}, 'YYYYMMDDHH24MISS') - INTERVAL '10' MINUTE
                   AND A.LOCALDATE > TO_DATE(#{prcsTime}, 'YYYYMMDDHH24MISS') - INTERVAL '20' MINUTE
                   AND A.SPEED BETWEEN 1 AND 149
                   AND NOT EXISTS (
                     SELECT 1 FROM LOCAL_MATCH M WHERE M.LINKID = A.LINKID
                 )
             ) WHERE rn = 1
        ]]>
    </select>
<!--    <select id="findAllLinkTrafPRIOETC" resultType="com.utic.center.utic.traf.server.dto.LinkCollectDto" parameterType="com.utic.center.utic.traf.server.dto.LinkCollectParam" fetchSize="2000">-->
<!--        <![CDATA[-->
<!--        SELECT A.LINKID AS linkId,-->
<!--               1        AS crtPriority,-->
<!--               'R'      AS missValueYn,-->
<!--               'P'      AS dataResType,-->
<!--               'L00'    AS centerId,-->
<!--               TO_NUMBER(SUBSTR(MAX(TO_CHAR(A.LOGDATE,'YYYYMMDDHH24MISS')||LTRIM(TO_CHAR(A.SPEED,'000'))),15,3)) AS speed-->
<!--        FROM TRAFFIC_LOC A, LINK B-->
<!--        WHERE A.LOGDATE   > TO_DATE(#{prcsTime}, 'YYYYMMDDHH24MISS') - 10/1440-->
<!--          AND A.LOCALDATE > TO_DATE(#{prcsTime}, 'YYYYMMDDHH24MISS') - 20/1440-->
<!--          AND A.LINKID    = B.LINKID-->
<!--          AND B.LINKLEVEL = '1'-->
<!--          AND A.SPEED BETWEEN 1 AND 149-->
<!--          AND A.LINKID NOT IN (SELECT DISTINCT LINKID FROM LOCAL_MATCH)-->
<!--        GROUP BY A.LINKID-->
<!--        ]]>-->
<!--    </select>-->

</mapper>
