<?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.its.op.dao.mapper.its.atrd.AtrdTrafficStatisticsMapper">

    <!--
        기간 검색 - 15분, 시간, 일, 월, 년(링크, 서비스링크, 도로)
    -->
    <select id="findAllLinkStatByIdTerm" parameterType="com.its.op.dto.its.statistics.TrafficTermParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.LINK_ID AS ID, 1 AS ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.LINK_LENG AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.LINK_ID,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_15M"'>
                FROM TB_LINK_STAT_15M A
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_HH"'>
                FROM TB_LINK_STAT_HH A
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_DD"'>
                FROM TB_LINK_STAT_DD A
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_MN"'>
                FROM TB_LINK_STAT_MN A
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_YY"'>
                FROM TB_LINK_STAT_YY A
            </if>
              WHERE A.LINK_ID = TO_NUMBER(#{cond.ID})
                AND A.STAT_DT BETWEEN #{cond.FROM_DT} AND #{cond.TO_DT}
             ) A,
             TB_LINK B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN = 'N'
          AND A.LINK_ID = B.LINK_ID
          AND B.F_NODE_ID = C.NODE_ID(+)
          AND B.T_NODE_ID = D.NODE_ID(+)
        ORDER BY A.STAT_DT
    </select>

    <select id="findAllLinkStatByAtrdIdTerm" parameterType="com.its.op.dto.its.statistics.TrafficTermParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.LINK_ID AS ID, A.ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.LINK_LENG AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.LINK_ID, B.ORD,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_15M"'>
                FROM TB_LINK_STAT_15M A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_HH"'>
                FROM TB_LINK_STAT_HH A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_DD"'>
                FROM TB_LINK_STAT_DD A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_MN"'>
                FROM TB_LINK_STAT_MN A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_YY"'>
                FROM TB_LINK_STAT_YY A,
            </if>
                   (SELECT C.LINK_ID,
                           RANK() OVER(PARTITION BY A.ATRD_ID ORDER BY A.ORD, B.ORD, C.ORD) AS ORD
                    FROM TB_ATRD_RLTN_ROAD A, TB_ROAD_RLTN_IFSC B, TB_IFSC_RLTN_LINK C
                    WHERE A.ATRD_ID = #{cond.ID}
                      AND A.ROAD_ID = B.ROAD_ID
                      AND B.IFSC_ID = C.IFSC_ID
                   ) B
              WHERE A.LINK_ID = B.LINK_ID
                AND A.STAT_DT BETWEEN #{cond.FROM_DT} AND #{cond.TO_DT}
             ) A,
             TB_LINK B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN = 'N'
          AND A.LINK_ID = B.LINK_ID
          AND B.F_NODE_ID = C.NODE_ID(+)
          AND B.T_NODE_ID = D.NODE_ID(+)
        ORDER BY A.ORD, A.STAT_DT
    </select>

    <select id="findAllIfscStatByIdTerm" parameterType="com.its.op.dto.its.statistics.TrafficTermParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.IFSC_ID AS ID, 1 AS ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.SECT_LNGT AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.IFSC_ID,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_15M"'>
                FROM TB_IFSC_STAT_15M A
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_HH"'>
                FROM TB_IFSC_STAT_HH A
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_DD"'>
                FROM TB_IFSC_STAT_DD A
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_MN"'>
                FROM TB_IFSC_STAT_MN A
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_YY"'>
                FROM TB_IFSC_STAT_YY A
            </if>
              WHERE A.IFSC_ID = TO_NUMBER(#{cond.ID})
                AND A.STAT_DT BETWEEN #{cond.FROM_DT} AND #{cond.TO_DT}
             ) A,
             TB_IFSC B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN    = 'N'
          AND A.IFSC_ID   = B.IFSC_ID
          AND B.F_NODE_ID = C.NODE_ID(+)
          AND B.T_NODE_ID = D.NODE_ID(+)
        ORDER BY A.STAT_DT
    </select>

    <select id="findAllIfscStatByAtrdIdTerm" parameterType="com.its.op.dto.its.statistics.TrafficTermParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.IFSC_ID AS ID, A.ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.SECT_LNGT AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.IFSC_ID, B.ORD,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_15M"'>
                FROM TB_IFSC_STAT_15M A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_HH"'>
                FROM TB_IFSC_STAT_HH A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_DD"'>
                FROM TB_IFSC_STAT_DD A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_MN"'>
                FROM TB_IFSC_STAT_MN A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_YY"'>
                FROM TB_IFSC_STAT_YY A,
            </if>
                   (SELECT B.IFSC_ID,
                           RANK() OVER(PARTITION BY A.ATRD_ID ORDER BY A.ORD, B.ORD) AS ORD
                    FROM TB_ATRD_RLTN_ROAD A, TB_ROAD_RLTN_IFSC B
                    WHERE A.ATRD_ID = #{cond.ID}
                      AND A.ROAD_ID = B.ROAD_ID
                   ) B
              WHERE A.IFSC_ID = B.IFSC_ID
                AND A.STAT_DT BETWEEN #{cond.FROM_DT} AND #{cond.TO_DT}
             ) A,
             TB_IFSC B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN    = 'N'
          AND A.IFSC_ID   = B.IFSC_ID
          AND B.F_NODE_ID = C.NODE_ID(+)
          AND B.T_NODE_ID = D.NODE_ID(+)
        ORDER BY A.ORD, A.STAT_DT
    </select>

    <select id="findAllRoadStatByIdTerm" parameterType="com.its.op.dto.its.statistics.TrafficTermParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.ROAD_ID AS ID, 1 AS ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.SECT_LNGT AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.ROAD_ID,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_15M"'>
                FROM TB_ROAD_STAT_15M A
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_HH"'>
                FROM TB_ROAD_STAT_HH A
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_DD"'>
                FROM TB_ROAD_STAT_DD A
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_MN"'>
                FROM TB_ROAD_STAT_MN A
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_YY"'>
                FROM TB_ROAD_STAT_YY A
            </if>
              WHERE ROAD_ID = TO_NUMBER(#{cond.ID})
                AND STAT_DT BETWEEN #{cond.FROM_DT} AND #{cond.TO_DT}
             ) A,
             TB_ROAD B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN = 'N'
          AND A.ROAD_ID = B.ROAD_ID
          AND B.F_NODE_ID = C.NODE_ID(+)
          AND B.T_NODE_ID = D.NODE_ID(+)
        ORDER BY A.STAT_DT
    </select>

    <select id="findAllRoadStatByAtrdIdTerm" parameterType="com.its.op.dto.its.statistics.TrafficTermParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.ROAD_ID AS ID, A.ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.SECT_LNGT AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.ROAD_ID, B.ORD,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_15M"'>
                FROM TB_ROAD_STAT_15M A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_HH"'>
                FROM TB_ROAD_STAT_HH A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_DD"'>
                FROM TB_ROAD_STAT_DD A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_MN"'>
                FROM TB_ROAD_STAT_MN A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_YY"'>
                FROM TB_ROAD_STAT_YY A,
            </if>
                   (SELECT ROAD_ID, ORD
                      FROM TB_ATRD_RLTN_ROAD
                     WHERE ATRD_ID = #{cond.ID}
                   ) B
              WHERE A.ROAD_ID = B.ROAD_ID
                AND A.STAT_DT BETWEEN #{cond.FROM_DT} AND #{cond.TO_DT}
             ) A,
             TB_ROAD B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN    = 'N'
          AND A.ROAD_ID   = B.ROAD_ID
          AND B.F_NODE_ID = C.NODE_ID(+)
          AND B.T_NODE_ID = D.NODE_ID(+)
        ORDER BY A.ORD, A.STAT_DT
    </select>

    <!--
        시간대 검색 - 15분, 시간(링크, 서비스링크, 도로)
    -->
    <select id="findAllLinkStatByIdHour" parameterType="com.its.op.dto.its.statistics.TrafficHourParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.LINK_ID AS ID, 1 AS ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.LINK_LENG AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.LINK_ID,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_15M"'>
                FROM TB_LINK_STAT_15M A
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_HH"'>
                FROM TB_LINK_STAT_HH A
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_DD"'>
                FROM TB_LINK_STAT_DD A
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_MN"'>
                FROM TB_LINK_STAT_MN A
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_YY"'>
                FROM TB_LINK_STAT_YY A
            </if>
              WHERE A.LINK_ID = TO_NUMBER(#{cond.ID})
                AND A.STAT_DT BETWEEN #{cond.FROM_DT} AND #{cond.TO_DT}
                AND SUBSTR(A.STAT_DT, 9, 6) BETWEEN #{cond.FROM_HM} AND #{cond.TO_HM}
             ) A,
             TB_LINK B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN  = 'N'
          AND A.LINK_ID = B.LINK_ID
          AND B.F_NODE_ID  = C.NODE_ID(+)
          AND B.T_NODE_ID  = D.NODE_ID(+)
        ORDER BY A.STAT_DT
    </select>

    <select id="findAllLinkStatByAtrdIdHour" parameterType="com.its.op.dto.its.statistics.TrafficHourParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.LINK_ID AS ID, A.ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.LINK_LENG AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.LINK_ID, B.ORD,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_15M"'>
                FROM TB_LINK_STAT_15M A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_HH"'>
                FROM TB_LINK_STAT_HH A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_DD"'>
                FROM TB_LINK_STAT_DD A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_MN"'>
                FROM TB_LINK_STAT_MN A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_YY"'>
                FROM TB_LINK_STAT_YY A,
            </if>
                   (SELECT C.LINK_ID,
                           RANK() OVER(PARTITION BY A.ATRD_ID ORDER BY A.ORD, B.ORD, C.ORD) AS ORD
                    FROM TB_ATRD_RLTN_ROAD A, TB_ROAD_RLTN_IFSC B, TB_IFSC_RLTN_LINK C
                    WHERE A.ATRD_ID = #{cond.ID}
                      AND A.ROAD_ID = B.ROAD_ID
                      AND B.IFSC_ID = C.IFSC_ID
                   ) B
              WHERE A.LINK_ID = B.LINK_ID
                AND A.STAT_DT BETWEEN #{cond.FROM_DT} AND #{cond.TO_DT}
                AND SUBSTR(A.STAT_DT, 9, 6) BETWEEN #{cond.FROM_HM} AND #{cond.TO_HM}
             ) A,
             TB_LINK B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN  = 'N'
          AND A.LINK_ID = B.LINK_ID
          AND B.F_NODE_ID  = C.NODE_ID(+)
          AND B.T_NODE_ID  = D.NODE_ID(+)
        ORDER BY A.ORD, A.STAT_DT
    </select>

    <select id="findAllIfscStatByIdHour" parameterType="com.its.op.dto.its.statistics.TrafficHourParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.IFSC_ID AS ID, 1 AS ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.SECT_LNGT AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.IFSC_ID,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_15M"'>
                FROM TB_IFSC_STAT_15M A
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_HH"'>
                FROM TB_IFSC_STAT_HH A
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_DD"'>
                FROM TB_IFSC_STAT_DD A
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_MN"'>
                FROM TB_IFSC_STAT_MN A
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_YY"'>
                FROM TB_IFSC_STAT_YY A
            </if>
              WHERE A.IFSC_ID = TO_NUMBER(#{cond.ID})
                AND A.STAT_DT BETWEEN #{cond.FROM_DT} AND #{cond.TO_DT}
                AND SUBSTR(A.STAT_DT, 9, 6) BETWEEN #{cond.FROM_HM} AND #{cond.TO_HM}
             ) A,
             TB_IFSC B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN    = 'N'
          AND A.IFSC_ID   = B.IFSC_ID
          AND B.F_NODE_ID = C.NODE_ID(+)
          AND B.T_NODE_ID = D.NODE_ID(+)
        ORDER BY A.STAT_DT
    </select>

    <select id="findAllIfscStatByAtrdIdHour" parameterType="com.its.op.dto.its.statistics.TrafficHourParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.IFSC_ID AS ID, A.ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.SECT_LNGT AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.IFSC_ID, B.ORD,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_15M"'>
                FROM TB_IFSC_STAT_15M A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_HH"'>
                FROM TB_IFSC_STAT_HH A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_DD"'>
                FROM TB_IFSC_STAT_DD A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_MN"'>
                FROM TB_IFSC_STAT_MN A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_YY"'>
                FROM TB_IFSC_STAT_YY A,
            </if>
                   (SELECT B.IFSC_ID,
                           RANK() OVER(PARTITION BY A.ATRD_ID ORDER BY A.ORD, B.ORD) AS ORD
                    FROM TB_ATRD_RLTN_ROAD A, TB_ROAD_RLTN_IFSC B
                    WHERE A.ATRD_ID = #{cond.ID}
                      AND A.ROAD_ID = B.ROAD_ID
                   ) B
              WHERE A.IFSC_ID = B.IFSC_ID
                AND A.STAT_DT BETWEEN #{cond.FROM_DT} AND #{cond.TO_DT}
                AND SUBSTR(A.STAT_DT, 9, 6) BETWEEN #{cond.FROM_HM} AND #{cond.TO_HM}
             ) A,
             TB_IFSC B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN    = 'N'
          AND A.IFSC_ID   = B.IFSC_ID
          AND B.F_NODE_ID = C.NODE_ID(+)
          AND B.T_NODE_ID = D.NODE_ID(+)
        ORDER BY A.ORD, A.STAT_DT
    </select>

    <select id="findAllRoadStatByIdHour" parameterType="com.its.op.dto.its.statistics.TrafficHourParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.ROAD_ID AS ID, 1 AS ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.SECT_LNGT AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.ROAD_ID,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_15M"'>
                FROM TB_ROAD_STAT_15M A
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_HH"'>
                FROM TB_ROAD_STAT_HH A
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_DD"'>
                FROM TB_ROAD_STAT_DD A
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_MN"'>
                FROM TB_ROAD_STAT_MN A
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_YY"'>
                FROM TB_ROAD_STAT_YY A
            </if>
              WHERE A.ROAD_ID = TO_NUMBER(#{cond.ID})
                AND A.STAT_DT BETWEEN #{cond.FROM_DT} AND #{cond.TO_DT}
                AND SUBSTR(A.STAT_DT, 9, 6) BETWEEN #{cond.FROM_HM} AND #{cond.TO_HM}
             ) A,
             TB_ROAD B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN    = 'N'
          AND A.ROAD_ID   = B.ROAD_ID
          AND B.F_NODE_ID = C.NODE_ID(+)
          AND B.T_NODE_ID = D.NODE_ID(+)
        ORDER BY A.STAT_DT
    </select>

    <select id="findAllRoadStatByAtrdIdHour" parameterType="com.its.op.dto.its.statistics.TrafficHourParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.ROAD_ID AS ID, A.ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.SECT_LNGT AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.ROAD_ID, B.ORD,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_15M"'>
                FROM TB_ROAD_STAT_15M A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_HH"'>
                FROM TB_ROAD_STAT_HH A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_DD"'>
                FROM TB_ROAD_STAT_DD A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_MN"'>
                FROM TB_ROAD_STAT_MN A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_YY"'>
                FROM TB_ROAD_STAT_YY A,
            </if>
                   (SELECT ROAD_ID, ORD
                      FROM TB_ATRD_RLTN_ROAD
                     WHERE ATRD_ID = #{cond.ID}
                   ) B
              WHERE A.ROAD_ID = B.ROAD_ID
                AND A.STAT_DT BETWEEN #{cond.FROM_DT} AND #{cond.TO_DT}
                AND SUBSTR(A.STAT_DT, 9, 6) BETWEEN #{cond.FROM_HM} AND #{cond.TO_HM}
             ) A,
             TB_ROAD B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN    = 'N'
          AND A.ROAD_ID   = B.ROAD_ID
          AND B.F_NODE_ID = C.NODE_ID(+)
          AND B.T_NODE_ID = D.NODE_ID(+)
        ORDER BY A.ORD, A.STAT_DT
    </select>

    <!--
        지정시각 거색 - 15분, 시간(링크, 서비스링크, 도로)
    -->
    <select id="findAllLinkStatByIdSpec" parameterType="com.its.op.dto.its.statistics.TrafficSpecParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.LINK_ID AS ID, 1 AS ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.LINK_LENG AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.LINK_ID,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_15M"'>
                FROM TB_LINK_STAT_15M A
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_HH"'>
                FROM TB_LINK_STAT_HH A
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_DD"'>
                FROM TB_LINK_STAT_DD A
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_MN"'>
                FROM TB_LINK_STAT_MN A
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_YY"'>
                FROM TB_LINK_STAT_YY A
            </if>
              WHERE A.LINK_ID = TO_NUMBER(#{cond.ID})
            <if test="cond.statDays != null and cond.statDays.size > 0">
                AND
                <foreach collection="cond.statDays" item="day" index="index" open="(" close=")" separator=" OR ">
                    A.STAT_DT LIKE '' || #{day} || '%'
                </foreach>
            </if>
                AND SUBSTR(A.STAT_DT, 9, 6) BETWEEN #{cond.FROM_HM} AND #{cond.TO_HM}
             ) A,
             TB_LINK B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN  = 'N'
          AND A.LINK_ID = B.LINK_ID
          AND B.F_NODE_ID  = C.NODE_ID(+)
          AND B.T_NODE_ID  = D.NODE_ID(+)
        ORDER BY A.STAT_DT
    </select>

    <select id="findAllLinkStatByAtrdIdSpec" parameterType="com.its.op.dto.its.statistics.TrafficSpecParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.LINK_ID AS ID, A.ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.LINK_LENG AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.LINK_ID, B.ORD,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_15M"'>
                FROM TB_LINK_STAT_15M A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_HH"'>
                FROM TB_LINK_STAT_HH A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_DD"'>
                FROM TB_LINK_STAT_DD A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_MN"'>
                FROM TB_LINK_STAT_MN A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_LINK_STAT_YY"'>
                FROM TB_LINK_STAT_YY A,
            </if>
                   (SELECT C.LINK_ID,
                           RANK() OVER(PARTITION BY A.ATRD_ID ORDER BY A.ORD, B.ORD, C.ORD) AS ORD
                    FROM TB_ATRD_RLTN_ROAD A, TB_ROAD_RLTN_IFSC B, TB_IFSC_RLTN_LINK C
                    WHERE A.ATRD_ID = #{cond.ID}
                      AND A.ROAD_ID = B.ROAD_ID
                      AND B.IFSC_ID = C.IFSC_ID
                   ) B
              WHERE A.LINK_ID = B.LINK_ID
            <if test="cond.statDays != null and cond.statDays.size > 0">
                AND
                <foreach collection="cond.statDays" item="day" index="index" open="(" close=")" separator=" OR ">
                    A.STAT_DT LIKE '' || #{day} || '%'
                </foreach>
            </if>
                AND SUBSTR(A.STAT_DT, 9, 6) BETWEEN #{cond.FROM_HM} AND #{cond.TO_HM}
             ) A,
             TB_LINK B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN  = 'N'
          AND A.LINK_ID = B.LINK_ID
          AND B.F_NODE_ID  = C.NODE_ID(+)
          AND B.T_NODE_ID  = D.NODE_ID(+)
        ORDER BY A.ORD, A.STAT_DT
    </select>

    <select id="findAllIfscStatByIdSpec" parameterType="com.its.op.dto.its.statistics.TrafficSpecParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.IFSC_ID AS ID, 1 AS ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.SECT_LNGT AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.IFSC_ID,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_15M"'>
                FROM TB_IFSC_STAT_15M A
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_HH"'>
                FROM TB_IFSC_STAT_HH A
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_DD"'>
                FROM TB_IFSC_STAT_DD A
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_MN"'>
                FROM TB_IFSC_STAT_MN A
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_YY"'>
                FROM TB_IFSC_STAT_YY A
            </if>
              WHERE A.IFSC_ID = TO_NUMBER(#{cond.ID})
            <if test="cond.statDays != null and cond.statDays.size > 0">
                AND
                <foreach collection="cond.statDays" item="day" index="index" open="(" close=")" separator=" OR ">
                    A.STAT_DT LIKE '' || #{day} || '%'
                </foreach>
            </if>
                AND SUBSTR(A.STAT_DT, 9, 6) BETWEEN #{cond.FROM_HM} AND #{cond.TO_HM}
             ) A,
             TB_IFSC B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN    = 'N'
          AND A.IFSC_ID   = B.IFSC_ID
          AND B.F_NODE_ID = C.NODE_ID(+)
          AND B.T_NODE_ID = D.NODE_ID(+)
        ORDER BY A.STAT_DT
    </select>

    <select id="findAllIfscStatByAtrdIdSpec" parameterType="com.its.op.dto.its.statistics.TrafficSpecParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.IFSC_ID AS ID, A.ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.SECT_LNGT AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.IFSC_ID, B.ORD,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_15M"'>
                FROM TB_IFSC_STAT_15M A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_HH"'>
                FROM TB_IFSC_STAT_HH A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_DD"'>
                FROM TB_IFSC_STAT_DD A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_MN"'>
                FROM TB_IFSC_STAT_MN A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_IFSC_STAT_YY"'>
                FROM TB_IFSC_STAT_YY A,
            </if>
                   (SELECT B.IFSC_ID,
                           RANK() OVER(PARTITION BY A.ATRD_ID ORDER BY A.ORD, B.ORD) AS ORD
                    FROM TB_ATRD_RLTN_ROAD A, TB_ROAD_RLTN_IFSC B
                    WHERE A.ATRD_ID = #{cond.ID}
                      AND A.ROAD_ID = B.ROAD_ID
                   ) B
              WHERE A.IFSC_ID = B.IFSC_ID
            <if test="cond.statDays != null and cond.statDays.size > 0">
                AND
                <foreach collection="cond.statDays" item="day" index="index" open="(" close=")" separator=" OR ">
                    A.STAT_DT LIKE '' || #{day} || '%'
                </foreach>
            </if>
                AND SUBSTR(A.STAT_DT, 9, 6) BETWEEN #{cond.FROM_HM} AND #{cond.TO_HM}
             ) A,
             TB_IFSC B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN    = 'N'
          AND A.IFSC_ID   = B.IFSC_ID
          AND B.F_NODE_ID = C.NODE_ID(+)
          AND B.T_NODE_ID = D.NODE_ID(+)
        ORDER BY A.ORD, A.STAT_DT
    </select>

    <select id="findAllRoadStatByIdSpec" parameterType="com.its.op.dto.its.statistics.TrafficSpecParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.ROAD_ID AS ID, 1 AS ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.SECT_LNGT AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.ROAD_ID,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_15M"'>
                FROM TB_ROAD_STAT_15M A
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_HH"'>
                FROM TB_ROAD_STAT_HH A
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_DD"'>
                FROM TB_ROAD_STAT_DD A
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_MN"'>
                FROM TB_ROAD_STAT_MN A
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_YY"'>
                FROM TB_ROAD_STAT_YY A
            </if>
              WHERE A.ROAD_ID = TO_NUMBER(#{cond.ID})
            <if test="cond.statDays != null and cond.statDays.size > 0">
                AND
                <foreach collection="cond.statDays" item="day" index="index" open="(" close=")" separator=" OR ">
                    A.STAT_DT LIKE '' || #{day} || '%'
                </foreach>
            </if>
                AND SUBSTR(A.STAT_DT, 9, 6) BETWEEN #{cond.FROM_HM} AND #{cond.TO_HM}
             ) A,
             TB_ROAD B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN    = 'N'
          AND A.ROAD_ID   = B.ROAD_ID
          AND B.F_NODE_ID = C.NODE_ID(+)
          AND B.T_NODE_ID = D.NODE_ID(+)
        ORDER BY A.STAT_DT
    </select>

    <select id="findAllRoadStatByAtrdIdSpec" parameterType="com.its.op.dto.its.statistics.TrafficSpecParam" resultType="com.its.op.dto.its.atrd.AtrdTrafficStatDto">
        SELECT A.ROAD_ID ID, A.ORD, A.STAT_DT,
               NVL(TRIM(C.NODE_NAME), '값없음') AS F_NAME, NVL(TRIM(D.NODE_NAME), '값없음') AS T_NAME,
               B.SECT_LNGT AS SECT_LNGT,
               A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
        FROM (SELECT A.ROAD_ID, B.ORD,
                     A.STAT_DT,
                     A.TFVL, A.SPED, A.OCPY_RATE, A.TRVL_HH
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_15M"'>
                FROM TB_ROAD_STAT_15M A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_HH"'>
                FROM TB_ROAD_STAT_HH A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_DD"'>
                FROM TB_ROAD_STAT_DD A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_MN"'>
                FROM TB_ROAD_STAT_MN A,
            </if>
            <if test='cond.TABLE_NAME eq "TB_ROAD_STAT_YY"'>
                FROM TB_ROAD_STAT_YY A,
            </if>
                   (SELECT ROAD_ID, ORD
                    FROM TB_ATRD_RLTN_ROAD
                    WHERE ATRD_ID = #{cond.ID}
                    ) B
              WHERE A.ROAD_ID = B.ROAD_ID
            <if test="cond.statDays != null and cond.statDays.size > 0">
                AND
                <foreach collection="cond.statDays" item="day" index="index" open="(" close=")" separator=" OR ">
                    A.STAT_DT LIKE '' || #{day} || '%'
                </foreach>
            </if>
                AND SUBSTR(A.STAT_DT, 9, 6) BETWEEN #{cond.FROM_HM} AND #{cond.TO_HM}
             ) A,
             TB_ROAD B, TB_NODE C, TB_NODE D
        WHERE B.DEL_YN    = 'N'
          AND A.ROAD_ID   = B.ROAD_ID
          AND B.F_NODE_ID = C.NODE_ID(+)
          AND B.T_NODE_ID = D.NODE_ID(+)
        ORDER BY A.ORD, A.STAT_DT
    </select>

    <select id="findAtrdRltnLinkAll" parameterType="java.lang.String" resultType="com.its.op.dto.its.atrd.AtrdRltnIdDto">
        SELECT RANK() OVER(PARTITION BY A.ATRD_ID ORDER BY B.ORD, D.ORD, F.ORD) AS ord, G.LINK_ID as id, G.ROAD_NAME as name, H.NODE_NAME as strtNm, I.NODE_NAME as endNm, G.LINK_LENG as sectLngt
        FROM TB_ATRD A, TB_ATRD_RLTN_ROAD B, TB_ROAD C, TB_ROAD_RLTN_IFSC D, TB_IFSC E, TB_IFSC_RLTN_LINK F, TB_LINK G, TB_NODE H, TB_NODE I
        WHERE 1=1
          AND A.ATRD_ID = #{ATRD_ID}
          AND A.ATRD_ID = B.ATRD_ID
          AND B.ROAD_ID = C.ROAD_ID
          AND C.ROAD_ID = D.ROAD_ID
          AND D.IFSC_ID = E.IFSC_ID
          AND E.IFSC_ID = F.IFSC_ID
          AND F.LINK_ID = G.LINK_ID
          AND G.F_NODE_ID  = H.NODE_ID
          AND G.T_NODE_ID  = I.NODE_ID
          AND C.DEL_YN  = 'N'
          AND E.DEL_YN  = 'N'
          AND G.DEL_YN  = 'N'
    </select>

    <select id="findAtrdRltnIfscAll" parameterType="java.lang.String" resultType="com.its.op.dto.its.atrd.AtrdRltnIdDto">
        SELECT RANK() OVER(PARTITION BY A.ATRD_ID ORDER BY B.ORD, D.ORD) AS ord, E.IFSC_ID as id, E.IFSC_NM as name, E.STRT_NM as strtNm, E.END_NM as endNm, E.SECT_LNGT as sectLngt
        FROM TB_ATRD A, TB_ATRD_RLTN_ROAD B, TB_ROAD C, TB_ROAD_RLTN_IFSC D, TB_IFSC E
        WHERE 1=1
          AND A.ATRD_ID = #{ATRD_ID}
          AND A.ATRD_ID = B.ATRD_ID
          AND B.ROAD_ID = C.ROAD_ID
          AND C.ROAD_ID = D.ROAD_ID
          AND D.IFSC_ID = E.IFSC_ID
          AND C.DEL_YN  = 'N'
          AND E.DEL_YN  = 'N'
    </select>

    <select id="findAtrdRltnRoadAll" parameterType="java.lang.String" resultType="com.its.op.dto.its.atrd.AtrdRltnIdDto">
        SELECT B.ORD AS ord, C.ROAD_ID AS id, C.ROAD_NM AS name, C.STRT_NM as strtNm, C.END_NM as endNm, C.SECT_LNGT as sectLngt
        FROM TB_ATRD A, TB_ATRD_RLTN_ROAD B, TB_ROAD C
        WHERE 1=1
          AND A.ATRD_ID = #{ATRD_ID}
          AND A.ATRD_ID = B.ATRD_ID
          AND B.ROAD_ID = C.ROAD_ID
          AND C.DEL_YN  = 'N'
    </select>

</mapper>
