<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="User">

	<statement id="selectList" resultClass="java.util.HashMap">
		SELECT *
		FROM (
		 	<!-- SELECT ROW_NUMBER() OVER (ORDER BY T02.USERID) ROWNUM, -->
		 	SELECT ROWNUM AS ROWNO 
		 	    ,RM02.USERID                 ,RM02.USERNAME           
				,RM02.ROLEIDNFINAME  		 ,'' AS ROLENAME 
                ,RM02.PAFIARINFOBRNCD        ,RM02.CPHNNO      
                ,RM02.OFCTELNO               ,RM02.EMAD       
                ,RM02.JOBCLCD                ,RM02.JOBTLNAME 
                ,RM02.LASTAMNDYMS            ,RM02.DVSNNAME   
                ,RM02.INTNLOUTSRCDSTICNAME   ,RM02.EAIGROUPCODSTCD
                ,RM02.SPOTPRXYNAME           ,RM02.SPOTPRXYEMPID 
                ,RM02.TEAMNAME
			  FROM 
                $schemaId$.TSEAIRM02 RM02				
			<dynamic prepend="WHERE">
				<isNotEmpty prepend="AND" property="searchUserId">
					UPPER(USERID) LIKE  '%'||UPPER(#searchUserId#)||'%'
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchUserName">
					UPPER(USERNAME) LIKE  '%'||UPPER(#searchUserName#)||'%'
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchRoleName">
					USERID IN (SELECT DISTINCT USERID FROM $schemaId$.TSEAIRM04 WHERE ROLEID LIKE '%'||#searchRoleName#||'%' )
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchDepart">
					UPPER(DVSNNAME) LIKE  '%'||UPPER(#searchDepart#)||'%'
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchTeamName">
					UPPER(TEAMNAME) LIKE  '%'||UPPER(#searchTeamName#)||'%'
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchPosition">
					UPPER(JOBTLNAME) LIKE  '%'||UPPER(#searchPosition#)||'%'
				</isNotEmpty>
			</dynamic>				
			ORDER BY RM02.USERID ASC
			) ORGTABLE
		WHERE ROWNO BETWEEN #startNum# AND #endNum#
	</statement>	

	<statement id="selectListCount" resultClass="java.lang.Integer">
	  SELECT  
			COUNT(*) 
        FROM 
        	$schemaId$.TSEAIRM02 RM02
			<dynamic prepend="WHERE">						 
				<isNotEmpty prepend="AND" property="searchUserId">
					UPPER(USERID) LIKE  '%'||UPPER(#searchUserId#)||'%'
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchUserName">
					UPPER(USERNAME) LIKE  '%'||UPPER(#searchUserName#)||'%'
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchRoleName">
					USERID IN (SELECT DISTINCT USERID FROM $schemaId$.TSEAIRM04 WHERE ROLEID LIKE '%'||#searchRoleName#||'%' )
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchDepart">
					UPPER(DVSNNAME) LIKE  '%'||UPPER(#searchDepart#)||'%'
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchTeamName">
					UPPER(TEAMNAME) LIKE  '%'||UPPER(#searchTeamName#)||'%'
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchPosition">
					UPPER(JOBTLNAME) LIKE  '%'||UPPER(#searchPosition#)||'%'
				</isNotEmpty>
			</dynamic>
	</statement>	
	
	<statement id="selectDetail" resultClass="java.util.HashMap">
	 	SELECT 
			 T02.USERID					 AS "USERID"
			,T02.USERNAME				 AS "USERNAME"
			,T02.ROLEIDNFINAME			 AS "ROLEIDNFINAME"
			,T02.PAFIARINFOBRNCD		 AS "PAFIARINFOBRNCD"
			,T02.CPHNNO					 AS "CPHNNO"
			,T02.OFCTELNO	             AS "OFCTELNO"
			,T02.EMAD		             AS "EMAD"
			,T02.JOBCLCD	             AS "JOBCLCD"
			,T02.JOBTLNAME	           	 AS "JOBTLNAME"
			,T02.LASTAMNDYMS	         AS "LASTAMNDYMS"
			,T02.DVSNNAME	             AS "DVSNNAME"
			,T02.INTNLOUTSRCDSTICNAME	 AS "INTNLOUTSRCDSTICNAME"
			,T02.EAIGROUPCODSTCD	 	 AS "EAIGROUPCODSTCD"
			,T02.SPOTPRXYNAME	         AS "SPOTPRXYNAME"
			,T02.SPOTPRXYEMPID	 		 AS "SPOTPRXYEMPID"
			,T02.TEAMNAME				 AS "TEAMNAME"
			,T02.SECONDMENTBRNCD		 AS "SECONDMENTBRNCD"
			,T02.SECONDMENTSTDT  		 AS "SECONDMENTSTDT"
			,T02.SECONDMENTENDT			 AS "SECONDMENTENDT"	
		FROM $schemaId$.TSEAIRM02 T02 
		WHERE USERID = #userId#
	</statement>  
	
	<statement id="selectRole" resultClass="java.util.HashMap">
	 	SELECT ROLEID AS "ROLEID"
				 , ROLENAME AS "ROLENAME"				 
		      FROM $schemaId$.TSEAIRM05
		   WHERE UseYn ='Y'	
	</statement>  
		
	<insert id="insert" parameterClass="java.util.HashMap">
		INSERT INTO $schemaId$.TSEAIRM02(
			 USERID
			,USERNAME
			,ROLEIDNFINAME
			,PAFIARINFOBRNCD
			,CPHNNO
			,OFCTELNO
			,EMAD
			,JOBCLCD
			,JOBTLNAME
			,LASTAMNDYMS
			,DVSNNAME
			,TEAMNAME
			,INTNLOUTSRCDSTICNAME
			,EAIGROUPCODSTCD
			,SPOTPRXYNAME
			,SPOTPRXYEMPID
			,PASSWORD			    
		)
    	VALUES ( 
      		 #userId#					      
			,#userName#							
			,#roleidnfiname#				  
			,#pafiarinfobrncd#	
			,#cphnno#								
			,#ofctelno#	            
			,#emad#		              
			,#jobclcd#	              
			,#jobtlname#	            
			,TO_CHAR(LOCALTIMESTAMP,'YYYYMMDDHH24MISS')          
			,#dvsnname#	
			,#teamName#	             
			,#intnloutsrcdsticname#	
			,#eaigroupcodstcd#
			,#spotprxyname#	        
			,#spotprxyempid#
			,#password#	     
    	 )
	</insert>	
		
	<statement id="update" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
	 	UPDATE $schemaId$.TSEAIRM02 
	 	    SET USERNAME				  = #userName#				
			,ROLEIDNFINAME            = #roleidnfiname#		
			,PAFIARINFOBRNCD		  = #pafiarinfobrncd#	                          
			,CPHNNO                   = #cphnno#								                             
			,OFCTELNO                 = #ofctelno#	                                         
			,EMAD                     = #emad#		                                           
			,JOBCLCD                  = #jobclcd#	                                         
			,JOBTLNAME                = #jobtlname#	                                       
			,LASTAMNDYMS              = TO_CHAR(LOCALTIMESTAMP,'YYYYMMDDHH24MISS')          
			,DVSNNAME                 = #dvsnname#	                                         
			,TEAMNAME                 = #teamName#	                                         
			,INTNLOUTSRCDSTICNAME     = #intnloutsrcdsticname#	                             
			,EAIGROUPCODSTCD          = #eaigroupcodstcd#	                                 
			,SPOTPRXYNAME             = #spotprxyname#	                                     
			,SPOTPRXYEMPID            = #spotprxyempid#	          
	   WHERE USERID        = #userId#
	</statement>
	
	<statement id="updatePassword" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
	 	UPDATE $schemaId$.TSEAIRM02 
	 	   SET PASSWORD      = #password#
	 	     , LOGINFAILCOUNT = 0
	   WHERE USERID        = #userId#
	</statement>
	
	<statement id="selectUserRoleList" resultClass="java.util.HashMap">
			SELECT R05.ROLEID ROLEID
				 , R05.ROLENAME ROLENAME
				 , R05.ROLEDESC ROLEDESC
				 , decode(R04.ROLEID,null,'false','true') CHK
		      FROM $schemaId$.TSEAIRM05 R05
		      LEFT OUTER JOIN $schemaId$.TSEAIRM04 R04 ON 
		       ( R05.ROLEID = R04.ROLEID	AND R04.USERID = #userId# )
		   WHERE R05.UseYn ='Y'		   
	</statement>	
	<statement id="insertUserRole" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
	 	INSERT INTO $schemaId$.TSEAIRM04(USERID, ROLEID) 
		VALUES	(#userId#, #roleId#)	
	</statement>
			
	<statement id="selectRoleCnt" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
	 	SELECT COUNT(USERID) FROM $schemaId$.TSEAIRM04 
	 	WHERE 	USERID = #USERID# 
	</statement>	
	
	<statement id="deleteUserRole" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
	 	DELETE 	FROM $schemaId$.TSEAIRM04 
	 	WHERE 	USERID = #userId# 
	</statement>	
	
	<statement id="selectUserCnt" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
	 	SELECT COUNT(USERID) FROM $schemaId$.TSEAIRM02 
	 	WHERE 	USERID = #USERID# 
	</statement>
		
	<insert id="insertHrms" parameterClass="java.util.HashMap">
		INSERT INTO $schemaId$.TSEAIRM02(
			 USERID					 
			,USERNAME							
			,ROLEIDNFINAME				 
			,PAFIARINFOBRNCD			 
			,CPHNNO								
			,OFCTELNO	           
			,EMAD		             
			,JOBCLCD	             
			,JOBTLNAME	           
			,LASTAMNDYMS	         
			,DVSNNAME	           
			,INTNLOUTSRCDSTICNAME	
			,EAIGROUPCODSTCD	     
			,SPOTPRXYNAME	       
			,SPOTPRXYEMPID
			,TEAMNAME	
			,SECONDMENTBRNCD
			,SECONDMENTSTDT  
			,SECONDMENTENDT	  
		    )
    	VALUES ( 
             #USERID#					      
			,#USERNAME#							
			,#ROLEIDNFINAME#				  
			,#PAFIARINFOBRNCD#			  
			,#CPHNNO#								
			,#OFCTELNO#	            
			,#EMAD#		              
			,#JOBCLCD#	              
			,#JOBTLNAME#	            
			,to_char(sysdate,'yyyymmddhh24miss')         
			,#DVSNNAME#	            
			,#INTNLOUTSRCDSTICNAME#	
			,#EAIGROUPCODSTCD#	      
			,#SPOTPRXYNAME#	        
			,#SPOTPRXYEMPID#	
			,#TEAMNAME#        
			,#SECONDMENTBRNCD#
			,#SECONDMENTSTDT# 
			,#SECONDMENTENDT#	
           )
	</insert>	
		
	<statement id="updateHrms" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
	 	UPDATE $schemaId$.TSEAIRM02 
	 	   SET USERNAME				= #USERNAME#				
			,PAFIARINFOBRNCD 		= #PAFIARINFOBRNCD#			                              
			,CPHNNO					= #CPHNNO#								                              
			,OFCTELNO	         	= #OFCTELNO#	                                          
			,EMAD		        	= #EMAD#		                                            
			,JOBCLCD	         	= #JOBCLCD#	                                          
			,JOBTLNAME	         	= #JOBTLNAME#	                                        
			,LASTAMNDYMS			= to_char(sysdate,'yyyymmddhh24miss')           
	 		,DVSNNAME	            = #DVSNNAME#	                                          
			,INTNLOUTSRCDSTICNAME	= #INTNLOUTSRCDSTICNAME#	                              
			,EAIGROUPCODSTCD	    = #EAIGROUPCODSTCD#	                                  
			,SPOTPRXYNAME	        = #SPOTPRXYNAME#	                                      
			,SPOTPRXYEMPID	  		= #SPOTPRXYEMPID# 
			,TEAMNAME				= #TEAMNAME# 
			,SECONDMENTBRNCD		= #SECONDMENTBRNCD#
			,SECONDMENTSTDT 		= #SECONDMENTSTDT#
			,SECONDMENTENDT			= #SECONDMENTENDT#                
	   WHERE USERID        = #USERID#
	</statement>
	
	<statement id="mergeRM02" parameterClass="java.util.HashMap">
	 MERGE INTO $schemaId$.TSEAIRM02 RM02  USING(
	     select #USERID# AS USERID , #USERNAME# AS USERNAME,#ROLEIDNFINAME# AS ROLEIDNFINAME, #PAFIARINFOBRNCD# AS PAFIARINFOBRNCD ,#CPHNNO# AS CPHNNO  
	          ,#OFCTELNO# AS OFCTELNO	,#EMAD# AS EMAD ,#JOBCLCD# AS JOBCLCD ,#JOBTLNAME# AS JOBTLNAME	,TO_CHAR(LOCALTIMESTAMP,'YYYYMMDDHH24MISS')	AS LASTAMNDYMS
	          ,#DVSNNAME# AS DVSNNAME ,#INTNLOUTSRCDSTICNAME# AS INTNLOUTSRCDSTICNAME	,#EAIGROUPCODSTCD# AS EAIGROUPCODSTCD ,#SPOTPRXYNAME# AS SPOTPRXYNAME,#SPOTPRXYEMPID# AS SPOTPRXYEMPID
	     from dual
	     ) INSROW
	 ON RM02.USERID = INSROW.USERID 
		WHEN NOT MATCHED THEN
			INSERT VALUES (INSROW.USERID ,INSROW.USERNAME ,INSROW.ROLEIDNFINAME, INSROW.PAFIARINFOBRNCD	,INSROW.CPHNNO ,INSROW.OFCTELNO	,INSROW.EMAD	
					,INSROW.JOBCLCD	,INSROW.JOBTLNAME, INSROW.LASTAMNDYMS ,INSROW.DVSNNAME ,INSROW.INTNLOUTSRCDSTICNAME ,INSROW.EAIGROUPCODSTCD
					,INSROW.SPOTPRXYNAME ,INSROW.SPOTPRXYEMPID	) 	
			 WHEN MATCHED THEN
		 	 UPDATE SET 		 							
				USERNAME			  =	 INSROW.USERNAME    
				,PAFIARINFOBRNCD	  =  INSROW.PAFIARINFOBRNCD				
				,CPHNNO				  =  INSROW.CPHNNO								
				,OFCTELNO			  =  INSROW.OFCTELNO							
				,EMAD				  =  INSROW.EMAD									
				,JOBCLCD			  =  INSROW.JOBCLCD								
				,JOBTLNAME			  =  INSROW.JOBTLNAME	
       			,LASTAMNDYMS 		  =  INSROW.LASTAMNDYMS
				,DVSNNAME			  =  INSROW.DVSNNAME							
				,INTNLOUTSRCDSTICNAME =  INSROW.INTNLOUTSRCDSTICNAME	
				,EAIGROUPCODSTCD	  =  INSROW.EAIGROUPCODSTCD				
				,SPOTPRXYNAME		  =  INSROW.SPOTPRXYNAME					
				,SPOTPRXYEMPID		  =  INSROW.SPOTPRXYEMPID
	</statement>
	
	<statement id="selectUserInfo" resultClass="java.util.HashMap">
		SELECT  
		  USERID    AS "USERID"           
		 ,DVSNNAME  AS "DVSNNAME"
		 ,TEAMNAME  AS "TEAMNAME"     
		 ,OFCTELNO  AS "OFCTELNO"            
	   FROM $schemaId$.TSEAIRM02
	   WHERE USERID IN ($USERIDS$)
	</statement>
	
	<statement id="selectAdminRoleUser" resultClass="java.util.HashMap">
	 	SELECT
	 		RM02.USERID AS "USERID"
	 	   ,RM04.ROLEID AS "ROLEID"
	    FROM $schemaId$.TSEAIRM02 RM02 ,$schemaId$.TSEAIRM04 RM04
	   WHERE RM02.USERID = RM04.USERID
	    AND RM04.ROLEID = #roleId#
	</statement>  
	
	<statement id="selectBossList" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
  		SELECT USERID AS "CODE", USERNAME AS "NAME"
			FROM $schemaId$.TSEAIRM02 
		WHERE JOBTLNAME = '팀장' 
		<isEmpty prepend="AND" property="secondMentBrnCd">
			DVSNNAME = (SELECT DVSNNAME FROM $schemaId$.TSEAIRM02 WHERE USERID= #userId# ) 
		</isEmpty>
		<isNotEmpty prepend="AND" property="secondMentBrnCd">
			PAFIARINFOBRNCD = #secondMentBrnCd#
		</isNotEmpty>
 	</statement>
 	
	<statement id="selectAgentList" resultClass="java.util.HashMap">
  		SELECT SPOTPRXYEMPID AS "BOSSNUM", SPOTPRXYNAME AS "BOSSNAME"
		FROM $schemaId$.TSEAIRM02 
		WHERE USERID= #userId#
 	</statement>
 	
 	<statement id="updateChangeRole" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
		UPDATE $schemaId$.TSEAIRM04
			SET ROLEID = 'dept_developer'
		WHERE USERID = #userId# AND ROLEID IN ('newbie','newboss')
 	</statement>
 	
 	<statement id="selectUserRoleCnt" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
	 	SELECT COUNT(USERID) FROM $schemaId$.TSEAIRM04 
	 	WHERE 	USERID = #userId# AND ROLEID = #chkRole#
	</statement>
	
	<statement id="updateUserRole" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
		UPDATE $schemaId$.TSEAIRM04
			SET ROLEID = #roleId#
	    WHERE USERID = #userId# AND ROLEID = #chkRole#
	</statement>
	
	<statement id="selectUsersByIdList" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
		SELECT * FROM $schemaId$.TSEAIRM02 RM02
		<dynamic prepend="WHERE RM02.USERID IN" open="(" close=")">
			<iterate property="userIdList" conjunction=", ">
                     #userIdList[]#
			</iterate>
		</dynamic>
	</statement>
	
	<statement id="selectUserServiceTypeList" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
		SELECT 
			USERID,
			USESERVICETYPE
		FROM 
			$schemaId$.TSEAIRM07
		WHERE
			USERID = #userId#
	</statement>

	<statement id="insertUserServiceType" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
		INSERT INTO
			$schemaId$.TSEAIRM07
		(USERID,
		USESERVICETYPE)
		VALUES
		(#userId#,
		#useServiceName#)
	</statement>
	
	<statement id="deleteUserServiceType" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
		DELETE
			$schemaId$.TSEAIRM07
		WHERE
			USERID = #userId#
		AND	USESERVICETYPE = #deleteServiceName#
	</statement>
	
	<statement id="insertUserServiceTypeAll" parameterClass="java.util.HashMap">
		MERGE INTO 
			$schemaId$.TSEAIRM07 RM07
		USING
			( $caseQuery$ ) DUAL
		ON
			(RM07.USERID = #userId# AND USESERVICETYPE IN DUAL.SERVICETYPE)
		WHEN NOT MATCHED THEN
			INSERT (USERID, USESERVICETYPE) VALUES (#userId#, DUAL.SERVICETYPE)
	</statement>
	
</sqlMap>
