From d34e555aa08177cc0cb4754441e6921a6c17193e Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Mon, 13 Jul 2020 07:50:07 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=20Permission=20=E7=9B=B8=E5=85=B3=E6=A8=A1=E5=9D=97=EF=BC=8C?= =?UTF-8?q?=E6=9B=B4=E5=8A=A0=E6=B8=85=E6=99=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../passport/PassportController.java | 2 +- .../permission/PermissionController.java | 41 ++++++++++ .../controller/permission/RoleController.java | 3 +- .../dto/PermissionAssignRoleResourceDTO.java | 20 +++++ .../convert/permission/PermissionConvert.java | 14 ++++ .../manager/permission/PermissionManager.java | 44 ++++++++++ .../src/main/resources/application.yml | 2 + .../rpc/permission/PermissionRpc.java | 29 +++++++ .../dto/PermissionAssignRoleResourceDTO.java | 26 ++++++ .../manager/permission/PermissionManager.java | 38 +++++++++ .../rpc/permission/PermissionRpcImpl.java | 33 ++++++++ .../service/permission/PermissionService.java | 81 +++++++++++++++++++ .../src/main/resources/application.yaml | 2 + .../authorization/AuthorizationService.java | 7 +- .../AuthorizationServiceImpl.java | 42 ---------- .../authorization/ResourceService.java | 8 -- .../authorization/ResourceServiceImpl.java | 14 ---- .../AdminsResourceController.java | 41 ---------- 18 files changed, 334 insertions(+), 113 deletions(-) create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/PermissionController.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/PermissionAssignRoleResourceDTO.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/PermissionConvert.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/PermissionManager.java create mode 100644 system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/PermissionRpc.java create mode 100644 system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/PermissionAssignRoleResourceDTO.java create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/PermissionManager.java create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/PermissionRpcImpl.java create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/PermissionService.java delete mode 100644 system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsResourceController.java diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/PassportController.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/PassportController.java index 079c07219..d39423b56 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/PassportController.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/PassportController.java @@ -42,7 +42,7 @@ public class PassportController { @GetMapping("/info") @ApiOperation(value = "获得当前管理员信息") - public CommonResult info() { + public CommonResult getInfo() { return success(passportManager.getAdmin(AdminSecurityContextHolder.getAdminId())); } 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 new file mode 100644 index 000000000..fb91a0ea9 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/PermissionController.java @@ -0,0 +1,41 @@ +package cn.iocoder.mall.managementweb.controller.permission; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.managementweb.manager.permission.PermissionManager; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +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.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Set; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +/** + * 权限 Controller + */ +@RestController +@RequestMapping("/permission") +@Api(tags = "权限") +@Validated +public class PermissionController { + + @Autowired + private PermissionManager permissionManager; + + @GetMapping("/list-role-resource") + @ApiOperation("获得角色拥有的资源编号") + @ApiImplicitParam(name = "roleId", value = "角色编号", required = true) + public CommonResult> listRoleResource(Integer roleId) { + return success(permissionManager.listRoleResource(roleId)); + } + + public CommonResult assignRoleResource() { + return success(true); + } + +} 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 5a4ca8945..e3c6337b6 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 @@ -55,13 +55,14 @@ public class RoleController { @GetMapping("/get") @ApiOperation("获得角色") + @ApiImplicitParam(name = "roleId", value = "角色编号", required = true) public CommonResult getRole(@RequestParam("roleId") Integer roleId) { return success(roleManager.getRole(roleId)); } @GetMapping("/list") @ApiOperation("获得角色列表") - @ApiImplicitParam(name = "roleId", value = "角色编号列表", required = true) + @ApiImplicitParam(name = "roleIds", value = "角色编号列表", required = true) public CommonResult> getRoles(@RequestParam("roleIds") List roleIds) { return success(roleManager.listRole(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 new file mode 100644 index 000000000..7091f0ef5 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/PermissionAssignRoleResourceDTO.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 PermissionAssignRoleResourceDTO { + + @ApiModelProperty(value = "角色名", required = true, example = "管理员") + @NotNull(message = "角色编号不能为空") + private Integer roleId; + @ApiModelProperty(value = "资源编号列表", required = true, 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 new file mode 100644 index 000000000..d72cf23fa --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/PermissionConvert.java @@ -0,0 +1,14 @@ +package cn.iocoder.mall.managementweb.convert.permission; + +import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionAssignRoleResourceDTO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface PermissionConvert { + + PermissionConvert INSTANCE = Mappers.getMapper(PermissionConvert.class); + + PermissionAssignRoleResourceDTO convert(cn.iocoder.mall.managementweb.controller.permission.dto.PermissionAssignRoleResourceDTO 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 new file mode 100644 index 000000000..fc942d67b --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/PermissionManager.java @@ -0,0 +1,44 @@ +package cn.iocoder.mall.managementweb.manager.permission; + +import cn.iocoder.common.framework.vo.CommonResult; +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; +import org.apache.dubbo.config.annotation.Reference; +import org.springframework.stereotype.Service; + +import java.util.Set; + +/** + * 权限 Manager + */ +@Service +public class PermissionManager { + + @Reference(version = "${dubbo.consumer.PermissionRpc.version}", validation = "false") + private PermissionRpc permissionRpc; + + /** + * 获得角色拥有的资源编号 + * + * @param roleId 角色编号 + * @return 资源编号列表 + */ + public Set listRoleResource(Integer roleId) { + CommonResult> listAdminRoleIdsResult = permissionRpc.listRoleResourceId(roleId); + listAdminRoleIdsResult.checkError(); + return listAdminRoleIdsResult.getData(); + } + + /** + * 赋予角色资源 + * + * @param assignRoleResourceDTO 赋予角色资源 DTO + */ + public void assignRoleResource(PermissionAssignRoleResourceDTO assignRoleResourceDTO) { + CommonResult assignRoleResourceResult = permissionRpc.assignRoleResource( + PermissionConvert.INSTANCE.convert(assignRoleResourceDTO)); + assignRoleResourceResult.checkError(); + } + +} diff --git a/management-web-app/src/main/resources/application.yml b/management-web-app/src/main/resources/application.yml index 5ae6743d5..1fb73f303 100644 --- a/management-web-app/src/main/resources/application.yml +++ b/management-web-app/src/main/resources/application.yml @@ -34,6 +34,8 @@ dubbo: version: 1.0.0 RoleRpc: version: 1.0.0 + PermissionRpc: + version: 1.0.0 # Swagger 配置项 swagger: diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/PermissionRpc.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/PermissionRpc.java new file mode 100644 index 000000000..12708905a --- /dev/null +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/PermissionRpc.java @@ -0,0 +1,29 @@ +package cn.iocoder.mall.systemservice.rpc.permission; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionAssignRoleResourceDTO; + +import java.util.Set; + +/** + * 权限 Rpc 接口 + */ +public interface PermissionRpc { + + /** + * 获得角色拥有的资源编号 + * + * @param roleId 角色编号 + * @return 资源编号列表 + */ + CommonResult> listRoleResourceId(Integer roleId); + + /** + * 赋予角色资源 + * + * @param assignRoleResourceDTO 赋予角色资源 DTO + * @return 成功 + */ + CommonResult assignRoleResource(PermissionAssignRoleResourceDTO assignRoleResourceDTO); + +} 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 new file mode 100644 index 000000000..d5d7e6092 --- /dev/null +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/PermissionAssignRoleResourceDTO.java @@ -0,0 +1,26 @@ +package cn.iocoder.mall.systemservice.rpc.permission.dto; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import java.util.Set; + +/** + * 赋予角色资源 DTO + */ +@Data +@Accessors(chain = true) +public class PermissionAssignRoleResourceDTO { + + /** + * 角色编号 + */ + @NotNull(message = "角色编号不能为空") + private Integer roleId; + /** + * 资源编号列表 + */ + private Set resourceIds; + +} 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 new file mode 100644 index 000000000..1e5a0919c --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/PermissionManager.java @@ -0,0 +1,38 @@ +package cn.iocoder.mall.systemservice.manager.permission; + +import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionAssignRoleResourceDTO; +import cn.iocoder.mall.systemservice.service.permission.PermissionService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Set; + +/** + * 权限 Manager + */ +@Service +public class PermissionManager { + + @Autowired + private PermissionService permissionService; + + /** + * 获得角色拥有的资源编号 + * + * @param roleId 角色编号 + * @return 资源编号列表 + */ + public Set listRoleResourceId(Integer roleId) { + return permissionService.listRoleResourceId(roleId); + } + + /** + * 赋予角色资源 + * + * @param assignResourceDTO 赋予角色资源 DTO + */ + public void assignRoleResource(PermissionAssignRoleResourceDTO assignResourceDTO) { + permissionService.assignRoleResource(assignResourceDTO.getRoleId(), assignResourceDTO.getResourceIds()); + } + +} 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 new file mode 100644 index 000000000..dc4f162a1 --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/PermissionRpcImpl.java @@ -0,0 +1,33 @@ +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.PermissionAssignRoleResourceDTO; +import org.apache.dubbo.config.annotation.Service; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Set; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +/** + * 权限 Rpc 实现类 + */ +@Service(version = "${dubbo.provider.PermissionRpc.version}", validation = "false") +public class PermissionRpcImpl implements PermissionRpc { + + @Autowired + private PermissionManager permissionManager; + + @Override + public CommonResult> listRoleResourceId(Integer roleId) { + return success(permissionManager.listRoleResourceId(roleId)); + } + + @Override + public CommonResult assignRoleResource(PermissionAssignRoleResourceDTO assignRoleResourceDTO) { + permissionManager.assignRoleResource(assignRoleResourceDTO); + return success(true); + } + +} 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 new file mode 100644 index 000000000..9beab3f69 --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/PermissionService.java @@ -0,0 +1,81 @@ +package cn.iocoder.mall.systemservice.service.permission; + +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.permission.RoleResourceDO; +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 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; + +/** + * 权限 Service + */ +@Service +public class PermissionService { + + @Autowired + private RoleMapper roleMapper; + @Autowired + private ResourceMapper resourceMapper; + @Autowired + private AdminRoleMapper adminRoleMapper; + @Autowired + private RoleResourceMapper roleResourceMapper; + + /** + * 获得角色拥有的资源编号 + * + * @param roleId 角色编号 + * @return 资源编号列表 + */ + public Set listRoleResourceId(Integer roleId) { + List roleResourceDOs = roleResourceMapper.selectListByRoleId(roleId); + return CollectionUtils.convertSet(roleResourceDOs, RoleResourceDO::getResourceId); + } + + /** + * 赋予角色资源 + * + * @param roleId 角色编号 + * @param resourceIds 资源编号列表 + */ + public void assignRoleResource(Integer roleId, Set resourceIds) { + // 校验角色是否存在 + if (roleMapper.selectById(roleId) == null) { + throw ServiceExceptionUtil.exception(ROLE_NOT_EXISTS); + } + // 校验是否有不存在的资源 + if (!CollectionUtils.isEmpty(resourceIds)) { + int dbResourceSize = resourceMapper.selectCountByIdsAndType(resourceIds, null); + if (resourceIds.size() != dbResourceSize) { + throw ServiceExceptionUtil.exception(AUTHORIZATION_ROLE_ASSIGN_RESOURCE_NOT_EXISTS); + } + } + // TODO 芋艿,这里先简单实现。即方式是,删除老的分配的资源关系,然后添加新的分配的资源关系 + // 标记角色原资源关系都为删除 + 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()); + roleResourceMapper.insertList(roleResources); + } + } + +} diff --git a/system-service-project/system-service-app/src/main/resources/application.yaml b/system-service-project/system-service-app/src/main/resources/application.yaml index 3ad04327a..4fcb373cc 100644 --- a/system-service-project/system-service-app/src/main/resources/application.yaml +++ b/system-service-project/system-service-app/src/main/resources/application.yaml @@ -43,3 +43,5 @@ dubbo: version: 1.0.0 RoleRpc: version: 1.0.0 + PermissionRpc: + version: 1.0.0 diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationService.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationService.java index 080d8c96c..d6b43ff88 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationService.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationService.java @@ -58,10 +58,5 @@ public interface AuthorizationService { */ Set getRoleResources(AuthorizationGetRoleResourcesDTO getRoleResourcesDTO); - /** - * 给指定权限授予权限。如果更新失败,则抛出 {@link ServiceException} 异常 - * - * @param assignRoleResourceDTO 授予权限 DTO - */ - void assignRoleResource(AuthorizationAssignRoleResourceDTO assignRoleResourceDTO); + } 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 0115b3f14..0eb906d81 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 @@ -114,17 +114,6 @@ public class AuthorizationServiceImpl implements AuthorizationService { // return accountRoleMap; // } - @Override - public List getResourceTreeByAccountId(AuthorizationGetResourcesByAccountIdDTO getResourcesByAccountIdDTO) { - // 查询管理员拥有的角色关联数据 - List accountRoleDOs = accountRoleMapper.selectByAccountId(getResourcesByAccountIdDTO.getAccountId()); - if (CollectionUtil.isEmpty(accountRoleDOs)) { - return Collections.emptyList(); - } - Set roleIds = CollectionUtil.convertSet(accountRoleDOs, AccountRoleDO::getRoleId); - - } - @Override public Set getRoleResources(AuthorizationGetRoleResourcesDTO getRoleResourcesDTO) { Set roleIds = Collections.singleton(getRoleResourcesDTO.getRoleId()); @@ -140,37 +129,6 @@ public class AuthorizationServiceImpl implements AuthorizationService { return CollectionUtil.convertSet(roleResourceDOs, RoleResourceDO::getResourceId); } - @Override - public void assignRoleResource(AuthorizationAssignRoleResourceDTO assignRoleResourceDTO) { - Integer roleId = assignRoleResourceDTO.getRoleId(); - Set resourceIds = assignRoleResourceDTO.getResourceIds(); - // 校验角色是否存在 - if (roleService.getRole(roleId) == null) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ROLE_NOT_EXISTS.getCode()); - } - // 校验是否有不存在的资源 - if (!CollectionUtil.isEmpty(resourceIds)) { - int dbResourceSize = resourceService.countResource(new ResourceCountDTO().setIds(resourceIds)); - if (resourceIds.size() != dbResourceSize) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.AUTHORIZATION_ROLE_ASSIGN_RESOURCE_NOT_EXISTS.getCode()); - } - } - // TODO 芋艿,这里先简单实现。即方式是,删除老的分配的资源关系,然后添加新的分配的资源关系 - // 标记角色原资源关系都为删除 - roleResourceMapper.deleteByRoleId(roleId); - // 创建 RoleResourceDO 数组,并插入到数据库 - if (!CollectionUtil.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()); - roleResourceMapper.insertList(roleResources); - } - // TODO 插入操作日志 - } - @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 index f60b1b2b2..e4430bd6d 100644 --- 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 @@ -20,12 +20,4 @@ public interface ResourceService { int countResource(ResourceCountDTO countDTO); - /** - * 获得资源树 - * - * @param getTreeDTO 查询条件 - * @return 资源树 - */ - List getResourceTree(ResourceGetTreeDTO getTreeDTO); - } 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 index 18e4b7d5e..9b8d0b0ef 100644 --- 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 @@ -28,9 +28,6 @@ public class ResourceServiceImpl implements ResourceService { @Autowired private ApplicationEventPublisher eventPublisher; - @Autowired - private ResourceMapper resourceMapper; - @Override public List getResourcesByPermissions(Collection permissions) { List resourceDOs = resourceMapper.selectListByPermissions(permissions); @@ -43,17 +40,6 @@ public class ResourceServiceImpl implements ResourceService { return ResourceConvert.INSTANCE.convertList(resourceDOs); } - @Override - public int countResource(ResourceCountDTO countDTO) { - return resourceMapper.selectCountByIdsAndType(countDTO.getIds(), countDTO.getType()); - } - @Override - public List getResourceTree(ResourceGetTreeDTO getTreeDTO) { - // 获得对应的资源列表 - List resourceDOs = resourceMapper.selectListByIdsAndType(getTreeDTO.getIds(), getTreeDTO.getType()); - // 拼装成树 - - } } diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsResourceController.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsResourceController.java deleted file mode 100644 index 2e78e610b..000000000 --- a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsResourceController.java +++ /dev/null @@ -1,41 +0,0 @@ -package cn.iocoder.mall.system.rest.controller.authorization; - -import cn.iocoder.common.framework.enums.MallConstants; -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.security.core.annotation.RequiresPermissions; -import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder; -import cn.iocoder.mall.system.biz.bo.authorization.ResourceTreeNodeBO; -import cn.iocoder.mall.system.biz.dto.authorization.ResourceAddDTO; -import cn.iocoder.mall.system.biz.dto.authorization.ResourceDeleteDTO; -import cn.iocoder.mall.system.biz.dto.authorization.ResourceGetTreeDTO; -import cn.iocoder.mall.system.biz.dto.authorization.ResourceUpdateDTO; -import cn.iocoder.mall.system.biz.service.authorization.ResourceService; -import cn.iocoder.mall.system.rest.convert.authorization.AdminsResourceConvert; -import cn.iocoder.mall.system.rest.request.authorization.AdminsResourceAddRequest; -import cn.iocoder.mall.system.rest.request.authorization.AdminsResourceUpdateRequest; -import cn.iocoder.mall.system.rest.response.authorization.AdminsResourceTreeResponse; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiOperation; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@RequestMapping(MallConstants.ROOT_PATH_ADMIN + "/resource") -@Api(tags = "管理员 - 资源 API") -public class AdminsResourceController { - - @Autowired - private ResourceService resourceService; - - @GetMapping("/tree") - @ApiOperation(value = "获得所有资源,按照树形结构返回") - @RequiresPermissions("system:resource:tree") - public CommonResult> tree() { - List resourceTreeNodeBOs = resourceService.getResourceTree(new ResourceGetTreeDTO()); - return CommonResult.success(AdminsResourceConvert.INSTANCE.convertList(resourceTreeNodeBOs)); - } - -}