<?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="Moniter">
	
	<resultMap id="moniterResultMap" type="moniterVO">
		<result property="jmIdx" column="jm_idx" />
		<result property="jmDepth" column="jm_depth" />
		<result property="jmDepth1Idx" column="jm_depth1_idx" />
		<result property="jmDepth2Idx" column="jm_depth2_idx" />
		<result property="jmDepth3Idx" column="jm_depth3_idx" />
		<result property="jmDepth4Idx" column="jm_depth4_idx" />
		<result property="jmDepth5Idx" column="jm_depth5_idx" />
		<result property="jmDepth6Idx" column="jm_depth6_idx" />
		<result property="jmName" column="jm_name" />
		<result property="jmOrder" column="jm_order" />
		<result property="jmChild" column="jm_child" />
		<result property="jmHref" column="jm_href" />
	</resultMap>
	
	<select id="Moniter.getMoniterList" parameterType="String" resultMap="moniterResultMap">
	/* Moniter.getMoniterList */
		SELECT	JM_IDX,
			JM_DEPTH,
			JM_DEPTH1_IDX,
			JM_DEPTH2_IDX,
			JM_DEPTH3_IDX,
			JM_DEPTH4_IDX,
			JM_DEPTH5_IDX,
			JM_DEPTH6_IDX,
			JM_NAME,
			JM_ORDER,
			JM_CHILD,
			JM_HREF
		FROM	H2_JSS_MONITER
		WHERE
			JM_DEPTH1_IDX = #{idx}
		ORDER BY JM_DEPTH1_IDX, JM_DEPTH2_IDX, JM_DEPTH3_IDX, JM_DEPTH4_IDX, JM_DEPTH5_IDX, JM_DEPTH6_IDX, JM_ORDER ASC
	</select>	
	
	<select id="Moniter.getMoniterTree" parameterType="moniterSearchVO" resultType="HashMap">
	/* Moniter.getMoniterTree */
		SELECT	
			JM_IDX AS id,
			JM_DEPTH AS depth ,
			JM_NAME as text,
			<!-- 	WHEN  JM_CHILD = '0' THEN 'open'
				ELSE  'closed' 
			END state, -->
			'closed' AS state,
			JM_HREF as href
		FROM	H2_JSS_MONITER
		WHERE 
			JM_DEPTH = #{depth}
		<if test="depth ==  2 ">
		AND JM_DEPTH1_IDX = #{idx}
		</if>
		<if test="depth ==  3 ">
		AND JM_DEPTH2_IDX = #{idx}
		</if>
		<if test="depth ==  4 ">
		AND JM_DEPTH3_IDX = #{idx}
		</if>
		<if test="depth == 5 ">
		AND JM_DEPTH4_IDX = #{idx}
		</if>
		<if test="depth == 6 ">
		AND JM_DEPTH5_IDX = #{idx}
		</if>
		ORDER BY JM_DEPTH1_IDX, JM_DEPTH2_IDX, JM_DEPTH3_IDX, JM_DEPTH4_IDX, JM_DEPTH5_IDX, JM_DEPTH6_IDX, JM_ORDER ASC
	</select>	
	
	<select id="Moniter.getMoniterInfo" parameterType="String" resultMap="moniterResultMap">
	/* Moniter.getMoniterInfo */
		SELECT	JM_IDX,
			JM_DEPTH,
			JM_DEPTH1_IDX,
			JM_DEPTH2_IDX,
			JM_DEPTH3_IDX,
			JM_DEPTH4_IDX,
			JM_DEPTH5_IDX,
			JM_DEPTH6_IDX,
			JM_NAME,
			JM_ORDER,
			JM_CHILD,
			JM_HREF
		FROM	H2_JSS_MONITER
		WHERE
			JM_IDX = #{idx}
	</select>
	
	<update id="Moniter.updateMoniterInfo">
	UPDATE H2_JSS_MONITER
	SET
		JM_NAME = #{jmName},
		JM_HREF = #{jmHref}
	WHERE
		JM_IDX = #{jmIdx}
	</update>
	
	<insert id="Moniter.insertMoniterInfo">
	INSERT INTO H2_JSS_MONITER
	(
		jm_idx, jm_depth
		, jm_depth1_idx, jm_depth2_idx, jm_depth3_idx
		, jm_depth4_idx, jm_depth5_idx, jm_depth6_idx
		, jm_name, jm_order, jm_child, jm_href
	) VALUES (
		#{jmIdx}, #{jmDepth}
		, #{jmDepth1Idx}, #{jmDepth2Idx}, #{jmDepth3Idx}
		, #{jmDepth4Idx}, #{jmDepth5Idx}, #{jmDepth6Idx}
		, #{jmName}, #{jmOrder}, #{jmChild}, #{jmHref}
	)
	</insert>
	
	<select id="Moniter.getMaxIdx" resultType="int">
	SELECT
		MAX(jm_idx) + 1
	FROM
	H2_JSS_MONITER
	</select>
	
	<select id="Moniter.deleteMoniterTree" parameterType="moniterSearchVO" resultType="HashMap">
		/* Moniter.deleteMoniterTree */
		DELETE  FROM	H2_JSS_MONITER
		WHERE 
		<choose>
			<when test="depth ==  1 ">
			JM_DEPTH1_IDX = #{idx}
			</when>
			<when test="depth ==  2 ">
			JM_DEPTH2_IDX = #{idx}
			</when>
			<when test="depth ==  3 ">
			JM_DEPTH3_IDX = #{idx}
			</when>
			<when test="depth ==  4 ">
			JM_DEPTH4_IDX = #{idx}
			</when>
			<when test="depth == 5 ">
			JM_DEPTH5_IDX = #{idx}
			</when>
			<when test="depth == 6 ">
			JM_DEPTH6_IDX = #{idx}
			</when>
			<otherwise>
			JM_IDX = NULL
			</otherwise>
		</choose>
	</select>	
</mapper>