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

	<resultMap id="eduResult" type="eduVO">
		<result property="idx" column="ES_IDX" />
		<result property="name" column="ES_NAME" />
		<result property="stdate" column="ES_STDATE" />
		<result property="eddate" column="ES_EDDATE" />
		<result property="eduCourse" column="ES_EDU_COURSE" />
		<result property="eduCourseStr" column="ES_EDU_COURSE_NM" />
		<result property="eduPlace" column="ES_EDU_PLACE" />
		<result property="userId" column="ES_USERID" />
		<result property="place1" column="ES_PLACE1" />
		<result property="place2" column="ES_PLACE2" />
		<result property="scholarship" column="ES_SCHOLARSHIP" />
		<result property="scholarshipStr" column="ES_SCHOLARSHIP_NM" />
		<result property="position" column="ES_POSITION" />
		<result property="positionStr" column="ES_POSITION_NM" />
		<result property="jobtype" column="ES_JOBTYPE" />
		<result property="sdate" column="ES_SDATE" />
		<result property="pdate" column="ES_PDATE" />
		<result property="adate" column="ES_ADATE" />
		<result property="comment" column="ES_COMMENT" />
		<result property="regdate" column="ES_REGDATE" />
		<result property="logdate" column="ES_LOGDATE" />
		<result property="writer" column="ES_WRITER" />
		<result property="birth" column="ES_BIRTH" />
	</resultMap>

	<insert id="insert" parameterType="eduVO">
	<![CDATA[
		INSERT INTO H3_EDU_STAT
		(
			ES_IDX, ES_NAME, ES_STDATE, ES_EDDATE, ES_EDU_COURSE, 
			ES_EDU_PLACE, ES_USERID, ES_PLACE1, ES_PLACE2, ES_SCHOLARSHIP, 
			ES_POSITION, ES_JOBTYPE, ES_SDATE, ES_PDATE, ES_ADATE, 
			ES_COMMENT, ES_REGDATE, ES_LOGDATE, ES_WRITER, ES_BIRTH
		)
		VALUES
		(
			(SELECT COALESCE(MAX(ES_IDX), 0) + 1 FROM H3_EDU_STAT), #{name}, #{stdate}, #{eddate}, #{eduCourse},
			#{eduPlace}, #{userId}, #{place1}, #{place2}, #{scholarship}, 
			#{position}, #{jobtype}, #{sdate}, #{pdate}, #{adate}, 
			#{comment}, NOW(), NOW(), #{writer}, #{birth}
		)	
	]]>
	</insert>

	<select id="select" parameterType="eduVO" resultMap="eduResult">
	<![CDATA[
		SELECT
			ES.*, EDUC.CODENM AS ES_EDU_COURSE_NM, SCH.CODENM AS ES_SCHOLARSHIP_NM, POS.CODENM AS ES_POSITION_NM
		FROM
			H3_EDU_STAT ES, TCODE EDUC, TCODE SCH, TCODE POS
		WHERE
			ES.ES_EDU_COURSE = EDUC.CODE2 AND EDUC.CODE1 = 'EDUC'
			AND ES.ES_SCHOLARSHIP = SCH.CODE2 AND SCH.CODE1 = 'C005'
			AND ES.ES_POSITION = POS.CODE2 AND POS.CODE1 = 'C002'
			AND ES.ES_IDX = #{idx}
	]]>
	</select>

	<select id="selectList" parameterType="eduSearchVO" resultMap="eduResult">
	<![CDATA[
		SELECT
		  ES.*, EDUC.CODENM AS ES_EDU_COURSE_NM, SCH.CODENM AS ES_SCHOLARSHIP_NM, POS.CODENM AS ES_POSITION_NM
		FROM
		  H3_EDU_STAT ES, TCODE EDUC, TCODE SCH, TCODE POS
		WHERE
		  ES.ES_EDU_COURSE = EDUC.CODE2 AND EDUC.CODE1 = 'EDUC'
		  AND ES.ES_SCHOLARSHIP = SCH.CODE2 AND SCH.CODE1 = 'C005'
		  AND ES.ES_POSITION = POS.CODE2 AND POS.CODE1 = 'C002' 
  	]]>
  		<if test="eduCourse != null and eduCourse != ''"><![CDATA[ 
			AND ES.ES_EDU_COURSE = #{eduCourse}
		]]></if>
		<if test="place1 != null and place1 != ''"><![CDATA[ 
			AND ES.ES_PLACE1 = #{place1}
		]]></if>
		<if test="name != null and name != ''"><![CDATA[ 
			AND ES.ES_NAME LIKE '%' || #{name} || '%'
		]]></if>
		<if test="orderCol != null and orderCol != '' and orderAsc != null and orderAsc != ''"><![CDATA[ 
		ORDER BY ${orderCol} ${orderAsc}
		]]></if>
	</select>
	
	<update id="update" parameterType="eduVO">
	<![CDATA[
		UPDATE H3_EDU_STAT
		SET	ES_NAME = #{name},  
			ES_STDATE = #{stdate}, 
			ES_EDDATE = #{eddate}, 
			ES_EDU_COURSE = #{eduCourse}, 
			ES_EDU_PLACE = #{eduPlace}, 
			ES_USERID = #{userId}, 
			ES_PLACE1 = #{place1}, 
			ES_PLACE2 = #{place2}, 
			ES_SCHOLARSHIP = #{scholarship}, 
			ES_POSITION = #{position}, 
			ES_JOBTYPE = #{jobtype}, 
			ES_SDATE = #{sdate}, 
			ES_PDATE = #{pdate}, 
			ES_ADATE = #{adate}, 
			ES_COMMENT = #{comment}, 
			ES_LOGDATE = NOW(),
			ES_WRITER = #{writer}, 
			ES_BIRTH = #{birth}
		WHERE ES_IDX = #{idx}
	]]>		
	</update>
	
	<delete id="delete" parameterType="eduVO">
	<![CDATA[
		DELETE 
		FROM
			H3_EDU_STAT
		WHERE 
			ES_IDX = #{idx}
	]]>
	</delete>
</mapper>
