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

<!--	<select id="getVertexHistoryByRoadText" resultType="java.util.HashMap">-->
<!--		SELECT A.ROAD_ID,-->
<!--			   &#45;&#45;B.ROAD_NM,-->
<!--			   REPLACE(B.ROAD_NM, ROAD_NM, #{atrdNm}) AS ROAD_NM,-->
<!--			   B.STRT_NM,-->
<!--			   B.END_NM,-->
<!--			   A.STAT_DT,-->
<!--			   A.SPED,-->
<!--			   A.TRVL_HH-->
<!--		FROM-->
<!--			(SELECT ROAD_ID,-->
<!--					STAT_DT,-->
<!--					SPED,-->
<!--					TRVL_HH-->
<!--			 FROM-->
<!--				<if test='sTimeTypeVal == "sTime"'>-->
<!--					TB_ROAD_STAT_HH WHERE SUBSTR(STAT_DT,0,10) BETWEEN #{yyyymmddhh} AND #{yyyymmddhh2}-->
<!--				</if>-->
<!--				<if test='sTimeTypeVal == "sDay"'>-->
<!--					TB_ROAD_STAT_DD WHERE SUBSTR(STAT_DT,0,8) BETWEEN #{yyyymmddhh} AND #{yyyymmddhh2}-->
<!--				</if>-->
<!--				<if test='sTimeTypeVal == "sMonth"'>-->
<!--					TB_ROAD_STAT_MN WHERE SUBSTR(STAT_DT,0,6) BETWEEN #{yyyymmddhh} AND #{yyyymmddhh2}-->
<!--				</if>-->
<!--				<if test='sTimeTypeVal == "sYear"'>-->
<!--					TB_ROAD_STAT_YY WHERE SUBSTR(STAT_DT,0,4) BETWEEN #{yyyymmddhh} AND #{yyyymmddhh2}-->
<!--				</if>-->
<!--			   AND ROAD_ID IN (SELECT-->
<!--							 	A.ROAD_ID-->
<!--							 FROM-->
<!--								 TB_ATRD_RLTN_ROAD A,-->
<!--								 TB_ATRD B-->
<!--							 WHERE-->
<!--								 A.ATRD_ID = B.ATRD_ID-->
<!--									<if test="atrdNm != null">-->
<!--										AND	B.ATRD_NM LIKE '%'|| #{atrdNm} ||'%'-->
<!--									</if>-->
<!--							 )-->
<!--			 ORDER BY STAT_DT,ROAD_ID) A, TB_ROAD B-->
<!--		WHERE A.ROAD_ID = B.ROAD_ID-->
<!--		ORDER BY ROAD_NM, STAT_DT-->

<!--	</select>-->
	<select id="getAtrdStat" resultType="egovframework.com.its.web.server.vo.AtrdStatVO">
		SELECT
			A.ROAD_ID,
			C.ATRD_NM AS ROAD_NM,
			NVL(D.STRT_NM, '') AS STRT_NM,
			NVL(D.END_NM, '') AS END_NM,
			A.STAT_DT,
			NVL(A.SPED, '') AS SPED,
			NVL(A.TRVL_HH, '') AS TRVL_HH
		FROM
			<choose>
				<when test="type == 'sTime'">TB_ROAD_STAT_HH</when>
				<when test="type == 'sDay'">TB_ROAD_STAT_DD</when>
				<when test="type == 'sMonth'">TB_ROAD_STAT_MN</when>
				<when test="type == 'sYear'">TB_ROAD_STAT_YY</when>
			</choose> A,
			TB_ATRD_RLTN_ROAD B,
			TB_ATRD C,
			TB_ROAD D
		WHERE
			A.ROAD_ID = B.ROAD_ID
			AND	B.ATRD_ID = C.ATRD_ID
			AND B.ROAD_ID = D.ROAD_ID
			AND A.STAT_DT BETWEEN #{from} AND #{to}
			AND	C.ATRD_ID IN (<foreach collection="atrdIds" item="item" separator=",">#{item}</foreach> )
		ORDER BY A.STAT_DT, B.ATRD_ID, B.ORD
	</select>

	<select id="getAtrdNm" resultType="egovframework.com.its.web.server.vo.AtrdVO">
		SELECT
			ATRD_ID,
			ATRD_NM
		FROM
			TB_ATRD
		WHERE
			DRCT_CD = '1'
		ORDER BY
			ATRD_NM
	</select>

	<select id="findIxr15M" parameterType="java.util.HashMap" resultType="egovframework.com.its.web.server.vo.ScIxrTrafficVO" fetchSize="1000">
		SELECT C.CLCT_DT clctDt,
		       A.IXR_ID AS ixrId,
			   B.IXR_NM AS ixrNm,
			   NVL(A.ISTL_LCTN, '-') AS cmraNm,
			   A.DRCT_DVSN_CD_R AS drctDvsnCdR,
			   NVL(C.SMAL_LEFT_TFVL,  0) AS smalLeftTfvl,
			   NVL(C.MDDL_LEFT_TFVL,  0) AS mddlLeftTfvl,
			   NVL(C.LRG_LEFT_TFVL,   0) AS lrgLeftTfvl,
			   NVL(C.SMAL_GO_TFVL,    0) AS smalGoTfvl,
			   NVL(C.MDDL_GO_TFVL,    0) AS mddlGoTfvl,
			   NVL(C.LRG_GO_TFVL,     0) AS lrgGoTfvl,
			   NVL(C.SMAL_RGHT_TFVL,  0) AS smalRghtTfvl,
			   NVL(C.MDDL_RGHT_TFVL,  0) AS mddlRghtTfvl,
			   NVL(C.LRG_RGHT_TFVL,   0) AS lrgRghtTfvl,
			   NVL(C.SMAL_UTURN_TFVL, 0) AS smalUturnTfvl,
			   NVL(C.MDDL_UTURN_TFVL, 0) AS mddlUturnTfvl,
			   NVL(C.LRG_UTURN_TFVL,  0) AS lrgUturnTfvl,
			   (
					   NVL(C.SMAL_LEFT_TFVL,  0) +
					   NVL(C.MDDL_LEFT_TFVL,  0) +
					   NVL(C.LRG_LEFT_TFVL,   0) +
					   NVL(C.SMAL_GO_TFVL,    0) +
					   NVL(C.MDDL_GO_TFVL,    0) +
					   NVL(C.LRG_GO_TFVL,     0) +
					   NVL(C.SMAL_RGHT_TFVL,  0) +
					   NVL(C.MDDL_RGHT_TFVL,  0) +
					   NVL(C.LRG_RGHT_TFVL,   0) +
					   NVL(C.SMAL_UTURN_TFVL, 0) +
					   NVL(C.MDDL_UTURN_TFVL, 0) +
					   NVL(C.LRG_UTURN_TFVL,  0)
				   ) AS totTfvl
		FROM TB_SC_IXR_CMRA_MNGM A
		JOIN TB_SC_IXR_MNGM B
		  ON A.IXR_ID = B.IXR_ID
		LEFT OUTER JOIN TB_SC_ACRD_STAT_15M C
		    		 ON C.IXR_ID = A.IXR_ID
					AND C.DRCT_DVSN_CD = A.DRCT_DVSN_CD
		WHERE A.IXR_ID IN (<foreach collection="ixrIds" item="item" separator=",">#{item}</foreach>)
		  AND C.CLCT_DT BETWEEN #{from} AND #{to}
		ORDER BY C.CLCT_DT, TO_NUMBER(A.IXR_ID), A.DRCT_DVSN_CD
	</select>
<!--	<select id="findIxr15M" parameterType="java.util.HashMap" resultType="egovframework.com.its.web.server.vo.ScIxrTrafficVO" fetchSize="1000">-->
<!--		WITH DATE_RANGE AS (-->
<!--			SELECT TO_CHAR(TO_DATE(#{from}, 'YYYYMMDDHH24MISS') + (LEVEL - 1)  * INTERVAL '15' MINUTE, 'YYYYMMDDHH24MISS') AS CLCT_DT-->
<!--			FROM DUAL-->
<!--			CONNECT BY LEVEL <![CDATA[<=]]> (TO_DATE(#{to}, 'YYYYMMDDHH24MISS') - TO_DATE(#{from}, 'YYYYMMDDHH24MISS') + 1) * 24 * 4-->
<!--		),-->
<!--		IXR_COMBINATIONS AS (-->
<!--			SELECT DISTINCT A.IXR_ID, A.DRCT_DVSN_CD-->
<!--			  FROM TB_SC_IXR_CMRA_MNGM A-->
<!--		),-->
<!--		BASE_DATA AS (-->
<!--			SELECT D.CLCT_DT, I.IXR_ID, I.DRCT_DVSN_CD-->
<!--			  FROM DATE_RANGE D-->
<!--			 CROSS JOIN IXR_COMBINATIONS I-->
<!--		),-->
<!--		TRAFFIC_DATA AS (-->
<!--			SELECT IXR_ID, DRCT_DVSN_CD, CLCT_DT AS CLCT_DT,-->
<!--				   SUM(NVL(SMAL_LEFT_TFVL,  0)) AS SMAL_LEFT_TFVL,-->
<!--				   SUM(NVL(MDDL_LEFT_TFVL,  0)) AS MDDL_LEFT_TFVL,-->
<!--				   SUM(NVL(LRG_LEFT_TFVL,   0)) AS LRG_LEFT_TFVL,-->
<!--				   SUM(NVL(SMAL_GO_TFVL,    0)) AS SMAL_GO_TFVL,-->
<!--				   SUM(NVL(MDDL_GO_TFVL,    0)) AS MDDL_GO_TFVL,-->
<!--				   SUM(NVL(LRG_GO_TFVL,     0)) AS LRG_GO_TFVL,-->
<!--				   SUM(NVL(SMAL_RGHT_TFVL,  0)) AS SMAL_RGHT_TFVL,-->
<!--				   SUM(NVL(MDDL_RGHT_TFVL,  0)) AS MDDL_RGHT_TFVL,-->
<!--				   SUM(NVL(LRG_RGHT_TFVL,   0)) AS LRG_RGHT_TFVL,-->
<!--				   SUM(NVL(SMAL_UTURN_TFVL, 0)) AS SMAL_UTURN_TFVL,-->
<!--				   SUM(NVL(MDDL_UTURN_TFVL, 0)) AS MDDL_UTURN_TFVL,-->
<!--				   SUM(NVL(LRG_UTURN_TFVL,  0)) AS LRG_UTURN_TFVL-->
<!--			  FROM TB_SC_ACRD_STAT_15M-->
<!--		     WHERE IXR_ID IN-->
<!--			<foreach collection="ixrIds" item="item" open="(" separator="," close=")">-->
<!--				#{item}-->
<!--			</foreach>-->
<!--		       AND CLCT_DT BETWEEN #{from} AND #{to}-->
<!--		     GROUP BY IXR_ID, DRCT_DVSN_CD, CLCT_DT-->
<!--		)-->
<!--		SELECT B.CLCT_DT AS clctDt,-->
<!--			   A.IXR_ID AS ixrId,-->
<!--			   X.IXR_NM AS ixrNm,-->
<!--			   NVL(A.ISTL_LCTN, '-') AS cmraNm,-->
<!--			   A.DRCT_DVSN_CD_R AS drctDvsnCdR,-->
<!--			   NVL(T.SMAL_LEFT_TFVL,  0) smalLeftTfvl,-->
<!--			   NVL(T.MDDL_LEFT_TFVL,  0) mddlLeftTfvl,-->
<!--			   NVL(T.LRG_LEFT_TFVL,   0) lrgLeftTfvl,-->
<!--			   NVL(T.SMAL_GO_TFVL,    0) smalGoTfvl,-->
<!--			   NVL(T.MDDL_GO_TFVL,    0) mddlGoTfvl,-->
<!--			   NVL(T.LRG_GO_TFVL,     0) lrgGoTfvl,-->
<!--			   NVL(T.SMAL_RGHT_TFVL,  0) smalRghtTfvl,-->
<!--			   NVL(T.MDDL_RGHT_TFVL,  0) mddlRghtTfvl,-->
<!--			   NVL(T.LRG_RGHT_TFVL,   0) lrgRghtTfvl,-->
<!--			   NVL(T.SMAL_UTURN_TFVL, 0) smalUturnTfvl,-->
<!--			   NVL(T.MDDL_UTURN_TFVL, 0) mddlUturnTfvl,-->
<!--			   NVL(T.LRG_UTURN_TFVL,  0) lrgUturnTfvl,-->
<!--			   (-->
<!--				   NVL(T.SMAL_LEFT_TFVL,  0) +-->
<!--				   NVL(T.MDDL_LEFT_TFVL,  0) +-->
<!--				   NVL(T.LRG_LEFT_TFVL,   0) +-->
<!--				   NVL(T.SMAL_GO_TFVL,    0) +-->
<!--				   NVL(T.MDDL_GO_TFVL,    0) +-->
<!--				   NVL(T.LRG_GO_TFVL,     0) +-->
<!--				   NVL(T.SMAL_RGHT_TFVL,  0) +-->
<!--				   NVL(T.MDDL_RGHT_TFVL,  0) +-->
<!--				   NVL(T.LRG_RGHT_TFVL,   0) +-->
<!--				   NVL(T.SMAL_UTURN_TFVL, 0) +-->
<!--				   NVL(T.MDDL_UTURN_TFVL, 0) +-->
<!--				   NVL(T.LRG_UTURN_TFVL,  0)-->
<!--			   ) AS totTfvl-->
<!--		  FROM BASE_DATA B-->
<!--		  LEFT JOIN TB_SC_IXR_CMRA_MNGM A ON B.IXR_ID = A.IXR_ID AND B.DRCT_DVSN_CD = A.DRCT_DVSN_CD-->
<!--		  LEFT JOIN TB_SC_IXR_MNGM X ON A.IXR_ID = X.IXR_ID-->
<!--		  LEFT JOIN TRAFFIC_DATA T ON B.IXR_ID = T.IXR_ID AND B.DRCT_DVSN_CD = T.DRCT_DVSN_CD AND B.CLCT_DT = T.CLCT_DT-->
<!--		 ORDER BY B.CLCT_DT, TO_NUMBER(A.IXR_ID), A.DRCT_DVSN_CD-->
<!--	</select>-->

	<select id="findIxrHH" parameterType="java.util.HashMap" resultType="egovframework.com.its.web.server.vo.ScIxrTrafficVO" fetchSize="1000">
		SELECT C.CLCT_DT clctDt,
			   A.IXR_ID AS ixrId,
			   B.IXR_NM AS ixrNm,
			   NVL(A.ISTL_LCTN, '-') AS cmraNm,
		       A.DRCT_DVSN_CD_R AS drctDvsnCdR,
			   NVL(C.SMAL_LEFT_TFVL,  0) AS smalLeftTfvl,
			   NVL(C.MDDL_LEFT_TFVL,  0) AS mddlLeftTfvl,
			   NVL(C.LRG_LEFT_TFVL,   0) AS lrgLeftTfvl,
			   NVL(C.SMAL_GO_TFVL,    0) AS smalGoTfvl,
			   NVL(C.MDDL_GO_TFVL,    0) AS mddlGoTfvl,
			   NVL(C.LRG_GO_TFVL,     0) AS lrgGoTfvl,
			   NVL(C.SMAL_RGHT_TFVL,  0) AS smalRghtTfvl,
			   NVL(C.MDDL_RGHT_TFVL,  0) AS mddlRghtTfvl,
			   NVL(C.LRG_RGHT_TFVL,   0) AS lrgRghtTfvl,
			   NVL(C.SMAL_UTURN_TFVL, 0) AS smalUturnTfvl,
			   NVL(C.MDDL_UTURN_TFVL, 0) AS mddlUturnTfvl,
			   NVL(C.LRG_UTURN_TFVL,  0) AS lrgUturnTfvl,
			   (
				   NVL(C.SMAL_LEFT_TFVL,  0) +
				   NVL(C.MDDL_LEFT_TFVL,  0) +
				   NVL(C.LRG_LEFT_TFVL,   0) +
				   NVL(C.SMAL_GO_TFVL,    0) +
				   NVL(C.MDDL_GO_TFVL,    0) +
				   NVL(C.LRG_GO_TFVL,     0) +
				   NVL(C.SMAL_RGHT_TFVL,  0) +
				   NVL(C.MDDL_RGHT_TFVL,  0) +
				   NVL(C.LRG_RGHT_TFVL,   0) +
				   NVL(C.SMAL_UTURN_TFVL, 0) +
				   NVL(C.MDDL_UTURN_TFVL, 0) +
				   NVL(C.LRG_UTURN_TFVL,  0)
			   ) AS totTfvl
		 FROM TB_SC_IXR_CMRA_MNGM A
		 JOIN TB_SC_IXR_MNGM B
		   ON A.IXR_ID = B.IXR_ID
		 LEFT OUTER JOIN TB_SC_ACRD_STAT_HH C
		              ON C.IXR_ID = A.IXR_ID
				     AND C.DRCT_DVSN_CD = A.DRCT_DVSN_CD
		WHERE A.IXR_ID IN (<foreach collection="ixrIds" item="item" separator=",">#{item}</foreach>)
		  AND C.CLCT_DT BETWEEN #{from} AND #{to}
		ORDER BY C.CLCT_DT, TO_NUMBER(A.IXR_ID), A.DRCT_DVSN_CD
	</select>
<!--	<select id="findIxrHH" parameterType="java.util.HashMap" resultType="egovframework.com.its.web.server.vo.ScIxrTrafficVO" fetchSize="1000">-->
<!--		WITH DATE_RANGE AS (-->
<!--			SELECT TO_CHAR(TO_DATE(#{from}, 'YYYYMMDDHH24MISS') + (LEVEL - 1) / 24, 'YYYYMMDDHH24MISS') AS CLCT_DT-->
<!--			FROM DUAL-->
<!--			CONNECT BY LEVEL <![CDATA[<=]]> (TO_DATE(#{to}, 'YYYYMMDDHH24MISS') - TO_DATE(#{from}, 'YYYYMMDDHH24MISS') + 1) * 24-->
<!--		),-->
<!--		IXR_COMBINATIONS AS (-->
<!--			SELECT DISTINCT A.IXR_ID, A.DRCT_DVSN_CD-->
<!--			  FROM TB_SC_IXR_CMRA_MNGM A-->
<!--		),-->
<!--		BASE_DATA AS (-->
<!--			SELECT D.CLCT_DT, I.IXR_ID, I.DRCT_DVSN_CD-->
<!--			  FROM DATE_RANGE D-->
<!--			 CROSS JOIN IXR_COMBINATIONS I-->
<!--		),-->
<!--		TRAFFIC_DATA AS (-->
<!--			SELECT IXR_ID, DRCT_DVSN_CD, CLCT_DT AS CLCT_DT,-->
<!--				   SUM(NVL(SMAL_LEFT_TFVL,  0)) AS SMAL_LEFT_TFVL,-->
<!--				   SUM(NVL(MDDL_LEFT_TFVL,  0)) AS MDDL_LEFT_TFVL,-->
<!--				   SUM(NVL(LRG_LEFT_TFVL,   0)) AS LRG_LEFT_TFVL,-->
<!--				   SUM(NVL(SMAL_GO_TFVL,    0)) AS SMAL_GO_TFVL,-->
<!--				   SUM(NVL(MDDL_GO_TFVL,    0)) AS MDDL_GO_TFVL,-->
<!--				   SUM(NVL(LRG_GO_TFVL,     0)) AS LRG_GO_TFVL,-->
<!--				   SUM(NVL(SMAL_RGHT_TFVL,  0)) AS SMAL_RGHT_TFVL,-->
<!--				   SUM(NVL(MDDL_RGHT_TFVL,  0)) AS MDDL_RGHT_TFVL,-->
<!--				   SUM(NVL(LRG_RGHT_TFVL,   0)) AS LRG_RGHT_TFVL,-->
<!--				   SUM(NVL(SMAL_UTURN_TFVL, 0)) AS SMAL_UTURN_TFVL,-->
<!--				   SUM(NVL(MDDL_UTURN_TFVL, 0)) AS MDDL_UTURN_TFVL,-->
<!--				   SUM(NVL(LRG_UTURN_TFVL,  0)) AS LRG_UTURN_TFVL-->
<!--			  FROM TB_SC_ACRD_STAT_HH-->
<!--		     WHERE IXR_ID IN-->
<!--			<foreach collection="ixrIds" item="item" open="(" separator="," close=")">-->
<!--				#{item}-->
<!--			</foreach>-->
<!--		       AND CLCT_DT BETWEEN #{from} AND #{to}-->
<!--		     GROUP BY IXR_ID, DRCT_DVSN_CD, CLCT_DT-->
<!--		)-->
<!--		SELECT B.CLCT_DT AS clctDt,-->
<!--			   A.IXR_ID AS ixrId,-->
<!--			   X.IXR_NM AS ixrNm,-->
<!--			   NVL(A.ISTL_LCTN, '-') AS cmraNm,-->
<!--			   A.DRCT_DVSN_CD_R AS drctDvsnCdR,-->
<!--			   NVL(T.SMAL_LEFT_TFVL,  0) smalLeftTfvl,-->
<!--			   NVL(T.MDDL_LEFT_TFVL,  0) mddlLeftTfvl,-->
<!--			   NVL(T.LRG_LEFT_TFVL,   0) lrgLeftTfvl,-->
<!--			   NVL(T.SMAL_GO_TFVL,    0) smalGoTfvl,-->
<!--			   NVL(T.MDDL_GO_TFVL,    0) mddlGoTfvl,-->
<!--			   NVL(T.LRG_GO_TFVL,     0) lrgGoTfvl,-->
<!--			   NVL(T.SMAL_RGHT_TFVL,  0) smalRghtTfvl,-->
<!--			   NVL(T.MDDL_RGHT_TFVL,  0) mddlRghtTfvl,-->
<!--			   NVL(T.LRG_RGHT_TFVL,   0) lrgRghtTfvl,-->
<!--			   NVL(T.SMAL_UTURN_TFVL, 0) smalUturnTfvl,-->
<!--			   NVL(T.MDDL_UTURN_TFVL, 0) mddlUturnTfvl,-->
<!--			   NVL(T.LRG_UTURN_TFVL,  0) lrgUturnTfvl,-->
<!--			   (-->
<!--				   NVL(T.SMAL_LEFT_TFVL,  0) +-->
<!--				   NVL(T.MDDL_LEFT_TFVL,  0) +-->
<!--				   NVL(T.LRG_LEFT_TFVL,   0) +-->
<!--				   NVL(T.SMAL_GO_TFVL,    0) +-->
<!--				   NVL(T.MDDL_GO_TFVL,    0) +-->
<!--				   NVL(T.LRG_GO_TFVL,     0) +-->
<!--				   NVL(T.SMAL_RGHT_TFVL,  0) +-->
<!--				   NVL(T.MDDL_RGHT_TFVL,  0) +-->
<!--				   NVL(T.LRG_RGHT_TFVL,   0) +-->
<!--				   NVL(T.SMAL_UTURN_TFVL, 0) +-->
<!--				   NVL(T.MDDL_UTURN_TFVL, 0) +-->
<!--				   NVL(T.LRG_UTURN_TFVL,  0)-->
<!--			   ) AS totTfvl-->
<!--		  FROM BASE_DATA B-->
<!--		  LEFT JOIN TB_SC_IXR_CMRA_MNGM A ON B.IXR_ID = A.IXR_ID AND B.DRCT_DVSN_CD = A.DRCT_DVSN_CD-->
<!--		  LEFT JOIN TB_SC_IXR_MNGM X ON A.IXR_ID = X.IXR_ID-->
<!--		  LEFT JOIN TRAFFIC_DATA T ON B.IXR_ID = T.IXR_ID AND B.DRCT_DVSN_CD = T.DRCT_DVSN_CD AND B.CLCT_DT = T.CLCT_DT-->
<!--		 ORDER BY B.CLCT_DT, TO_NUMBER(A.IXR_ID), A.DRCT_DVSN_CD-->
<!--	</select>-->

<!--	<select id="findIxrDD" parameterType="java.util.HashMap" resultType="egovframework.com.its.web.server.vo.ScIxrTrafficVO" fetchSize="1000">-->
<!--		WITH DATE_RANGE AS (-->
<!--			SELECT TO_CHAR(TO_DATE(#{from}, 'YYYYMMDDHH24MISS') + LEVEL - 1, 'YYYYMMDDHH24MISS') AS CLCT_DT-->
<!--			FROM DUAL-->
<!--			CONNECT BY LEVEL <![CDATA[<=]]> TO_DATE(#{to}, 'YYYYMMDDHH24MISS') - TO_DATE(#{from}, 'YYYYMMDDHH24MISS') + 1-->
<!--		),-->
<!--		IXR_COMBINATIONS AS (-->
<!--			SELECT DISTINCT A.IXR_ID, A.DRCT_DVSN_CD-->
<!--			  FROM TB_SC_IXR_CMRA_MNGM A-->
<!--		),-->
<!--		BASE_DATA AS (-->
<!--			SELECT D.CLCT_DT, I.IXR_ID, I.DRCT_DVSN_CD-->
<!--			  FROM DATE_RANGE D-->
<!--			 CROSS JOIN IXR_COMBINATIONS I-->
<!--		),-->
<!--		TRAFFIC_DATA AS (-->
<!--			SELECT IXR_ID, DRCT_DVSN_CD, CLCT_DT AS CLCT_DT,-->
<!--				   SUM(NVL(SMAL_LEFT_TFVL,  0)) AS SMAL_LEFT_TFVL,-->
<!--				   SUM(NVL(MDDL_LEFT_TFVL,  0)) AS MDDL_LEFT_TFVL,-->
<!--				   SUM(NVL(LRG_LEFT_TFVL,   0)) AS LRG_LEFT_TFVL,-->
<!--				   SUM(NVL(SMAL_GO_TFVL,    0)) AS SMAL_GO_TFVL,-->
<!--				   SUM(NVL(MDDL_GO_TFVL,    0)) AS MDDL_GO_TFVL,-->
<!--				   SUM(NVL(LRG_GO_TFVL,     0)) AS LRG_GO_TFVL,-->
<!--				   SUM(NVL(SMAL_RGHT_TFVL,  0)) AS SMAL_RGHT_TFVL,-->
<!--				   SUM(NVL(MDDL_RGHT_TFVL,  0)) AS MDDL_RGHT_TFVL,-->
<!--				   SUM(NVL(LRG_RGHT_TFVL,   0)) AS LRG_RGHT_TFVL,-->
<!--				   SUM(NVL(SMAL_UTURN_TFVL, 0)) AS SMAL_UTURN_TFVL,-->
<!--				   SUM(NVL(MDDL_UTURN_TFVL, 0)) AS MDDL_UTURN_TFVL,-->
<!--				   SUM(NVL(LRG_UTURN_TFVL,  0)) AS LRG_UTURN_TFVL-->
<!--			  FROM TB_SC_ACRD_STAT_DD-->
<!--		     WHERE IXR_ID IN-->
<!--			<foreach collection="ixrIds" item="item" open="(" separator="," close=")">-->
<!--				#{item}-->
<!--			</foreach>-->
<!--		       AND CLCT_DT BETWEEN #{from} AND #{to}-->
<!--		     GROUP BY IXR_ID, DRCT_DVSN_CD, CLCT_DT-->
<!--		)-->
<!--		SELECT B.CLCT_DT AS clctDt,-->
<!--			   A.IXR_ID AS ixrId,-->
<!--			   X.IXR_NM AS ixrNm,-->
<!--			   NVL(A.ISTL_LCTN, '-') AS cmraNm,-->
<!--			   A.DRCT_DVSN_CD_R AS drctDvsnCdR,-->
<!--			   NVL(T.SMAL_LEFT_TFVL,  0) smalLeftTfvl,-->
<!--			   NVL(T.MDDL_LEFT_TFVL,  0) mddlLeftTfvl,-->
<!--			   NVL(T.LRG_LEFT_TFVL,   0) lrgLeftTfvl,-->
<!--			   NVL(T.SMAL_GO_TFVL,    0) smalGoTfvl,-->
<!--			   NVL(T.MDDL_GO_TFVL,    0) mddlGoTfvl,-->
<!--			   NVL(T.LRG_GO_TFVL,     0) lrgGoTfvl,-->
<!--			   NVL(T.SMAL_RGHT_TFVL,  0) smalRghtTfvl,-->
<!--			   NVL(T.MDDL_RGHT_TFVL,  0) mddlRghtTfvl,-->
<!--			   NVL(T.LRG_RGHT_TFVL,   0) lrgRghtTfvl,-->
<!--			   NVL(T.SMAL_UTURN_TFVL, 0) smalUturnTfvl,-->
<!--			   NVL(T.MDDL_UTURN_TFVL, 0) mddlUturnTfvl,-->
<!--			   NVL(T.LRG_UTURN_TFVL,  0) lrgUturnTfvl,-->
<!--			   (-->
<!--				   NVL(T.SMAL_LEFT_TFVL,  0) +-->
<!--				   NVL(T.MDDL_LEFT_TFVL,  0) +-->
<!--				   NVL(T.LRG_LEFT_TFVL,   0) +-->
<!--				   NVL(T.SMAL_GO_TFVL,    0) +-->
<!--				   NVL(T.MDDL_GO_TFVL,    0) +-->
<!--				   NVL(T.LRG_GO_TFVL,     0) +-->
<!--				   NVL(T.SMAL_RGHT_TFVL,  0) +-->
<!--				   NVL(T.MDDL_RGHT_TFVL,  0) +-->
<!--				   NVL(T.LRG_RGHT_TFVL,   0) +-->
<!--				   NVL(T.SMAL_UTURN_TFVL, 0) +-->
<!--				   NVL(T.MDDL_UTURN_TFVL, 0) +-->
<!--				   NVL(T.LRG_UTURN_TFVL,  0)-->
<!--			   ) AS totTfvl-->
<!--		  FROM BASE_DATA B-->
<!--		  LEFT JOIN TB_SC_IXR_CMRA_MNGM A ON B.IXR_ID = A.IXR_ID AND B.DRCT_DVSN_CD = A.DRCT_DVSN_CD-->
<!--		  LEFT JOIN TB_SC_IXR_MNGM X ON A.IXR_ID = X.IXR_ID-->
<!--		  LEFT JOIN TRAFFIC_DATA T ON B.IXR_ID = T.IXR_ID AND B.DRCT_DVSN_CD = T.DRCT_DVSN_CD AND B.CLCT_DT = T.CLCT_DT-->
<!--		 ORDER BY B.CLCT_DT, TO_NUMBER(A.IXR_ID), A.DRCT_DVSN_CD-->
<!--	 </select>-->
	<select id="findIxrDD" parameterType="java.util.HashMap" resultType="egovframework.com.its.web.server.vo.ScIxrTrafficVO" fetchSize="1000">
		SELECT C.CLCT_DT clctDt,
			   A.IXR_ID AS ixrId,
			   B.IXR_NM AS ixrNm,
			   NVL(A.ISTL_LCTN, '-') AS cmraNm,
			   A.DRCT_DVSN_CD_R AS drctDvsnCdR,
			   NVL(C.SMAL_LEFT_TFVL,  0) AS smalLeftTfvl,
			   NVL(C.MDDL_LEFT_TFVL,  0) AS mddlLeftTfvl,
			   NVL(C.LRG_LEFT_TFVL,   0) AS lrgLeftTfvl,
			   NVL(C.SMAL_GO_TFVL,    0) AS smalGoTfvl,
			   NVL(C.MDDL_GO_TFVL,    0) AS mddlGoTfvl,
			   NVL(C.LRG_GO_TFVL,     0) AS lrgGoTfvl,
			   NVL(C.SMAL_RGHT_TFVL,  0) AS smalRghtTfvl,
			   NVL(C.MDDL_RGHT_TFVL,  0) AS mddlRghtTfvl,
			   NVL(C.LRG_RGHT_TFVL,   0) AS lrgRghtTfvl,
			   NVL(C.SMAL_UTURN_TFVL, 0) AS smalUturnTfvl,
			   NVL(C.MDDL_UTURN_TFVL, 0) AS mddlUturnTfvl,
			   NVL(C.LRG_UTURN_TFVL,  0) AS lrgUturnTfvl,
			   (
				   NVL(C.SMAL_LEFT_TFVL,  0) +
				   NVL(C.MDDL_LEFT_TFVL,  0) +
				   NVL(C.LRG_LEFT_TFVL,   0) +
				   NVL(C.SMAL_GO_TFVL,    0) +
				   NVL(C.MDDL_GO_TFVL,    0) +
				   NVL(C.LRG_GO_TFVL,     0) +
				   NVL(C.SMAL_RGHT_TFVL,  0) +
				   NVL(C.MDDL_RGHT_TFVL,  0) +
				   NVL(C.LRG_RGHT_TFVL,   0) +
				   NVL(C.SMAL_UTURN_TFVL, 0) +
				   NVL(C.MDDL_UTURN_TFVL, 0) +
				   NVL(C.LRG_UTURN_TFVL,  0)
			   ) AS totTfvl
		 FROM TB_SC_IXR_CMRA_MNGM A
		 JOIN TB_SC_IXR_MNGM B
		   ON A.IXR_ID = B.IXR_ID
		 LEFT OUTER JOIN TB_SC_ACRD_STAT_DD C
		              ON C.IXR_ID = A.IXR_ID
				     AND C.DRCT_DVSN_CD = A.DRCT_DVSN_CD
		WHERE A.IXR_ID IN (<foreach collection="ixrIds" item="item" separator=",">#{item}</foreach>)
		  AND C.CLCT_DT BETWEEN #{from} AND #{to}
		ORDER BY C.CLCT_DT, TO_NUMBER(A.IXR_ID), A.DRCT_DVSN_CD
    </select>

	<select id="findIxrMN" parameterType="java.util.HashMap" resultType="egovframework.com.its.web.server.vo.ScIxrTrafficVO" fetchSize="1000">
		SELECT C.CLCT_DT || '01000000' clctDt,
			   A.IXR_ID AS ixrId,
			   B.IXR_NM AS ixrNm,
			   NVL(A.ISTL_LCTN, '-') AS cmraNm,
			   DECODE(A.DRCT_DVSN_CD, 1, '북', 2, '동', 3, '남', 4, '서', 5, '북동', 6, '남동', 7, '남서', 8, '북서', '-') AS drctDvsnCd,
			   A.DRCT_DVSN_CD_R AS drctDvsnCdR,
			   NVL(C.SMAL_LEFT_TFVL,  0) AS smalLeftTfvl,
			   NVL(C.MDDL_LEFT_TFVL,  0) AS mddlLeftTfvl,
			   NVL(C.LRG_LEFT_TFVL,   0) AS lrgLeftTfvl,
			   NVL(C.SMAL_GO_TFVL,    0) AS smalGoTfvl,
			   NVL(C.MDDL_GO_TFVL,    0) AS mddlGoTfvl,
			   NVL(C.LRG_GO_TFVL,     0) AS lrgGoTfvl,
			   NVL(C.SMAL_RGHT_TFVL,  0) AS smalRghtTfvl,
			   NVL(C.MDDL_RGHT_TFVL,  0) AS mddlRghtTfvl,
			   NVL(C.LRG_RGHT_TFVL,   0) AS lrgRghtTfvl,
			   NVL(C.SMAL_UTURN_TFVL, 0) AS smalUturnTfvl,
			   NVL(C.MDDL_UTURN_TFVL, 0) AS mddlUturnTfvl,
			   NVL(C.LRG_UTURN_TFVL,  0) AS lrgUturnTfvl,
			   (
					   NVL(C.SMAL_LEFT_TFVL,  0) +
					   NVL(C.MDDL_LEFT_TFVL,  0) +
					   NVL(C.LRG_LEFT_TFVL,   0) +
					   NVL(C.SMAL_GO_TFVL,    0) +
					   NVL(C.MDDL_GO_TFVL,    0) +
					   NVL(C.LRG_GO_TFVL,     0) +
					   NVL(C.SMAL_RGHT_TFVL,  0) +
					   NVL(C.MDDL_RGHT_TFVL,  0) +
					   NVL(C.LRG_RGHT_TFVL,   0) +
					   NVL(C.SMAL_UTURN_TFVL, 0) +
					   NVL(C.MDDL_UTURN_TFVL, 0) +
					   NVL(C.LRG_UTURN_TFVL,  0)
				   ) AS totTfvl
		FROM TB_SC_IXR_CMRA_MNGM A
				 JOIN TB_SC_IXR_MNGM B
					  ON A.IXR_ID = B.IXR_ID
				 JOIN (SELECT IXR_ID, DRCT_DVSN_CD, SUBSTR(CLCT_DT, 1, 6) AS CLCT_DT,
										 SUM(SMAL_LEFT_TFVL) AS SMAL_LEFT_TFVL,
										 SUM(MDDL_LEFT_TFVL) AS MDDL_LEFT_TFVL,
										 SUM(LRG_LEFT_TFVL) AS LRG_LEFT_TFVL,
										 SUM(SMAL_GO_TFVL) AS SMAL_GO_TFVL,
										 SUM(MDDL_GO_TFVL) AS MDDL_GO_TFVL,
										 SUM(LRG_GO_TFVL) AS LRG_GO_TFVL,
										 SUM(SMAL_RGHT_TFVL) AS SMAL_RGHT_TFVL,
										 SUM(MDDL_RGHT_TFVL) AS MDDL_RGHT_TFVL,
										 SUM(LRG_RGHT_TFVL) AS LRG_RGHT_TFVL,
										 SUM(SMAL_UTURN_TFVL) AS SMAL_UTURN_TFVL,
										 SUM(MDDL_UTURN_TFVL) AS MDDL_UTURN_TFVL,
										 SUM(LRG_UTURN_TFVL) AS LRG_UTURN_TFVL
								  FROM TB_SC_ACRD_STAT_DD
								  WHERE IXR_ID IN (select ixr_id from TB_SC_IXR_CMRA_MNGM)
									AND CLCT_DT BETWEEN #{from} AND #{to}
								  GROUP BY IXR_ID, DRCT_DVSN_CD, SUBSTR(CLCT_DT, 1, 6)
				 ) C
				  ON C.IXR_ID = A.IXR_ID
				 AND C.DRCT_DVSN_CD = A.DRCT_DVSN_CD
		WHERE A.IXR_ID IN (<foreach collection="ixrIds" item="item" separator=",">#{item}</foreach>)
		ORDER BY C.CLCT_DT, TO_NUMBER(A.IXR_ID), A.DRCT_DVSN_CD
	</select>
<!--	<select id="findIxrMN" parameterType="java.util.HashMap" resultType="egovframework.com.its.web.server.vo.ScIxrTrafficVO" fetchSize="1000">-->
<!--		WITH DATE_RANGE AS (-->
<!--			SELECT TO_CHAR(ADD_MONTHS(TO_DATE(#{from}, 'YYYYMMDDHH24MISS'), LEVEL - 1), 'YYYYMM') AS DT-->
<!--			  FROM DUAL-->
<!--		   CONNECT BY LEVEL <![CDATA[<=]]> MONTHS_BETWEEN(TO_DATE(#{to}, 'YYYYMMDDHH24MISS'), TO_DATE(#{from}, 'YYYYMMDDHH24MISS')) + 1-->
<!--		),-->
<!--		IXR_COMBINATIONS AS (-->
<!--			SELECT DISTINCT A.IXR_ID, A.DRCT_DVSN_CD-->
<!--			  FROM TB_SC_IXR_CMRA_MNGM A-->
<!--		),-->
<!--		BASE_DATA AS (-->
<!--			SELECT D.DT, I.IXR_ID, I.DRCT_DVSN_CD-->
<!--			  FROM DATE_RANGE D-->
<!--		     CROSS JOIN IXR_COMBINATIONS I-->
<!--		),-->
<!--		TRAFFIC_DATA AS (-->
<!--			SELECT IXR_ID, DRCT_DVSN_CD, SUBSTR(CLCT_DT, 1, 6) AS DT,-->
<!--				SUM(SMAL_LEFT_TFVL) AS SMAL_LEFT_TFVL,-->
<!--				SUM(MDDL_LEFT_TFVL) AS MDDL_LEFT_TFVL,-->
<!--				SUM(LRG_LEFT_TFVL) AS LRG_LEFT_TFVL,-->
<!--				SUM(SMAL_GO_TFVL) AS SMAL_GO_TFVL,-->
<!--				SUM(MDDL_GO_TFVL) AS MDDL_GO_TFVL,-->
<!--				SUM(LRG_GO_TFVL) AS LRG_GO_TFVL,-->
<!--				SUM(SMAL_RGHT_TFVL) AS SMAL_RGHT_TFVL,-->
<!--				SUM(MDDL_RGHT_TFVL) AS MDDL_RGHT_TFVL,-->
<!--				SUM(LRG_RGHT_TFVL) AS LRG_RGHT_TFVL,-->
<!--				SUM(SMAL_UTURN_TFVL) AS SMAL_UTURN_TFVL,-->
<!--				SUM(MDDL_UTURN_TFVL) AS MDDL_UTURN_TFVL,-->
<!--				SUM(LRG_UTURN_TFVL) AS LRG_UTURN_TFVL-->
<!--			 FROM TB_SC_ACRD_STAT_DD-->
<!--			WHERE IXR_ID IN (<foreach collection="ixrIds" item="item" separator=",">#{item}</foreach>)-->
<!--			  AND CLCT_DT BETWEEN #{from} AND #{to}-->
<!--		    GROUP BY IXR_ID, DRCT_DVSN_CD, SUBSTR(CLCT_DT, 1, 6)-->
<!--		)-->
<!--		SELECT B.DT || '01000000' AS clctDt,-->
<!--			A.IXR_ID AS ixrId,-->
<!--			X.IXR_NM AS ixrNm,-->
<!--			NVL(A.ISTL_LCTN, '-') AS cmraNm,-->
<!--			A.DRCT_DVSN_CD_R AS drctDvsnCdR,-->
<!--			NVL(T.SMAL_LEFT_TFVL,  0) smalLeftTfvl,-->
<!--			NVL(T.MDDL_LEFT_TFVL,  0) mddlLeftTfvl,-->
<!--			NVL(T.LRG_LEFT_TFVL,   0) lrgLeftTfvl,-->
<!--			NVL(T.SMAL_GO_TFVL,    0) smalGoTfvl,-->
<!--			NVL(T.MDDL_GO_TFVL,    0) mddlGoTfvl,-->
<!--			NVL(T.LRG_GO_TFVL,     0) lrgGoTfvl,-->
<!--			NVL(T.SMAL_RGHT_TFVL,  0) smalRghtTfvl,-->
<!--			NVL(T.MDDL_RGHT_TFVL,  0) mddlRghtTfvl,-->
<!--			NVL(T.LRG_RGHT_TFVL,   0) lrgRghtTfvl,-->
<!--			NVL(T.SMAL_UTURN_TFVL, 0) smalUturnTfvl,-->
<!--			NVL(T.MDDL_UTURN_TFVL, 0) mddlUturnTfvl,-->
<!--			NVL(T.LRG_UTURN_TFVL,  0) lrgUturnTfvl,-->
<!--			(-->
<!--				NVL(T.SMAL_LEFT_TFVL,  0) +-->
<!--				NVL(T.MDDL_LEFT_TFVL,  0) +-->
<!--				NVL(T.LRG_LEFT_TFVL,   0) +-->
<!--				NVL(T.SMAL_GO_TFVL,    0) +-->
<!--				NVL(T.MDDL_GO_TFVL,    0) +-->
<!--				NVL(T.LRG_GO_TFVL,     0) +-->
<!--				NVL(T.SMAL_RGHT_TFVL,  0) +-->
<!--				NVL(T.MDDL_RGHT_TFVL,  0) +-->
<!--				NVL(T.LRG_RGHT_TFVL,   0) +-->
<!--				NVL(T.SMAL_UTURN_TFVL, 0) +-->
<!--				NVL(T.MDDL_UTURN_TFVL, 0) +-->
<!--				NVL(T.LRG_UTURN_TFVL,  0)-->
<!--			) AS totTfvl-->
<!--		  FROM BASE_DATA B-->
<!--		  LEFT JOIN TB_SC_IXR_CMRA_MNGM A ON B.IXR_ID = A.IXR_ID AND B.DRCT_DVSN_CD = A.DRCT_DVSN_CD-->
<!--		  LEFT JOIN TB_SC_IXR_MNGM X ON A.IXR_ID = X.IXR_ID-->
<!--		  LEFT JOIN TRAFFIC_DATA T ON B.IXR_ID = T.IXR_ID AND B.DRCT_DVSN_CD = T.DRCT_DVSN_CD AND B.DT = T.DT-->
<!--		 ORDER BY B.DT, TO_NUMBER(A.IXR_ID), A.DRCT_DVSN_CD-->
<!--	</select>-->


	<select id="getIxrList" resultType="egovframework.com.its.web.server.vo.ScIxrVO" fetchSize="1000">
		SELECT
			A.IXR_ID,
			A.IXR_NM,
			A.IXR_X_CRDN,
			A.IXR_Y_CRDN,
			COUNT(B.IXR_ID) CMRA_COUNT
		FROM (SELECT * FROM TB_SC_IXR_MNGM WHERE USE_EN = 1) A
		JOIN TB_SC_IXR_CMRA_MNGM B
		  ON A.IXR_ID = B.IXR_ID
	   GROUP BY A.IXR_ID, A.IXR_NM, A.IXR_X_CRDN, A.IXR_Y_CRDN
	   ORDER BY CAST(IXR_ID AS decimal) ASC
	</select>

	<select id="getRoadCount" parameterType="java.lang.String" resultType="java.lang.Integer">
		SELECT COUNT(*)
		 FROM (SELECT * FROM TB_ATRD WHERE DEL_YN = 'N' AND ATRD_ID IN <foreach collection="atrdIds" open="(" separator="," close=")" item="item">#{item}</foreach>) A
		 JOIN TB_ATRD_RLTN_ROAD B
		   ON A.ATRD_ID = B.ATRD_ID
	</select>

	<select id="getCameraCount" parameterType="java.lang.String" resultType="java.lang.Integer">
		SELECT COUNT(*)
		 FROM (SELECT * FROM TB_SC_IXR_MNGM WHERE USE_EN = 1 AND IXR_ID IN <foreach collection="ixrIds" open="(" separator="," close=")" item="item">#{item}</foreach>) A
		 JOIN TB_SC_IXR_CMRA_MNGM B
		   ON A.IXR_ID = B.IXR_ID
	</select>

</mapper>