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

    <!--  우선순위가 높은 순서로 처리해야 함 팻치 순서에 따라 먼저 처리됨 -->
    <select id="findAllLinkTrafPRIO" 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,
            crtPriority,
            missValueYn,
            dataResType,
            centerId,
            speed
        FROM (
                 SELECT
                     A.LINKID AS linkId,
                     (B.PRIORITY * 3) - 2 AS crtPriority,
                     'R' AS missValueYn,
                     DECODE(A.CENTERID, 'L90', DECODE(B.PRIORITY, 3, 'G'), 'P') AS dataResType,
                     A.CENTERID AS centerId,
                     A.SPEED AS speed,
                     ROW_NUMBER() OVER (PARTITION BY A.LINKID ORDER BY (B.PRIORITY * 3) - 2 ASC) AS rn
                 FROM TRAFFIC_LOC A
                 JOIN LOCAL_MATCH B ON A.LINKID = B.LINKID AND A.CENTERID = B.CENTERID
                 JOIN LINK C ON A.LINKID = C.LINKID
                 WHERE C.LINKLEVEL = '1'
                   AND B.CENTERID BETWEEN 'L01' AND 'L99'
                   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
             ) WHERE rn = 1
        ]]>
    </select>
<!--    <select id="findAllLinkTrafPRIO" resultType="com.utic.center.utic.traf.server.dto.LinkCollectDto" parameterType="com.utic.center.utic.traf.server.dto.LinkCollectParam" fetchSize="2000">-->
<!--        <![CDATA[-->
<!--        SELECT LINKID      AS linkId,-->
<!--               CRTPRIORITY AS crtPriority,-->
<!--               MISSVALUEYN AS missValueYn,-->
<!--               DATARESTYPE AS dataResType,-->
<!--               CENTERID    AS centerId,-->
<!--               SPEED       AS speed-->
<!--        FROM (SELECT A.LINKID AS LINKID,-->
<!--                     (B.PRIORITY*3)-2 AS CRTPRIORITY,-->
<!--                     'R' AS MISSVALUEYN,-->
<!--                     DECODE(A.CENTERID, 'L90', DECODE(B.PRIORITY, 3, 'G'), 'P') AS DATARESTYPE,-->
<!--                     A.CENTERID AS CENTERID,-->
<!--                     A.SPEED AS SPEED-->
<!--              FROM TRAFFIC_LOC A, LOCAL_MATCH B, LINK C-->
<!--              WHERE A.LINKID = B.LINKID-->
<!--                AND C.LINKID = B.LINKID-->
<!--                AND C.LINKID = A.LINKID-->
<!--                AND C.LINKLEVEL = '1'-->
<!--                AND A.CENTERID  = B.CENTERID-->
<!--                AND B.CENTERID BETWEEN 'L01' AND 'L99'-->
<!--                AND A.LOGDATE   > TO_DATE(#{prcsTime}, 'YYYYMMDDHH24MISS') - 10/1440-->
<!--                AND A.LOCALDATE > TO_DATE(#{prcsTime}, 'YYYYMMDDHH24MISS') - 20/1440-->
<!--                AND A.SPEED BETWEEN 1 AND 149-->
<!--             )-->
<!--        ORDER BY LINKID, CRTPRIORITY-->
<!--        ]]>-->
<!--    </select>-->
</mapper>
