<?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="cn.superdesk.uniorder.dao.mapper.sys.role.SysMenuMapperEx">

	<resultMap id="TreeResultMap" type="cn.superdesk.uniorder.dto.vo.sys.role.ViewMenuTree">
		<id column="id" property="id" jdbcType="BIGINT"/>
		<result column="pid" property="pid" jdbcType="BIGINT"/>
		<result column="menu_name" property="menuName" jdbcType="VARCHAR"/>
		<result column="menu_url" property="menuUrl" jdbcType="VARCHAR"/>
		<result column="perms" property="perms" jdbcType="VARCHAR"/>
		<result column="menu_type" property="menuType" jdbcType="VARCHAR"/>
		<result column="menu_icon" property="menuIcon" jdbcType="VARCHAR"/>
		<result column="order_num" property="orderNum" jdbcType="INTEGER"/>
		<collection property="childList" ofType="cn.superdesk.uniorder.dto.vo.sys.role.ViewMenuTree"
					javaType="java.util.List" column="id" select="getChildById">
		</collection>
	</resultMap>
	<resultMap id="TreeResultMapNew" type="cn.superdesk.uniorder.dto.vo.sys.role.ViewMenuTree">
		<id column="id" property="id" jdbcType="BIGINT"/>
		<result column="pid" property="pid" jdbcType="BIGINT"/>
		<result column="menu_name" property="menuName" jdbcType="VARCHAR"/>
		<result column="menu_url" property="menuUrl" jdbcType="VARCHAR"/>
		<result column="perms" property="perms" jdbcType="VARCHAR"/>
		<result column="menu_type" property="menuType" jdbcType="VARCHAR"/>
		<result column="menu_icon" property="menuIcon" jdbcType="VARCHAR"/>
		<result column="order_num" property="orderNum" jdbcType="INTEGER"/>
	</resultMap>
	<select id="getTreeByIdNew" resultMap="TreeResultMapNew" parameterType="java.lang.Long">
		select
			id,pid,menu_name,menu_url,perms,menu_type,menu_icon,order_num
		from
			sys_menu sm
		<where>
			<choose>
				<when test="enabled != null and enabled != ''">
					and sm.enabled = #{enabled,jdbcType=TINYINT}
				</when>
				<otherwise>
					and sm.enabled = 1
				</otherwise>
			</choose>

			<choose>
				<when test="deleted != null and deleted != ''">
					and sm.deleted = #{deleted,jdbcType=TINYINT}
				</when>
				<otherwise>
					and sm.deleted = 0
				</otherwise>
			</choose>
		</where>
		order by sm.menu_type, sm.order_num
	</select>
	<select id="getTreeById" resultMap="TreeResultMap" parameterType="java.lang.Long">
		select
			id,pid,menu_name,menu_url,perms,menu_type,menu_icon,order_num
		from
			sys_menu sm
		<where>
			<choose>
				<when test="_parameter != null ">
					and id = #{_parameter,jdbcType=BIGINT}
				</when>
				<otherwise>
					and pid is null
				</otherwise>
			</choose>
			<choose>
				<when test="enabled != null and enabled != ''">
					and sm.enabled = #{enabled,jdbcType=TINYINT}
				</when>
				<otherwise>
					and sm.enabled = 1
				</otherwise>
			</choose>

			<choose>
				<when test="deleted != null and deleted != ''">
					and sm.deleted = #{deleted,jdbcType=TINYINT}
				</when>
				<otherwise>
					and sm.deleted = 0
				</otherwise>
			</choose>
		</where>
		order by sm.order_num
	</select>
	<select id="getChildById" resultMap="TreeResultMap">
		select
			id,pid,menu_name,menu_url,perms,menu_type,menu_icon,order_num
		from
			sys_menu sm
		<where>
			and pid = #{_parameter,jdbcType=BIGINT}
			<choose>
				<when test="enabled != null and enabled != ''">
					and sm.enabled = #{enabled,jdbcType=TINYINT}
				</when>
				<otherwise>
					and sm.enabled = 1
				</otherwise>
			</choose>

			<choose>
				<when test="deleted != null and deleted != ''">
					and sm.deleted = #{deleted,jdbcType=TINYINT}
				</when>
				<otherwise>
					and sm.deleted = 0
				</otherwise>
			</choose>
		</where>
		order by order_num
	</select>
	<select id="findAll" resultMap="cn.superdesk.uniorder.dao.mapper.sys.role.SysMenuMapper.BaseResultMap">
		select
		<include refid="cn.superdesk.uniorder.dao.mapper.sys.role.SysMenuMapper.Base_Column_List"/>
		from
			sys_menu sm
		<where>

			<if test="menuType != null and menuType != '' ">
				and menu_type = #{menuType,jdbcType=INTEGER}
			</if>
			<if test="pid != null and pid != '' ">
				and pid = #{pid,jdbcType=INTEGER}
			</if>
			<choose>
				<when test="enabled != null and enabled != ''">
					and sm.enabled = #{enabled,jdbcType=TINYINT}
				</when>
				<otherwise>
					and sm.enabled = 1
				</otherwise>
			</choose>

			<choose>
				<when test="deleted != null and deleted != ''">
					and sm.deleted = #{deleted,jdbcType=TINYINT}
				</when>
				<otherwise>
					and sm.deleted = 0
				</otherwise>
			</choose>
		</where>
	</select>
</mapper>