<?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.siginfo.dao.AdminDao">

	<select id="login" parameterType="java.util.HashMap" resultType="java.util.HashMap">
		SELECT T1.OPER_SEQ
			 , T1.TYPE_TOP_CD
			 , T2.TYPE_TOP_NM
			 , REPLACE(T1.TYPE_MID_CD, '-', '') AS TYPE_MID_CD
			 , REPLACE(T2.TYPE_MID_NM, '-', '') AS TYPE_MID_NM
			 , REPLACE(T1.TYPE_BOT_CD, '-', '') AS TYPE_BOT_CD
			 , REPLACE(T2.TYPE_BOT_NM, '-', '') AS TYPE_BOT_NM
			 , CASE WHEN T1.TYPE_BOT_CD IS NOT NULL THEN (SELECT S1.INCIDENT_REGION_CD
			                                                FROM TB_CENTER_INFO@UTISINCI S1 
			                                               WHERE S1.TYPE_BOT_CD = T1.TYPE_BOT_CD)
			 		WHEN T1.TYPE_TOP_CD = 'T03' THEN CASE WHEN T1.TYPE_MID_CD IS NOT NULL THEN (SELECT S1.KEYWORD2 
			 		                                                                              FROM TB_CENTER_INFO@UTISINCI S1 
			 		                                                                             WHERE S1.TYPE_MID_CD = T1.TYPE_MID_CD GROUP BY S1.KEYWORD2) END
					WHEN T1.TYPE_TOP_CD = 'T04' THEN CASE WHEN T1.TYPE_MID_CD IS NOT NULL THEN (SELECT S1.INCIDENT_REGION_CD 
					                                                                              FROM TB_CENTER_INFO@UTISINCI S1 
					                                                                             WHERE S1.TYPE_MID_CD = T1.TYPE_MID_CD GROUP BY S1.INCIDENT_REGION_CD) END
			        ELSE ''
			    END OPER_REGION_CD
			 , CASE WHEN T1.TYPE_BOT_CD IS NOT NULL THEN (SELECT S1.INCIDENT_REGION_NM 
			                                                FROM TB_CENTER_INFO@UTISINCI S1 
			                                               WHERE S1.TYPE_BOT_CD = T1.TYPE_BOT_CD)
			        WHEN T1.TYPE_TOP_CD = 'T03' THEN CASE WHEN T1.TYPE_MID_CD IS NOT NULL THEN (SELECT S1.KEYWORD3 
			                                                                                      FROM TB_CENTER_INFO@UTISINCI S1 
			                                                                                     WHERE S1.TYPE_MID_CD = T1.TYPE_MID_CD GROUP BY S1.KEYWORD3) END
			       	WHEN T1.TYPE_TOP_CD = 'T04' THEN CASE WHEN T1.TYPE_MID_CD IS NOT NULL THEN (SELECT S1.INCIDENT_REGION_NM 
			       	                                                                              FROM TB_CENTER_INFO@UTISINCI S1 
			       	                                                                             WHERE S1.TYPE_MID_CD = T1.TYPE_MID_CD GROUP BY S1.INCIDENT_REGION_NM) END
			        ELSE ''
			  	END OPER_REGION_NM
			 , T1.OPER_GRD 
			 , T1.OPER_NM 
		     , T1.OPER_GR 
		     , T1.OPER_IP 
		     , T1.OPER_IP2 
		     , T1.OPER_IP3 
		     , T1.OPER_EMAIL 
		     , T1.OPER_PHONE 
		     , T1.OPER_PASSWD 
		     , CASE WHEN SUBSTR(T1.OPER_IP, 1, INSTR(T1.OPER_IP, '.', 1, 3) - 1) = SUBSTR(null, 1, INSTR(null, '.', 1, 3) - 1) THEN 'TRUE' 
			        WHEN SUBSTR(T1.OPER_IP2, 1, INSTR(T1.OPER_IP2, '.', 1, 3) - 1) = SUBSTR(null, 1, INSTR(null, '.',1, 3) - 1) THEN 'TRUE'
			        WHEN SUBSTR(T1.OPER_IP3, 1, INSTR(T1.OPER_IP3, '.', 1, 3) - 1) = SUBSTR(null, 1, INSTR(null, '.',1, 3) - 1) THEN 'TRUE'
			        ELSE 'FALSE'
			    END IP_CHECK
			 , OPER_GUBUN 
			 , OPER_ORG           
		FROM TB_UTIS_MEMBER@UTISINCI T1
		   , TB_CENTER_INFO@UTISINCI T2
		WHERE T1.TYPE_TOP_CD = T2.TYPE_TOP_CD(+)
		  AND T1.TYPE_MID_CD = T2.TYPE_MID_CD(+)
		  AND T1.TYPE_BOT_CD = T2.TYPE_BOT_CD(+)
		  AND T1.OPER_EMAIL = #{OPER_EMAIL}
		  AND T1.OPER_PASSWD = #{OPER_PASSWD}
	</select>
	
    <!-- 돌발정보조회 -->
	<select id="getIMS" parameterType="java.util.HashMap" resultType="java.util.HashMap">
		 SELECT 
		        T1.INCIDENTID AS INCIDENT_ID
		      , T2.INCIDENT_INSERT_CD
		      , T2.INCIDENT_TYPE_CD
		      , T1.COORDX AS LOCATION_DATA_X
		      , T1.COORDY AS LOCATION_DATA_Y
		      , T2.LOCATION_TYPE_CD
		      , T2.INCIDENT_GRADE_CD
		      , (SELECT ROAD_NM FROM UTISINCI.VIEW_NODE_LINK WHERE LINK_ID = T2.LINK_ID) AS ROAD_NM 
		      , NVL(T2.INCIDENT_TITLE, T1.INCIDENTTITLE) AS INCIDENT_TITLE
		      , T2.INCIDENT_REPORT
		      , T2.TYPE_TOP_CD
		      , T2.TYPE_MID_CD
		      , T2.TYPE_BOT_CD
		      , T2.INCIDENT_REGION_CD
		      , TO_CHAR(T1.STARTDATE,'YYYY"년 "MM"월 "DD"일 " HH24"시 "MI"분"') AS START_DATE
		      , TO_CHAR(T1.ENDDATE,'YYYY"년 "MM"월 "DD"일 " HH24"시 "MI"분"') AS END_DATE
		      , IMS_IMAGES_PATH
		      , T2.LOCATION_DATA
		 FROM INCIDENT_CENTER T1
		    , UTISINCI.TB_IMS_DATA T2
		WHERE T1.INCIDENTID = T2.INCIDENT_ID
		  AND T1.COORDX IS NOT NULL
		  AND T1.COORDY IS NOT NULL
		  AND T1.COORDX BETWEEN #{MIN_X} AND #{MAX_X}
		  AND T1.COORDY BETWEEN #{MIN_Y} AND #{MAX_Y} 
		  AND T1.ENDDATE >= SYSDATE
		  AND T1.STARTDATE <![CDATA[ <= ]]> SYSDATE
	    ORDER BY STARTDATE DESC 
	</select>
</mapper>