fix: 角色可分配权限优化

This commit is contained in:
萌狼蓝天 2024-11-07 17:08:58 +08:00
parent b7d9a2036d
commit f18a16ddb9
2 changed files with 17 additions and 2 deletions

View File

@ -22,13 +22,18 @@ public class SystemController {
@Operation( @Operation(
summary = "菜单 加载", summary = "菜单 加载",
description = "加载用户拥有的菜单", description = "加载用户拥有的菜单(用于显示在左侧)",
tags = {"系统相关接口"} tags = {"系统相关接口"}
) )
@GetMapping("/menu") @GetMapping("/menu")
public ResponseEntity getMenu() { public ResponseEntity getMenu() {
return ResponseEntity.ok(systemService.getMenu()); return ResponseEntity.ok(systemService.getMenu());
} }
@Operation(
summary = "菜单 加载 全部",
description = "加载用户拥有的所有菜单,常常用于管理菜单",
tags = {"系统相关接口"}
)
@GetMapping("/menu-all") @GetMapping("/menu-all")
public ResponseEntity getMenuAll() { public ResponseEntity getMenuAll() {
return ResponseEntity.ok(systemService.getMenuAll()); return ResponseEntity.ok(systemService.getMenuAll());

View File

@ -2,6 +2,7 @@ package com.guaiguailang.harmony.service.impl;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import com.guaiguailang.harmony.domain.entity.MenuDataItem; import com.guaiguailang.harmony.domain.entity.MenuDataItem;
import com.guaiguailang.harmony.domain.entity.SystemRole;
import com.guaiguailang.harmony.domain.entity.UserInfo; import com.guaiguailang.harmony.domain.entity.UserInfo;
import com.guaiguailang.harmony.domain.vo.ResponseResult; import com.guaiguailang.harmony.domain.vo.ResponseResult;
import com.guaiguailang.harmony.mapper.SystemMapper; import com.guaiguailang.harmony.mapper.SystemMapper;
@ -37,7 +38,16 @@ public class SystemServiceImpl implements SystemService {
@Override @Override
public ResponseResult getMenuAll() { public ResponseResult getMenuAll() {
List<MenuDataItem> menus = systemMapper.getMenusAll(); // 仅仅管理员放行其他的只能加载自己有的
SystemRole sr = userMapper.getRoleLevelByUserId(Long.parseLong(StpUtil.getLoginId().toString()));
List<MenuDataItem> menus;
if(sr.getLevel()==1){
// 超级管理员加载全部
menus= systemMapper.getMenusAll();
}else {
menus = systemMapper.getMenus(sr.getRoleId());
}
return ResponseResult.success(menus); return ResponseResult.success(menus);
} }