<?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="egovframework.com.its.web.server.mapper.CommonMapper">

	<select id="getRoadVertexArr" resultType="egovframework.com.its.web.server.vo.RoadVertexArrVO" fetchSize="1000">
        SELECT
            TT.ATRD_ID as atrd_id,
            NVL(TT.ATRD_NM, TR.ROAD_NM) as atrd_nm,
            DECODE(TT.DRCT_CD,0,'상행','하행') as drct_cd,
            TT.ROAD_ORD as road_ord,
            NULL as ifsc_ord,
            NULL as link_ord,
            TR.ROAD_ID as road_id,
            TR.ROAD_NM as road_nm,
            NVL((SELECT NODE_NAME FROM TB_NODE WHERE TR.F_NODE_ID = NODE_ID),'-') as strt_nm_node,
            NVL((SELECT NODE_NAME FROM TB_NODE WHERE TR.T_NODE_ID = NODE_ID),'-') as end_nm_node,
            TR.SECT_LNGT as sect_lngt,
            TRVA.LEVL as levl,
            TRVA.X_CRDN as x_crdn,
            TRVA.Y_CRDN as y_crdn,
            TRVA.X_CRDN_MIN as x_crdn_min,
            TRVA.X_CRDN_MAX as x_crdn_max,
            TRVA.Y_CRDN_MIN as y_crdn_min,
            TRVA.Y_CRDN_MAX as y_crdn_max,
            CASE
                WHEN TRT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                    THEN TRT.CMTR_GRAD_CD
                ELSE 'LTC0'
                END cmtr_grad_cd,
            CASE
                WHEN TRT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                    THEN NVL(TRT.SPED,0)
                ELSE 0
                END sped,
            CASE
                WHEN TRT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                    THEN NVL(ROUND(TRT.TRVL_HH / 60) + 1,0)
                ELSE 0
                END as trvl_hh
        FROM TB_ROAD TR, (SELECT ROAD_ID AS ROAD_ID,
                                 LEVL,
                                 X_CRDN_ARR AS X_CRDN,
                                 Y_CRDN_ARR AS Y_CRDN,
                                 X_CRDN_MIN,
                                 X_CRDN_MAX,
                                 Y_CRDN_MIN,
                                 Y_CRDN_MAX
                          FROM TB_ROAD_VRTX_ARR
             ) TRVA,
             TB_ROAD_TRAF TRT, (SELECT T1.ATRD_ID,T1.ATRD_NM,T1.DRCT_CD,T2.ROAD_ID, T2.ORD ROAD_ORD
                                FROM TB_ATRD T1, TB_ATRD_RLTN_ROAD T2
                                WHERE T1.ATRD_ID = T2.ATRD_ID
             ) TT
        WHERE TR.ROAD_ID = TRVA.ROAD_ID
          AND TR.ROAD_ID = TRT.ROAD_ID(+)
          AND TR.ROAD_ID = TT.ROAD_ID(+)
        ORDER BY LEVL,DRCT_CD,ROAD_ORD,IFSC_ORD,LINK_ORD
	</select>

    <select id="getWeatherInfo" resultType="egovframework.com.its.web.server.vo.WeatherInfoVO">
        SELECT *
        FROM
            (SELECT
                 TO_DATE(ANNC_DT, 'YYYYMMDDHH24MISS') AS ANNOUNCEDATE,
                 0 AS ANNOUNCETIMECODE,
                 PRST_TMPR AS TEMPERATURE,
                 DECODE(WTCD_KOR_NM,
                        '맑음', 'DB01',
                        '구름 조금', 'DB02',
                        '구름 많음', 'DB03',
                        '흐림', 'DB04',
                        '비', 'DB05',
                        '비/눈', 'DB06',
                        '눈', 'DB07',
                        '소나기', 'DB08',
                        'DB00') AS WEATHERCODE,

                 LWST_TMPR AS MINTEMPERATURE,
                 HGHS_TMPR AS MAXTEMPERATURE,
                 PRST_TMPR
             FROM TB_VILG_FRCS_PNST
             WHERE ANNC_DT > TO_CHAR(SYSDATE - 1, 'YYYYMMDDHH24MISS')
               --AND VILG_FRCS_ZONE_CD = 4146151000
               AND VILG_FRCS_ZONE_CD = 4122000000
             ORDER BY ORD DESC)
        WHERE ROWNUM = 1
    </select>
    
	<select id="getIfscVertexArr" resultType="egovframework.com.its.web.server.vo.RoadVertexArrVO" fetchSize="7000">
        SELECT
                TT.ATRD_ID,
                NVL(TT.ATRD_NM,TI.IFSC_NM) ATRD_NM,
                DECODE(TT.DRCT_CD,0,'상행','하행') DRCT_CD,
                TT.ROAD_ORD,
                TT.IFSC_ORD,
                NULL LINK_ORD,
                TI.IFSC_ID ROAD_ID,
                TI.IFSC_NM ROAD_NM,
                NVL((SELECT NODE_NAME FROM TB_NODE WHERE TI.F_NODE_ID = NODE_ID),'-') STRT_NM_NODE,
                NVL((SELECT NODE_NAME FROM TB_NODE WHERE TI.T_NODE_ID = NODE_ID),'-') END_NM_NODE,
                TI.SECT_LNGT SECT_LNGT,
                TIVA.LEVL,
                TIVA.X_CRDN,
                TIVA.Y_CRDN,
                TIVA.X_CRDN_MIN,
                TIVA.X_CRDN_MAX,
                TIVA.Y_CRDN_MIN,
                TIVA.Y_CRDN_MAX,
                CASE WHEN TIT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                 THEN TIT.CMTR_GRAD_CD
                 ELSE 'LTC0'
                END CMTR_GRAD_CD,
				CASE WHEN TIT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                 THEN NVL(TIT.SPED,0)
                 ELSE 0
                END SPED,
                CASE WHEN TIT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                 THEN NVL(ROUND(TIT.TRVL_HH / 60) + 1,0)
                 ELSE 0
                END TRVL_HH
                FROM
                TB_IFSC TI,
                (SELECT
                        IFSC_ID,
                        LEVL,
                        X_CRDN_ARR AS X_CRDN,
                        Y_CRDN_ARR AS Y_CRDN,
                        X_CRDN_MIN, 
                        X_CRDN_MAX,
                        Y_CRDN_MIN, 
                        Y_CRDN_MAX 
                   FROM TB_IFSC_VRTX_ARR) TIVA, TB_IFSC_TRAF TIT,
                   (
                    SELECT T1.ATRD_ID,T1.ATRD_NM,T1.DRCT_CD,T2.ORD ROAD_ORD,T3.IFSC_ID,T3.ORD IFSC_ORD 
                      FROM TB_ATRD T1, TB_ATRD_RLTN_ROAD T2, TB_ROAD_RLTN_IFSC T3 
                     WHERE T1.ATRD_ID = T2.ATRD_ID
                       AND T2.ROAD_ID = T3.ROAD_ID
                   ) TT
                  WHERE TI.IFSC_ID = TIVA.IFSC_ID
                    AND TI.IFSC_ID = TIT.IFSC_ID(+)
                    AND TI.IFSC_ID = TT.IFSC_ID(+)
                  ORDER BY LEVL,DRCT_CD,ROAD_ORD,IFSC_ORD,LINK_ORD
    </select>

	<select id="getLinkVertexArr" resultType="egovframework.com.its.web.server.vo.RoadVertexArrVO" fetchSize="12000">
    SELECT
            TT.ATRD_ID,
            NVL(TT.ATRD_NM,TL.ROAD_NAME) ATRD_NM,
            DECODE(TT.DRCT_CD,0,'상행','하행') DRCT_CD,
            TT.ROAD_ORD,
            TT.IFSC_ORD,
            TT.LINK_ORD,
            TL.LINK_ID ROAD_ID,
            TL.ROAD_NAME ROAD_NM,
            NVL((SELECT NODE_NAME FROM TB_NODE WHERE TL.F_NODE_ID = NODE_ID),'-') STRT_NM_NODE,
            NVL((SELECT NODE_NAME FROM TB_NODE WHERE TL.T_NODE_ID = NODE_ID),'-') END_NM_NODE,
            0 SECT_LNGT,
            TLVA.LEVL,
            TLVA.X_CRDN,
            TLVA.Y_CRDN,
            TLVA.X_CRDN_MIN,
            TLVA.X_CRDN_MAX,
            TLVA.Y_CRDN_MIN,
            TLVA.Y_CRDN_MAX,
            CASE WHEN TLT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                THEN TLT.CMTR_GRAD_CD
                ELSE 'LTC0'
            END CMTR_GRAD_CD,
            CASE WHEN TLT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                THEN NVL(TLT.SPED,0)
                ELSE 0
                END SPED,
                CASE WHEN TLT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                THEN NVL(ROUND(TLT.TRVL_HH / 60) + 1,0)
                ELSE 0
                END TRVL_HH
      FROM TB_LINK TL, (SELECT
                                LINK_ID,
                                LEVL,
                                X_CRDN_ARR AS X_CRDN,
                                Y_CRDN_ARR AS Y_CRDN,
                                X_CRDN_MIN, 
                                X_CRDN_MAX,
                                Y_CRDN_MIN, 
                                Y_CRDN_MAX 
                          FROM TB_LINK_VRTX_ARR
                          ) TLVA, TB_LINK_TRAF TLT, (SELECT T1.ATRD_ID,T1.ATRD_NM,T1.DRCT_CD,T2.ORD ROAD_ORD,T3.ORD IFSC_ORD,T4.ORD LINK_ORD,T4.LINK_ID
                                                      FROM TB_ATRD T1, TB_ATRD_RLTN_ROAD T2, TB_ROAD_RLTN_IFSC T3, TB_IFSC_RLTN_LINK T4
                                                      WHERE T1.ATRD_ID = T2.ATRD_ID
                                                        AND T2.ROAD_ID = T3.ROAD_ID
                                                        AND T3.IFSC_ID = T4.IFSC_ID
                                                    ) TT
      WHERE TL.LINK_ID = TLVA.LINK_ID
        AND TL.LINK_ID = TLT.LINK_ID(+)
        AND TL.LINK_ID = TT.LINK_ID(+)
        AND TLVA.LEVL <![CDATA[ = ]]> 2
    ORDER BY LEVL,DRCT_CD,ROAD_ORD,IFSC_ORD,LINK_ORD
	</select>

	<select id="getVertexArr" resultType="egovframework.com.its.web.server.vo.RoadVertexArrVO" fetchSize="1000">
		SELECT
            TT.ATRD_ID,
            NVL(TT.ATRD_NM,'-') ATRD_NM,
            DECODE(TT.DRCT_CD,0,'상행','하행') DRCT_CD,
            TT.ROAD_ORD,
            TT.IFSC_ORD,
            TT.LINK_ORD,
            TL.LINK_ID ROAD_ID,
            TL.ROAD_NAME ROAD_NM,
            NVL((SELECT NODE_NAME FROM TB_NODE WHERE TL.F_NODE = NODE_ID),'-') STRT_NM_NODE,
            NVL((SELECT NODE_NAME FROM TB_NODE WHERE TL.T_NODE = NODE_ID),'-') END_NM_NODE,
            0 SECT_LNGT,
            TLVA.LEVL,
            TLVA.X_CRDN,
            TLVA.Y_CRDN,
            TLVA.X_CRDN_MIN,
            TLVA.X_CRDN_MAX,
            TLVA.Y_CRDN_MIN,
            TLVA.Y_CRDN_MAX,
            CASE WHEN TLT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                 THEN TLT.CMTR_GRAD_CD
                 ELSE 'LTC0'
             END CMTR_GRAD_CD,
            CASE WHEN TLT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                 THEN NVL(TLT.SPED,0)
                 ELSE 0
                END SPED,
                CASE WHEN TLT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                 THEN NVL(ROUND(TLT.TRVL_HH / 60) + 1,0)
                 ELSE 0
                END TRVL_HH
            FROM
            TB_LINK TL,
            (SELECT
                LINK_ID,
                LEVL,
                X_CRDN_ARR AS X_CRDN,
                Y_CRDN_ARR AS Y_CRDN,
                X_CRDN_MIN,
                X_CRDN_MAX,
                Y_CRDN_MIN,
                Y_CRDN_MAX
               FROM TB_LINK_VRTX_ARR) TLVA, TB_LINK_TRAF TLT,
               (
                SELECT T1.ATRD_ID,T1.ATRD_NM,T1.DRCT_CD,T2.ORD ROAD_ORD,T3.ORD IFSC_ORD,T4.ORD LINK_ORD,T4.LINK_ID
                  FROM TB_ATRD T1, TB_ATRD_ROAD_RLTN T2, TB_ROAD_IFSC_RLTN T3, TB_IFSC_LINK_RLTN T4
                 WHERE T1.ATRD_ID = T2.ATRD_ID
                   AND T2.ROAD_ID = T3.ROAD_ID
                   AND T3.IFSC_ID = T4.IFSC_ID
               ) TT
              WHERE TL.LINK_ID = TLVA.LINK_ID
                AND TL.LINK_ID = TLT.LINK_ID(+)
                AND TL.LINK_ID = TT.LINK_ID(+)
        UNION ALL
            SELECT
                TT.ATRD_ID,
                NVL(TT.ATRD_NM,'-') ATRD_NM,
                DECODE(TT.DRCT_CD,0,'상행','하행') DRCT_CD,
                TT.ROAD_ORD,
                TT.IFSC_ORD,
                NULL LINK_ORD,
                TI.IFSC_ID ROAD_ID,
                TI.IFSC_NM ROAD_NM,
                NVL((SELECT NODE_NAME FROM TB_NODE WHERE TI.F_NODE_ID = NODE_ID),'-') STRT_NM_NODE,
                NVL((SELECT NODE_NAME FROM TB_NODE WHERE TI.T_NODE_ID = NODE_ID),'-') END_NM_NODE,
                TI.SECT_LNGT SECT_LNGT,
                TIVA.LEVL,
                TIVA.X_CRDN,
                TIVA.Y_CRDN,
                TIVA.X_CRDN_MIN,
                TIVA.X_CRDN_MAX,
                TIVA.Y_CRDN_MIN,
                TIVA.Y_CRDN_MAX,
                CASE WHEN TIT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                 THEN TIT.CMTR_GRAD_CD
                 ELSE 'LTC0'
                END CMTR_GRAD_CD,
				CASE WHEN TIT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                 THEN NVL(TIT.SPED,0)
                 ELSE 0
                END SPED,
                CASE WHEN TIT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                 THEN NVL(ROUND(TIT.TRVL_HH / 60) + 1,0)
                 ELSE 0
                END TRVL_HH
                FROM
                TB_IFSC TI,
                (SELECT
                        IFSC_ID,
                        LEVL,
                        X_CRDN_ARR AS X_CRDN,
                        Y_CRDN_ARR AS Y_CRDN,
                        X_CRDN_MIN,
                        X_CRDN_MAX,
                        Y_CRDN_MIN,
                        Y_CRDN_MAX
                   FROM TB_IFSC_VRTX_ARR) TIVA, TB_IFSC_TRAF TIT,
                   (
                    SELECT T1.ATRD_ID,T1.ATRD_NM,T1.DRCT_CD,T2.ORD ROAD_ORD,T3.IFSC_ID,T3.ORD IFSC_ORD
                      FROM TB_ATRD T1, TB_ATRD_ROAD_RLTN T2, TB_ROAD_IFSC_RLTN T3
                     WHERE T1.ATRD_ID = T2.ATRD_ID
                       AND T2.ROAD_ID = T3.ROAD_ID
                   ) TT
                  WHERE TI.IFSC_ID = TIVA.IFSC_ID
                    AND TI.IFSC_ID = TIT.IFSC_ID(+)
                    AND TI.IFSC_ID = TT.IFSC_ID(+)
        UNION ALL
        SELECT
                TT.ATRD_ID,
                NVL(TT.ATRD_NM,'-') ATRD_NM,
                DECODE(TT.DRCT_CD,0,'상행','하행') DRCT_CD,
                TT.ROAD_ORD,
                NULL IFSC_ORD,
                NULL LINK_ORD,
                TR.ROAD_ID ROAD_ID,
                TR.ROAD_NAME ROAD_NAME,
                NVL((SELECT NODE_NAME FROM TB_NODE WHERE TR.F_NODE_ID = NODE_ID),'-') STRT_NM_NODE,
                NVL((SELECT NODE_NAME FROM TB_NODE WHERE TR.T_NODE_ID = NODE_ID),'-') END_NM_NODE,
                TR.SECT_LNGT,
                TRVA.LEVL,
                TRVA.X_CRDN,
                TRVA.Y_CRDN,
                TRVA.X_CRDN_MIN,
                TRVA.X_CRDN_MAX,
                TRVA.Y_CRDN_MIN,
                TRVA.Y_CRDN_MAX,
                CASE WHEN TRT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                 THEN TRT.CMTR_GRAD_CD
                 ELSE 'LTC0'
                END CMTR_GRAD_CD,
                CASE WHEN TRT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                 THEN NVL(TRT.SPED,0)
                 ELSE 0
                END SPED,
                CASE WHEN TRT.PRCN_DT >= TO_CHAR(SYSDATE - 10/24/60,'YYYYMMDDHH24MISS')
                 THEN NVL(ROUND(TRT.TRVL_HH / 60) + 1,0)
                 ELSE 0
                END TRVL_HH
                FROM
                TB_ROAD TR,
                (SELECT
                        ROAD_ID AS ROAD_ID,
                        LEVL,
                        X_CRDN_ARR AS X_CRDN,
                        Y_CRDN_ARR AS Y_CRDN,
                        X_CRDN_MIN,
                        X_CRDN_MAX,
                        Y_CRDN_MIN,
                        Y_CRDN_MAX
                   FROM TB_ROAD_VRTX_ARR) TRVA, TB_ROAD_TRAF TRT,
                (SELECT T1.ATRD_ID,T1.ATRD_NM,T1.DRCT_CD,T2.ROAD_ID, T2.ORD ROAD_ORD
                   FROM TB_ATRD T1, TB_ATRD_ROAD_RLTN T2
                  WHERE T1.ATRD_ID = T2.ATRD_ID
                ) TT
                WHERE TR.ROAD_ID = TRVA.ROAD_ID
                  AND TR.ROAD_ID = TRT.ROAD_ID(+)
                  AND TR.ROAD_ID = TT.ROAD_ID(+)
        ORDER BY LEVL,DRCT_CD,ROAD_ORD,IFSC_ORD,LINK_ORD
	</select>

 	<select id="getVmsCtlr" resultType="egovframework.com.its.web.server.vo.VmsCtlrVO">
		SELECT A.VMS_CTLR_NMBR,
		       A.VMS_NM,
		       A.X_CRDN,
		       A.Y_CRDN,
		       NVL(B.CMNC_STTS_CD, 'CMS1') AS CMNC_STTS_CD,
               C.VMS_WDTH AS phas_img_width,
               C.VMS_HGHT AS phas_img_height
		FROM TB_VMS_CTLR A
		LEFT OUTER JOIN TB_VMS_CTLR_STTS B
		  ON A.VMS_CTLR_NMBR = B.VMS_CTLR_NMBR
        LEFT OUTER JOIN TB_VMS_TYPE C
          ON A.VMS_TYPE_CD = C.VMS_TYPE_CD
		WHERE A.DEL_YN = 'N'
		ORDER BY A.VMS_NM ASC
	</select>

	<select id="getVmsPhaseImgList" resultType="egovframework.com.its.web.server.vo.VmsCtlrVO">
		SELECT A.VMS_CTLR_NMBR,
               A.PHASE,
               A.VMS_DSPL_MSG_IMAG,
               A.VMS_DSPL_MSG_TXT
          FROM TB_VMS_DSPL_PRST A,
               (SELECT VMS_CTLR_NMBR, MAX(DSPL_DT) AS DSPL_DT
                  FROM TB_VMS_DSPL_PRST
                 WHERE DSPL_DT >= TO_CHAR((SYSDATE - 8/1440),'YYYYMMDDHH24MISS')
                 GROUP by VMS_CTLR_NMBR) B
          WHERE A.VMS_CTLR_NMBR = B.VMS_CTLR_NMBR
            AND A.DSPL_DT       = B.DSPL_DT
          ORDER BY A.VMS_CTLR_NMBR, A.PHASE
	</select>

	<select id="getVmsImgTxt" resultType="egovframework.com.its.web.server.vo.VmsCtlrVO" parameterType="java.util.HashMap">
		SELECT
                A.VMS_CTLR_NMBR,
                B.VMS_WDTH AS phas_img_width,
                B.VMS_HGHT AS phas_img_height,
                C.PHASE,
                C.VMS_DSPL_MSG_IMAG,
                C.VMS_DSPL_MSG_TXT
                --,NVL((SELECT CMNC_STTS_CD
                --   FROM TB_VMS_CTLR_STTS
                --  WHERE VMS_CTLR_NMBR = A.VMS_CTLR_NMBR
                --    AND UPDT_DT >= TO_CHAR((SYSDATE - 8/1440),'YYYYMMDDHH24MISS')), 'CMS1') AS CMNC_STTS_CD
		  FROM TB_VMS_CTLR A
		    INNER JOIN TB_VMS_TYPE B
		            ON A.VMS_CTLR_NMBR = #{vms_ctlr_nmbr}
		           AND A.VMS_TYPE_CD = B.VMS_TYPE_CD
		    LEFT OUTER JOIN (SELECT
		                            VMS_CTLR_NMBR,
		                            PHASE,
		                            VMS_DSPL_MSG_IMAG,
		                            VMS_DSPL_MSG_TXT
		                       FROM TB_VMS_DSPL_PRST
		                      WHERE (VMS_CTLR_NMBR, DSPL_DT)
                                    IN
                                      (SELECT
                                              VMS_CTLR_NMBR,
                                              MAX(DSPL_DT) AS DSPL_DT
		                                 FROM TB_VMS_DSPL_PRST
		                                WHERE VMS_CTLR_NMBR = #{vms_ctlr_nmbr}
		                                  AND DSPL_DT >= TO_CHAR((SYSDATE - 8/1440),'YYYYMMDDHH24MISS')
		                                GROUP BY VMS_CTLR_NMBR
		                          )
		                    ) C
		    ON  A.VMS_CTLR_NMBR  = C.VMS_CTLR_NMBR
	</select>
