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

	<resultMap id="divMngResult" type="divMngVO">
		<result property="place" column="DS_PLACE" />
		<result property="placeStr" column="CODENM" />
		<result property="no" column="DS_NO" />
		<result property="local" column="DS_LOCAL" />
		<result property="gubun" column="DS_GUBUN" />
		<result property="staffNum" column="DS_STAFF_NUM" />
		<result property="tel" column="DS_TEL" />
		<result property="condition" column="DS_CONDITION" />
		<result property="equipStat" column="DS_EQUIP_STAT" />
		<result property="fileImg" column="DS_FILEIMG" />
		<result property="file1" column="DS_FILE1" />
		<result property="file2" column="DS_FILE2" />
		<result property="file3" column="DS_FILE3" />
		<result property="creDate" column="DS_CREDATE" />
		<result property="logDate" column="DS_LOGDATE" />
		<result property="writer" column="DS_WRITER" />
	</resultMap>
	
	<select id="select" parameterType="divMngVO" resultMap="divMngResult">
	<![CDATA[	
		SELECT
			DS.*, C.CODENM
		FROM
			H3_DIVISION_MANAGE_STAT DS, TCODE C
		WHERE
			C.CODE1 = 'C001'
			AND DS.DS_PLACE = C.CODE2
			AND DS.DS_PLACE = #{place}
        	AND DS.DS_NO = #{no}
	]]>
	</select>

	<select id="selectList" parameterType="divMngSearchVO" resultMap="divMngResult">
	<![CDATA[
        SELECT
        	DS.*, C.CODENM
        FROM
        	H3_DIVISION_MANAGE_STAT DS, TCODE C
        WHERE
        	C.CODE1 = 'C001'
        	AND DS.DS_PLACE = C.CODE2
        	
  	]]>
  		<if test="place != null and place != ''">
			AND DS.DS_PLACE = #{place}
		</if>
	<![CDATA[
		ORDER BY
			DS.DS_PLACE ASC,
			DS.DS_NO ASC
	]]>
	</select>

	<insert id="insert" parameterType="divMngVO">
	<![CDATA[
		INSERT INTO H3_DIVISION_MANAGE_STAT
     	(
			DS_PLACE, DS_NO, DS_LOCAL, DS_GUBUN, DS_STAFF_NUM, 
			DS_TEL, DS_CONDITION, DS_EQUIP_STAT, DS_FILEIMG, DS_FILE1,
			DS_FILE2, DS_FILE3, DS_CREDATE, DS_WRITER
		)
     	VALUES
     	(
			#{place}, #{no}, #{local}, #{gubun}, #{staffNum}, 
			#{tel}, #{condition}, #{equipStat}, #{fileImg}, #{file1},
			#{file2}, #{file3}, NOW(), #{writer}
     	)
	]]>
	</insert>

	<update id="update" parameterType="divMngVO">
	<![CDATA[
		UPDATE 
			H3_DIVISION_MANAGE_STAT
		SET 
			DS_LOCAL = #{local}, 
			DS_GUBUN = #{gubun}, 
			DS_STAFF_NUM = #{staffNum}, 
			DS_TEL = #{tel}, 
			DS_CONDITION = #{condition}, 
			DS_EQUIP_STAT = #{equipStat},
			DS_FILEIMG = #{fileImg},
			DS_FILE1 = #{file1},
			DS_FILE2 = #{file2},
			DS_FILE3 = #{file3},
			DS_LOGDATE = NOW()
		WHERE 
			DS_PLACE = #{place}
			AND DS_NO = #{no}
	]]>
	</update>

	<delete id="delete" parameterType="divMngVO">
	<![CDATA[
		DELETE 
		FROM
			H3_DIVISION_MANAGE_STAT
		WHERE 
			DS_PLACE = #{place}
        	AND DS_NO = #{no}
	]]>
	</delete>

	<select id="selectMaxNo" parameterType="divMngVO" resultType="int">
	<![CDATA[	
		SELECT
			MAX(DS_NO)
		FROM
			H3_DIVISION_MANAGE_STAT
		WHERE
        	DS_PLACE = #{place}
	]]>
	</select>
</mapper>
