<?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.file.mapper.FileMapper">

	<select id="select" parameterType="fileSearch" resultType="file">
		select	
			FILE_ID, REG_ID, REG_DT, UPD_ID, UPD_DT
		from		
			JCMS_FILE
		where
			1=1
		<if test="!empty(fileId)" > and FILE_ID = #{fileId} </if>
	</select>
	
	<select id="selectList" parameterType="fileSearch" resultType="file">
		SELECT *
		FROM (
			SELECT ROWNUM RNUM , LIST.*
			FROM (
				SELECT FILE_ID, REG_ID, REG_DT, UPD_ID, UPD_DT
				FROM JCMS_FILE
				WHERE 1=1
				<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>
	
	<insert id="insert" parameterType="file" >
		<selectKey keyProperty="fileId" resultType="java.lang.Long" order="BEFORE" >
	    	select FILE_ID_SEQ.NEXTVAL from DUAL
	  	</selectKey>
		insert into JCMS_FILE (
			FILE_ID,
			REG_ID,
			REG_DT
		) values (
			#{fileId}
			, #{regId,jdbcType=VARCHAR}
			, SYSDATE
		)
	</insert>

	<update id="update" parameterType="file">
		update JCMS_FILE set 
			UPD_ID = #{updId}
			,UPD_DT = SYSDATE
		where 
			FILE_ID = #{fileId}
	</update>
	
</mapper>
