<?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="egovframework.com.mtdata.cmmnty.mapper.CmmntyMapper">

	<resultMap id="cmmntyVO" type="egovframework.com.mtdata.cmmnty.vo.CmmntyVO">
		<result property="cmmntyId" column="CMMNTY_ID"/>
		<result property="cmmntyNm" column="CMMNTY_NM"/>
		<result property="useYn" column="USE_YN"/>
		<result property="frstRegDt" column="FRST_REG_DT"/>
		<result property="frsRegId" column="FRST_REG_ID"/>
		<result property="lastMdfrDt" column="LAST_MDFR_DT"/>
		<result property="lastMdfrId" column="LAST_MDFR_ID"/>
		<result property="cmmntyIntrcn" column="CMMNTY_INTRCN"/>
		<result property="regSeCd" column="REG_SE_CD"/>
		<result property="tmplatId" column="TMPLAT_ID"/>
	</resultMap>

	<insert id="insertCmmnty" parameterType="CmmntyVO">
		<![CDATA[
			INSERT INTO COMTNCMMNTY 
				( CMMNTY_ID
				  , CMMNTY_NM
				  , USE_YN
				  , FRST_REG_DT
				  , FRST_REG_ID 
				  , LAST_MDFR_DT 
				  , LAST_MDFR_ID 
				  , CMMNTY_INTRCN 
				  , REG_SE_CD 
				  , TMPLAT_ID )
			VALUES ( #cmmntyId#
				  , #cmmntyNm#
				  , #useYn#
				  , #frstRegDt#
				  , #frsRegId# 
				  , #lastMdfrDt# 
				  , #lastMdfrId# 
				  , #cmmntyIntrcn# 
				  , #regSeCd# 
				  , #tmplatId# )
		]]>
	</insert>
	
	<select id="selectCmmntyList" resultType="cmmntyVO">

			SELECT
				CMMNTY_ID as cmmntyId, 
				CMMNTY_NM as cmmntyNm, 
				FRST_REG_ID as frsRegId, 
				FRST_REG_DT as frstRegDt, 
				REG_SE_CD as regSeCd
			FROM COMTNCMMNTY
			WHERE 1=1
			<!-- <isEqual prepend="AND" property="searchCondition" compareValue="0">
				ID LIKE '%' || #searchKeyword# || '%'
			</isEqual>
			<isEqual prepend="AND" property="searchCondition" compareValue="1">
				NAME LIKE '%' || #searchKeyword# || '%'
			</isEqual> -->
			ORDER BY cmmntyId DESC
			LIMIT 10
	</select>
	
	<select id="selectCmmntyListTotCnt" resultType="int">

			SELECT COUNT(*) totcnt
			FROM COMTNCMMNTY
			WHERE 1=1
			<!-- <isEqual prepend="AND" property="searchCondition" compareValue="0">
				ID LIKE '%' || #searchKeyword# || '%'
			</isEqual>
			<isEqual prepend="AND" property="searchCondition" compareValue="1">
				NAME LIKE '%' || #searchKeyword# || '%'
			</isEqual> -->
	</select>

	<update id="updateCmmnty">

			UPDATE COMTNCMMNTY
			SET NAME=#{name}
				, DESCRIPTION=#{description}
				, USE_YN=#{useYn}
				  WHERE ID=#{id}

	</update>

	<delete id="deleteCmmnty">

			DELETE FROM SAMPLE
			WHERE ID=#{id}

	</delete>

	<select id="selectCmmnty" resultMap="cmmntyVO">

			SELECT
				ID, NAME, DESCRIPTION, USE_YN, REG_USER
			FROM SAMPLE
			WHERE ID=#{id}

	</select>
</mapper>