Browse Source

优化多租户角色创建逻辑

test
smallchill 4 years ago
parent
commit
737e570e0b
  1. 19
      blade-service/blade-system/src/main/java/org/springblade/system/controller/RoleController.java
  2. 11
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/RoleServiceImpl.java

19
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.BladeConstant;
import org.springblade.core.tool.constant.RoleConstant; import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springblade.system.cache.SysCache;
import org.springblade.system.entity.Role; import org.springblade.system.entity.Role;
import org.springblade.system.service.IRoleService; import org.springblade.system.service.IRoleService;
import org.springblade.system.vo.GrantVO; import org.springblade.system.vo.GrantVO;
@ -97,11 +98,23 @@ public class RoleController extends BladeController {
return R.data(tree); return R.data(tree);
} }
/**
* 获取指定角色树形结构
*/
@GetMapping("/tree-by-id")
@ApiOperationSupport(order = 4)
@ApiOperation(value = "树形结构", notes = "树形结构")
public R<List<RoleVO>> treeById(Long roleId, BladeUser bladeUser) {
Role role = SysCache.getRole(roleId);
List<RoleVO> tree = roleService.tree(Func.notNull(role) ? role.getTenantId() : bladeUser.getTenantId());
return R.data(tree);
}
/** /**
* 新增或修改 * 新增或修改
*/ */
@PostMapping("/submit") @PostMapping("/submit")
@ApiOperationSupport(order = 4) @ApiOperationSupport(order = 5)
@ApiOperation(value = "新增或修改", notes = "传入role") @ApiOperation(value = "新增或修改", notes = "传入role")
public R submit(@Valid @RequestBody Role role) { public R submit(@Valid @RequestBody Role role) {
CacheUtil.clear(SYS_CACHE); CacheUtil.clear(SYS_CACHE);
@ -113,7 +126,7 @@ public class RoleController extends BladeController {
* 删除 * 删除
*/ */
@PostMapping("/remove") @PostMapping("/remove")
@ApiOperationSupport(order = 5) @ApiOperationSupport(order = 6)
@ApiOperation(value = "删除", notes = "传入ids") @ApiOperation(value = "删除", notes = "传入ids")
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
CacheUtil.clear(SYS_CACHE); CacheUtil.clear(SYS_CACHE);
@ -124,7 +137,7 @@ public class RoleController extends BladeController {
* 设置角色权限 * 设置角色权限
*/ */
@PostMapping("/grant") @PostMapping("/grant")
@ApiOperationSupport(order = 6) @ApiOperationSupport(order = 7)
@ApiOperation(value = "权限设置", notes = "传入roleId集合以及menuId集合") @ApiOperation(value = "权限设置", notes = "传入roleId集合以及menuId集合")
public R grant(@RequestBody GrantVO grantVO) { public R grant(@RequestBody GrantVO grantVO) {
CacheUtil.clear(SYS_CACHE); CacheUtil.clear(SYS_CACHE);

11
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/RoleServiceImpl.java

@ -174,12 +174,17 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
throw new ServiceException("无权限创建超管角色!"); throw new ServiceException("无权限创建超管角色!");
} }
} }
if (Func.isEmpty(role.getId())) {
role.setTenantId(AuthUtil.getTenantId());
}
if (Func.isEmpty(role.getParentId())) { if (Func.isEmpty(role.getParentId())) {
role.setTenantId(AuthUtil.getTenantId());
role.setParentId(BladeConstant.TOP_PARENT_ID); 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); role.setIsDeleted(BladeConstant.DB_NOT_DELETED);
return saveOrUpdate(role); return saveOrUpdate(role);
} }

Loading…
Cancel
Save