mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-21 02:25:56 +08:00
update 优化 重构业务权限 适配多租户
This commit is contained in:
parent
2be7cc161f
commit
6938c7ef0f
@ -254,8 +254,8 @@ public class SysLoginService {
|
|||||||
loginUser.setDeptId(user.getDeptId());
|
loginUser.setDeptId(user.getDeptId());
|
||||||
loginUser.setUsername(user.getUserName());
|
loginUser.setUsername(user.getUserName());
|
||||||
loginUser.setUserType(user.getUserType());
|
loginUser.setUserType(user.getUserType());
|
||||||
loginUser.setMenuPermission(permissionService.getMenuPermission(user.getUserId(), user.isAdmin()));
|
loginUser.setMenuPermission(permissionService.getMenuPermission(user.getUserId()));
|
||||||
loginUser.setRolePermission(permissionService.getRolePermission(user.getUserId(), user.isAdmin()));
|
loginUser.setRolePermission(permissionService.getRolePermission(user.getUserId()));
|
||||||
loginUser.setDeptName(ObjectUtil.isNull(user.getDept()) ? "" : user.getDept().getDeptName());
|
loginUser.setDeptName(ObjectUtil.isNull(user.getDept()) ? "" : user.getDept().getDeptName());
|
||||||
List<RoleDTO> roles = BeanUtil.copyToList(user.getRoles(), RoleDTO.class);
|
List<RoleDTO> roles = BeanUtil.copyToList(user.getRoles(), RoleDTO.class);
|
||||||
loginUser.setRoles(roles);
|
loginUser.setRoles(roles);
|
||||||
|
|||||||
@ -26,7 +26,12 @@ public interface TenantConstants {
|
|||||||
/**
|
/**
|
||||||
* 超级管理员ID
|
* 超级管理员ID
|
||||||
*/
|
*/
|
||||||
Long TENANT_SUPER_ADMIN_ID = 1L;
|
Long SUPER_ADMIN_ID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 超级管理员角色 roleKey
|
||||||
|
*/
|
||||||
|
String SUPER_ADMIN_ROLE_KEY = "superadmin";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 租户管理员角色 roleKey
|
* 租户管理员角色 roleKey
|
||||||
|
|||||||
@ -35,7 +35,6 @@ import java.lang.reflect.Method;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据权限过滤
|
* 数据权限过滤
|
||||||
@ -79,7 +78,7 @@ public class PlusDataPermissionHandler {
|
|||||||
DataPermissionHelper.setVariable("user", currentUser);
|
DataPermissionHelper.setVariable("user", currentUser);
|
||||||
}
|
}
|
||||||
// 如果是超级管理员,则不过滤数据
|
// 如果是超级管理员,则不过滤数据
|
||||||
if (LoginHelper.isAdmin()) {
|
if (LoginHelper.isSuperAdmin()) {
|
||||||
return where;
|
return where;
|
||||||
}
|
}
|
||||||
String dataFilterSql = buildDataFilter(dataColumns, isSelect);
|
String dataFilterSql = buildDataFilter(dataColumns, isSelect);
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package com.ruoyi.common.satoken.utils;
|
|||||||
import cn.dev33.satoken.context.SaHolder;
|
import cn.dev33.satoken.context.SaHolder;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.ruoyi.common.core.constant.TenantConstants;
|
||||||
import com.ruoyi.common.core.constant.UserConstants;
|
import com.ruoyi.common.core.constant.UserConstants;
|
||||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||||
import com.ruoyi.common.core.enums.DeviceType;
|
import com.ruoyi.common.core.enums.DeviceType;
|
||||||
@ -12,6 +13,8 @@ import com.ruoyi.common.core.utils.StringUtils;
|
|||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录鉴权助手
|
* 登录鉴权助手
|
||||||
* <p>
|
* <p>
|
||||||
@ -132,17 +135,31 @@ public class LoginHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否为管理员
|
* 是否为超级管理员
|
||||||
*
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public static boolean isAdmin(Long userId) {
|
public static boolean isSuperAdmin(Long userId) {
|
||||||
return UserConstants.SUPER_ADMIN_ID.equals(userId);
|
return UserConstants.SUPER_ADMIN_ID.equals(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAdmin() {
|
public static boolean isSuperAdmin() {
|
||||||
return isAdmin(getUserId());
|
return isSuperAdmin(getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为超级管理员
|
||||||
|
*
|
||||||
|
* @param rolePermission 角色权限标识组
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public static boolean isTenantAdmin(Set<String> rolePermission) {
|
||||||
|
return rolePermission.contains(TenantConstants.TENANT_ADMIN_ROLE_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isTenantAdmin() {
|
||||||
|
return isTenantAdmin(getLoginUser().getRolePermission());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
package com.ruoyi.system.controller.system;
|
package com.ruoyi.system.controller.system;
|
||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckRole;
|
||||||
|
import cn.dev33.satoken.annotation.SaMode;
|
||||||
import cn.hutool.core.lang.tree.Tree;
|
import cn.hutool.core.lang.tree.Tree;
|
||||||
|
import com.ruoyi.common.core.constant.TenantConstants;
|
||||||
import com.ruoyi.common.core.constant.UserConstants;
|
import com.ruoyi.common.core.constant.UserConstants;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
@ -35,6 +38,10 @@ public class SysMenuController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 获取菜单列表
|
* 获取菜单列表
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(value = {
|
||||||
|
TenantConstants.SUPER_ADMIN_ROLE_KEY,
|
||||||
|
TenantConstants.TENANT_ADMIN_ROLE_KEY
|
||||||
|
}, mode = SaMode.OR)
|
||||||
@SaCheckPermission("system:menu:list")
|
@SaCheckPermission("system:menu:list")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public R<List<SysMenuVo>> list(SysMenuBo menu) {
|
public R<List<SysMenuVo>> list(SysMenuBo menu) {
|
||||||
@ -47,6 +54,10 @@ public class SysMenuController extends BaseController {
|
|||||||
*
|
*
|
||||||
* @param menuId 菜单ID
|
* @param menuId 菜单ID
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(value = {
|
||||||
|
TenantConstants.SUPER_ADMIN_ROLE_KEY,
|
||||||
|
TenantConstants.TENANT_ADMIN_ROLE_KEY
|
||||||
|
}, mode = SaMode.OR)
|
||||||
@SaCheckPermission("system:menu:query")
|
@SaCheckPermission("system:menu:query")
|
||||||
@GetMapping(value = "/{menuId}")
|
@GetMapping(value = "/{menuId}")
|
||||||
public R<SysMenuVo> getInfo(@PathVariable Long menuId) {
|
public R<SysMenuVo> getInfo(@PathVariable Long menuId) {
|
||||||
@ -56,6 +67,11 @@ public class SysMenuController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 获取菜单下拉树列表
|
* 获取菜单下拉树列表
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(value = {
|
||||||
|
TenantConstants.SUPER_ADMIN_ROLE_KEY,
|
||||||
|
TenantConstants.TENANT_ADMIN_ROLE_KEY
|
||||||
|
}, mode = SaMode.OR)
|
||||||
|
@SaCheckPermission("system:menu:query")
|
||||||
@GetMapping("/treeselect")
|
@GetMapping("/treeselect")
|
||||||
public R<List<Tree<Long>>> treeselect(SysMenuBo menu) {
|
public R<List<Tree<Long>>> treeselect(SysMenuBo menu) {
|
||||||
List<SysMenuVo> menus = menuService.selectMenuList(menu, LoginHelper.getUserId());
|
List<SysMenuVo> menus = menuService.selectMenuList(menu, LoginHelper.getUserId());
|
||||||
@ -67,6 +83,11 @@ public class SysMenuController extends BaseController {
|
|||||||
*
|
*
|
||||||
* @param roleId 角色ID
|
* @param roleId 角色ID
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(value = {
|
||||||
|
TenantConstants.SUPER_ADMIN_ROLE_KEY,
|
||||||
|
TenantConstants.TENANT_ADMIN_ROLE_KEY
|
||||||
|
}, mode = SaMode.OR)
|
||||||
|
@SaCheckPermission("system:menu:query")
|
||||||
@GetMapping(value = "/roleMenuTreeselect/{roleId}")
|
@GetMapping(value = "/roleMenuTreeselect/{roleId}")
|
||||||
public R<MenuTreeSelectVo> roleMenuTreeselect(@PathVariable("roleId") Long roleId) {
|
public R<MenuTreeSelectVo> roleMenuTreeselect(@PathVariable("roleId") Long roleId) {
|
||||||
List<SysMenuVo> menus = menuService.selectMenuList(LoginHelper.getUserId());
|
List<SysMenuVo> menus = menuService.selectMenuList(LoginHelper.getUserId());
|
||||||
@ -81,6 +102,8 @@ public class SysMenuController extends BaseController {
|
|||||||
*
|
*
|
||||||
* @param packageId 租户套餐ID
|
* @param packageId 租户套餐ID
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
|
@SaCheckPermission("system:menu:query")
|
||||||
@GetMapping(value = "/tenantPackageMenuTreeselect/{packageId}")
|
@GetMapping(value = "/tenantPackageMenuTreeselect/{packageId}")
|
||||||
public R<MenuTreeSelectVo> tenantPackageMenuTreeselect(@PathVariable("packageId") Long packageId) {
|
public R<MenuTreeSelectVo> tenantPackageMenuTreeselect(@PathVariable("packageId") Long packageId) {
|
||||||
List<SysMenuVo> menus = menuService.selectMenuList(LoginHelper.getUserId());
|
List<SysMenuVo> menus = menuService.selectMenuList(LoginHelper.getUserId());
|
||||||
@ -93,6 +116,7 @@ public class SysMenuController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 新增菜单
|
* 新增菜单
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
@SaCheckPermission("system:menu:add")
|
@SaCheckPermission("system:menu:add")
|
||||||
@Log(title = "菜单管理", businessType = BusinessType.INSERT)
|
@Log(title = "菜单管理", businessType = BusinessType.INSERT)
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ -108,6 +132,7 @@ public class SysMenuController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 修改菜单
|
* 修改菜单
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
@SaCheckPermission("system:menu:edit")
|
@SaCheckPermission("system:menu:edit")
|
||||||
@Log(title = "菜单管理", businessType = BusinessType.UPDATE)
|
@Log(title = "菜单管理", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@ -127,6 +152,7 @@ public class SysMenuController extends BaseController {
|
|||||||
*
|
*
|
||||||
* @param menuId 菜单ID
|
* @param menuId 菜单ID
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
@SaCheckPermission("system:menu:remove")
|
@SaCheckPermission("system:menu:remove")
|
||||||
@Log(title = "菜单管理", businessType = BusinessType.DELETE)
|
@Log(title = "菜单管理", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{menuId}")
|
@DeleteMapping("/{menuId}")
|
||||||
@ -139,4 +165,5 @@ public class SysMenuController extends BaseController {
|
|||||||
}
|
}
|
||||||
return toAjax(menuService.deleteMenuById(menuId));
|
return toAjax(menuService.deleteMenuById(menuId));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -113,8 +113,8 @@ public class SysRoleController extends BaseController {
|
|||||||
// 更新缓存用户权限
|
// 更新缓存用户权限
|
||||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||||
SysUserVo sysUser = userService.selectUserById(loginUser.getUserId());
|
SysUserVo sysUser = userService.selectUserById(loginUser.getUserId());
|
||||||
if (ObjectUtil.isNotNull(sysUser) && !LoginHelper.isAdmin()) {
|
if (ObjectUtil.isNotNull(sysUser)) {
|
||||||
loginUser.setMenuPermission(permissionService.getMenuPermission(sysUser.getUserId(), sysUser.isAdmin()));
|
loginUser.setMenuPermission(permissionService.getMenuPermission(sysUser.getUserId()));
|
||||||
LoginHelper.setLoginUser(loginUser);
|
LoginHelper.setLoginUser(loginUser);
|
||||||
}
|
}
|
||||||
return R.ok();
|
return R.ok();
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
package com.ruoyi.system.controller.system;
|
package com.ruoyi.system.controller.system;
|
||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckRole;
|
||||||
import com.baomidou.lock.annotation.Lock4j;
|
import com.baomidou.lock.annotation.Lock4j;
|
||||||
|
import com.ruoyi.common.core.constant.TenantConstants;
|
||||||
import com.ruoyi.common.core.constant.UserConstants;
|
import com.ruoyi.common.core.constant.UserConstants;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.common.core.exception.ServiceException;
|
import com.ruoyi.common.core.exception.ServiceException;
|
||||||
@ -45,6 +47,7 @@ public class SysTenantController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 查询租户列表
|
* 查询租户列表
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
@SaCheckPermission("system:tenant:list")
|
@SaCheckPermission("system:tenant:list")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public TableDataInfo<SysTenantVo> list(SysTenantBo bo, PageQuery pageQuery) {
|
public TableDataInfo<SysTenantVo> list(SysTenantBo bo, PageQuery pageQuery) {
|
||||||
@ -54,6 +57,7 @@ public class SysTenantController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 导出租户列表
|
* 导出租户列表
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
@SaCheckPermission("system:tenant:export")
|
@SaCheckPermission("system:tenant:export")
|
||||||
@Log(title = "租户", businessType = BusinessType.EXPORT)
|
@Log(title = "租户", businessType = BusinessType.EXPORT)
|
||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
@ -67,6 +71,7 @@ public class SysTenantController extends BaseController {
|
|||||||
*
|
*
|
||||||
* @param id 主键
|
* @param id 主键
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
@SaCheckPermission("system:tenant:query")
|
@SaCheckPermission("system:tenant:query")
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public R<SysTenantVo> getInfo(@NotNull(message = "主键不能为空")
|
public R<SysTenantVo> getInfo(@NotNull(message = "主键不能为空")
|
||||||
@ -77,6 +82,7 @@ public class SysTenantController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 新增租户
|
* 新增租户
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
@SaCheckPermission("system:tenant:add")
|
@SaCheckPermission("system:tenant:add")
|
||||||
@Log(title = "租户", businessType = BusinessType.INSERT)
|
@Log(title = "租户", businessType = BusinessType.INSERT)
|
||||||
@Lock4j
|
@Lock4j
|
||||||
@ -95,6 +101,7 @@ public class SysTenantController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 修改租户
|
* 修改租户
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
@SaCheckPermission("system:tenant:edit")
|
@SaCheckPermission("system:tenant:edit")
|
||||||
@Log(title = "租户", businessType = BusinessType.UPDATE)
|
@Log(title = "租户", businessType = BusinessType.UPDATE)
|
||||||
@RepeatSubmit()
|
@RepeatSubmit()
|
||||||
@ -106,6 +113,7 @@ public class SysTenantController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 状态修改
|
* 状态修改
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
@SaCheckPermission("system:tenantPackage:edit")
|
@SaCheckPermission("system:tenantPackage:edit")
|
||||||
@Log(title = "租户套餐", businessType = BusinessType.UPDATE)
|
@Log(title = "租户套餐", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping("/changeStatus")
|
@PutMapping("/changeStatus")
|
||||||
@ -118,6 +126,7 @@ public class SysTenantController extends BaseController {
|
|||||||
*
|
*
|
||||||
* @param ids 主键串
|
* @param ids 主键串
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
@SaCheckPermission("system:tenant:remove")
|
@SaCheckPermission("system:tenant:remove")
|
||||||
@Log(title = "租户", businessType = BusinessType.DELETE)
|
@Log(title = "租户", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{ids}")
|
@DeleteMapping("/{ids}")
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package com.ruoyi.system.controller.system;
|
package com.ruoyi.system.controller.system;
|
||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckRole;
|
||||||
|
import com.ruoyi.common.core.constant.TenantConstants;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.common.core.validate.AddGroup;
|
import com.ruoyi.common.core.validate.AddGroup;
|
||||||
import com.ruoyi.common.core.validate.EditGroup;
|
import com.ruoyi.common.core.validate.EditGroup;
|
||||||
@ -39,6 +41,7 @@ public class SysTenantPackageController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 查询租户套餐列表
|
* 查询租户套餐列表
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
@SaCheckPermission("system:tenantPackage:list")
|
@SaCheckPermission("system:tenantPackage:list")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public TableDataInfo<SysTenantPackageVo> list(SysTenantPackageBo bo, PageQuery pageQuery) {
|
public TableDataInfo<SysTenantPackageVo> list(SysTenantPackageBo bo, PageQuery pageQuery) {
|
||||||
@ -48,6 +51,7 @@ public class SysTenantPackageController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 导出租户套餐列表
|
* 导出租户套餐列表
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
@SaCheckPermission("system:tenantPackage:export")
|
@SaCheckPermission("system:tenantPackage:export")
|
||||||
@Log(title = "租户套餐", businessType = BusinessType.EXPORT)
|
@Log(title = "租户套餐", businessType = BusinessType.EXPORT)
|
||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
@ -61,6 +65,7 @@ public class SysTenantPackageController extends BaseController {
|
|||||||
*
|
*
|
||||||
* @param packageId 主键
|
* @param packageId 主键
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
@SaCheckPermission("system:tenantPackage:query")
|
@SaCheckPermission("system:tenantPackage:query")
|
||||||
@GetMapping("/{packageId}")
|
@GetMapping("/{packageId}")
|
||||||
public R<SysTenantPackageVo> getInfo(@NotNull(message = "主键不能为空")
|
public R<SysTenantPackageVo> getInfo(@NotNull(message = "主键不能为空")
|
||||||
@ -71,6 +76,7 @@ public class SysTenantPackageController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 新增租户套餐
|
* 新增租户套餐
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
@SaCheckPermission("system:tenantPackage:add")
|
@SaCheckPermission("system:tenantPackage:add")
|
||||||
@Log(title = "租户套餐", businessType = BusinessType.INSERT)
|
@Log(title = "租户套餐", businessType = BusinessType.INSERT)
|
||||||
@RepeatSubmit()
|
@RepeatSubmit()
|
||||||
@ -82,6 +88,7 @@ public class SysTenantPackageController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 修改租户套餐
|
* 修改租户套餐
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
@SaCheckPermission("system:tenantPackage:edit")
|
@SaCheckPermission("system:tenantPackage:edit")
|
||||||
@Log(title = "租户套餐", businessType = BusinessType.UPDATE)
|
@Log(title = "租户套餐", businessType = BusinessType.UPDATE)
|
||||||
@RepeatSubmit()
|
@RepeatSubmit()
|
||||||
@ -93,6 +100,7 @@ public class SysTenantPackageController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 状态修改
|
* 状态修改
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
@SaCheckPermission("system:tenantPackage:edit")
|
@SaCheckPermission("system:tenantPackage:edit")
|
||||||
@Log(title = "租户套餐", businessType = BusinessType.UPDATE)
|
@Log(title = "租户套餐", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping("/changeStatus")
|
@PutMapping("/changeStatus")
|
||||||
@ -105,6 +113,7 @@ public class SysTenantPackageController extends BaseController {
|
|||||||
*
|
*
|
||||||
* @param packageIds 主键串
|
* @param packageIds 主键串
|
||||||
*/
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
@SaCheckPermission("system:tenantPackage:remove")
|
@SaCheckPermission("system:tenantPackage:remove")
|
||||||
@Log(title = "租户套餐", businessType = BusinessType.DELETE)
|
@Log(title = "租户套餐", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{packageIds}")
|
@DeleteMapping("/{packageIds}")
|
||||||
|
|||||||
@ -114,7 +114,7 @@ public class SysUserController extends BaseController {
|
|||||||
userService.checkUserDataScope(userId);
|
userService.checkUserDataScope(userId);
|
||||||
SysUserInfoVo userInfoVo = new SysUserInfoVo();
|
SysUserInfoVo userInfoVo = new SysUserInfoVo();
|
||||||
List<SysRoleVo> roles = roleService.selectRoleAll();
|
List<SysRoleVo> roles = roleService.selectRoleAll();
|
||||||
userInfoVo.setRoles(LoginHelper.isAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isAdmin()));
|
userInfoVo.setRoles(LoginHelper.isSuperAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isSuperAdmin()));
|
||||||
userInfoVo.setPosts(postService.selectPostAll());
|
userInfoVo.setPosts(postService.selectPostAll());
|
||||||
if (ObjectUtil.isNotNull(userId)) {
|
if (ObjectUtil.isNotNull(userId)) {
|
||||||
SysUserVo sysUser = userService.selectUserById(userId);
|
SysUserVo sysUser = userService.selectUserById(userId);
|
||||||
@ -224,7 +224,7 @@ public class SysUserController extends BaseController {
|
|||||||
List<SysRoleVo> roles = roleService.selectRolesByUserId(userId);
|
List<SysRoleVo> roles = roleService.selectRolesByUserId(userId);
|
||||||
SysUserInfoVo userInfoVo = new SysUserInfoVo();
|
SysUserInfoVo userInfoVo = new SysUserInfoVo();
|
||||||
userInfoVo.setUser(user);
|
userInfoVo.setUser(user);
|
||||||
userInfoVo.setRoles(LoginHelper.isAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isAdmin()));
|
userInfoVo.setRoles(LoginHelper.isSuperAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isSuperAdmin()));
|
||||||
return R.ok(userInfoVo);
|
return R.ok(userInfoVo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -108,7 +108,7 @@ public class SysUser extends TenantEntity {
|
|||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAdmin() {
|
public boolean isSuperAdmin() {
|
||||||
return UserConstants.SUPER_ADMIN_ID.equals(this.userId);
|
return UserConstants.SUPER_ADMIN_ID.equals(this.userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -87,7 +87,7 @@ public class SysRoleBo extends BaseEntity {
|
|||||||
this.roleId = roleId;
|
this.roleId = roleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAdmin() {
|
public boolean isSuperAdmin() {
|
||||||
return UserConstants.SUPER_ADMIN_ID.equals(this.roleId);
|
return UserConstants.SUPER_ADMIN_ID.equals(this.roleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -123,7 +123,7 @@ public class SysUserBo extends BaseEntity {
|
|||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAdmin() {
|
public boolean isSuperAdmin() {
|
||||||
return UserConstants.SUPER_ADMIN_ID.equals(this.userId);
|
return UserConstants.SUPER_ADMIN_ID.equals(this.userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -90,7 +90,7 @@ public class SysRoleVo implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private boolean flag = false;
|
private boolean flag = false;
|
||||||
|
|
||||||
public boolean isAdmin() {
|
public boolean isSuperAdmin() {
|
||||||
return UserConstants.SUPER_ADMIN_ID.equals(this.roleId);
|
return UserConstants.SUPER_ADMIN_ID.equals(this.roleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package com.ruoyi.system.domain.vo;
|
package com.ruoyi.system.domain.vo;
|
||||||
|
|
||||||
import com.ruoyi.common.core.constant.UserConstants;
|
|
||||||
import com.ruoyi.common.translation.annotation.Translation;
|
import com.ruoyi.common.translation.annotation.Translation;
|
||||||
import com.ruoyi.common.translation.constant.TransConstant;
|
import com.ruoyi.common.translation.constant.TransConstant;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -128,8 +127,4 @@ public class SysUserVo implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Long roleId;
|
private Long roleId;
|
||||||
|
|
||||||
public boolean isAdmin() {
|
|
||||||
return UserConstants.SUPER_ADMIN_ID.equals(this.userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,18 +13,16 @@ public interface ISysPermissionService {
|
|||||||
* 获取角色数据权限
|
* 获取角色数据权限
|
||||||
*
|
*
|
||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
* @param isAdmin 是否管理员
|
|
||||||
* @return 角色权限信息
|
* @return 角色权限信息
|
||||||
*/
|
*/
|
||||||
Set<String> getRolePermission(Long userId, boolean isAdmin);
|
Set<String> getRolePermission(Long userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取菜单数据权限
|
* 获取菜单数据权限
|
||||||
*
|
*
|
||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
* @param isAdmin 是否管理员
|
|
||||||
* @return 菜单权限信息
|
* @return 菜单权限信息
|
||||||
*/
|
*/
|
||||||
Set<String> getMenuPermission(Long userId, boolean isAdmin);
|
Set<String> getMenuPermission(Long userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -213,7 +213,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void checkDeptDataScope(Long deptId) {
|
public void checkDeptDataScope(Long deptId) {
|
||||||
if (!LoginHelper.isAdmin()) {
|
if (!LoginHelper.isSuperAdmin()) {
|
||||||
SysDeptBo dept = new SysDeptBo();
|
SysDeptBo dept = new SysDeptBo();
|
||||||
dept.setDeptId(deptId);
|
dept.setDeptId(deptId);
|
||||||
List<SysDeptVo> depts = this.selectDeptList(dept);
|
List<SysDeptVo> depts = this.selectDeptList(dept);
|
||||||
|
|||||||
@ -67,7 +67,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|||||||
public List<SysMenuVo> selectMenuList(SysMenuBo menu, Long userId) {
|
public List<SysMenuVo> selectMenuList(SysMenuBo menu, Long userId) {
|
||||||
List<SysMenuVo> menuList;
|
List<SysMenuVo> menuList;
|
||||||
// 管理员显示所有菜单信息
|
// 管理员显示所有菜单信息
|
||||||
if (LoginHelper.isAdmin(userId)) {
|
if (LoginHelper.isSuperAdmin(userId)) {
|
||||||
menuList = baseMapper.selectVoList(new LambdaQueryWrapper<SysMenu>()
|
menuList = baseMapper.selectVoList(new LambdaQueryWrapper<SysMenu>()
|
||||||
.like(StringUtils.isNotBlank(menu.getMenuName()), SysMenu::getMenuName, menu.getMenuName())
|
.like(StringUtils.isNotBlank(menu.getMenuName()), SysMenu::getMenuName, menu.getMenuName())
|
||||||
.eq(StringUtils.isNotBlank(menu.getVisible()), SysMenu::getVisible, menu.getVisible())
|
.eq(StringUtils.isNotBlank(menu.getVisible()), SysMenu::getVisible, menu.getVisible())
|
||||||
@ -133,7 +133,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|||||||
@Override
|
@Override
|
||||||
public List<SysMenu> selectMenuTreeByUserId(Long userId) {
|
public List<SysMenu> selectMenuTreeByUserId(Long userId) {
|
||||||
List<SysMenu> menus;
|
List<SysMenu> menus;
|
||||||
if (LoginHelper.isAdmin(userId)) {
|
if (LoginHelper.isSuperAdmin(userId)) {
|
||||||
menus = baseMapper.selectMenuTreeAll();
|
menus = baseMapper.selectMenuTreeAll();
|
||||||
} else {
|
} else {
|
||||||
menus = baseMapper.selectMenuTreeByUserId(userId);
|
menus = baseMapper.selectMenuTreeByUserId(userId);
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package com.ruoyi.system.service.impl;
|
package com.ruoyi.system.service.impl;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.constant.TenantConstants;
|
||||||
|
import com.ruoyi.common.satoken.utils.LoginHelper;
|
||||||
import com.ruoyi.system.service.ISysMenuService;
|
import com.ruoyi.system.service.ISysMenuService;
|
||||||
import com.ruoyi.system.service.ISysPermissionService;
|
import com.ruoyi.system.service.ISysPermissionService;
|
||||||
import com.ruoyi.system.service.ISysRoleService;
|
import com.ruoyi.system.service.ISysRoleService;
|
||||||
@ -25,15 +27,14 @@ public class SysPermissionServiceImpl implements ISysPermissionService {
|
|||||||
* 获取角色数据权限
|
* 获取角色数据权限
|
||||||
*
|
*
|
||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
* @param isAdmin 是否管理员
|
|
||||||
* @return 角色权限信息
|
* @return 角色权限信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getRolePermission(Long userId, boolean isAdmin) {
|
public Set<String> getRolePermission(Long userId) {
|
||||||
Set<String> roles = new HashSet<>();
|
Set<String> roles = new HashSet<>();
|
||||||
// 管理员拥有所有权限
|
// 管理员拥有所有权限
|
||||||
if (isAdmin) {
|
if (LoginHelper.isSuperAdmin(userId)) {
|
||||||
roles.add("admin");
|
roles.add(TenantConstants.SUPER_ADMIN_ROLE_KEY);
|
||||||
} else {
|
} else {
|
||||||
roles.addAll(roleService.selectRolePermissionByUserId(userId));
|
roles.addAll(roleService.selectRolePermissionByUserId(userId));
|
||||||
}
|
}
|
||||||
@ -44,14 +45,13 @@ public class SysPermissionServiceImpl implements ISysPermissionService {
|
|||||||
* 获取菜单数据权限
|
* 获取菜单数据权限
|
||||||
*
|
*
|
||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
* @param isAdmin 是否管理员
|
|
||||||
* @return 菜单权限信息
|
* @return 菜单权限信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getMenuPermission(Long userId, boolean isAdmin) {
|
public Set<String> getMenuPermission(Long userId) {
|
||||||
Set<String> perms = new HashSet<>();
|
Set<String> perms = new HashSet<>();
|
||||||
// 管理员拥有所有权限
|
// 管理员拥有所有权限
|
||||||
if (isAdmin) {
|
if (LoginHelper.isSuperAdmin(userId)) {
|
||||||
perms.add("*:*:*");
|
perms.add("*:*:*");
|
||||||
} else {
|
} else {
|
||||||
perms.addAll(menuService.selectMenuPermsByUserId(userId));
|
perms.addAll(menuService.selectMenuPermsByUserId(userId));
|
||||||
|
|||||||
@ -189,7 +189,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void checkRoleAllowed(SysRoleBo role) {
|
public void checkRoleAllowed(SysRoleBo role) {
|
||||||
if (ObjectUtil.isNotNull(role.getRoleId()) && role.isAdmin()) {
|
if (ObjectUtil.isNotNull(role.getRoleId()) && role.isSuperAdmin()) {
|
||||||
throw new ServiceException("不允许操作超级管理员角色");
|
throw new ServiceException("不允许操作超级管理员角色");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,7 +201,7 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void checkRoleDataScope(Long roleId) {
|
public void checkRoleDataScope(Long roleId) {
|
||||||
if (!LoginHelper.isAdmin()) {
|
if (!LoginHelper.isSuperAdmin()) {
|
||||||
SysRoleBo role = new SysRoleBo();
|
SysRoleBo role = new SysRoleBo();
|
||||||
role.setRoleId(roleId);
|
role.setRoleId(roleId);
|
||||||
List<SysRoleVo> roles = this.selectRoleList(role);
|
List<SysRoleVo> roles = this.selectRoleList(role);
|
||||||
|
|||||||
@ -20,7 +20,7 @@ public class SysSensitiveServiceImpl implements SensitiveService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isSensitive() {
|
public boolean isSensitive() {
|
||||||
return !LoginHelper.isAdmin();
|
return !LoginHelper.isSuperAdmin() || !LoginHelper.isTenantAdmin();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -250,7 +250,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void checkUserAllowed(SysUserBo user) {
|
public void checkUserAllowed(SysUserBo user) {
|
||||||
if (ObjectUtil.isNotNull(user.getUserId()) && user.isAdmin()) {
|
if (ObjectUtil.isNotNull(user.getUserId()) && user.isSuperAdmin()) {
|
||||||
throw new ServiceException("不允许操作超级管理员用户");
|
throw new ServiceException("不允许操作超级管理员用户");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,7 +262,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void checkUserDataScope(Long userId) {
|
public void checkUserDataScope(Long userId) {
|
||||||
if (!LoginHelper.isAdmin()) {
|
if (!LoginHelper.isSuperAdmin()) {
|
||||||
SysUserBo user = new SysUserBo();
|
SysUserBo user = new SysUserBo();
|
||||||
user.setUserId(userId);
|
user.setUserId(userId);
|
||||||
List<SysUserVo> users = this.selectUserList(user);
|
List<SysUserVo> users = this.selectUserList(user);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user