<?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.conts.lang.mapper.LangMapper">

	<select id="select" parameterType="langSearch" resultType="lang">
		select	
			LANG_ID, LANG_TP, DISP_NM, BASIC_YN, REG_DT, REG_ID, UPD_DT, UPD_ID
		from JCMS_LANG
		where DEL_DT IS NULL
		<if test="langId != null" > and LANG_ID = #{langId} </if>
	</select>
	
	<select id="selectList" parameterType="langSearch" resultType="lang">
		SELECT *
		FROM (
			SELECT ROWNUM RNUM , LIST.*
			FROM (
			    SELECT LANG_ID, LANG_TP, DISP_NM, BASIC_YN, REG_DT, REG_ID, UPD_DT, UPD_ID
				FROM JCMS_LANG
				WHERE DEL_DT IS NULL
					<if test="!empty(langTp)" > AND LANG_TP = #{langTp} </if>
					<if test="!empty(dispNmLike)" > AND DISP_NM LIKE '%'||#{dispNmLike}||'%' </if>
				<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="langSearch" resultType="java.lang.Integer">
		select 
			COUNT(LANG_ID)
		from
			JCMS_LANG
		where
	   		DEL_DT IS NULL
		<if test="!empty(langTp)" > and LANG_TP = #{langTp} </if>
		<if test="!empty(dispNmLike)" > and DISP_NM LIKE '%'||#{dispNmLike}||'%' </if>
	</select>
	
	<insert id="insert" parameterType="lang">
		insert into JCMS_LANG (
			LANG_ID,
			LANG_TP,
			DISP_NM,
			REG_DT,
			REG_ID
		) values (
			LANG_ID_SEQ.NEXTVAL
			, #{langTp}
			, #{dispNm}
			, SYSDATE
			, #{regId}
		)
	</insert>
	
	<update id="update" parameterType="lang">
		update JCMS_LANG set 
			LANG_TP = #{langTp}
			,DISP_NM = #{dispNm}
			,UPD_DT = SYSDATE
			,UPD_ID = #{updId}
		where 
			LANG_ID = #{langId}
	</update>
	
	<update id="delete" parameterType="lang">
		update JCMS_LANG set 
			DEL_ID = #{delId}
			,DEL_DT = SYSDATE
		where 
			LANG_ID = #{langId}
	</update>
	
	
	<select id="checkIdDuplicate" parameterType="lang" resultType="java.lang.Integer">
		select 
			COUNT(*)
		from
			JCMS_LANG
		where
	   		DISP_NM = #{dispNm}
	</select>
</mapper>
