Browse Source

超管默认拥有所有菜单权限

test
smallchill 6 years ago
parent
commit
4e4b8d5011
  1. 8
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.java
  2. 42
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.xml
  3. 7
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/MenuServiceImpl.java

8
blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.java

@ -132,6 +132,13 @@ public interface MenuMapper extends BaseMapper<Menu> {
*/
List<Menu> routes(List<Long> roleId);
/**
* 按钮树形结构
*
* @return
*/
List<Menu> allButtons();
/**
* 按钮树形结构
*
@ -142,6 +149,7 @@ public interface MenuMapper extends BaseMapper<Menu> {
/**
* 获取配置的角色权限
*
* @param roleIds
* @return
*/

42
blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.xml

@ -66,6 +66,48 @@
</foreach> )
</select>
<select id="allButtons" resultMap="menuResultMap">
SELECT
*
FROM
(
SELECT
id,
parent_id,
CODE,
NAME,
alias,
path,
source,
action,
sort
FROM
blade_menu
WHERE
id IN ( SELECT parent_id FROM blade_menu WHERE is_deleted = 0 AND category = 2 )
UNION ALL
SELECT
id,
parent_id,
CODE,
NAME,
alias,
path,
source,
action,
sort
FROM
blade_menu
WHERE
is_deleted = 0
AND category = 2
) menu
ORDER BY
sort
</select>
<select id="buttons" resultMap="menuResultMap">
SELECT * FROM (
SELECT

7
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/MenuServiceImpl.java

@ -24,7 +24,6 @@ import lombok.AllArgsConstructor;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.SecureUtil;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.node.ForestNodeMerger;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.Func;
@ -72,10 +71,8 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
if (StringUtil.isBlank(roleId)) {
return null;
}
String userRole = SecureUtil.getUserRole();
boolean isAdministrator = StringUtil.containsAny(userRole, RoleConstant.ADMINISTRATOR);
List<Menu> allMenus = baseMapper.allMenu();
List<Menu> roleMenus = baseMapper.roleMenu(Func.toLongList(roleId), topMenuId);
List<Menu> roleMenus = (SecureUtil.isAdministrator()) ? allMenus : baseMapper.roleMenu(Func.toLongList(roleId), topMenuId);
return buildRoutes(allMenus, roleMenus);
}
@ -98,7 +95,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
@Override
public List<MenuVO> buttons(String roleId) {
List<Menu> buttons = baseMapper.buttons(Func.toLongList(roleId));
List<Menu> buttons = (SecureUtil.isAdministrator()) ? baseMapper.allButtons() : baseMapper.buttons(Func.toLongList(roleId));
MenuWrapper menuWrapper = new MenuWrapper();
return menuWrapper.listNodeVO(buttons);
}

Loading…
Cancel
Save