<?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="code1" column="CODE1" />
		<result property="code2" column="CODE2" />
		<result property="codenm" column="CODENM" />
		<result property="codenmYak" column="CODENM_YAK" />
		<result property="codeUseYN" column="CODE_USE_YN" />
	</resultMap>
	
	<select id="Code.getCodeValues" parameterType="codeVO" resultMap="codeResult">
	<![CDATA[
		SELECT 
		  CODE1, CODE2, CODENM, CODENM_YAK, CODE_USE_YN
		FROM
		  TCODE
		WHERE
		  CODE1 = #{code1}
	]]>
	
	<if test="code2 != null and code2 != ''">
	<![CDATA[
		  AND CODE2 = #{code2}
	]]>
	</if>
	
	<![CDATA[ 
		ORDER BY
		  CODE1, CODE2
	]]>
	</select>
	
	<select id="Code.getPlace1List" parameterType="boolean" resultMap="codeResult">
	<![CDATA[
		SELECT 
        	CODE1, CODE2 AS CODE2, CODENM, CODENM_YAK, CODE_USE_YN
	    FROM
	    	TCODE
	    WHERE
	    	CODE1 = 'C001'
	]]>
    	<if test="_parameter == true">
		<![CDATA[
			AND CODE2 NOT IN ('PS95','PS96','PS97','PS99', 'STAT')
		]]>
		</if>
	<![CDATA[			
	    ORDER BY
	    	UPPER(CODE2)
	]]>
	</select>
	
	<select id="Code.getPlace2List" parameterType="codeVO" resultMap="codeResult">
	<![CDATA[
		SELECT 
        	*
	    FROM
	    	TCODE
	    WHERE
	    	CODE1 = #{code1}
	    ORDER BY
	    	CODE2
	]]>
	</select>
	
	<select id="Code.getPlace3List" parameterType="codeVO" resultMap="codeResult">
	<![CDATA[
		SELECT 
        	*
	    FROM
	    	TCODE
	    WHERE
	    	CODE1 = #{code1}
	]]>
		<if test="code2 != null and code2 != ''">
			AND CODE2 = #{code2}
		</if>	    
	<![CDATA[
	    ORDER BY
	    	CODE2
	]]>
	</select>
	
	<select id="Code.getPositionList" resultMap="codeResult">
	<![CDATA[
		SELECT 
        	*
	    FROM
	    	TCODE
	    WHERE
	    	CODE1 = 'C002'
	    ORDER BY
	    	CODE2
	]]>
	</select>
	
	<select id="Code.getJobTypeList" resultMap="codeResult">
	<![CDATA[
		SELECT 
        	*
	    FROM
	    	TCODE
	    WHERE
	    	CODE1 = 'C003'
	    ORDER BY
	    	CODE2
	]]>
	</select>
	
	<select id="Code.getDutiesList" resultMap="codeResult">
	<![CDATA[
		SELECT 
        	*
	    FROM
	    	TCODE
	    WHERE
	    	CODE1 = 'C004'
	    ORDER BY
	    	CODE2
	]]>
	</select>
	
	<select id="Code.getScholarshipList" resultMap="codeResult">
	<![CDATA[
		SELECT 
        	*
	    FROM
	    	TCODE
	    WHERE
	    	CODE1 = 'C005'
	    ORDER BY
	    	CODE2
	]]>
	</select>
	
	<select id="Code.getPlace1NameByCode" parameterType="String" resultType="codeVO">
	<![CDATA[
		SELECT 
			A.CODENM_YAK AS CODENMYAK,
			A.CODENM
		FROM
		  	TCODE A
		WHERE
		  	A.CODE1 = 'C001' AND
			A.CODE2 = #{code}
	]]>
	</select>
	
	<select id="Code.getPlace2NameByCode" parameterType="hashmap" resultType="String">
	<![CDATA[	
		SELECT
		  	A.CODENM
		FROM
		  	TCODE A
		WHERE
		  	A.CODE1 = #{code1} AND
			A.CODE2 = #{code2}
	]]>
	</select>
	
	<select id="Code.getPlace3NameByCode" parameterType="String" resultType="String">
	<![CDATA[	
		SELECT
		  	A.CODENM
		FROM
		  	TCODE A
		WHERE
		  	A.CODE1 = 'C009' AND
			A.CODE2 = #{code}
	]]>
	</select>
	
	<select id="Code.getPositionNameByCode" parameterType="String" resultType="String">
	<![CDATA[	
		SELECT
		  	A.CODENM
		FROM
		  	TCODE A
		WHERE
		  	A.CODE1 = 'C002' AND
			A.CODE2 = #{code}
	]]>
	</select>
	
	<select id="Code.getDutiesNameByCode" parameterType="String" resultType="String">
	<![CDATA[	
		SELECT
		  	A.CODENM
		FROM
		  	TCODE A
		WHERE
		  	A.CODE1 = 'C004' AND
			A.CODE2 = #{code}
	]]>
	</select>
	
	<select id="Code.getJobtypeNameByCode" parameterType="String" resultType="String">
	<![CDATA[	
		SELECT
		  	A.CODENM
		FROM
		  	TCODE A
		WHERE
		  	A.CODE1 = 'C003' AND
			A.CODE2 = #{code}
	]]>
	</select>
	
	<select id="Code.getScholarshipNameByCode" parameterType="String" resultType="String">
	<![CDATA[	
		SELECT
		  	A.CODENM
		FROM
		  	TCODE A
		WHERE
		  	A.CODE1 = 'C005' AND
			A.CODE2 = #{code}
	]]>
	</select>
	
	<insert id="Code.insertCode" parameterType="codeVO">
	<![CDATA[
		INSERT INTO 
		TCODE (
			CODE1,
			CODE2,
			CODENM,
			CODENM_YAK,
			CODE_USE_YN
		) 
		VALUES (
			#{code1},
			#{code2},
			#{codenm},
			]]>
			<choose>
				<when test="codenmYak != null and codenmYak != ''">
					  #{codenmYak},
				</when>
				<otherwise>
					' ',
				</otherwise>
			</choose>
			<![CDATA[
			#{codeUseYN}
		)
	]]>
	</insert>
	
	<update id="Code.updateCode" parameterType="codeVO">
	<![CDATA[
		UPDATE
			TCODE
		SET
	]]>
		  CODENM = #{codenm},
		<if test="codenmYak != null and codenmYak != ''">
		  CODENM_YAK = #{codenmYak},
		</if>
		  CODE_USE_YN = #{codeUseYN}
	<![CDATA[
		WHERE
			CODE1 = #{code1}
	]]>
			<if test="code2 != null and code2 != ''">
			  AND CODE2 = #{code2}
			</if>
	</update>
	
	<delete id="Code.deleteCode" parameterType="codeVO">
	<![CDATA[
		DELETE
		FROM
			TCODE
		WHERE
			(CODE1 = #{code1} AND CODE2 = #{code2}) 
			OR (CODE1 = #{code2})
	]]>
	</delete>
</mapper>
