<?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="com.artfess.sysConfig.persistence.dao.SysSwiftMenuDao">
	<resultMap id="SysSwiftMenu" type="com.artfess.sysConfig.persistence.model.SysSwiftMenu">
		<id property="id" column="ID_" jdbcType="VARCHAR"/>
		<result property="userId" column="USER_ID_" jdbcType="VARCHAR"/>
		<result property="menuAlias" column="MENU_ALIAS_" jdbcType="VARCHAR"/>
		<result property="sn" column="SN_" jdbcType="NUMERIC"/>
	</resultMap>

	<select id="getSwiftMenuByUserId" resultType="com.artfess.sysConfig.persistence.model.SysMenu">
		select sysMenu.*,s.id_ swiftId  from portal_sys_menu sysMenu
		 INNER JOIN portal_sys_swift_menu s on sysMenu.alias_=s.menu_alias_
		  LEFT JOIN portal_sys_role_auth sysRoleAuth on sysMenu.ALIAS_ = sysRoleAuth.MENU_ALIAS_
		 WHERE s.user_id_ = #{userId}  and sysMenu.STATUS_='1' and sysRoleAuth.ROLE_ALIAS_ IN
		<foreach collection="roles" item="role" separator="," open="(" close=")">
			#{role}
		</foreach>
		<if test="tenantId!=null">
			AND	sysRoleAuth.TENANT_ID_=#{tenantId}
		</if>
		<if test="@com.artfess.base.ognl.Ognl@isNotEmpty(parentMenuPath)">
			and sysMenu.path_ like CONCAT(#{parentMenuPath},'%')
		</if>
		<if test="ignoreMenus!=null">
			AND sysMenu.ALIAS_ NOT IN
			<foreach collection="ignoreMenus" item="ignoreMenu" separator="," open="(" close=")">
				#{ignoreMenu}
			</foreach>
		</if>
		ORDER BY s.SN_ ASC
	</select>

	<select id="getSwiftMenuByAdmin" resultType="com.artfess.sysConfig.persistence.model.SysMenu">
		select sysMenu.*,s.id_ swiftId from portal_sys_menu sysMenu
		INNER JOIN portal_sys_swift_menu s on sysMenu.alias_=s.menu_alias_
		WHERE s.user_id_ = #{userId}  and sysMenu.STATUS_='1'
		<if test="@com.artfess.base.ognl.Ognl@isNotEmpty(parentMenuPath)">
		     and sysMenu.path_ like CONCAT(#{parentMenuPath},'%')
		</if>
		ORDER BY s.SN_ ASC
	</select>


	<select id="getParentMenus" resultType="com.artfess.sysConfig.persistence.model.SysMenu">
		select *  from portal_sys_menu
		where   #{menuPath} like CONCAT(path_,'%')
		<if test="@com.artfess.base.ognl.Ognl@isNotEmpty(rootMenuPath)">
		  and  path_ like CONCAT(#{rootMenuPath},'%')
		</if>
		order by path_

	</select>

</mapper>