<?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.pgm.mapper.PgmMapper">

	<select id="select" parameterType="pgmSearch" resultType="pgm">
		select	
			PGM_ID ,PGM_NM ,PGM_DESC ,PGM_URL ,USE_ST ,REG_ID ,REG_DT ,UPD_ID ,UPD_DT
		from		
			JCMS_PGM
		where
			DEL_DT IS NULL
		<if test="pgmId != null" > and PGM_ID = #{pgmId} </if>
	</select>
	
	<select id="selectList" parameterType="pgmSearch" resultType="pgm">
		SELECT *
		FROM (
			SELECT ROWNUM RNUM , LIST.*
			FROM (
				SELECT PGM_ID, PGM_NM, PGM_DESC, PGM_URL, USE_ST, REG_ID, REG_DT, UPD_ID, UPD_DT
				FROM JCMS_PGM
				WHERE DEL_DT IS NULL
					<if test="useSt != null" > AND USE_ST = #{useSt} </if>
					<if test="!empty(pgmNmLike)" > AND PGM_NM LIKE '%'|| #{pgmNmLike}|| '%' </if>
					<if test="!empty(pgmUrlLike)" > AND PGM_URL LIKE '%'|| #{pgmUrlLike}|| '%' </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="pgmSearch" resultType="java.lang.Integer">
		select 
			COUNT(PGM_ID)
		from
			JCMS_PGM
		where
	   		DEL_DT IS NULL
		<if test="!empty(pgmNmLike)" > and PGM_NM LIKE '%'|| #{pgmNmLike}|| '%' </if>
		<if test="!empty(pgmUrlLike)" > and PGM_URL LIKE '%'|| #{pgmUrlLike}|| '%' </if>
	</select>

	<insert id="insert" parameterType="pgm">
		insert into JCMS_PGM (
			PGM_ID
			,PGM_NM
			,PGM_DESC
			,PGM_URL
			,USE_ST
			,REG_ID
			,REG_DT
		) values (
			PGM_ID_SEQ.NEXTVAL
			, #{pgmNm}
			, #{pgmDesc}
			, #{pgmUrl}
			, #{useSt}
			, #{regId}
			, SYSDATE
		)
	</insert>
	
	<update id="update" parameterType="pgm">
		update JCMS_PGM set 
			PGM_NM = #{pgmNm}
			,PGM_DESC = #{pgmDesc}
			,PGM_URL = #{pgmUrl}
			,USE_ST = #{useSt}
			,UPD_ID = #{updId}
			,UPD_DT = SYSDATE
		where 
			PGM_ID = #{pgmId}
	</update>
	
	<update id="delete" parameterType="pgm">
		update JCMS_PGM set 
			DEL_ID = #{delId}
			,DEL_DT = SYSDATE
		where 
			PGM_ID = #{pgmId}
	</update>
</mapper>
