<?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="WebMenu">
    
	<select id="selectListMenu" parameterType="hashMap" resultType="hashMap">
		SELECT MM.MENU_CODE             AS "menuCode"
			  ,MM.MENU_NAME             AS "menuName"
			  ,MM.ICON                  AS "icon"
			  ,MM.ICON2                 AS "icon2"
			  ,MM.ACTION                AS "action"
		   <if test="type eq 'A'.toString()">
			  ,IFNULL((SELECT MM2.ACTION
						 FROM MU_MENU AS MM2
						WHERE MM2.USE_YN             = 'Y'
						  AND LENGTH(MM2.MENU_CODE)  > 4
						  AND LEFT(MM2.MENU_CODE, 2) = MM.MENU_CODE
					 ORDER BY MM2.MENU_CODE ASC
						LIMIT 0, 1
			   ),'')                    AS "subAction"
			  ,IFNULL((SELECT MM2.MENU_CODE
						 FROM MU_MENU AS MM2
						WHERE MM2.USE_YN             = 'Y'
						  AND LENGTH(MM2.MENU_CODE)  > 4
						  AND LEFT(MM2.MENU_CODE, 2) = MM.MENU_CODE
					 ORDER BY MM2.MENU_CODE ASC
						LIMIT 0, 1
			   ),'')                    AS "subMenuCode"
		   </if>
		   <if test="type eq 'C'.toString()">
			  ,IFNULL((SELECT MM2.ACTION
						 FROM MU_MENU AS MM2
						WHERE MM2.USE_YN             = 'Y'
						  AND LENGTH(MM2.MENU_CODE)  > 8
						  AND LEFT(MM2.MENU_CODE, 8) = MM.MENU_CODE
					 ORDER BY MM2.MENU_CODE ASC
						LIMIT 0, 1
			   ),'')                    AS "subAction"
			  ,IFNULL((SELECT MM2.MENU_CODE
						 FROM MU_MENU AS MM2
						WHERE MM2.USE_YN             = 'Y'
						  AND LENGTH(MM2.MENU_CODE)  > 8
						  AND LEFT(MM2.MENU_CODE, 8) = MM.MENU_CODE
					 ORDER BY MM2.MENU_CODE ASC
						LIMIT 0, 1
			   ),'')                    AS "subMenuCode"
		   </if>
		  FROM MU_MENU AS MM
		 WHERE MM.USE_YN             = 'Y'
		   <if test="type eq 'A'.toString()">
		   AND LENGTH(MM.MENU_CODE)  = 2
		   </if>
		   <if test="type eq 'B'.toString()">
		   AND LEFT(MM.MENU_CODE, 2) = #{groupCode}
		   AND (LENGTH(MM.MENU_CODE)  = 4
			OR LENGTH(MM.MENU_CODE)  = 6)
		   </if>
		   <if test="type eq 'C'.toString()">
		   AND LEFT(MM.MENU_CODE, 2) = #{groupCode}
		   AND LENGTH(MM.MENU_CODE)  > 6
		   </if>
	  ORDER BY MM.MENU_CODE ASC
	</select>

	<select id="selectMenuCode" parameterType="hashMap" resultType="String">
		SELECT MM.MENU_CODE             AS "menuCode"
		FROM MU_MENU MM
		WHERE MENU_NAME = #{menuName}
		AND USE_YN='Y'
		LIMIT 0,1
	</select>
	
</mapper>