From 99c591d6f9c58062663d9037e2a4d50bf99857b1 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Mon, 13 Jul 2020 09:26:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=A7=92=E8=89=B2=E6=9D=83?= =?UTF-8?q?=E9=99=90=E5=88=86=E9=85=8D=E5=8A=9F=E8=83=BD=E7=9A=84=E8=BF=81?= =?UTF-8?q?=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../permission/PermissionController.http | 6 ++++++ .../permission/PermissionController.java | 7 ++++++- .../dto/PermissionAssignRoleResourceDTO.java | 3 ++- .../manager/permission/PermissionManager.java | 14 ++++++++++++++ .../src/main/resources/mapper/AdminRoleMapper.xml | 8 ++++---- .../main/resources/mapper/RoleResourceMapper.xml | 2 +- 6 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/PermissionController.http diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/PermissionController.http b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/PermissionController.http new file mode 100644 index 000000000..e04adee27 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/PermissionController.http @@ -0,0 +1,6 @@ +### /permission/list 成功 +GET {{baseUrl}}/permission/list-role-resource?roleId=1 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{accessToken}} + +### diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/PermissionController.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/PermissionController.java index fb91a0ea9..6c31384d0 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/PermissionController.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/PermissionController.java @@ -1,6 +1,7 @@ package cn.iocoder.mall.managementweb.controller.permission; import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.managementweb.controller.permission.dto.PermissionAssignRoleResourceDTO; import cn.iocoder.mall.managementweb.manager.permission.PermissionManager; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -8,6 +9,7 @@ import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -34,7 +36,10 @@ public class PermissionController { return success(permissionManager.listRoleResource(roleId)); } - public CommonResult assignRoleResource() { + @PostMapping("/assign-role-resource") + @ApiOperation("赋予角色资源") + public CommonResult assignRoleResource(PermissionAssignRoleResourceDTO assignRoleResourceDTO) { + permissionManager.assignRoleResource(assignRoleResourceDTO); return success(true); } diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/PermissionAssignRoleResourceDTO.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/PermissionAssignRoleResourceDTO.java index d5d7e6092..0801b4164 100644 --- a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/PermissionAssignRoleResourceDTO.java +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/PermissionAssignRoleResourceDTO.java @@ -4,6 +4,7 @@ import lombok.Data; import lombok.experimental.Accessors; import javax.validation.constraints.NotNull; +import java.io.Serializable; import java.util.Set; /** @@ -11,7 +12,7 @@ import java.util.Set; */ @Data @Accessors(chain = true) -public class PermissionAssignRoleResourceDTO { +public class PermissionAssignRoleResourceDTO implements Serializable { /** * 角色编号 diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/PermissionManager.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/PermissionManager.java index 1e5a0919c..14e3b7287 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/PermissionManager.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/PermissionManager.java @@ -1,10 +1,15 @@ package cn.iocoder.mall.systemservice.manager.permission; +import cn.iocoder.common.framework.util.CollectionUtils; import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionAssignRoleResourceDTO; import cn.iocoder.mall.systemservice.service.permission.PermissionService; +import cn.iocoder.mall.systemservice.service.permission.ResourceService; +import cn.iocoder.mall.systemservice.service.permission.RoleService; +import cn.iocoder.mall.systemservice.service.permission.bo.ResourceBO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Collections; import java.util.Set; /** @@ -15,6 +20,10 @@ public class PermissionManager { @Autowired private PermissionService permissionService; + @Autowired + private RoleService roleService; + @Autowired + private ResourceService resourceService; /** * 获得角色拥有的资源编号 @@ -23,6 +32,11 @@ public class PermissionManager { * @return 资源编号列表 */ public Set listRoleResourceId(Integer roleId) { + // 超级管理员,拥有所有资源 + if (roleService.hasSuperAdmin(Collections.singleton(roleId))) { + return CollectionUtils.convertSet(resourceService.listResource(), ResourceBO::getId); + } + // 非超级管理员,查询拥有资源 return permissionService.listRoleResourceId(roleId); } diff --git a/system-service-project/system-service-app/src/main/resources/mapper/AdminRoleMapper.xml b/system-service-project/system-service-app/src/main/resources/mapper/AdminRoleMapper.xml index bd085ecff..23859c357 100644 --- a/system-service-project/system-service-app/src/main/resources/mapper/AdminRoleMapper.xml +++ b/system-service-project/system-service-app/src/main/resources/mapper/AdminRoleMapper.xml @@ -3,11 +3,11 @@ - INSERT INTO account_role ( - account_id, role_id, create_time, deleted + INSERT INTO permission_admin_role ( + admin_id, role_id, create_time, deleted ) VALUES - - (#{accountRole.accountId}, #{accountRole.roleId}, #{accountRole.createTime}, #{accountRole.deleted}) + + (#{adminRole.adminId}, #{adminRole.roleId}, #{adminRole.createTime}, #{adminRole.deleted}) diff --git a/system-service-project/system-service-app/src/main/resources/mapper/RoleResourceMapper.xml b/system-service-project/system-service-app/src/main/resources/mapper/RoleResourceMapper.xml index 30ad542ad..21be896ef 100644 --- a/system-service-project/system-service-app/src/main/resources/mapper/RoleResourceMapper.xml +++ b/system-service-project/system-service-app/src/main/resources/mapper/RoleResourceMapper.xml @@ -3,7 +3,7 @@ - INSERT INTO role_resource ( + INSERT INTO permission_role_resource ( resource_id, role_id, create_time, deleted ) VALUES