<?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="menu">
	
	<resultMap id="menuResult" type="menu">
		<id property="menuId" column="MENU_ID" />
		<id property="parentId" column="UPPER_SYS_RESOURCE_ID" />
		<result property="authorizationType" column="AUTHORIZATION_ID"/>
		<result property="label" column="LABEL" />
		<result property="labelJson" column="LABEL_JSON" />
		<result property="menuSequence" column="MENU_SEQUENCE" />
		<result property="menuLevel" column="MENU_LEVEL" />
		<result property="menuTypeCodeId" column="MENU_TYPE_CODE_ID" />
		<result property="menuUsePeriodCode" column="MENU_USE_PERIOD_CODE" />
		<result property="externalUrlUsed" column="EXTERNAL_URL_USE_YN" />
		<result property="externalUrl" column="EXTERNAL_URL" />
		<result property="used" column="USE_YN" />
		<result property="checked" column="CHECK_YN" />
	</resultMap>
	
	<resultMap id="menuLevelItems"  type="menu" >
		<id property="menuId" column="MENU_ID"/>
		<result property="label" column="LABEL"/>
		<result property="labelJson" column="LABEL_JSON" />
		<result property="menuLevel" column="MENU_LEVEL"/>
		<result property="upperSysResourceId" column="UPPER_SYS_RESOURCE_ID"/>
		<result property="menuSequence" column="MENU_SEQUENCE"/>
	</resultMap>

	<resultMap id="menuTreeInfo"  type="menu">
		<id property="menuId" column="MENU_ID"/>
		<result property="label" column="LABEL"/>
		<result property="labelJson" column="LABEL_JSON"/>
		<result property="menuLevel" column="MENU_LEVEL"/>
		<result property="menuSequence" column="MENU_SEQUENCE"/>
		<result property="used" column="USE_YN"/>
		<result property="upperSysResourceId" column="UPPER_SYS_RESOURCE_ID"/>
		<result property="sysId" column="SYS_ID"/>
		<result property="sysResourceTypeCodeId" column="SYS_RESOURCE_TYPE_CODE_ID"/>
	</resultMap>

	<resultMap id="myMenu" type="myMenu" extends="menuLevelItems">
		<result property="defaultPagePath" column="PAGE_PATH"/>
		<result property="myMenuSeq" column="MY_MENU_SEQ"/>
	</resultMap>
	
	<sql id="tableMenu">TN_CF_MENU</sql>
	<sql id="tableMyMenu">TN_CF_MY_MENU</sql>
	
	<sql id="sqlMenuLevel">
		SELECT A.MENU_ID, A.LABEL, A.LABEL_JSON,
		       A.MENU_LEVEL, A.MENU_SEQUENCE, A.USE_YN,
		       B.UPPER_SYS_RESOURCE_ID, B.SYS_ID,
		       B.SYS_RESOURCE_TYPE_CODE_ID
		FROM   <include refid="tableMenu" /> A
		    INNER JOIN <include refid="sysResource.tableSysResource" /> B
		        ON A.MENU_ID = B.SYS_RESOURCE_ID
		    LEFT OUTER JOIN (SELECT DISTINCT UPPER_SYS_RESOURCE_ID
		                     FROM   <include refid="sysResource.tableSysResource" />
		                     WHERE  DELETE_YN IS NULL OR DELETE_YN != '1') A2
		        ON B.SYS_RESOURCE_ID = A2.UPPER_SYS_RESOURCE_ID
	</sql>
	
	<select id="selectAllMenuPagePaths" parameterType="java.util.HashMap" resultType="java.util.HashMap">
		SELECT MENU.MENU_ID "menuId", MENU.LABEL "menuName",
		       PAGE.PAGE_ID "pageId", PAGE.PAGE_NAME "pageName",
		       #{contextPath} + PAGE.PAGE_PATH "pagePath",
		       UPPER_SYS_RESOURCE_ID "upperSysResourceId"
		FROM   (SELECT M.MENU_ID, M.LABEL, SR.UPPER_SYS_RESOURCE_ID
		        FROM   <include refid="tableMenu" /> M,
		               <include refid="sysResource.tableSysResource" /> SR
		        WHERE  M.MENU_ID = SR.SYS_RESOURCE_ID
		        AND    M.USE_YN = '1'
		        AND    M.DELETE_YN = '0'
		        AND    M.MENU_LEVEL != 0) MENU
		       LEFT OUTER JOIN (SELECT SRM.MAIN_SYS_RESOURCE_ID, P.PAGE_ID, P.PAGE_NAME, P.PAGE_PATH
		                        FROM   <include refid="page.tablePage" /> P,
		                               <include refid="sysResource.tableSysResourceMapp" /> SRM
		                        WHERE  P.PAGE_ID = SRM.SUB_SYS_RESOURCE_ID
		                        AND    P.USE_YN = '1'
		                        AND    P.DELETE_YN = '0') PAGE
		           ON MENU.MENU_ID = PAGE.MAIN_SYS_RESOURCE_ID
	</select>
	
	<select id="selectAllMenuFullPath" resultType="java.util.HashMap">
		WITH TREE_TABLE AS
		(SELECT SR.UPPER_SYS_RESOURCE_ID, M.MENU_ID,
		        CONVERT(NVARCHAR(100), M.LABEL) LABEL,
		        M.USE_YN, M.DELETE_YN
		 FROM   <include refid="tableMenu" /> M,
		        <include refid="sysResource.tableSysResource" /> SR
		 WHERE  M.MENU_ID = SR.SYS_RESOURCE_ID
		 AND    M.MENU_LEVEL = 1
		 UNION ALL
		 SELECT SR.UPPER_SYS_RESOURCE_ID, M.MENU_ID,
		        CONVERT(NVARCHAR(100), TT.LABEL + ' > ' + M.LABEL) LABEL,
		        M.USE_YN, M.DELETE_YN
		 FROM   <include refid="tableMenu" /> M,
		        <include refid="sysResource.tableSysResource" /> SR,
		        TREE_TABLE TT
		 WHERE  M.MENU_ID = SR.SYS_RESOURCE_ID
		 AND    SR.UPPER_SYS_RESOURCE_ID = TT.MENU_ID)
		SELECT TT.MENU_ID menuId, TT.LABEL fullPath
		FROM   TREE_TABLE TT
	</select>
	
	<select id="selectPageFullPathList" resultType="java.util.HashMap">
		WITH TREE_TABLE AS
		(SELECT SR.UPPER_SYS_RESOURCE_ID, M.MENU_ID,
		        CONVERT(NVARCHAR(100), M.LABEL) LABEL,
		        M.USE_YN, M.DELETE_YN
		 FROM   <include refid="tableMenu" /> M,
		        <include refid="sysResource.tableSysResource" /> SR
		 WHERE  M.MENU_ID = SR.SYS_RESOURCE_ID
		 AND    M.MENU_LEVEL = 1
		 UNION ALL
		 SELECT SR.UPPER_SYS_RESOURCE_ID, M.MENU_ID,
		        CONVERT(NVARCHAR(100), TT.LABEL + ' > ' + M.LABEL) LABEL,
		        M.USE_YN, M.DELETE_YN
		 FROM   <include refid="tableMenu" /> M,
		        <include refid="sysResource.tableSysResource" /> SR,
		        TREE_TABLE TT
		 WHERE  M.MENU_ID = SR.SYS_RESOURCE_ID
		 AND    SR.UPPER_SYS_RESOURCE_ID = TT.MENU_ID)
		SELECT TT.MENU_ID menuId, P.PAGE_ID pageId,
		       TT.LABEL + ' > ' + P.PAGE_NAME fullPath,
		       TT.USE_YN useYn, TT.DELETE_YN deleteYn
		FROM   TREE_TABLE TT,
		       <include refid="sysResource.tableSysResourceMapp" /> SRM,
		       <include refid="page.tablePage" /> P
		WHERE  TT.MENU_ID = SRM.MAIN_SYS_RESOURCE_ID
		AND    SRM.SUB_SYS_RESOURCE_ID = P.PAGE_ID
	</select>

	<select id="selectApiFullPathList" resultType="java.util.HashMap">
		WITH TREE_TABLE AS
		(SELECT SR.UPPER_SYS_RESOURCE_ID, M.MENU_ID,
		        CONVERT(NVARCHAR(100), M.LABEL) LABEL,
		        M.USE_YN, M.DELETE_YN
		 FROM   <include refid="tableMenu" /> M,
		        <include refid="sysResource.tableSysResource" /> SR
		 WHERE  M.MENU_ID = SR.SYS_RESOURCE_ID
		 AND    M.MENU_LEVEL = 1
		 AND    M.MENU_ID != 'COMM_URL'
		 UNION ALL
		 SELECT SR.UPPER_SYS_RESOURCE_ID, M.MENU_ID,
		        CONVERT(NVARCHAR(100), TT.LABEL + ' > ' + M.LABEL) LABEL,
		        M.USE_YN, M.DELETE_YN
		 FROM   <include refid="tableMenu" /> M,
		        <include refid="sysResource.tableSysResource" /> SR,
		        TREE_TABLE TT
		 WHERE  M.MENU_ID = SR.SYS_RESOURCE_ID
		 AND    SR.UPPER_SYS_RESOURCE_ID = TT.MENU_ID)
		SELECT TT.MENU_ID menuId, A.API_ID apiId,
			   A.HTTP_METHOD httpMethod, A.API_PATH apiPath,
		       TT.LABEL + ' > ' + A.API_NAME fullPath,
		       TT.USE_YN useYn, TT.DELETE_YN deleteYn
		FROM   TREE_TABLE TT,
		       <include refid="sysResource.tableSysResourceMapp" /> SRM,
		       <include refid="api.tableApi" /> A
		WHERE  TT.MENU_ID = SRM.MAIN_SYS_RESOURCE_ID
		AND    SRM.SUB_SYS_RESOURCE_ID = A.API_ID
		AND    A.DELETE_YN = 0
		ORDER BY TT.MENU_ID
	</select>
	
	<select id="selectMenuListByAdminAuth" parameterType="java.util.HashMap" resultMap="menuResult">
		SELECT SR.UPPER_SYS_RESOURCE_ID, M.MENU_ID,
			   M.LABEL, M.LABEL_JSON,
		       M.MENU_LEVEL, M.MENU_SEQUENCE,
		       M.EXTERNAL_URL_USE_YN, M.EXTERNAL_URL, M.USE_YN
		FROM   <include refid="tableMenu" /> M,
		       <include refid="sysResource.tableSysResource" /> SR
		WHERE  M.MENU_ID = SR.SYS_RESOURCE_ID
		AND    M.USE_YN = '1'
		AND    M.DELETE_YN = '0'
	</select>
	
	<select id="selectMenuListByWorkgroup" parameterType="java.util.HashMap" resultMap="menuResult">
		WITH TREE_TABLE AS
		(SELECT SR.UPPER_SYS_RESOURCE_ID, M.MENU_ID,
		        CONVERT(NVARCHAR(10), WM.AUTHORIZATION_ID) AUTHORIZATION_ID,
				M.LABEL, M.LABEL_JSON,
		        M.MENU_LEVEL, M.MENU_SEQUENCE,
		        M.EXTERNAL_URL_USE_YN, M.EXTERNAL_URL, M.USE_YN
		 FROM   (SELECT WM.SYS_RESOURCE_ID, WM.AUTHORIZATION_ID
		         FROM   <include refid="workgroupRole.tableWorkgroupRole" /> WR,
		                <include refid="workgroupMenu.tableWorkAuthorization" /> WM
		         WHERE  WR.WORKGROUP_ID = WM.WORKGROUP_ID
		         AND    WR.USER_ROLE_ID IN 
		         <foreach item="roleId" index="index" collection="roleIdList" open="(" separator="," close=")">
		         #{roleId}
		         </foreach>
		         ) WM,
		        <include refid="tableMenu" /> M,
		        <include refid="sysResource.tableSysResource" /> SR
		 WHERE  WM.SYS_RESOURCE_ID = M.MENU_ID
		 AND    WM.SYS_RESOURCE_ID = SR.SYS_RESOURCE_ID
		 AND    M.USE_YN = '1'
		 AND    M.DELETE_YN = '0'
		 UNION ALL
		 SELECT SR.UPPER_SYS_RESOURCE_ID, M.MENU_ID,
		        CONVERT(NVARCHAR(10), '') AUTHORIZATION_ID,
				M.LABEL, M.LABEL_JSON,
		        M.MENU_LEVEL, M.MENU_SEQUENCE,
		        M.EXTERNAL_URL_USE_YN, M.EXTERNAL_URL, M.USE_YN
		 FROM   <include refid="tableMenu" /> M,
		        <include refid="sysResource.tableSysResource" /> SR,
		        TREE_TABLE TT
		 WHERE  M.MENU_ID = SR.SYS_RESOURCE_ID
		 AND    M.MENU_ID = TT.UPPER_SYS_RESOURCE_ID
		 AND    M.USE_YN = '1'
		 AND    M.DELETE_YN = '0')
		SELECT DISTINCT
		       UPPER_SYS_RESOURCE_ID, MENU_ID, AUTHORIZATION_ID,
		       LABEL, LABEL_JSON,
		       MENU_LEVEL, MENU_SEQUENCE,
		       EXTERNAL_URL_USE_YN, EXTERNAL_URL, USE_YN
		FROM   TREE_TABLE
		ORDER BY MENU_ID
	</select>
	
	<select id="selectMenuListByUser" parameterType="java.util.HashMap" resultMap="menuResult">
		WITH TREE_TABLE AS
		(SELECT SR.UPPER_SYS_RESOURCE_ID, M.MENU_ID,
		        CONVERT(NVARCHAR(10), UM.AUTHORIZATION_ID) AUTHORIZATION_ID,
				M.LABEL, M.LABEL_JSON,
		        M.MENU_LEVEL, M.MENU_SEQUENCE,
		        M.EXTERNAL_URL_USE_YN, M.EXTERNAL_URL, M.USE_YN
		 FROM   <include refid="user.tableUserAuthorization" /> UM,
		        <include refid="tableMenu" /> M,
		        <include refid="sysResource.tableSysResource" /> SR
		 WHERE  UM.SYS_RESOURCE_ID = M.MENU_ID
		 AND    UM.SYS_RESOURCE_ID = SR.SYS_RESOURCE_ID
		 AND    M.USE_YN = '1'
		 AND    M.DELETE_YN = '0'
		 AND    UM.USER_ID = #{userId}
		 UNION ALL
		 SELECT SR.UPPER_SYS_RESOURCE_ID, M.MENU_ID,
		        CONVERT(NVARCHAR(10), '') AUTHORIZATION_ID,
		        M.LABEL, M.LABEL_JSON,
		        M.MENU_LEVEL, M.MENU_SEQUENCE,
		        M.EXTERNAL_URL_USE_YN, M.EXTERNAL_URL, M.USE_YN
		 FROM   <include refid="tableMenu" /> M,
		        <include refid="sysResource.tableSysResource" /> SR,
		        TREE_TABLE TT
		 WHERE  M.MENU_ID = SR.SYS_RESOURCE_ID
		 AND    M.MENU_ID = TT.UPPER_SYS_RESOURCE_ID
		 AND    M.USE_YN = '1'
		 AND    M.DELETE_YN = '0')
		SELECT DISTINCT
		       UPPER_SYS_RESOURCE_ID, MENU_ID, AUTHORIZATION_ID,
		       LABEL, LABEL_JSON,
		       MENU_LEVEL, MENU_SEQUENCE,
		       EXTERNAL_URL_USE_YN, EXTERNAL_URL, USE_YN
		FROM   TREE_TABLE
		ORDER BY MENU_ID
	</select>

	<select id="selectMenu" parameterType="java.util.HashMap" resultMap="menuResult">
		SELECT M.MENU_ID, M.LABEL, M.LABEL_JSON,
		       M.MENU_LEVEL, M.MENU_SEQUENCE,
		       M.MENU_TYPE_CODE_ID, M.MENU_USE_PERIOD_CODE,
		       M.EXTERNAL_URL_USE_YN, M.EXTERNAL_URL,
		       M.USE_YN, M.DELETE_YN
		FROM   <include refid="tableMenu" /> M,
		       <include refid="sysResource.tableSysResource" /> SR
		WHERE  M.MENU_ID = SR.SYS_RESOURCE_ID
		AND    M.DELETE_YN = '0'
		AND    M.MENU_ID = #{menuId}
	</select>

	<insert id="insertMenu" parameterType="menu">
		INSERT INTO <include refid="tableMenu" />
		(MENU_ID, LABEL, LABEL_JSON,
		 MENU_SEQUENCE, MENU_LEVEL, USE_YN, DELETE_YN,
		 MENU_TYPE_CODE_ID, MENU_USE_PERIOD_CODE,
		 EXTERNAL_URL_USE_YN, EXTERNAL_URL)
		VALUES
		(#{menuId}, #{label}, #{labelJson},
		 #{menuSequence}, #{menuLevel}, #{used}, '0',
		 #{menuTypeCodeId}, #{menuUsePeriodCode},
		 #{externalUrlUsed}, #{externalUrl})
	</insert>
	
	<update id="updateMenu" parameterType="menu">
		UPDATE <include refid="tableMenu" />
		SET    LABEL = #{label},
		       LABEL_JSON = #{labelJson},
		       MENU_SEQUENCE = #{menuSequence},
		       MENU_TYPE_CODE_ID = #{menuTypeCodeId},
		       MENU_USE_PERIOD_CODE = #{menuUsePeriodCode},
		       EXTERNAL_URL_USE_YN = #{externalUrlUsed},
		       EXTERNAL_URL = #{externalUrl},
		       USE_YN = #{used}
		WHERE  MENU_ID = #{menuId}
	</update>

	<delete id="deleteMenu" parameterType="java.util.HashMap">
		UPDATE <include refid="tableMenu" />
		SET    USE_YN = '0',
		       DELETE_YN = '1'
		WHERE  MENU_ID = #{menuId}
	</delete>

	<select id="selectMenuIdListByParentMenuId" parameterType="java.util.HashMap" resultType="java.util.HashMap">
		WITH TREE_TABLE AS
		(SELECT SR.UPPER_SYS_RESOURCE_ID, M.MENU_ID,
                1 SORT_SEQUENCE
		 FROM   <include refid="tableMenu" /> M,
		        <include refid="sysResource.tableSysResource" /> SR
		 WHERE  M.MENU_ID = SR.SYS_RESOURCE_ID
		 AND    M.MENU_ID = #{menuId}
		 UNION ALL
		 SELECT SR.UPPER_SYS_RESOURCE_ID, M.MENU_ID,
		        TT.SORT_SEQUENCE + 1 SORT_SEQUENCE
		 FROM   <include refid="tableMenu" /> M,
		        <include refid="sysResource.tableSysResource" /> SR,
		        TREE_TABLE TT
		 WHERE  M.MENU_ID = SR.SYS_RESOURCE_ID
		 AND    SR.UPPER_SYS_RESOURCE_ID = TT.MENU_ID)
		SELECT MENU_ID AS "menuId", CONVERT(NVARCHAR(3), SORT_SEQUENCE) AS "sortSequence"
		FROM   TREE_TABLE
		ORDER BY SORT_SEQUENCE ASC
	</select>
	
	<update id="updateParentMenuId" parameterType="java.util.HashMap">
		UPDATE <include refid="sysResource.tableSysResource" />
		SET    UPPER_SYS_RESOURCE_ID = #{parentMenuId}
		WHERE  SYS_RESOURCE_ID = #{menuId}
	</update>
	
	<update id="updateMenuSequence" parameterType="java.util.HashMap">
		UPDATE <include refid="tableMenu" />
		SET    MENU_SEQUENCE = #{moveToMenuSequence}
		WHERE  MENU_ID = #{menuId}
	</update>
	
	<update id="updateMenuLevel" parameterType="java.util.HashMap">
		UPDATE <include refid="tableMenu" />
		SET    MENU_LEVEL = #{menuLevel}
		WHERE  MENU_ID = #{menuId}
	</update>
	
	<select id="selectMenuListByMenuTree" parameterType="java.util.HashMap" resultMap="menuResult">
		SELECT SR.UPPER_SYS_RESOURCE_ID, M.MENU_ID, M.MENU_LEVEL, M.MENU_SEQUENCE,
		       M.LABEL, M.LABEL_JSON, M.USE_YN,
		       CASE
		          WHEN AM.SYS_RESOURCE_ID IS NULL THEN '0'
		          ELSE '1'
		       END CHECK_YN
		FROM   <include refid="menu.tableMenu" /> M
		       LEFT JOIN <include refid="sysResource.tableSysResource" /> SR
		           ON M.MENU_ID = SR.SYS_RESOURCE_ID
		       <if test="@com.samsung.SdlComparator@isNotEmpty(userId)">
		       LEFT OUTER JOIN (SELECT DISTINCT SYS_RESOURCE_ID
		                        FROM   <include refid="user.tableUserAuthorization" />
		                        WHERE  USER_ID = #{userId}) AM
		           ON M.MENU_ID = AM.SYS_RESOURCE_ID
		       </if>
		       <if test="@com.samsung.SdlComparator@isNotEmpty(workgroupId)">
		       LEFT OUTER JOIN (SELECT DISTINCT SYS_RESOURCE_ID
		                        FROM   <include refid="workgroupMenu.tableWorkAuthorization" />
		                        WHERE  WORKGROUP_ID = #{workgroupId}) AM
		           ON M.MENU_ID = AM.SYS_RESOURCE_ID
		       </if>
		WHERE  M.DELETE_YN = '0'
	</select>

	<select id="selectMenuLevelItem" parameterType="java.util.HashMap" resultMap="menuLevelItems">
		SELECT B.UPPER_SYS_RESOURCE_ID AS PARENTID,
		       A.MENU_ID, A.LABEL, A.LABEL_JSON,
		       A.MENU_LEVEL, A.MENU_SEQUENCE
		FROM   <include refid="tableMenu" /> A
		    INNER JOIN <include refid="sysResource.tableSysResource" /> B
		        ON A.MENU_ID = B.SYS_RESOURCE_ID
		WHERE  A.MENU_LEVEL != 0
		<if test="@com.samsung.SdlComparator@isNotEmpty(menuLevel)">
		AND    A.MENU_LEVEL = #{menuLevel}
		</if>
		AND    A.USE_YN = '1'
		AND    (A.DELETE_YN IS NULL OR A.DELETE_YN != '1')
		ORDER BY A.MENU_LEVEL, PARENTID, A.MENU_SEQUENCE
	</select>

	<select id="selectMenuLevel" parameterType="java.util.HashMap" resultMap="menuTreeInfo">
		SELECT *
		FROM   (<include refid="sqlMenuLevel" />
		        WHERE (A.DELETE_YN IS NULL OR A.DELETE_YN !='1')) AA
		ORDER BY AA.MENU_LEVEL, AA.MENU_SEQUENCE
	</select>

	<select id="selectMenuLevelOne" parameterType="java.util.HashMap" resultMap="menuTreeInfo">
		SELECT *
		FROM   (<include refid="sqlMenuLevel" />
		        WHERE A.MENU_LEVEL IN (0, 1)
		        <if test="@com.samsung.SdlComparator@isNotEmpty(used)">
		        AND   A.USE_YN = #{used}
		        </if>
		        <if test="@com.samsung.SdlComparator@isNotEmpty(upperSysResourceId)">
		        AND   B.UPPER_SYS_RESOURCE_ID = #{upperSysResourceId}
		        </if>
		        AND   (A.DELETE_YN IS NULL OR A.DELETE_YN !='1')) AA
		ORDER BY AA.MENU_LEVEL, AA.MENU_SEQUENCE
	</select>

	<select id="selectMyMenuList" parameterType="java.util.HashMap" resultMap="myMenu">
		SELECT A.MENU_ID, A.LABEL, A.LABEL_JSON,
		       A.PAGE_PATH, MY.MY_MENU_SEQ, A.MENU_LEVEL, A.MENU_SEQUENCE
		FROM   <include refid="tableMyMenu" /> MY
		    INNER JOIN (SELECT M.*, P.PAGE_PATH
		                FROM   <include refid="tableMenu" /> M
		                    INNER JOIN <include refid="sysResource.tableSysResourceMapp" /> SRM
		                        ON M.MENU_ID = SRM.MAIN_SYS_RESOURCE_ID
		                    INNER JOIN <include refid="page.tablePage" /> P
		                        ON SRM.SUB_SYS_RESOURCE_ID = P.PAGE_ID
		                WHERE  M.MENU_LEVEL != 0
		                AND    M.USE_YN = '1'
		                AND    (M.DELETE_YN IS NULL OR M.DELETE_YN != '1')
		                AND    P.USE_YN = '1'
		                AND    (P.DELETE_YN IS NULL OR P.DELETE_YN != '1')
		                AND    P.DEFAULTED = '1') A
		        ON MY.MENU_ID = A.MENU_ID
		WHERE  MY.USER_ID = #{userId}
		ORDER BY MY.MY_MENU_SEQ, A.MENU_LEVEL, A.MENU_SEQUENCE
	</select>
	
	<delete id="deleteMyMenuByUserId" parameterType="java.util.HashMap">
		DELETE FROM <include refid="tableMyMenu" />
		WHERE  USER_ID = #{userId}
	</delete>

	<insert id="insertMyMenu" parameterType="myMenu">
		INSERT INTO <include refid="tableMyMenu" />
		(USER_ID, MENU_ID, MY_MENU_SEQ,
		 FIRST_REG_DATETIME, FIRST_REGR_ID, LAST_MOD_DATETIME, LAST_MODR_ID)
		VALUES
		(#{userId}, #{menuId}, #{myMenuSeq},
		 #{firstRegDatetime}, #{userId}, #{lastModDatetime}, #{userId})
	</insert>
	
	<delete id="deleteMyMenu" parameterType="java.util.HashMap">
		DELETE FROM <include refid="tableMyMenu" />
		WHERE  USER_ID = #{userId}
		AND    MENU_ID = #{menuId}
	</delete>

</mapper>