From 737e570e0b6b6b15ba425e3259143cfb37cd3f31 Mon Sep 17 00:00:00 2001 From: smallchill Date: Wed, 27 Jan 2021 23:09:11 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E4=BC=98=E5=8C=96=E5=A4=9A=E7=A7=9F?= =?UTF-8?q?=E6=88=B7=E8=A7=92=E8=89=B2=E5=88=9B=E5=BB=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/controller/RoleController.java | 19 ++++++++++++++++--- .../system/service/impl/RoleServiceImpl.java | 11 ++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/controller/RoleController.java b/blade-service/blade-system/src/main/java/org/springblade/system/controller/RoleController.java index 8f7b4eea..e5be56e9 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/controller/RoleController.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/controller/RoleController.java @@ -30,6 +30,7 @@ import org.springblade.core.tool.api.R; import org.springblade.core.tool.constant.BladeConstant; import org.springblade.core.tool.constant.RoleConstant; import org.springblade.core.tool.utils.Func; +import org.springblade.system.cache.SysCache; import org.springblade.system.entity.Role; import org.springblade.system.service.IRoleService; import org.springblade.system.vo.GrantVO; @@ -97,11 +98,23 @@ public class RoleController extends BladeController { return R.data(tree); } + /** + * 获取指定角色树形结构 + */ + @GetMapping("/tree-by-id") + @ApiOperationSupport(order = 4) + @ApiOperation(value = "树形结构", notes = "树形结构") + public R> treeById(Long roleId, BladeUser bladeUser) { + Role role = SysCache.getRole(roleId); + List tree = roleService.tree(Func.notNull(role) ? role.getTenantId() : bladeUser.getTenantId()); + return R.data(tree); + } + /** * 新增或修改 */ @PostMapping("/submit") - @ApiOperationSupport(order = 4) + @ApiOperationSupport(order = 5) @ApiOperation(value = "新增或修改", notes = "传入role") public R submit(@Valid @RequestBody Role role) { CacheUtil.clear(SYS_CACHE); @@ -113,7 +126,7 @@ public class RoleController extends BladeController { * 删除 */ @PostMapping("/remove") - @ApiOperationSupport(order = 5) + @ApiOperationSupport(order = 6) @ApiOperation(value = "删除", notes = "传入ids") public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { CacheUtil.clear(SYS_CACHE); @@ -124,7 +137,7 @@ public class RoleController extends BladeController { * 设置角色权限 */ @PostMapping("/grant") - @ApiOperationSupport(order = 6) + @ApiOperationSupport(order = 7) @ApiOperation(value = "权限设置", notes = "传入roleId集合以及menuId集合") public R grant(@RequestBody GrantVO grantVO) { CacheUtil.clear(SYS_CACHE); diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/RoleServiceImpl.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/RoleServiceImpl.java index 50aaee47..d9e0d665 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/RoleServiceImpl.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/RoleServiceImpl.java @@ -174,12 +174,17 @@ public class RoleServiceImpl extends ServiceImpl implements IR throw new ServiceException("无权限创建超管角色!"); } } - if (Func.isEmpty(role.getId())) { - role.setTenantId(AuthUtil.getTenantId()); - } if (Func.isEmpty(role.getParentId())) { + role.setTenantId(AuthUtil.getTenantId()); role.setParentId(BladeConstant.TOP_PARENT_ID); } + if (role.getParentId() > 0) { + Role parent = getById(role.getParentId()); + if (Func.toLong(role.getParentId()) == Func.toLong(role.getId())) { + throw new ServiceException("父节点不可选择自身!"); + } + role.setTenantId(parent.getTenantId()); + } role.setIsDeleted(BladeConstant.DB_NOT_DELETED); return saveOrUpdate(role); }