<?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="Code">

	<resultMap id="codeResult" type="CodeVO">
		<result property="group" column="CC_GROUP" />
		<result property="code" column="CC_CODE" />
		<result property="name" column="CC_CODE_NAME" />
		<result property="shortName" column="CC_CODE_YAK" />
		<result property="order" column="CC_ORDER" />
		<result property="useYn" column="CC_USE_YN" />
	</resultMap>
	
	<select id="Code.getCodeList" parameterType="codeVO" resultMap="codeResult">
	/* Code.getCodeList */
		SELECT 
		  CC_GROUP, CC_CODE, CC_CODE_NAME, CC_CODE_YAK, CC_ORDER, CC_USE_YN
		FROM
		  H2_COMMON_CODE
		<if test=" group != null and !''.equals(group) ">
		WHERE  CC_GROUP = #{group}
		</if>		  
		ORDER BY
		  CC_GROUP, CC_CODE
	</select>
	
	<select id="Code.getCode" parameterType="codeVO" resultMap="codeResult">
	<![CDATA[
	/* Code.getCode */
		SELECT 
		  CC_GROUP, CC_CODE, CC_CODE_NAME, CC_CODE_YAK
		FROM
		  H2_COMMON_CODE
		WHERE
		  CC_GROUP = #{group}
		AND
		  CC_CODE = #{code}
		ORDER BY
		  CC_GROUP, CC_CODE
	]]>
	</select>
	
	<insert id="Code.insertCode" parameterType="codeVO">
	<![CDATA[
	/* Code.insertCode */
		INSERT INTO 
		H2_COMMON_CODE (
			CC_GROUP
			, CC_CODE
			, CC_CODE_NAME
			, CC_CODE_YAK
			, CC_ORDER
			, CC_USE_YN
			, CC_REGDATE
		) 
		VALUES (
			#{group}
			, #{code}
			, #{name}
			, #{shortName}
			, #{order}
			, #{useYn}
			, NOW()
		)
	]]>
	</insert>
	
	<update id="Code.updateCode" parameterType="codeVO">
	/* Code.updateCode */
		UPDATE
			H2_COMMON_CODE
		SET
		  CC_CODE_NAME = #{name},
	    <if test="code != null and code != ''">
		  CC_CODE = #{code},
		</if>
		<if test="shortName != null and shortName != ''">
		  CC_CODE_YAK = #{shortName},
		</if>
		<if test="order != null and order != ''">
		  CC_ORDER = #{order},
		</if>
		  CC_USE_YN = #{useYn}
		WHERE
			CC_GROUP = #{group}
        AND CC_CODE = #{code}
	</update>
	
	<delete id="Code.deleteCode" parameterType="codeVO">
	/* Code.deleteCode */
		DELETE
		FROM
			H2_COMMON_CODE
		WHERE
			CC_GROUP = #{group} 
		AND CC_CODE = #{code} 
	</delete>
</mapper>