<!--    <select id="getVmsImgTxt" resultType="egovframework.com.its.web.server.vo.VmsCtlrVO" parameterType="java.util.HashMap">-->
<!--        SELECT-->
<!--            A.VMS_CTLR_NMBR,-->
<!--            C.PHASE,-->
<!--            C.VMS_DSPL_MSG_IMAG,-->
<!--            C.VMS_DSPL_MSG_TXT-->
<!--        FROM TB_VMS_CTLR A-->
<!--        LEFT OUTER JOIN (SELECT-->
<!--                              VMS_CTLR_NMBR,-->
<!--                              PHASE,-->
<!--                              VMS_DSPL_MSG_IMAG,-->
<!--                              VMS_DSPL_MSG_TXT-->
<!--                           FROM TB_VMS_DSPL_PRST ) C-->
<!--                      ON A.VMS_CTLR_NMBR  = C.VMS_CTLR_NMBR-->
<!--        WHERE A.VMS_CTLR_NMBR = #{vms_ctlr_nmbr}-->
<!--    </select>-->

	<select id="getWcamCtlr" resultType="egovframework.com.its.web.server.vo.WcamCtlrVO">
		 SELECT WCAM_CTLR_NMBR,
		       WCAM_NM,
		       WCAM_TYPE_CD,
		       NVL(ISTL_LCTN_NM,'-') ISTL_LCTN_NM,
		       X_CRDN,
		       Y_CRDN,
		       STRM_RTSP_ADDR,
		       STRM_RTMP_ADDR,
		       STRM_HTTP_ADDR
		  FROM TB_WCAM_CTLR
		 WHERE DEL_YN = 'N'
	</select>

	<select id="getCctvCtlr" resultType="egovframework.com.its.web.server.vo.CctvCtlrVO">
        SELECT A.CCTV_CTLR_NMBR as cctv_mngm_nmbr,
               A.CCTV_CTLR_ID as cctv_ctlr_id,
               A.CCTV_CTLR_IP as cctv_ctlr_ip,
               A.CCTV_CTLR_PORT as cctv_ctlr_port,
               A.CCTV_CAPT_IP as cctv_capt_ip,
               A.CCTV_CAPT_PORT as cctv_capt_port,
               --A.CCTV_FIBR_IP as cctv_fibr_ip,
               --A.CCTV_ENCD_IP as cctv_encd_ip,
               A.STRM_SVR_IP as strm_svr_ip,
               A.STRM_SVR_PORT as strm_svr_port,
               A.STRM_SESN_NM as strm_sesn_nm,
               A.X_CRDN as x_crdn,
               A.Y_CRDN as y_crdn,
               A.ISTL_LCTN_NM as istl_lctn_nm,
               A.ISTL_LCTN_ADDR as istl_lctn_addr,
               --A.CCTV_CHNL as cctv_chnl,
               A.DEL_YN as del_yn,
               A.LINK_ID as link_id,
               A.NODE_ID as node_id,
               --A.RELY_PORT as rely_port,
               A.STRM_RTSP_ADDR as strm_rtsp_addr,
               --A.STRM_RTMP_ADDR as strm_rtmp_addr,
               A.STRM_HTTP_ADDR as strm_http_addr,
               --A.STRM_STOR_ADDR as strm_stor_addr,
               --A.AREA_CD as area_cd,
               B.CMNC_STTS_CD as cmnc_stts_cd,
               A.WEB_RTC_SVR_PORT as web_rtc_svr_port,
               A.WEB_RTC_SVR_IP as web_rtc_svr_ip,
               A.WEB_RTC_ID as web_rtc_id
        FROM TB_CCTV_CTLR A
        LEFT OUTER JOIN TB_CCTV_CTLR_STTS B
        ON A.CCTV_CTLR_NMBR = B.CCTV_CTLR_NMBR
        WHERE A.DEL_YN = 'N'
        AND   A.HOMEPAGE_YN = 'Y'
        ORDER BY A.ISTL_LCTN_NM ASC
	</select>

    <select id="getOneCctvCtlr" resultType="egovframework.com.its.web.server.vo.CctvCtlrVO" parameterType="String">
		SELECT
            A.CCTV_CTLR_NMBR as cctv_mngm_nmbr,
            A.CCTV_CTLR_ID as cctv_ctlr_id,
            A.CCTV_CTLR_IP as cctv_ctlr_ip,
            A.CCTV_CTLR_PORT as cctv_ctlr_port,
            A.CCTV_CAPT_IP as cctv_capt_ip,
            A.CCTV_CAPT_PORT as cctv_capt_port,
            --A.CCTV_FIBR_IP as cctv_fibr_ip,
            --A.CCTV_ENCD_IP as cctv_encd_ip,
            A.STRM_SVR_IP as strm_svr_ip,
            A.STRM_SVR_PORT as strm_svr_port,
            A.STRM_SESN_NM as strm_sesn_nm,
            A.X_CRDN as x_crdn,
            A.Y_CRDN as y_crdn,
            A.ISTL_LCTN_NM as istl_lctn_nm,
            A.ISTL_LCTN_ADDR as istl_lctn_addr,
            --A.CCTV_CHNL as cctv_chnl,
            A.DEL_YN as del_yn,
            A.LINK_ID as link_id,
            A.NODE_ID as node_id,
            --A.RELY_PORT as rely_port,
            A.STRM_RTSP_ADDR as strm_rtsp_addr,
            --A.STRM_RTMP_ADDR as strm_rtmp_addr,
            A.STRM_HTTP_ADDR as strm_http_addr,
            --A.STRM_STOR_ADDR as strm_stor_addr,
            --A.AREA_CD as area_cd,
            B.CMNC_STTS_CD as cmnc_stts_cd,
            A.WEB_RTC_SVR_PORT as web_rtc_svr_port,
            A.WEB_RTC_SVR_IP as web_rtc_svr_ip,
            A.WEB_RTC_ID as web_rtc_id
        FROM
                TB_CCTV_CTLR A LEFT OUTER JOIN TB_CCTV_CTLR_STTS B
        ON A.CCTV_CTLR_NMBR = B.CCTV_CTLR_NMBR
        WHERE A.DEL_YN = 'N'
        AND A.CCTV_CTLR_NMBR = #{nmbr}
        ORDER BY ISTL_LCTN_NM ASC
	</select>
	
	<select id="getIncdOcrr" resultType="egovframework.com.its.web.server.vo.IncdVO">
        SELECT  A.INCD_OCRR_ID as incd_ocrr_id,
                A.LINK_ID as link_id,
                SUBSTR(A.INCD_STRT_DT, 0,4) || '년' ||
                SUBSTR(A.INCD_STRT_DT, 5,2) || '월' ||
                SUBSTR(A.INCD_STRT_DT, 7,2) || '일 ' ||
                SUBSTR(A.INCD_STRT_DT, 9,2) || '시' as incd_strt_dt,
                SUBSTR(A.INCD_END_PRAR_DT, 0,4) || '년' ||
                SUBSTR(A.INCD_END_PRAR_DT, 5,2) || '월' ||
                SUBSTR(A.INCD_END_PRAR_DT, 7,2) || '일 ' ||
                SUBSTR(A.INCD_END_PRAR_DT, 9,2) || '시' as incd_end_prar_dt,
                A.OCRR_LCTN_NM AS road_name,
                NVL(TRIM(A.INCD_TITL),'-') AS incd_titl,
                NVL(TRIM(A.INCD_EXPL),'-') AS incd_expl,
                A.INCD_TYPE_CLSF_CD AS incd_type_code,
                B.CMMN_CD_KOR_NM as cmmn_cd_kor_nm,
                A.X_CRDN as x_crdn,
                A.Y_CRDN as y_crdn
      FROM TB_INCD_OCRR A, TB_CMMN_CD B
      WHERE A.INCD_PRGR_STEP_CD = 'ISS2'
        AND B.CMMN_CLSF_CD = 'IDTU'
        AND A.INCD_END_PRAR_DT >= to_char(sysdate, 'YYYYMMDDHH24MISS')
        AND A.INCD_TYPE_CLSF_CD = B.CMMN_CD
      ORDER BY ROAD_NAME
	</select>
	
	<select id="getAtrdNm" resultType="egovframework.com.its.web.server.vo.AtrdVO">
