<?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="kr.co.jinwoosi.clfd.framework.security.mapper.ScurRscRoleMapper">

	<select id="selectList" parameterType="scurRscRole" resultType="scurRscRole">
		SELECT *
		FROM (
			SELECT ROWNUM RNUM , LIST.*
			FROM (
				SELECT CSR.RSC_ID, CSR.RSC_NM, CSR.RSC_TP, CSR.RSC_PATN, CSR.RSC_DESC, CSRR.ROLE_AUTH, CSRR.REG_DT
				FROM JCMS_SCUR_RSC CSR
					LEFT JOIN
				    (SELECT * FROM JCMS_SCUR_RSC_ROLE WHERE 1=1 <if test="!empty(roleAuth)" > AND ROLE_AUTH = #{roleAuth} </if>) CSRR
					ON CSR.RSC_ID = CSRR.RSC_ID
				<if test="!empty(sort) and !empty(sortOrd)">
	    		ORDER BY ${sort} ${sortOrd}
			 	</if>
	    	) LIST
		)
	    <if test="pagingYn == true" >
	    	<![CDATA[
				WHERE RNUM > #{start} AND RNUM <= #{start} + #{length}
			]]>
		</if>
	</select>
	
	<select id="count" parameterType="scurRscRole" resultType="java.lang.Integer">
		select
			COUNT(*)
		from
			JCMS_SCUR_RSC_ROLE
		where
			1=1
		<if test="!empty(rscId)"> and RSC_ID = #{rscId} </if>
		<if test="!empty(roleAuth)"> and ROLE_AUTH = #{roleAuth} </if>
	</select>
	
	<insert id="insert" parameterType="scurRscRole">
		insert into JCMS_SCUR_RSC_ROLE(
			RSC_ID,
			ROLE_AUTH,
			REG_ID,
			REG_DT
		) values (
			#{rscId},
			#{roleAuth},
			#{regId},
			SYSDATE
		)
	</insert>
	
	<delete id="delete" parameterType="scurRscRole">
		delete from JCMS_SCUR_RSC_ROLE
		where 
			RSC_ID = #{rscId}
			and ROLE_AUTH = #{roleAuth} 
	</delete>
</mapper>