<?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.cont.mapper.ContItemHistMapper">
	
	<select id="selectList" parameterType="contItemHistSearch" resultType="contItemHist">
		SELECT *
		FROM (
			SELECT ROWNUM RNUM , LIST.*
			FROM (
				SELECT CONT_ITEM_HIST_ID, CONT_ITEM_NM, CONT_ID, CONT, LANG_ID, REG_ID, REG_DT,
					(SELECT USER_LOGIN_ID FROM JCMS_USER WHERE USER_ID = JCMS_CONT_ITEM_HIST.REG_ID) AS CONT_REG_ID,
					(SELECT USER_NM FROM JCMS_USER WHERE USER_ID = JCMS_CONT_ITEM_HIST.REG_ID) AS CONT_REG_NM
				FROM JCMS_CONT_ITEM_HIST
				WHERE 1 = 1
					<if test="!empty(contId)" > AND CONT_ID = #{contId} </if>
					<if test="!empty(langId)" > AND LANG_ID = #{langId} </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="contItemHistSearch" resultType="java.lang.Integer">
			select	
				COUNT(CONT_ITEM_HIST_ID)
			from		
				JCMS_CONT_ITEM_HIST
			where
		   		1 = 1
			<if test="!empty(contId)" > and CONT_ID = #{contId} </if>
			<if test="!empty(langId)" > and LANG_ID = #{langId} </if>
	</select>
	
	<insert id="insert" parameterType="contItemHist">
		insert into JCMS_CONT_ITEM_HIST (
			CONT_ITEM_HIST_ID,
			CONT_ITEM_NM,
			CONT_ID,
			CONT,
			LANG_ID,
			REG_ID,
			REG_DT
		) values (
		CONT_ITEM_HIST_ID_SEQ.NEXTVAL
			, #{contItemNm}
			, #{contId}
			, #{cont ,jdbcType=CLOB}
			, #{langId}
			, #{regId}
			, SYSDATE
		)
	</insert>
	
</mapper>