<!-- (오라클) WM_CONCAT : 여러행 데이터를 하나의 컬럼으로..
        Oracle 10g에서 사용
-->
-- 		SELECT ATRD_NM as atrd_nm,
-- 	           WM_CONCAT(ATRD_ID) as atrd_id
--           FROM TB_ATRD
--          WHERE DEL_YN = 'N'
--          GROUP BY ATRD_NM

<!-- (오라클) LISTAGG : 여러행 데이터를 하나의 컬럼으로..
        Oracle XE 11g 이상에서는 WM_CONCAT() 사용을 못하고,
        대신에 LISTAGG 사용하면 된다.
-->
        SELECT A.ATRD_NM as atrd_nm,
               LISTAGG(DISTINCT(A.ATRD_ID),',') as atrd_id,
               COUNT(B.ATRD_ID) AS road_count
          FROM TB_ATRD A
          JOIN TB_ATRD_RLTN_ROAD B
            ON A.ATRD_ID = B.ATRD_ID
         WHERE DEL_YN = 'N'
         GROUP BY ATRD_NM ORDER BY ATRD_NM

<!-- (티베로) AGGR_CONCAT : 여러행 데이터를 하나의 컬럼으로..
        SELECT ATRD_NM as atrd_nm,
               AGGR_CONCAT(ATRD_ID,',') as atrd_id,
		  FROM TB_ATRD
		 WHERE DEL_YN = 'N' 
		 GROUP BY ATRD_NM ; 
 -->
	</select>

	<select id="getVisitCount" resultType="egovframework.com.its.web.server.vo.VisitCountVO">
		SELECT SUM(TODAY) AS TODAY,
		       SUM(TOTAL) AS TOTAL
  			FROM (SELECT NVL(SUM(CONN_CNT), 1) AS TODAY, 0 AS TOTAL
          			FROM TB_WWW_CONN_PAGE_STAT_DD t 
         			WHERE T.STAT_MON = TO_CHAR(SYSDATE, 'YYYYMM') 
           		AND T.STAT_DD  = TO_CHAR(SYSDATE, 'DD')
           		AND T.PAGE_ID = 'W1'
                UNION ALL
                    SELECT 0 AS TODAY, NVL(SUM(CONN_CNT), 1) AS TOTAL
                        FROM TB_WWW_CONN_PAGE_STAT_MN T
                        WHERE T.PAGE_ID = 'W1'
                )
	</select>

	<update id="addUpdateHourLogWeb" parameterType="java.util.HashMap">
        MERGE INTO
                TB_WWW_CONN_PAGE_STAT_HH
        USING
                DUAL
        ON
                (
                 STAT_DAY = TO_CHAR (SYSDATE, 'YYYYMMDD')
                 AND STAT_HH = TO_CHAR (SYSDATE, 'HH24')
                 AND PAGE_ID = (SELECT PAGE_ID FROM TB_WWW_PAGE WHERE PAGE_URL = #{uri})
                )
        WHEN MATCHED THEN
        UPDATE SET
                    CONN_CNT = CONN_CNT + 1
        WHEN NOT MATCHED THEN
        INSERT(
               CONN_CNT,
               PAGE_ID,
               STAT_HH,
               STAT_DAY
               )
        VALUES(
               1,
               (SELECT PAGE_ID FROM TB_WWW_PAGE WHERE PAGE_URL = #{uri}),
               TO_CHAR (SYSDATE, 'HH24'),
               TO_CHAR (SYSDATE, 'YYYYMMDD')
               )

	</update>

	<update id="addUpdateDateLogWeb" parameterType="java.util.HashMap">
        MERGE INTO
        TB_WWW_CONN_PAGE_STAT_DD
        USING
            DUAL ON (
                STAT_MON = TO_CHAR (SYSDATE, 'YYYYMM')
                AND STAT_DD = TO_CHAR (SYSDATE, 'DD')
                AND PAGE_ID = (SELECT PAGE_ID FROM TB_WWW_PAGE WHERE PAGE_URL = #{uri})
            )
        WHEN
            MATCHED THEN
            UPDATE SET CONN_CNT = CONN_CNT + 1
        WHEN
            NOT MATCHED THEN
            INSERT (
                 CONN_CNT,
                 PAGE_ID,
                 STAT_DD,
                 STAT_MON
            )
            VALUES (
                1,
                (SELECT PAGE_ID FROM TB_WWW_PAGE WHERE PAGE_URL = #{uri}),
                TO_CHAR (SYSDATE, 'DD'),
                TO_CHAR (SYSDATE, 'YYYYMM')
            )

	</update>

	<update id="addUpdateMonthLogWeb" parameterType="java.util.HashMap">
        MERGE INTO
            TB_WWW_CONN_PAGE_STAT_MN
        USING
            DUAL ON (
                STAT_YEAR   = TO_CHAR(SYSDATE, 'YYYY')
                AND STAT_MN = TO_CHAR(SYSDATE, 'MM')
                AND PAGE_ID = (SELECT PAGE_ID FROM TB_WWW_PAGE WHERE PAGE_URL = #{uri})
            )
        WHEN
            MATCHED THEN
            UPDATE SET CONN_CNT = CONN_CNT + 1
        WHEN
            NOT MATCHED THEN
            INSERT (
                 CONN_CNT,
                 PAGE_ID,
                 STAT_MN,
                 STAT_YEAR
            )
            VALUES (
                1,
                (SELECT PAGE_ID FROM TB_WWW_PAGE WHERE PAGE_URL = #{uri}),
                TO_CHAR(SYSDATE, 'MM'),
                TO_CHAR(SYSDATE, 'YYYY')
            )

	</update>

</mapper>