MenuMapper.xml 9.71 KB
<?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.runsa.portal.base.dao.MenuMapper" >
	<cache eviction="LRU" flushInterval="60000" size="512" readOnly="true"/>
	<resultMap id="BaseResultMap" type="cn.runsa.portal.base.entity.Menu">
	    <id column="meId" property="id" />
	    <result column="pltId" property="pltId" />
	    <result column="meSys" property="sys" />
	    <result column="meName" property="name" />
	    <result column="meCode" property="code" />
	    <result column="meAsCode" property="asCode" />
	    <result column="meAsName" property="asname" />
	    <result column="meLevel" property="level" />
	    <result column="meParent" property="parent" />
	    <result column="meType" property="type" />
	    <result column="meUrl" property="url" />
	    <result column="meIcon" property="icon" />
	    <result column="meUptime" property="uptime" />
	    <result column="ptUpdater" property="updater" />
	    <result column="meInclude" property="include" />
	    <collection property="actions" javaType="ArrayList" ofType="cn.runsa.portal.base.entity.MenuAction">
	    	<id column="meaId" property="id" />
	    	<result column="meaName" property="name" />
	    	<result column="meaCode" property="code" />
	    	<result column="meaSort" property="sort" />
	    	<result column="meaSelect" property="select"/>
	    </collection>
  </resultMap>
 <select id="selectList" parameterType="cn.runsa.portal.base.entity.Menu" resultType="cn.runsa.portal.base.entity.Menu" useCache="false">
    select * from smMenu where meDisable=0
    <if test="id!=null">
		and t1.meId=#{id}
	</if>
	<if test="pltId!=null">
	    and t1.pltId=#{pltId}
	</if>
	<if test="name!=null and name!=''">
		and t1.meName=#{name}
	</if>
	<if test="code!=null and code!='' ">
		and t1.meCode=#{code}
	</if>
	<if test="asname!=null and asname!=''">
		and t1.meAsName=#{asname}
	</if>
	<if test="level!=null">
		and t1.meLevel=#{level}
	</if>
	<if test="parent!=null">
		and t1.meParent=#{parent}
	</if>
	<if test="type!=null">
		and t1.meType=#{type}
	</if>
	<if test="url!=null and url!=''">
	    and t1.meUrl=#{url}
	 </if>
	<if test="updater!=null and updater!=''">
		and t1.ptUpdater=#{updater}
	</if>
	order by t1.meId desc
 </select>
 <!-- 按用户查询菜单/菜单动作(权限/shiro) -->
 <select id="selectByUserIds" resultMap="BaseResultMap" useCache="true">
 	select t1.*, 
 	(select count(*) from smMenu where meParent=t1.meId) meInclude,
 	t2.*
	from smMenu t1
	left join smMenuAction t2 on t1.meId=t2.meId and t2.meaId in(
	    select meaId from vUsersMenuAction where usId in 
	    <foreach collection="array" item="usId" open="(" close=")" separator=",">
	    	#{usId}
	    </foreach>
	)
	where t1.meId in (
    	select distinct t3.meParent 
        from vUsersMenuAction t1
        inner join smMenuAction t2 on t1.meaId=t2.meaId
        inner join smMenuInfo t3 on t3.meId=t2.meId
        where t1.usId in 
        <foreach collection="array" item="usId" open="(" close=")" separator=",">
	    	#{usId}
	   	</foreach>
	) 
	<if test="null!=limitParentId">
		and t1.meId in (
			select meId from smMenuInfo where meParent=#{limitParentId}
		)
	</if>
	and t1.meType in(4,5) and t1.meDisable=0
 	order by t1.meParent,t1.meSort asc,t2.meaSort asc
 </select>
 <!-- 按用户查询菜单(首页菜单) -->
 <select id="selectAllByUserIds" resultMap="BaseResultMap" useCache="true">
 	select *, 
 	(select count(*) from smMenu where meParent=t1.meId) meInclude
	from smMenu t1
	<!-- left join smMenuAction t2 on t1.meId=t2.meId and t2.meaId in(
	    select meaId from vUsersMenuAction where usId in 
	    <foreach collection="array" item="usId" open="(" close=")" separator=",">
	    	#{usId}
	    </foreach>
	) -->
	where t1.meId in (
    	select distinct t3.meParent 
        from vUsersMenuAction t1
        inner join smMenuAction t2 on t1.meaId=t2.meaId
        inner join smMenuInfo t3 on t3.meId=t2.meId
        where t1.usId in 
        <foreach collection="array" item="usId" open="(" close=")" separator=",">
	    	#{usId}
	   	</foreach>
	) and t1.meDisable=0
 	order by t1.meParent,t1.meSort asc<!-- ,t2.meaSort asc -->
 </select>
 <select id="selectAllByParent" resultMap="BaseResultMap" useCache="true">
 	select *, 
 	(select count(*) from smMenu where meParent=t1.meId) meInclude
	from smMenu t1
	<!-- left join smMenuAction t2 on t1.meId=t2.meId and t2.meaId in(
	    select meaId from vUsersMenuAction where usId in 
	    <foreach collection="array" item="usId" open="(" close=")" separator=",">
	    	#{usId}
	    </foreach>
	) -->
	where t1.meId in (
    	select distinct t3.meParent 
        from vUsersMenuAction t1
        inner join smMenuAction t2 on t1.meaId=t2.meaId
        inner join smMenuInfo t4 on t4.meId=t2.meId and t4.meParent=#{parent}
        inner join smMenuInfo t3 on t3.meId=t2.meId
        where t1.usId in 
        <foreach collection="userIds" item="usId" open="(" close=")" separator=",">
	    	#{usId}
	   	</foreach>
	) and t1.meDisable=0
 	order by t1.meParent,t1.meSort asc<!-- ,t2.meaSort asc -->
 </select>
 <select id="selectByType" resultMap="BaseResultMap" useCache="true">
 	select *, 
 	(select count(*) from smMenu where meParent=t1.meId) meInclude
	from smMenu t1
	where t1.meId in (
    	select distinct t3.meParent 
        from vUsersMenuAction t1
        inner join smMenuAction t2 on t1.meaId=t2.meaId
        inner join smMenuInfo t3 on t3.meId=t2.meId
        where t1.usId = #{userId}
	) and t1.meType=${type} and t1.meDisable=0 /*and t1.meParent is null*/
	order by t1.meSort asc
 </select>
  <!-- 按平台类型,平台编号,和角色编号查询(当前角色动作是否选择) -->
 <select id="selectByPlatAndRole" resultMap="BaseResultMap" useCache="false">
	select t1.*,t2.*
	<if test="roleId !=null and roleId > 0">
 		,t3.meaId meaSelect
 	</if>
	from smMenu t1 
	left join (
	    select t1.* 
	    from smMenuAction t1 
	    inner join (
	        select meaId from smMenuActionPlatType where pltId=#{platType} and meaId not in(
	            select meaId from smPlatformMenuAction where plId=#{platId} and plmLimit=1
	        )
	        union
	        select meaId from smPlatformMenuAction where plId=#{platId} and plmAppend=1 
	    ) t2 on t1.meaId=t2.meaId
	) t2 on t1.meId=t2.meId
	<if test="roleId !=null and roleId > 0">
		left join smRoleMenuAction t3 on t3.roId=#{roleId} and t3.meaId=t2.meaId
	</if>
	where t1.meId in (
	    select distinct t1.meParent  
	    from smMenuInfo t1 
	    inner join smMenuAction t2 on t1.meId=t2.meId
	    inner join (
	        select meaId from smMenuActionPlatType where pltId=#{platType} and meaId not in(
	            select meaId from smPlatformMenuAction where plId=#{platId} and plmLimit=1
	        )
	        union
	        select meaId from smPlatformMenuAction where plId=#{platId} and plmAppend=1 
	    ) t3 on t2.meaId=t3.meaId
	) and t1.meDisable=0
	order by t1.meParent asc,t1.meSort asc,t2.meaSort asc
 </select>
 <select id="selectByRoleIds" parameterType="list" resultMap="BaseResultMap">
    select  t3.* ,t2.*
    from smRoleMenuAction t1 
    join smMenuAction t2 on t1.meaId=t2.meaId 
    join smMenu t3 on t2.meId=t3.meId and t3.meDisable=0
    where t1.roId in 
    <foreach item="item" index="index" collection="list" open="(" separator="," close=")" >
      #{item}
    </foreach>
 </select>
 <select id="selectAllChild" parameterType="cn.runsa.portal.base.entity.Menu" resultType="cn.runsa.portal.base.entity.Menu" useCache="false">
      select distinct t2.* 
      from smMenuInfo t1 
      inner join smMenu t2 on t1.meId = t2.meId and t2.meDisable=0
      where t1.meParent = #{id}
 </select>
 <select id="selectAllParent" parameterType="cn.runsa.portal.base.entity.Menu" resultType="cn.runsa.portal.base.entity.Menu" useCache="false">
      select distinct t2.* 
      from smMenuInfo t1 
          join smMenu t2 on t1.meParent = t2.meId
      where t1.meId = #{id}
 </select>
 <select id="selectById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select *
     from smMenu  where meId=#{id} 
 </select>
 <insert id="insert" parameterType="cn.runsa.portal.base.entity.Menu" useGeneratedKeys="true" keyProperty="id">
    insert into smMenu(
    meId,ptUpTime,ptUpdater
	<if test="code!=null and code!='' ">
	    ,meCode
	</if>
	<if test="name!=null and name!=''">
		,meName
	</if>
	<if test="asname!=null and asname!=''">
		,meAsName
	</if>
	<if test="level!=null ">
		,meLevel
	</if>
	<if test="pltId!=null ">
		,pltId
	</if>
	<if test="parent!=null ">
		,meParent
	</if>
	<if test="type!=null ">
		,meType
	</if>
	<if test="url!=null ">
		,meUrl
	</if>
	)
	values(
	#{id},now(),#{updater}
	<if test="code!=null and code!='' ">
	    ,#{code}
	</if>
	<if test="name!=null and name!=''">
		,#{name}
	</if>
	<if test="asname!=null and asname!=''">
		,#{asname}
	</if>
	<if test="Level!=null">
		,#{Level}
	</if>
	<if test="pltId!=null">
		,#{pltId}
	</if>
	<if test="parent!=null ">
		,#{parent}
	</if>
	<if test="type!=null ">
		,#{type}
	</if>
	<if test="url!=null and url!=''">
		,#{url}
	</if>
	)
	
 </insert>
 <update id="update"  parameterType="cn.runsa.portal.base.entity.Menu" >
   update smMenu set ptUpTime=now(),ptUpdater=#{updater}
   <if test="code!=null and code!='' ">
	    ,meCode=#{code}
	</if>
	<if test="name!=null and name!=''">
		,meName=#{name}
	</if>
	<if test="asname!=null and asname!=''">
		,meAsName=#{asname}
	</if>
	<if test="Level!=null">
		,meLevel=#{Level}
	</if>
	<if test="pltId!=null">
		,pltId=#{pltId}
	</if>
	<if test="parent!=null ">
		,meParent=#{parent}
	</if>
	<if test="type!=null ">
		,meType=#{type}
	</if>
	<if test="url!=null and url!=''">
		,meUrl=#{url}
	</if>
    where meId = #{id}
 </update>
 <delete id="delete"  parameterType="cn.runsa.portal.base.entity.Menu" >
   delete smMenu where meId=#{id}
 </delete>
</mapper>