From 61e5cfe6174d0cac685377a6b2e47106fc0024ce Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Mon, 13 Jul 2020 19:24:42 +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 --- .../controller/admin/AdminController.java | 2 +- .../permission/PermissionController.http | 5 ++ .../permission/PermissionController.java | 21 +++++- .../permission/ResourceController.java | 4 +- .../controller/permission/RoleController.http | 5 ++ .../controller/permission/RoleController.java | 10 ++- .../dto/PermissionAssignAdminRoleDTO.java | 20 ++++++ .../dto/PermissionAssignRoleResourceDTO.java | 4 +- .../convert/permission/PermissionConvert.java | 3 + .../manager/permission/PermissionManager.java | 34 ++++++++-- .../manager/permission/ResourceManager.java | 2 +- .../manager/permission/RoleManager.java | 15 ++++- .../enums/SystemErrorCodeEnum.java | 2 +- .../rpc/permission/PermissionRpc.java | 19 +++++- .../systemservice/rpc/permission/RoleRpc.java | 9 ++- .../dto/PermissionAssignAdminRoleDTO.java | 27 ++++++++ .../mapper/permission/AdminRoleMapper.java | 26 ++++---- .../manager/permission/PermissionManager.java | 27 +++++++- .../manager/permission/ResourceManager.java | 14 ++-- .../manager/permission/RoleManager.java | 12 +++- .../rpc/permission/PermissionRpcImpl.java | 16 ++++- .../rpc/permission/ResourceRpcImpl.java | 6 +- .../rpc/permission/RoleRpcImpl.java | 9 ++- .../service/permission/PermissionService.java | 66 +++++++++++++++---- .../service/permission/ResourceService.java | 8 +-- .../service/permission/RoleService.java | 10 +++ .../systemlog/bo/ExceptionLogAddBO.java | 3 +- .../main/resources/mapper/AdminRoleMapper.xml | 4 +- .../resources/mapper/RoleResourceMapper.xml | 4 +- .../biz/bo/authorization/AuthorizationBO.java | 15 ----- .../bo/authorization/ResourceTreeNodeBO.java | 24 ------- .../system/biz/bo/authorization/RoleBO.java | 36 ---------- .../authorization/ResourceConvert.java | 22 ------- .../AuthorizationAssignRoleResourceDTO.java | 27 -------- ...thorizationGetResourcesByAccountIdDTO.java | 22 ------- ...uthorizationGetRoleMapByAccountIdsDTO.java | 19 ------ .../AuthorizationGetRoleResourcesDTO.java | 18 ----- .../dto/authorization/ResourceCountDTO.java | 25 ------- .../dto/authorization/ResourceGetListDTO.java | 27 -------- .../dto/authorization/ResourceGetTreeDTO.java | 25 ------- .../OAuth2AccessTokenAuthenticateDTO.java | 20 ------ .../OAuth2MobileCodAuthenticateDTO.java | 14 ---- .../OAuth2MobileCodeAuthenticateDTO.java | 15 ----- .../dto/oatuh2/OAuth2MobileCodeSendDTO.java | 14 ---- .../OAuth2RefreshTokenAuthenticateDTO.java | 20 ------ .../oatuh2/OAuth2UsernameAuthenticateDTO.java | 21 ------ .../authorization/ResourceDeleteEvent.java | 29 -------- .../event/authorization/RoleDeleteEvent.java | 28 -------- .../AuthorizationServiceImpl.java | 56 ---------------- .../authorization/ResourceService.java | 23 ------- .../authorization/ResourceServiceImpl.java | 45 ------------- .../AdminsAuthorizationController.java | 39 ----------- .../iocoder/mall/system/rpc/package-info.java | 4 -- .../system/rpc/rpc/oauth2/OAuth2RPCImpl.java | 30 --------- 54 files changed, 314 insertions(+), 691 deletions(-) create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/PermissionAssignAdminRoleDTO.java create mode 100644 system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/PermissionAssignAdminRoleDTO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/AuthorizationBO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/ResourceTreeNodeBO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/RoleBO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/authorization/ResourceConvert.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationAssignRoleResourceDTO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetResourcesByAccountIdDTO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetRoleMapByAccountIdsDTO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetRoleResourcesDTO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceCountDTO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceGetListDTO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceGetTreeDTO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2AccessTokenAuthenticateDTO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2MobileCodAuthenticateDTO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2MobileCodeAuthenticateDTO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2MobileCodeSendDTO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2RefreshTokenAuthenticateDTO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2UsernameAuthenticateDTO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/event/authorization/ResourceDeleteEvent.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/event/authorization/RoleDeleteEvent.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceService.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceServiceImpl.java delete mode 100644 system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/package-info.java delete mode 100644 system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/rpc/oauth2/OAuth2RPCImpl.java diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/admin/AdminController.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/admin/AdminController.java index e48a93abb..e3479139b 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/admin/AdminController.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/admin/AdminController.java @@ -33,7 +33,7 @@ public class AdminController { @ApiOperation(value = "管理员分页") @GetMapping("/page") - @RequiresPermissions("system.admin.page") + @RequiresPermissions("system:page") public CommonResult> page(AdminPageDTO adminPageDTO) { return success(adminManager.pageAdmin(adminPageDTO)); } 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 index e04adee27..290bd3da2 100644 --- 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 @@ -3,4 +3,9 @@ GET {{baseUrl}}/permission/list-role-resource?roleId=1 Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{accessToken}} +### /permission/list-admin-roles 成功 +GET {{baseUrl}}/permission/list-admin-roles?adminId=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 6c31384d0..30c0e5544 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.PermissionAssignAdminRoleDTO; import cn.iocoder.mall.managementweb.controller.permission.dto.PermissionAssignRoleResourceDTO; import cn.iocoder.mall.managementweb.manager.permission.PermissionManager; import io.swagger.annotations.Api; @@ -29,11 +30,11 @@ public class PermissionController { @Autowired private PermissionManager permissionManager; - @GetMapping("/list-role-resource") + @GetMapping("/list-role-resources") @ApiOperation("获得角色拥有的资源编号") @ApiImplicitParam(name = "roleId", value = "角色编号", required = true) - public CommonResult> listRoleResource(Integer roleId) { - return success(permissionManager.listRoleResource(roleId)); + public CommonResult> listRoleResources(Integer roleId) { + return success(permissionManager.listRoleResources(roleId)); } @PostMapping("/assign-role-resource") @@ -43,4 +44,18 @@ public class PermissionController { return success(true); } + @GetMapping("/list-admin-roles") + @ApiOperation("获得管理员拥有的角色编号列表") + @ApiImplicitParam(name = "adminId", value = "管理员编号", required = true) + public CommonResult> listAdminRoles(Integer adminId) { + return success(permissionManager.listAdminRoles(adminId)); + } + + @PostMapping("/assign-admin-role") + @ApiOperation("赋予用户角色") + public CommonResult assignAdminRole(PermissionAssignAdminRoleDTO assignAdminRoleDTO) { + permissionManager.assignAdminRole(assignAdminRoleDTO); + return success(true); + } + } diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.java index dba74edca..501baea9b 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.java @@ -61,8 +61,8 @@ public class ResourceController { @GetMapping("/list") @ApiOperation("获得资源列表") @ApiImplicitParam(name = "resourceId", value = "资源编号列表", required = true) - public CommonResult> listResource(@RequestParam("resourceIds") List resourceIds) { - return success(resourceManager.listResource(resourceIds)); + public CommonResult> listResources(@RequestParam("resourceIds") List resourceIds) { + return success(resourceManager.listResources(resourceIds)); } @GetMapping("/tree") diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/RoleController.http b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/RoleController.http index 6797f14c5..8244ac372 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/RoleController.http +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/RoleController.http @@ -24,6 +24,11 @@ GET {{baseUrl}}/role/get?roleId=13 Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{accessToken}} +### /role/list-all 成功 +GET {{baseUrl}}/role/list-all +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{accessToken}} + ### /role/list 成功 GET {{baseUrl}}/role/list?roleIds=1,13 Content-Type: application/x-www-form-urlencoded diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/RoleController.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/RoleController.java index e3c6337b6..a4116eb6b 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/RoleController.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/RoleController.java @@ -60,11 +60,17 @@ public class RoleController { return success(roleManager.getRole(roleId)); } + @GetMapping("/list-all") + @ApiOperation("获得所有角色列表") + public CommonResult> listAllRoles() { + return success(roleManager.listAllRoles()); + } + @GetMapping("/list") @ApiOperation("获得角色列表") @ApiImplicitParam(name = "roleIds", value = "角色编号列表", required = true) - public CommonResult> getRoles(@RequestParam("roleIds") List roleIds) { - return success(roleManager.listRole(roleIds)); + public CommonResult> listRoles(@RequestParam("roleIds") List roleIds) { + return success(roleManager.listRoles(roleIds)); } @GetMapping("/page") diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/PermissionAssignAdminRoleDTO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/PermissionAssignAdminRoleDTO.java new file mode 100644 index 000000000..4680a95bf --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/PermissionAssignAdminRoleDTO.java @@ -0,0 +1,20 @@ +package cn.iocoder.mall.managementweb.controller.permission.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; +import java.util.Set; + +@ApiModel("赋予用户角色 DTO") +@Data +public class PermissionAssignAdminRoleDTO { + + @ApiModelProperty(value = "管理员编号", required = true, example = "1") + @NotNull(message = "管理员编号不能为空") + private Integer adminId; + @ApiModelProperty(value = "角色编号列表", example = "1,3,5") + private Set roleIds; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/PermissionAssignRoleResourceDTO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/PermissionAssignRoleResourceDTO.java index 7091f0ef5..7742d852b 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/PermissionAssignRoleResourceDTO.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/PermissionAssignRoleResourceDTO.java @@ -11,10 +11,10 @@ import java.util.Set; @Data public class PermissionAssignRoleResourceDTO { - @ApiModelProperty(value = "角色名", required = true, example = "管理员") + @ApiModelProperty(value = "角色名", required = true, example = "1") @NotNull(message = "角色编号不能为空") private Integer roleId; - @ApiModelProperty(value = "资源编号列表", required = true, example = "1,3,5") + @ApiModelProperty(value = "资源编号列表", example = "1,3,5") private Set resourceIds; } diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/PermissionConvert.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/PermissionConvert.java index d72cf23fa..bc63a8aad 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/PermissionConvert.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/PermissionConvert.java @@ -1,5 +1,6 @@ package cn.iocoder.mall.managementweb.convert.permission; +import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionAssignAdminRoleDTO; import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionAssignRoleResourceDTO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -11,4 +12,6 @@ public interface PermissionConvert { PermissionAssignRoleResourceDTO convert(cn.iocoder.mall.managementweb.controller.permission.dto.PermissionAssignRoleResourceDTO bean); + PermissionAssignAdminRoleDTO convert(cn.iocoder.mall.managementweb.controller.permission.dto.PermissionAssignAdminRoleDTO bean); + } diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/PermissionManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/PermissionManager.java index fc942d67b..2463a6c50 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/PermissionManager.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/PermissionManager.java @@ -1,6 +1,7 @@ package cn.iocoder.mall.managementweb.manager.permission; import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.managementweb.controller.permission.dto.PermissionAssignAdminRoleDTO; import cn.iocoder.mall.managementweb.controller.permission.dto.PermissionAssignRoleResourceDTO; import cn.iocoder.mall.managementweb.convert.permission.PermissionConvert; import cn.iocoder.mall.systemservice.rpc.permission.PermissionRpc; @@ -19,15 +20,15 @@ public class PermissionManager { private PermissionRpc permissionRpc; /** - * 获得角色拥有的资源编号 + * 获得角色拥有的资源编号列表 * * @param roleId 角色编号 * @return 资源编号列表 */ - public Set listRoleResource(Integer roleId) { - CommonResult> listAdminRoleIdsResult = permissionRpc.listRoleResourceId(roleId); - listAdminRoleIdsResult.checkError(); - return listAdminRoleIdsResult.getData(); + public Set listRoleResources(Integer roleId) { + CommonResult> listRoleResourceIdsResult = permissionRpc.listRoleResourceIds(roleId); + listRoleResourceIdsResult.checkError(); + return listRoleResourceIdsResult.getData(); } /** @@ -41,4 +42,27 @@ public class PermissionManager { assignRoleResourceResult.checkError(); } + /** + * 赋予用户角色 + * + * @param assignAdminRoleDTO 赋予用户角色 DTO + */ + public void assignAdminRole(PermissionAssignAdminRoleDTO assignAdminRoleDTO) { + CommonResult assignAdminRoleResult = permissionRpc.assignAdminRole( + PermissionConvert.INSTANCE.convert(assignAdminRoleDTO)); + assignAdminRoleResult.checkError(); + } + + /** + * 获得用户拥有的角色编号列表 + * + * @param adminId 管理员编号 + * @return 角色编号列表 + */ + public Set listAdminRoles(Integer adminId) { + CommonResult> listAdminRoleIdsResult = permissionRpc.listAdminRoleIds(adminId); + listAdminRoleIdsResult.checkError(); + return listAdminRoleIdsResult.getData(); + } + } diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/ResourceManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/ResourceManager.java index 61a22a84d..48812e2eb 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/ResourceManager.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/ResourceManager.java @@ -79,7 +79,7 @@ public class ResourceManager { * @param resourceIds 资源编号列表 * @return 资源列表 */ - public List listResource(List resourceIds) { + public List listResources(List resourceIds) { CommonResult> listResourceResult = resourceRpc.listResource(resourceIds); return ResourceConvert.INSTANCE.convertList(listResourceResult.getData()); } diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/RoleManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/RoleManager.java index 480e578b6..d5aa78170 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/RoleManager.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/RoleManager.java @@ -66,14 +66,25 @@ public class RoleManager { return RoleConvert.INSTANCE.convert(getRoleResult.getData()); } + /** + * 获得所有角色 + * + * @return 角色列表 + */ + public List listAllRoles() { + CommonResult> listRoleResult = roleRpc.listAllRoles(); + listRoleResult.checkError(); + return RoleConvert.INSTANCE.convertList(listRoleResult.getData()); + } + /** * 获得角色列表 * * @param roleIds 角色编号列表 * @return 角色列表 */ - public List listRole(List roleIds) { - CommonResult> listRoleResult = roleRpc.listRole(roleIds); + public List listRoles(List roleIds) { + CommonResult> listRoleResult = roleRpc.listRoles(roleIds); listRoleResult.checkError(); return RoleConvert.INSTANCE.convertList(listRoleResult.getData()); } diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/enums/SystemErrorCodeEnum.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/enums/SystemErrorCodeEnum.java index 9a6578055..c643a274e 100644 --- a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/enums/SystemErrorCodeEnum.java +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/enums/SystemErrorCodeEnum.java @@ -30,7 +30,7 @@ public enum SystemErrorCodeEnum implements ServiceExceptionUtil.Enumerable> listRoleResourceId(Integer roleId); + CommonResult> listRoleResourceIds(Integer roleId); /** * 赋予角色资源 @@ -26,4 +27,20 @@ public interface PermissionRpc { */ CommonResult assignRoleResource(PermissionAssignRoleResourceDTO assignRoleResourceDTO); + /** + * 获得管理员拥有的角色编号列表 + * + * @param adminId 管理员编号 + * @return 资源编号列表 + */ + CommonResult> listAdminRoleIds(Integer adminId); + + /** + * 赋予管理员角色 + * + * @param assignAdminRoleDTO 赋予管理员角色 DTO + * @return 成功 + */ + CommonResult assignAdminRole(PermissionAssignAdminRoleDTO assignAdminRoleDTO); + } diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpc.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpc.java index df5048b94..1319ecc92 100644 --- a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpc.java +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpc.java @@ -45,13 +45,20 @@ public interface RoleRpc { */ CommonResult getRole(Integer roleId); + /** + * 获得所有角色 + * + * @return 角色列表 + */ + CommonResult> listAllRoles(); + /** * 获得角色列表 * * @param roleIds 角色编号列表 * @return 角色列表 */ - CommonResult> listRole(List roleIds); + CommonResult> listRoles(List roleIds); /** * 获得角色分页 diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/PermissionAssignAdminRoleDTO.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/PermissionAssignAdminRoleDTO.java new file mode 100644 index 000000000..bd55c1e9e --- /dev/null +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/PermissionAssignAdminRoleDTO.java @@ -0,0 +1,27 @@ +package cn.iocoder.mall.systemservice.rpc.permission.dto; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.Set; + +/** + * 赋予管理员角色 DTO + */ +@Data +@Accessors(chain = true) +public class PermissionAssignAdminRoleDTO implements Serializable { + + /** + * 管理员编号 + */ + @NotNull(message = "管理员编号不能为空") + private Integer adminId; + /** + * 角色编号列表 + */ + private Set roleIds; + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/AdminRoleMapper.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/AdminRoleMapper.java index acf51ad37..4a9923762 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/AdminRoleMapper.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/AdminRoleMapper.java @@ -15,23 +15,23 @@ public interface AdminRoleMapper extends BaseMapper { return selectList(new QueryWrapper().eq("admin_id", adminId)); } -// default List selectListByAccountIds(Collection accountIds) { -// return selectList(new QueryWrapper().in("account_id", accountIds)); -// } -// -// default int deleteByAccountId(Integer accountId) { -// return delete(new QueryWrapper().eq("account_id", accountId)); -// } -// -// default int deleteByRoleId(Integer roleId) { -// return delete(new QueryWrapper().eq("role_id", roleId)); -// } + default List selectListByAdminId(Integer adminId) { + return selectList(new QueryWrapper().eq("admin_id", adminId)); + } + + default int deleteByAdminId(Integer adminId) { + return delete(new QueryWrapper().eq("admin_id", adminId)); + } + + default int deleteByRoleId(Integer roleId) { + return delete(new QueryWrapper().eq("role_id", roleId)); + } /** * 批量插入。因为 MyBaits Plus 的批量插入是基于 Service 实现,所以只好写 XML * - * @param accountRoleDOs 数组 + * @param adminRoleDOs 数组 */ - int insertList(@Param("accountRoleDOs") List accountRoleDOs); + int insertList(@Param("adminRoleDOs") List adminRoleDOs); } 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 14e3b7287..65e8977e2 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,6 +1,7 @@ package cn.iocoder.mall.systemservice.manager.permission; import cn.iocoder.common.framework.util.CollectionUtils; +import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionAssignAdminRoleDTO; 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; @@ -31,13 +32,13 @@ public class PermissionManager { * @param roleId 角色编号 * @return 资源编号列表 */ - public Set listRoleResourceId(Integer roleId) { + public Set listRoleResourceIds(Integer roleId) { // 超级管理员,拥有所有资源 if (roleService.hasSuperAdmin(Collections.singleton(roleId))) { - return CollectionUtils.convertSet(resourceService.listResource(), ResourceBO::getId); + return CollectionUtils.convertSet(resourceService.listResources(), ResourceBO::getId); } // 非超级管理员,查询拥有资源 - return permissionService.listRoleResourceId(roleId); + return permissionService.listRoleResourceIds(roleId); } /** @@ -49,4 +50,24 @@ public class PermissionManager { permissionService.assignRoleResource(assignResourceDTO.getRoleId(), assignResourceDTO.getResourceIds()); } + /** + * 获得管理员拥有的角色编号列表 + * + * @param adminId 管理员编号 + * @return 角色编号列表 + */ + public Set listAdminRoleIds(Integer adminId) { + return permissionService.listAdminRoleIds(adminId); + } + + /** + * 赋予管理员角色 + * + * @param assignAdminRoleDTO 赋予管理员角色 DTO + */ + public void assignAdminRole(PermissionAssignAdminRoleDTO assignAdminRoleDTO) { + permissionService.assignAdminRole(assignAdminRoleDTO.getAdminId(), assignAdminRoleDTO.getRoleIds()); + } + + } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/ResourceManager.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/ResourceManager.java index b67c563f9..ed9dcc072 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/ResourceManager.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/ResourceManager.java @@ -69,8 +69,8 @@ public class ResourceManager { * * @return 资源列表 */ - public List listResource() { - List resourceBOs = resourceService.listResource(); + public List listResources() { + List resourceBOs = resourceService.listResources(); return ResourceConvert.INSTANCE.convertList02(resourceBOs); } @@ -80,8 +80,8 @@ public class ResourceManager { * @param resourceIds 资源编号列表 * @return 资源列表 */ - public List listResource(List resourceIds) { - List resourceBOs = resourceService.listResource(resourceIds); + public List listResources(List resourceIds) { + List resourceBOs = resourceService.listResources(resourceIds); return ResourceConvert.INSTANCE.convertList02(resourceBOs); } @@ -92,13 +92,13 @@ public class ResourceManager { * @param type 资源类型,允许空 * @return 资源列表 */ - public List listRoleResource(Collection roleIds, Integer type) { + public List listRoleResources(Collection roleIds, Integer type) { List resourceBOs; // 判断是否为超管。若是超管,默认有所有权限 if (roleService.hasSuperAdmin(roleIds)) { - resourceBOs = resourceService.listResourceByType(type); + resourceBOs = resourceService.listResourcesByType(type); } else { - resourceBOs = resourceService.listRoleResourceByType(roleIds, type); + resourceBOs = resourceService.listRoleResourcesByType(roleIds, type); } return ResourceConvert.INSTANCE.convertList02(resourceBOs); } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/RoleManager.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/RoleManager.java index 00fd17315..773070ab4 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/RoleManager.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/RoleManager.java @@ -63,13 +63,23 @@ public class RoleManager { return RoleConvert.INSTANCE.convert(roleBO); } + /** + * 获得所有角色 + * + * @return 角色列表 + */ + public List listAllRoles() { + List roleBOs = roleService.listAllRole(); + return RoleConvert.INSTANCE.convertList02(roleBOs); + } + /** * 获得角色列表 * * @param roleIds 角色编号列表 * @return 角色列表 */ - public List listRole(List roleIds) { + public List listRoles(List roleIds) { List roleBOs = roleService.listRole(roleIds); return RoleConvert.INSTANCE.convertList02(roleBOs); } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/PermissionRpcImpl.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/PermissionRpcImpl.java index dc4f162a1..4ed0310f9 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/PermissionRpcImpl.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/PermissionRpcImpl.java @@ -2,6 +2,7 @@ package cn.iocoder.mall.systemservice.rpc.permission; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.systemservice.manager.permission.PermissionManager; +import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionAssignAdminRoleDTO; import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionAssignRoleResourceDTO; import org.apache.dubbo.config.annotation.Service; import org.springframework.beans.factory.annotation.Autowired; @@ -20,8 +21,8 @@ public class PermissionRpcImpl implements PermissionRpc { private PermissionManager permissionManager; @Override - public CommonResult> listRoleResourceId(Integer roleId) { - return success(permissionManager.listRoleResourceId(roleId)); + public CommonResult> listRoleResourceIds(Integer roleId) { + return success(permissionManager.listRoleResourceIds(roleId)); } @Override @@ -30,4 +31,15 @@ public class PermissionRpcImpl implements PermissionRpc { return success(true); } + @Override + public CommonResult> listAdminRoleIds(Integer adminId) { + return success(permissionManager.listAdminRoleIds(adminId)); + } + + @Override + public CommonResult assignAdminRole(PermissionAssignAdminRoleDTO assignAdminRoleDTO) { + permissionManager.assignAdminRole(assignAdminRoleDTO); + return success(true); + } + } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpcImpl.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpcImpl.java index 9d0ddd007..cd04d3c8b 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpcImpl.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpcImpl.java @@ -46,17 +46,17 @@ public class ResourceRpcImpl implements ResourceRpc { @Override public CommonResult> listResource() { - return success(resourceManager.listResource()); + return success(resourceManager.listResources()); } @Override public CommonResult> listResource(List resourceIds) { - return success(resourceManager.listResource(resourceIds)); + return success(resourceManager.listResources(resourceIds)); } @Override public CommonResult> listRoleResource(Collection roleIds, Integer type) { - return success(resourceManager.listRoleResource(roleIds, type)); + return success(resourceManager.listRoleResources(roleIds, type)); } } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpcImpl.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpcImpl.java index fee1e5a96..48885877e 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpcImpl.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpcImpl.java @@ -47,8 +47,13 @@ public class RoleRpcImpl implements RoleRpc { } @Override - public CommonResult> listRole(List roleIds) { - return success(roleManager.listRole(roleIds)); + public CommonResult> listAllRoles() { + return success(roleManager.listAllRoles()); + } + + @Override + public CommonResult> listRoles(List roleIds) { + return success(roleManager.listRoles(roleIds)); } @Override diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/PermissionService.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/PermissionService.java index 9beab3f69..37437ff96 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/PermissionService.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/PermissionService.java @@ -1,23 +1,26 @@ package cn.iocoder.mall.systemservice.service.permission; +import cn.hutool.core.collection.CollectionUtil; import cn.iocoder.common.framework.util.CollectionUtils; import cn.iocoder.common.framework.util.ServiceExceptionUtil; -import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum; +import cn.iocoder.mall.systemservice.dal.mysql.dataobject.admin.AdminDO; +import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.AdminRoleDO; +import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.RoleDO; import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.RoleResourceDO; +import cn.iocoder.mall.systemservice.dal.mysql.mapper.admin.AdminMapper; import cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.AdminRoleMapper; import cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.ResourceMapper; import cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.RoleMapper; import cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.RoleResourceMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; -import java.util.Date; import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.AUTHORIZATION_ROLE_ASSIGN_RESOURCE_NOT_EXISTS; -import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.ROLE_NOT_EXISTS; +import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.*; /** * 权限 Service @@ -25,6 +28,8 @@ import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.ROLE_NOT_E @Service public class PermissionService { + @Autowired + private AdminMapper adminMapper; @Autowired private RoleMapper roleMapper; @Autowired @@ -40,7 +45,7 @@ public class PermissionService { * @param roleId 角色编号 * @return 资源编号列表 */ - public Set listRoleResourceId(Integer roleId) { + public Set listRoleResourceIds(Integer roleId) { List roleResourceDOs = roleResourceMapper.selectListByRoleId(roleId); return CollectionUtils.convertSet(roleResourceDOs, RoleResourceDO::getResourceId); } @@ -51,6 +56,7 @@ public class PermissionService { * @param roleId 角色编号 * @param resourceIds 资源编号列表 */ + @Transactional public void assignRoleResource(Integer roleId, Set resourceIds) { // 校验角色是否存在 if (roleMapper.selectById(roleId) == null) { @@ -68,14 +74,52 @@ public class PermissionService { roleResourceMapper.deleteByRoleId(roleId); // 创建 RoleResourceDO 数组,并插入到数据库 if (!CollectionUtils.isEmpty(resourceIds)) { - List roleResources = resourceIds.stream().map(resourceId -> { - RoleResourceDO roleResource = new RoleResourceDO().setRoleId(roleId).setResourceId(resourceId); - roleResource.setCreateTime(new Date()); - roleResource.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); - return roleResource; - }).collect(Collectors.toList()); + List roleResources = resourceIds.stream() + .map(resourceId -> new RoleResourceDO().setRoleId(roleId).setResourceId(resourceId)).collect(Collectors.toList()); roleResourceMapper.insertList(roleResources); } } + /** + * 赋予管理员角色 + * + * @param adminId 管理员编号 + * @param roleIds 角色编号列表 + */ + @Transactional + public void assignAdminRole(Integer adminId, Set roleIds) { + // 校验账号存在 + AdminDO admin = adminMapper.selectById(adminId); + if (admin == null) { + throw ServiceExceptionUtil.exception(ADMIN_NOT_FOUND); + } + // 校验是否有不存在的角色 + if (!CollectionUtils.isEmpty(roleIds)) { + List roles = roleMapper.selectBatchIds(roleIds); + if (roles.size() != roleIds.size()) { + throw ServiceExceptionUtil.exception(ADMIN_ASSIGN_ROLE_NOT_EXISTS); + } + } + // TODO 芋艿,这里先简单实现。即方式是,删除老的分配的角色关系,然后添加新的分配的角色关系 + // 标记管理员角色源关系都为删除 + adminRoleMapper.deleteByAdminId(adminId); + // 创建 RoleResourceDO 数组,并插入到数据库 + if (!CollectionUtil.isEmpty(roleIds)) { + List adminRoleDOs = roleIds.stream() + .map(roleId -> new AdminRoleDO().setAdminId(adminId).setRoleId(roleId)).collect(Collectors.toList()); + adminRoleMapper.insertList(adminRoleDOs); + } + } + + /** + * 获得管理员拥有的角色编号列表 + * + * @param adminId 管理员编号 + * @return 角色编号列表 + */ + public Set listAdminRoleIds(Integer adminId) { + List adminRoleDOs = adminRoleMapper.selectListByAdminId(adminId); + return CollectionUtils.convertSet(adminRoleDOs, AdminRoleDO::getRoleId); + } + } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/ResourceService.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/ResourceService.java index 19ca7e43d..00fc4a4be 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/ResourceService.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/ResourceService.java @@ -114,7 +114,7 @@ public class ResourceService { * @param resourceIds 资源编号列表 * @return 资源列表 */ - public List listResource(List resourceIds) { + public List listResources(List resourceIds) { List resourceDOs = resourceMapper.selectBatchIds(resourceIds); return ResourceConvert.INSTANCE.convertList(resourceDOs); } @@ -124,7 +124,7 @@ public class ResourceService { * * @return 资源树结构 */ - public List listResource() { + public List listResources() { List resourceDOs = resourceMapper.selectList(null); return ResourceConvert.INSTANCE.convertList(resourceDOs); } @@ -135,7 +135,7 @@ public class ResourceService { * @param type 资源类型,允许空 * @return 资源列表 */ - public List listResourceByType(Integer type) { + public List listResourcesByType(Integer type) { List resourceDOs = resourceMapper.selectListByType(type); return ResourceConvert.INSTANCE.convertList(resourceDOs); } @@ -147,7 +147,7 @@ public class ResourceService { * @param type 资源类型,允许空 * @return 资源列表 */ - public List listRoleResourceByType(Collection roleIds, Integer type) { + public List listRoleResourcesByType(Collection roleIds, Integer type) { List roleResourceDOs = roleResourceMapper.selectListByRoleIds(roleIds); if (CollectionUtils.isEmpty(roleResourceDOs)) { return Collections.emptyList(); diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/RoleService.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/RoleService.java index 5f2f6cf7b..e8e401420 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/RoleService.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/RoleService.java @@ -110,6 +110,16 @@ public class RoleService { return RoleConvert.INSTANCE.convert(roleDO); } + /** + * 获得所有角色 + * + * @return 角色列表 + */ + public List listAllRole() { + List roleDOs = roleMapper.selectList(null); + return RoleConvert.INSTANCE.convertList(roleDOs); + } + /** * 获得角色列表 * diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/systemlog/bo/ExceptionLogAddBO.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/systemlog/bo/ExceptionLogAddBO.java index 904326c37..06d919264 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/systemlog/bo/ExceptionLogAddBO.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/systemlog/bo/ExceptionLogAddBO.java @@ -5,7 +5,6 @@ import lombok.Data; import lombok.experimental.Accessors; import javax.validation.constraints.NotNull; -import java.io.Serializable; import java.util.Date; /** @@ -13,7 +12,7 @@ import java.util.Date; */ @Data @Accessors(chain = true) -public class ExceptionLogAddBO implements Serializable { +public class ExceptionLogAddBO { /** * 账号编号 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 23859c357..b4b2d5997 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 @@ -4,10 +4,10 @@ INSERT INTO permission_admin_role ( - admin_id, role_id, create_time, deleted + admin_id, role_id ) VALUES - (#{adminRole.adminId}, #{adminRole.roleId}, #{adminRole.createTime}, #{adminRole.deleted}) + (#{adminRole.adminId}, #{adminRole.roleId}) 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 21be896ef..80e95c33b 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 @@ -4,10 +4,10 @@ INSERT INTO permission_role_resource ( - resource_id, role_id, create_time, deleted + resource_id, role_id ) VALUES - (#{roleResource.resourceId}, #{roleResource.roleId}, #{roleResource.createTime}, #{roleResource.deleted}) + (#{roleResource.resourceId}, #{roleResource.roleId}) diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/AuthorizationBO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/AuthorizationBO.java deleted file mode 100644 index b0e74fe35..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/AuthorizationBO.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.iocoder.mall.system.biz.bo.authorization; - -import lombok.Data; -import lombok.experimental.Accessors; - -/** - * 授权模块 - 授权信息 BO - */ -@Data -@Accessors(chain = true) -public class AuthorizationBO { - - - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/ResourceTreeNodeBO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/ResourceTreeNodeBO.java deleted file mode 100644 index db124ca94..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/ResourceTreeNodeBO.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.mall.system.biz.bo.authorization; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.List; - -/** - * 授权模块 - 资源信息树节点 BO - */ -@Data -@Accessors(chain = true) -public class ResourceTreeNodeBO { - - /** - * 当前节点 - */ - private ResourceBO node; - /** - * 子节点们 - */ - private List children; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/RoleBO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/RoleBO.java deleted file mode 100644 index 50e8d1974..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/RoleBO.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.iocoder.mall.system.biz.bo.authorization; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.Date; - -/** - * 授权模块 - 角色信息 BO - */ -@Data -@Accessors(chain = true) -public class RoleBO { - - /** - * 角色编号 - */ - private Integer id; - /** - * 角色名字 - */ - private String name; - /** - * 角色编码 - */ - private String code; - /** - * 角色类型 - */ - private Integer type; - /** - * 添加时间 - */ - private Date createTime; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/authorization/ResourceConvert.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/authorization/ResourceConvert.java deleted file mode 100644 index 06f879908..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/authorization/ResourceConvert.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.mall.system.biz.convert.authorization; - -import cn.iocoder.mall.system.biz.bo.authorization.ResourceBO; -import cn.iocoder.mall.system.biz.bo.authorization.ResourceTreeNodeBO; -import cn.iocoder.mall.system.biz.dataobject.authorization.ResourceDO; -import cn.iocoder.mall.system.biz.dto.authorization.ResourceAddDTO; -import cn.iocoder.mall.system.biz.dto.authorization.ResourceUpdateDTO; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface ResourceConvert { - - ResourceConvert INSTANCE = Mappers.getMapper(ResourceConvert.class); - - @Mapping(source = "bean", target = "node") - ResourceTreeNodeBO convertTreeNode(ResourceDO bean); - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationAssignRoleResourceDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationAssignRoleResourceDTO.java deleted file mode 100644 index 77c36c78c..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationAssignRoleResourceDTO.java +++ /dev/null @@ -1,27 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.authorization; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotNull; -import java.util.Set; - -/** - * 授权模块 - 分配角色资源 DTO - */ -@Data -@Accessors(chain = true) -public class AuthorizationAssignRoleResourceDTO { - - @NotNull(message = "管理员编号不能为空") - private Integer adminId; - - @NotNull(message = "角色编号不能为空") - private Integer roleId; - - /** - * 资源编号数组 - */ - private Set resourceIds; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetResourcesByAccountIdDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetResourcesByAccountIdDTO.java deleted file mode 100644 index a59f14867..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetResourcesByAccountIdDTO.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.authorization; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotNull; - -/** - * 授权模块 - 获得账号所拥有的资源列表 DTO - */ -@Data -@Accessors(chain = true) -public class AuthorizationGetResourcesByAccountIdDTO { - - @NotNull(message = "账号编号不能为空") - private Integer accountId; - /** - * 资源类型 - */ - private Integer type; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetRoleMapByAccountIdsDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetRoleMapByAccountIdsDTO.java deleted file mode 100644 index d846de709..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetRoleMapByAccountIdsDTO.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.authorization; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotNull; -import java.util.Collection; - -/** - * 授权模块 - 获得每个账号所拥有的角色 DTO - */ -@Data -@Accessors(chain = true) -public class AuthorizationGetRoleMapByAccountIdsDTO { - - @NotNull(message = "账号编号数组不能为空") - private Collection accountIds; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetRoleResourcesDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetRoleResourcesDTO.java deleted file mode 100644 index b5d9d29ec..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetRoleResourcesDTO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.authorization; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotNull; - -/** - * 授权模块 - 获得角色拥有资源集合 DTO - */ -@Data -@Accessors(chain = true) -public class AuthorizationGetRoleResourcesDTO { - - @NotNull(message = "角色编号不能为空") - private Integer roleId; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceCountDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceCountDTO.java deleted file mode 100644 index f87fb62fd..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceCountDTO.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.authorization; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.Collection; - -/** - * 资源模块 - 获得资源总数 DTO - */ -@Data -@Accessors(chain = true) -public class ResourceCountDTO { - - /** - * 资源编号数组 - */ - private Collection ids; - - /** - * 资源类型 - */ - private Integer type; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceGetListDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceGetListDTO.java deleted file mode 100644 index 1538c862e..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceGetListDTO.java +++ /dev/null @@ -1,27 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.authorization; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.Collection; - -/** - * 资源模块 - 获得资源列表 DTO - */ -@Data -@Accessors(chain = true) -public class ResourceGetListDTO { - - /** - * 资源编号数组 - * - * 如果传入空,则不进行资源编号的过滤 - */ - private Collection ids; - - /** - * 资源类型 - */ - private Integer type; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceGetTreeDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceGetTreeDTO.java deleted file mode 100644 index afdfb9cc0..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceGetTreeDTO.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.authorization; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.Collection; - -/** - * 资源模块 - 获得资源树 DTO - */ -@Data -@Accessors(chain = true) -public class ResourceGetTreeDTO { - - /** - * 资源编号数组 - */ - private Collection ids; - - /** - * 资源类型 - */ - private Integer type; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2AccessTokenAuthenticateDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2AccessTokenAuthenticateDTO.java deleted file mode 100644 index e146d12fc..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2AccessTokenAuthenticateDTO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.oatuh2; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotEmpty; - -/** - * 认证模块 - 访问令牌认证 DTO - */ -@Data -@Accessors(chain = true) -public class OAuth2AccessTokenAuthenticateDTO { - - @NotEmpty(message = "访问令牌不能为空") - private String accessToken; - @NotEmpty(message = "IP 不能为空") - private String ip; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2MobileCodAuthenticateDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2MobileCodAuthenticateDTO.java deleted file mode 100644 index e9594b7a0..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2MobileCodAuthenticateDTO.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.oatuh2; - -import lombok.Data; -import lombok.experimental.Accessors; - -// TODO 注释 -@Data -@Accessors(chain = true) -public class OAuth2MobileCodAuthenticateDTO { - - private String mobile; - private String code; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2MobileCodeAuthenticateDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2MobileCodeAuthenticateDTO.java deleted file mode 100644 index 7d9c0a913..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2MobileCodeAuthenticateDTO.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.oatuh2; - -import lombok.Data; -import lombok.experimental.Accessors; - -// TODO 注释 -@Data -@Accessors(chain = true) -public class OAuth2MobileCodeAuthenticateDTO { - - private String mobile; - private String code; - private String ip; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2MobileCodeSendDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2MobileCodeSendDTO.java deleted file mode 100644 index 65bf06be3..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2MobileCodeSendDTO.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.oatuh2; - -import lombok.Data; -import lombok.experimental.Accessors; - -// TODO 注释 -@Data -@Accessors(chain = true) -public class OAuth2MobileCodeSendDTO { - - private String mobile; - private String ip; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2RefreshTokenAuthenticateDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2RefreshTokenAuthenticateDTO.java deleted file mode 100644 index 095149c73..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2RefreshTokenAuthenticateDTO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.oatuh2; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotEmpty; - -/** - * 认证模块 - 访问令牌认证 DTO - */ -@Data -@Accessors(chain = true) -public class OAuth2RefreshTokenAuthenticateDTO { - - @NotEmpty(message = "访问令牌不能为空") - private String refreshToken; - @NotEmpty(message = "IP 不能为空") - private String ip; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2UsernameAuthenticateDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2UsernameAuthenticateDTO.java deleted file mode 100644 index aebd947f1..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/oatuh2/OAuth2UsernameAuthenticateDTO.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.oatuh2; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; - -/** - * 认证模块 - 账号 + 密码认证 DTO - */ -@Data -@Accessors(chain = true) -public class OAuth2UsernameAuthenticateDTO { - - @NotEmpty(message = "账号不能为空") - private String username; - @NotNull(message = "密码不能为空") - private String password; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/event/authorization/ResourceDeleteEvent.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/event/authorization/ResourceDeleteEvent.java deleted file mode 100644 index 795fe9987..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/event/authorization/ResourceDeleteEvent.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.iocoder.mall.system.biz.event.authorization; - -import cn.iocoder.mall.system.biz.dataobject.authorization.ResourceDO; -import org.springframework.context.ApplicationEvent; - -/** - * {@link ResourceDO} 删除事件 - */ -public class ResourceDeleteEvent extends ApplicationEvent { - - /** - * 资源编号 - */ - private Integer id; - - public ResourceDeleteEvent(Object source) { - super(source); - } - - public ResourceDeleteEvent(Object source, Integer id) { - super(source); - this.id = id; - } - - public Integer getId() { - return id; - } - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/event/authorization/RoleDeleteEvent.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/event/authorization/RoleDeleteEvent.java deleted file mode 100644 index 4f2054a44..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/event/authorization/RoleDeleteEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.mall.system.biz.event.authorization; - -import cn.iocoder.mall.system.biz.dataobject.authorization.RoleDO; -import org.springframework.context.ApplicationEvent; - -/** - * {@link RoleDO} 删除事件 - */ -public class RoleDeleteEvent extends ApplicationEvent { - /** - * 角色编号 - */ - private Integer id; - - public RoleDeleteEvent(Object source) { - super(source); - } - - public RoleDeleteEvent(Object source, Integer id) { - super(source); - this.id = id; - } - - public Integer getId() { - return id; - } - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationServiceImpl.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationServiceImpl.java index 0eb906d81..da83b63df 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationServiceImpl.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationServiceImpl.java @@ -73,62 +73,6 @@ public class AuthorizationServiceImpl implements AuthorizationService { } } - @Override - public List getResourcesByAccountId(AuthorizationGetResourcesByAccountIdDTO getResourcesByAccountIdDTO) { - // 查询管理员拥有的角色关联数据 - List accountRoleDOs = accountRoleMapper.selectByAccountId(getResourcesByAccountIdDTO.getAccountId()); - if (CollectionUtil.isEmpty(accountRoleDOs)) { - return Collections.emptyList(); - } - Set roleIds = CollectionUtil.convertSet(accountRoleDOs, AccountRoleDO::getRoleId); - // 判断是否为超管。若是超管,默认有所有权限 - if (roleService.hasSuperAdmin(roleIds)) { - return resourceService.getResources(new ResourceGetListDTO().setType(getResourcesByAccountIdDTO.getType())); - } - // 查询角色拥有的资源关联数据 - List roleResourceDOs = roleResourceMapper.selectListByRoleIds(roleIds); - if (CollectionUtil.isEmpty(roleResourceDOs)) { - return Collections.emptyList(); - } - Set resourceIds = CollectionUtil.convertSet(roleResourceDOs, RoleResourceDO::getResourceId); - // 查询对应资源列表 - return resourceService.getResources(new ResourceGetListDTO().setIds(resourceIds).setType(getResourcesByAccountIdDTO.getType())); - } - - @Override - public Map> getRoleMapByAccountIds(AuthorizationGetRoleMapByAccountIdsDTO getRoleMapByAccountIdsDTO) { - return null; - } - -// @Override -// public Map> getRoleIdMapByAccountIds(AuthorizationGetRoleMapByAccountIdsDTO getRoleMapByAccountIdsDTO) { -// // 查询管理员拥有的角色关联数据 -// List accountRoleDOs = accountRoleMapper.selectListByAccountIds(getRoleMapByAccountIdsDTO.getAccountIds()); -// if (CollectionUtil.isEmpty(accountRoleDOs)) { -// return Collections.emptyMap(); -// } -// // 构建结果 -// Map> accountRoleMap = CollectionUtil.convertMultiMap2(accountRoleDOs, -// AccountRoleDO::getAccountId, AccountRoleDO::getRoleId); -// getRoleMapByAccountIdsDTO.getAccountIds().forEach(accountId -> accountRoleMap.putIfAbsent(accountId, Collections.emptySet())); -// return accountRoleMap; -// } - - @Override - public Set getRoleResources(AuthorizationGetRoleResourcesDTO getRoleResourcesDTO) { - Set roleIds = Collections.singleton(getRoleResourcesDTO.getRoleId()); - // 判断是否为超管。若是超管,默认有所有权限 - if (roleService.hasSuperAdmin(roleIds)) { - return CollectionUtil.convertSet(resourceService.getResources(new ResourceGetListDTO()), ResourceBO::getId); - } - // 查询角色拥有的资源关联数据 - List roleResourceDOs = roleResourceMapper.selectListByRoleIds(roleIds); - if (CollectionUtil.isEmpty(roleResourceDOs)) { - return Collections.emptySet(); - } - return CollectionUtil.convertSet(roleResourceDOs, RoleResourceDO::getResourceId); - } - @EventListener public void handleResourceDeleteEvent(ResourceDeleteEvent event) { roleResourceMapper.deleteByResourceId(event.getId()); diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceService.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceService.java deleted file mode 100644 index e4430bd6d..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceService.java +++ /dev/null @@ -1,23 +0,0 @@ -package cn.iocoder.mall.system.biz.service.authorization; - -import cn.iocoder.mall.system.biz.bo.authorization.ResourceBO; -import cn.iocoder.mall.system.biz.bo.authorization.ResourceTreeNodeBO; -import cn.iocoder.mall.system.biz.dto.authorization.ResourceCountDTO; -import cn.iocoder.mall.system.biz.dto.authorization.ResourceGetListDTO; -import cn.iocoder.mall.system.biz.dto.authorization.ResourceGetTreeDTO; - -import java.util.Collection; -import java.util.List; - -/** - * 资源模块 - Service 接口 - */ -public interface ResourceService { - - List getResourcesByPermissions(Collection permissions); - - List getResources(ResourceGetListDTO getListDTO); - - int countResource(ResourceCountDTO countDTO); - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceServiceImpl.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceServiceImpl.java deleted file mode 100644 index 9b8d0b0ef..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceServiceImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -package cn.iocoder.mall.system.biz.service.authorization; - -import cn.iocoder.common.framework.util.ServiceExceptionUtil; -import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum; -import cn.iocoder.mall.system.biz.bo.authorization.ResourceBO; -import cn.iocoder.mall.system.biz.bo.authorization.ResourceTreeNodeBO; -import cn.iocoder.mall.system.biz.convert.authorization.ResourceConvert; -import cn.iocoder.mall.system.biz.dao.authorization.ResourceMapper; -import cn.iocoder.mall.system.biz.dataobject.authorization.ResourceDO; -import cn.iocoder.mall.system.biz.dto.authorization.*; -import cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum; -import cn.iocoder.mall.system.biz.enums.authorization.ResourceIdEnum; -import cn.iocoder.mall.system.biz.enums.authorization.ResourceTypeEnum; -import cn.iocoder.mall.system.biz.event.authorization.ResourceDeleteEvent; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.*; -import java.util.stream.Collectors; - -@Service -@Slf4j -public class ResourceServiceImpl implements ResourceService { - - @Autowired - private ApplicationEventPublisher eventPublisher; - - @Override - public List getResourcesByPermissions(Collection permissions) { - List resourceDOs = resourceMapper.selectListByPermissions(permissions); - return ResourceConvert.INSTANCE.convertList(resourceDOs); - } - - @Override - public List getResources(ResourceGetListDTO getListDTO) { - List resourceDOs = resourceMapper.selectListByIdsAndType(getListDTO.getIds(), getListDTO.getType()); - return ResourceConvert.INSTANCE.convertList(resourceDOs); - } - - - -} diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsAuthorizationController.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsAuthorizationController.java index 468a020d7..6a3cb2eaf 100644 --- a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsAuthorizationController.java +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsAuthorizationController.java @@ -42,45 +42,6 @@ public class AdminsAuthorizationController { @Autowired private RoleService roleService; - @GetMapping("/menu-resource-tree") - @ApiOperation(value = "获得当前账号的菜单资源树", notes = "以树结构返回") - public CommonResult> menuResourceTree() { - List resourceTreeNodeBOs = authorizationService.getResourceTreeByAccountId(new AuthorizationGetResourcesByAccountIdDTO() - .setAccountId(AdminSecurityContextHolder.getAccountId()).setType(ResourceTypeEnum.MENU.getType())); - return CommonResult.success(AdminsAuthorizationConvert.INSTANCE.convertList(resourceTreeNodeBOs)); - } - - @GetMapping("/resource-permissions") - @ApiOperation(value = "获得当前账号的资源权限列表") - public CommonResult> resourcePermissions() { - List resources = authorizationService.getResourcesByAccountId(new AuthorizationGetResourcesByAccountIdDTO() - .setAccountId(AdminSecurityContextHolder.getAccountId())); - return CommonResult.success(resources.stream().map(ResourceBO::getRoute).collect(Collectors.toSet())); - } - - @GetMapping("/role_resource_tree") - @ApiOperation(value = "获得角色拥有的菜单权限", notes = "以树结构返回。注意,返回的资源树是完整的结构,会标记每个资源节点是否被角色所拥有") - @ApiImplicitParam(name = "roleId", value = "角色编号", required = true, example = "1") - @RequiresPermissions("system:authorization:assign_role_resource") - public CommonResult> roleResourceTree(@RequestParam("roleId") Integer roleId) { - // 1. 获得完整的资源树 - List resourceTreeNodeBOs = resourceService.getResourceTree(new ResourceGetTreeDTO()); - // 2. 获得角色拥有的子树 - Set roleResourceIds = authorizationService.getRoleResources(new AuthorizationGetRoleResourcesDTO().setRoleId(roleId)); - // 3. 拼接,返回结果 - return CommonResult.success(AdminsAuthorizationConvert.INSTANCE.convertList(resourceTreeNodeBOs, roleResourceIds)); - } - - @PostMapping("/assign_role_resource") - @ApiOperation(value = "分配角色资源") - @RequiresPermissions("system:authorization:assign_role_resource") - public CommonResult assignRoleResource(AdminsAuthorizationAssignRoleResourceRequest request) { - AuthorizationAssignRoleResourceDTO authorizationAssignRoleResourceDTO = AdminsAuthorizationConvert.INSTANCE.convert(request) - .setAdminId(AdminSecurityContextHolder.getAdminId()); - authorizationService.assignRoleResource(authorizationAssignRoleResourceDTO); - return CommonResult.success(true); - } - // @GetMapping("/role_list") // @ApiOperation(value = "指定账号拥有的角色列表") // @ApiImplicitParam(name = "accountId", value = "账号编号", required = true, example = "1") diff --git a/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/package-info.java b/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/package-info.java deleted file mode 100644 index 24f83ae9e..000000000 --- a/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * 提供 system 服务的 RPC 接口的实现,提供内部调用 - */ -package cn.iocoder.mall.system.rpc; diff --git a/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/rpc/oauth2/OAuth2RPCImpl.java b/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/rpc/oauth2/OAuth2RPCImpl.java deleted file mode 100644 index 325510ac2..000000000 --- a/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/rpc/oauth2/OAuth2RPCImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.mall.system.rpc.rpc.oauth2; - -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.system.biz.bo.ouath2.OAuth2AuthenticateBO; -import cn.iocoder.mall.system.biz.dto.oatuh2.OAuth2AccessTokenAuthenticateDTO; -import cn.iocoder.mall.system.biz.service.oauth2.OAuth2Service; -import cn.iocoder.mall.system.rpc.api.oauth2.OAuth2RPC; -import cn.iocoder.mall.system.rpc.convert.oauth2.OAuth2Convert; -import cn.iocoder.mall.system.rpc.request.oauth2.OAuth2AccessTokenAuthenticateRequest; -import cn.iocoder.mall.system.rpc.response.oauth2.OAuth2AccessTokenResponse; -import org.apache.dubbo.config.annotation.Service; -import org.springframework.beans.factory.annotation.Autowired; - -@Service(version = "${dubbo.provider.OAuth2RPC.version}", validation = "true") -public class OAuth2RPCImpl implements OAuth2RPC { - - @Autowired - private OAuth2Service oauth2Service; - - @Override - public CommonResult authenticate(OAuth2AccessTokenAuthenticateRequest authenticateRequest) { - // 执行认证 - OAuth2AccessTokenAuthenticateDTO authenticateDTO = OAuth2Convert.INSTANCE.convert(authenticateRequest); - OAuth2AuthenticateBO accessTokenBO = oauth2Service.authenticate(authenticateDTO); - // 返回结果 - OAuth2AccessTokenResponse accessTokenResponse = OAuth2Convert.INSTANCE.convert(accessTokenBO); - return CommonResult.success(accessTokenResponse); - } - -}