完成角色权限分配功能的迁移

This commit is contained in:
YunaiV 2020-07-13 19:24:42 +08:00
parent 99c591d6f9
commit 61e5cfe617
54 changed files with 314 additions and 691 deletions

View File

@ -33,7 +33,7 @@ public class AdminController {
@ApiOperation(value = "管理员分页")
@GetMapping("/page")
@RequiresPermissions("system.admin.page")
@RequiresPermissions("system:page")
public CommonResult<PageResult<AdminPageItemVO>> page(AdminPageDTO adminPageDTO) {
return success(adminManager.pageAdmin(adminPageDTO));
}

View File

@ -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}}
###

View File

@ -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<Set<Integer>> listRoleResource(Integer roleId) {
return success(permissionManager.listRoleResource(roleId));
public CommonResult<Set<Integer>> 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<Set<Integer>> listAdminRoles(Integer adminId) {
return success(permissionManager.listAdminRoles(adminId));
}
@PostMapping("/assign-admin-role")
@ApiOperation("赋予用户角色")
public CommonResult<Boolean> assignAdminRole(PermissionAssignAdminRoleDTO assignAdminRoleDTO) {
permissionManager.assignAdminRole(assignAdminRoleDTO);
return success(true);
}
}

View File

@ -61,8 +61,8 @@ public class ResourceController {
@GetMapping("/list")
@ApiOperation("获得资源列表")
@ApiImplicitParam(name = "resourceId", value = "资源编号列表", required = true)
public CommonResult<List<ResourceVO>> listResource(@RequestParam("resourceIds") List<Integer> resourceIds) {
return success(resourceManager.listResource(resourceIds));
public CommonResult<List<ResourceVO>> listResources(@RequestParam("resourceIds") List<Integer> resourceIds) {
return success(resourceManager.listResources(resourceIds));
}
@GetMapping("/tree")

View File

@ -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

View File

@ -60,11 +60,17 @@ public class RoleController {
return success(roleManager.getRole(roleId));
}
@GetMapping("/list-all")
@ApiOperation("获得所有角色列表")
public CommonResult<List<RoleVO>> listAllRoles() {
return success(roleManager.listAllRoles());
}
@GetMapping("/list")
@ApiOperation("获得角色列表")
@ApiImplicitParam(name = "roleIds", value = "角色编号列表", required = true)
public CommonResult<List<RoleVO>> getRoles(@RequestParam("roleIds") List<Integer> roleIds) {
return success(roleManager.listRole(roleIds));
public CommonResult<List<RoleVO>> listRoles(@RequestParam("roleIds") List<Integer> roleIds) {
return success(roleManager.listRoles(roleIds));
}
@GetMapping("/page")

View File

@ -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<Integer> roleIds;
}

View File

@ -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<Integer> resourceIds;
}

View File

@ -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);
}

View File

@ -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<Integer> listRoleResource(Integer roleId) {
CommonResult<Set<Integer>> listAdminRoleIdsResult = permissionRpc.listRoleResourceId(roleId);
listAdminRoleIdsResult.checkError();
return listAdminRoleIdsResult.getData();
public Set<Integer> listRoleResources(Integer roleId) {
CommonResult<Set<Integer>> 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<Boolean> assignAdminRoleResult = permissionRpc.assignAdminRole(
PermissionConvert.INSTANCE.convert(assignAdminRoleDTO));
assignAdminRoleResult.checkError();
}
/**
* 获得用户拥有的角色编号列表
*
* @param adminId 管理员编号
* @return 角色编号列表
*/
public Set<Integer> listAdminRoles(Integer adminId) {
CommonResult<Set<Integer>> listAdminRoleIdsResult = permissionRpc.listAdminRoleIds(adminId);
listAdminRoleIdsResult.checkError();
return listAdminRoleIdsResult.getData();
}
}

View File

@ -79,7 +79,7 @@ public class ResourceManager {
* @param resourceIds 资源编号列表
* @return 资源列表
*/
public List<ResourceVO> listResource(List<Integer> resourceIds) {
public List<ResourceVO> listResources(List<Integer> resourceIds) {
CommonResult<List<cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO>> listResourceResult = resourceRpc.listResource(resourceIds);
return ResourceConvert.INSTANCE.convertList(listResourceResult.getData());
}

View File

@ -66,14 +66,25 @@ public class RoleManager {
return RoleConvert.INSTANCE.convert(getRoleResult.getData());
}
/**
* 获得所有角色
*
* @return 角色列表
*/
public List<RoleVO> listAllRoles() {
CommonResult<List<cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO>> listRoleResult = roleRpc.listAllRoles();
listRoleResult.checkError();
return RoleConvert.INSTANCE.convertList(listRoleResult.getData());
}
/**
* 获得角色列表
*
* @param roleIds 角色编号列表
* @return 角色列表
*/
public List<RoleVO> listRole(List<Integer> roleIds) {
CommonResult<List<cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO>> listRoleResult = roleRpc.listRole(roleIds);
public List<RoleVO> listRoles(List<Integer> roleIds) {
CommonResult<List<cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO>> listRoleResult = roleRpc.listRoles(roleIds);
listRoleResult.checkError();
return RoleConvert.INSTANCE.convertList(listRoleResult.getData());
}

View File

@ -30,7 +30,7 @@ public enum SystemErrorCodeEnum implements ServiceExceptionUtil.Enumerable<Syste
ADMIN_STATUS_EQUALS(1002002003, "账号已经是该状态"),
// ADMIN_DELETE_ONLY_DISABLE(1002002004, "只有关闭的账号才可以删除"),
ADMIN_ADMIN_STATUS_CAN_NOT_UPDATE(1002002005, "管理员的账号状态不允许变更"),
// ADMIN_ASSIGN_ROLE_NOT_EXISTS(1002002006, "分配员工角色时,有角色不存在"),
ADMIN_ASSIGN_ROLE_NOT_EXISTS(1002002006, "分配员工角色时,有角色不存在"),
ADMIN_ADMIN_CAN_NOT_UPDATE(1002002008, "管理员的账号不允许变更"),
ADMIN_USERNAME_NOT_EXISTS(1002002008, "账号不存在"),

View File

@ -1,6 +1,7 @@
package cn.iocoder.mall.systemservice.rpc.permission;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionAssignAdminRoleDTO;
import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionAssignRoleResourceDTO;
import java.util.Set;
@ -16,7 +17,7 @@ public interface PermissionRpc {
* @param roleId 角色编号
* @return 资源编号列表
*/
CommonResult<Set<Integer>> listRoleResourceId(Integer roleId);
CommonResult<Set<Integer>> listRoleResourceIds(Integer roleId);
/**
* 赋予角色资源
@ -26,4 +27,20 @@ public interface PermissionRpc {
*/
CommonResult<Boolean> assignRoleResource(PermissionAssignRoleResourceDTO assignRoleResourceDTO);
/**
* 获得管理员拥有的角色编号列表
*
* @param adminId 管理员编号
* @return 资源编号列表
*/
CommonResult<Set<Integer>> listAdminRoleIds(Integer adminId);
/**
* 赋予管理员角色
*
* @param assignAdminRoleDTO 赋予管理员角色 DTO
* @return 成功
*/
CommonResult<Boolean> assignAdminRole(PermissionAssignAdminRoleDTO assignAdminRoleDTO);
}

View File

@ -45,13 +45,20 @@ public interface RoleRpc {
*/
CommonResult<RoleVO> getRole(Integer roleId);
/**
* 获得所有角色
*
* @return 角色列表
*/
CommonResult<List<RoleVO>> listAllRoles();
/**
* 获得角色列表
*
* @param roleIds 角色编号列表
* @return 角色列表
*/
CommonResult<List<RoleVO>> listRole(List<Integer> roleIds);
CommonResult<List<RoleVO>> listRoles(List<Integer> roleIds);
/**
* 获得角色分页

View File

@ -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<Integer> roleIds;
}

View File

@ -15,23 +15,23 @@ public interface AdminRoleMapper extends BaseMapper<AdminRoleDO> {
return selectList(new QueryWrapper<AdminRoleDO>().eq("admin_id", adminId));
}
// default List<AdminRoleDO> selectListByAccountIds(Collection<Integer> accountIds) {
// return selectList(new QueryWrapper<AdminRoleDO>().in("account_id", accountIds));
// }
//
// default int deleteByAccountId(Integer accountId) {
// return delete(new QueryWrapper<AdminRoleDO>().eq("account_id", accountId));
// }
//
// default int deleteByRoleId(Integer roleId) {
// return delete(new QueryWrapper<AdminRoleDO>().eq("role_id", roleId));
// }
default List<AdminRoleDO> selectListByAdminId(Integer adminId) {
return selectList(new QueryWrapper<AdminRoleDO>().eq("admin_id", adminId));
}
default int deleteByAdminId(Integer adminId) {
return delete(new QueryWrapper<AdminRoleDO>().eq("admin_id", adminId));
}
default int deleteByRoleId(Integer roleId) {
return delete(new QueryWrapper<AdminRoleDO>().eq("role_id", roleId));
}
/**
* 批量插入因为 MyBaits Plus 的批量插入是基于 Service 实现所以只好写 XML
*
* @param accountRoleDOs 数组
* @param adminRoleDOs 数组
*/
int insertList(@Param("accountRoleDOs") List<AdminRoleDO> accountRoleDOs);
int insertList(@Param("adminRoleDOs") List<AdminRoleDO> adminRoleDOs);
}

View File

@ -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<Integer> listRoleResourceId(Integer roleId) {
public Set<Integer> 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<Integer> listAdminRoleIds(Integer adminId) {
return permissionService.listAdminRoleIds(adminId);
}
/**
* 赋予管理员角色
*
* @param assignAdminRoleDTO 赋予管理员角色 DTO
*/
public void assignAdminRole(PermissionAssignAdminRoleDTO assignAdminRoleDTO) {
permissionService.assignAdminRole(assignAdminRoleDTO.getAdminId(), assignAdminRoleDTO.getRoleIds());
}
}

View File

@ -69,8 +69,8 @@ public class ResourceManager {
*
* @return 资源列表
*/
public List<ResourceVO> listResource() {
List<ResourceBO> resourceBOs = resourceService.listResource();
public List<ResourceVO> listResources() {
List<ResourceBO> resourceBOs = resourceService.listResources();
return ResourceConvert.INSTANCE.convertList02(resourceBOs);
}
@ -80,8 +80,8 @@ public class ResourceManager {
* @param resourceIds 资源编号列表
* @return 资源列表
*/
public List<ResourceVO> listResource(List<Integer> resourceIds) {
List<ResourceBO> resourceBOs = resourceService.listResource(resourceIds);
public List<ResourceVO> listResources(List<Integer> resourceIds) {
List<ResourceBO> resourceBOs = resourceService.listResources(resourceIds);
return ResourceConvert.INSTANCE.convertList02(resourceBOs);
}
@ -92,13 +92,13 @@ public class ResourceManager {
* @param type 资源类型允许空
* @return 资源列表
*/
public List<ResourceVO> listRoleResource(Collection<Integer> roleIds, Integer type) {
public List<ResourceVO> listRoleResources(Collection<Integer> roleIds, Integer type) {
List<ResourceBO> 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);
}

View File

@ -63,13 +63,23 @@ public class RoleManager {
return RoleConvert.INSTANCE.convert(roleBO);
}
/**
* 获得所有角色
*
* @return 角色列表
*/
public List<RoleVO> listAllRoles() {
List<RoleBO> roleBOs = roleService.listAllRole();
return RoleConvert.INSTANCE.convertList02(roleBOs);
}
/**
* 获得角色列表
*
* @param roleIds 角色编号列表
* @return 角色列表
*/
public List<RoleVO> listRole(List<Integer> roleIds) {
public List<RoleVO> listRoles(List<Integer> roleIds) {
List<RoleBO> roleBOs = roleService.listRole(roleIds);
return RoleConvert.INSTANCE.convertList02(roleBOs);
}

View File

@ -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<Set<Integer>> listRoleResourceId(Integer roleId) {
return success(permissionManager.listRoleResourceId(roleId));
public CommonResult<Set<Integer>> listRoleResourceIds(Integer roleId) {
return success(permissionManager.listRoleResourceIds(roleId));
}
@Override
@ -30,4 +31,15 @@ public class PermissionRpcImpl implements PermissionRpc {
return success(true);
}
@Override
public CommonResult<Set<Integer>> listAdminRoleIds(Integer adminId) {
return success(permissionManager.listAdminRoleIds(adminId));
}
@Override
public CommonResult<Boolean> assignAdminRole(PermissionAssignAdminRoleDTO assignAdminRoleDTO) {
permissionManager.assignAdminRole(assignAdminRoleDTO);
return success(true);
}
}

View File

@ -46,17 +46,17 @@ public class ResourceRpcImpl implements ResourceRpc {
@Override
public CommonResult<List<ResourceVO>> listResource() {
return success(resourceManager.listResource());
return success(resourceManager.listResources());
}
@Override
public CommonResult<List<ResourceVO>> listResource(List<Integer> resourceIds) {
return success(resourceManager.listResource(resourceIds));
return success(resourceManager.listResources(resourceIds));
}
@Override
public CommonResult<List<ResourceVO>> listRoleResource(Collection<Integer> roleIds, Integer type) {
return success(resourceManager.listRoleResource(roleIds, type));
return success(resourceManager.listRoleResources(roleIds, type));
}
}

View File

@ -47,8 +47,13 @@ public class RoleRpcImpl implements RoleRpc {
}
@Override
public CommonResult<List<RoleVO>> listRole(List<Integer> roleIds) {
return success(roleManager.listRole(roleIds));
public CommonResult<List<RoleVO>> listAllRoles() {
return success(roleManager.listAllRoles());
}
@Override
public CommonResult<List<RoleVO>> listRoles(List<Integer> roleIds) {
return success(roleManager.listRoles(roleIds));
}
@Override

View File

@ -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<Integer> listRoleResourceId(Integer roleId) {
public Set<Integer> listRoleResourceIds(Integer roleId) {
List<RoleResourceDO> 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<Integer> resourceIds) {
// 校验角色是否存在
if (roleMapper.selectById(roleId) == null) {
@ -68,14 +74,52 @@ public class PermissionService {
roleResourceMapper.deleteByRoleId(roleId);
// 创建 RoleResourceDO 数组并插入到数据库
if (!CollectionUtils.isEmpty(resourceIds)) {
List<RoleResourceDO> 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<RoleResourceDO> 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<Integer> roleIds) {
// 校验账号存在
AdminDO admin = adminMapper.selectById(adminId);
if (admin == null) {
throw ServiceExceptionUtil.exception(ADMIN_NOT_FOUND);
}
// 校验是否有不存在的角色
if (!CollectionUtils.isEmpty(roleIds)) {
List<RoleDO> 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<AdminRoleDO> adminRoleDOs = roleIds.stream()
.map(roleId -> new AdminRoleDO().setAdminId(adminId).setRoleId(roleId)).collect(Collectors.toList());
adminRoleMapper.insertList(adminRoleDOs);
}
}
/**
* 获得管理员拥有的角色编号列表
*
* @param adminId 管理员编号
* @return 角色编号列表
*/
public Set<Integer> listAdminRoleIds(Integer adminId) {
List<AdminRoleDO> adminRoleDOs = adminRoleMapper.selectListByAdminId(adminId);
return CollectionUtils.convertSet(adminRoleDOs, AdminRoleDO::getRoleId);
}
}

View File

@ -114,7 +114,7 @@ public class ResourceService {
* @param resourceIds 资源编号列表
* @return 资源列表
*/
public List<ResourceBO> listResource(List<Integer> resourceIds) {
public List<ResourceBO> listResources(List<Integer> resourceIds) {
List<ResourceDO> resourceDOs = resourceMapper.selectBatchIds(resourceIds);
return ResourceConvert.INSTANCE.convertList(resourceDOs);
}
@ -124,7 +124,7 @@ public class ResourceService {
*
* @return 资源树结构
*/
public List<ResourceBO> listResource() {
public List<ResourceBO> listResources() {
List<ResourceDO> resourceDOs = resourceMapper.selectList(null);
return ResourceConvert.INSTANCE.convertList(resourceDOs);
}
@ -135,7 +135,7 @@ public class ResourceService {
* @param type 资源类型允许空
* @return 资源列表
*/
public List<ResourceBO> listResourceByType(Integer type) {
public List<ResourceBO> listResourcesByType(Integer type) {
List<ResourceDO> resourceDOs = resourceMapper.selectListByType(type);
return ResourceConvert.INSTANCE.convertList(resourceDOs);
}
@ -147,7 +147,7 @@ public class ResourceService {
* @param type 资源类型允许空
* @return 资源列表
*/
public List<ResourceBO> listRoleResourceByType(Collection<Integer> roleIds, Integer type) {
public List<ResourceBO> listRoleResourcesByType(Collection<Integer> roleIds, Integer type) {
List<RoleResourceDO> roleResourceDOs = roleResourceMapper.selectListByRoleIds(roleIds);
if (CollectionUtils.isEmpty(roleResourceDOs)) {
return Collections.emptyList();

View File

@ -110,6 +110,16 @@ public class RoleService {
return RoleConvert.INSTANCE.convert(roleDO);
}
/**
* 获得所有角色
*
* @return 角色列表
*/
public List<RoleBO> listAllRole() {
List<RoleDO> roleDOs = roleMapper.selectList(null);
return RoleConvert.INSTANCE.convertList(roleDOs);
}
/**
* 获得角色列表
*

View File

@ -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 {
/**
* 账号编号

View File

@ -4,10 +4,10 @@
<insert id="insertList">
INSERT INTO permission_admin_role (
admin_id, role_id, create_time, deleted
admin_id, role_id
) VALUES
<foreach collection="adminRoleDOs" item="adminRole" separator=",">
(#{adminRole.adminId}, #{adminRole.roleId}, #{adminRole.createTime}, #{adminRole.deleted})
(#{adminRole.adminId}, #{adminRole.roleId})
</foreach>
</insert>

View File

@ -4,10 +4,10 @@
<insert id="insertList">
INSERT INTO permission_role_resource (
resource_id, role_id, create_time, deleted
resource_id, role_id
) VALUES
<foreach collection="roleResources" item="roleResource" separator=",">
(#{roleResource.resourceId}, #{roleResource.roleId}, #{roleResource.createTime}, #{roleResource.deleted})
(#{roleResource.resourceId}, #{roleResource.roleId})
</foreach>
</insert>

View File

@ -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 {
}

View File

@ -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<ResourceTreeNodeBO> children;
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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<Integer> resourceIds;
}

View File

@ -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;
}

View File

@ -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<Integer> accountIds;
}

View File

@ -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;
}

View File

@ -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<Integer> ids;
/**
* 资源类型
*/
private Integer type;
}

View File

@ -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<Integer> ids;
/**
* 资源类型
*/
private Integer type;
}

View File

@ -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<Integer> ids;
/**
* 资源类型
*/
private Integer type;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -73,62 +73,6 @@ public class AuthorizationServiceImpl implements AuthorizationService {
}
}
@Override
public List<ResourceBO> getResourcesByAccountId(AuthorizationGetResourcesByAccountIdDTO getResourcesByAccountIdDTO) {
// 查询管理员拥有的角色关联数据
List<AccountRoleDO> accountRoleDOs = accountRoleMapper.selectByAccountId(getResourcesByAccountIdDTO.getAccountId());
if (CollectionUtil.isEmpty(accountRoleDOs)) {
return Collections.emptyList();
}
Set<Integer> roleIds = CollectionUtil.convertSet(accountRoleDOs, AccountRoleDO::getRoleId);
// 判断是否为超管若是超管默认有所有权限
if (roleService.hasSuperAdmin(roleIds)) {
return resourceService.getResources(new ResourceGetListDTO().setType(getResourcesByAccountIdDTO.getType()));
}
// 查询角色拥有的资源关联数据
List<RoleResourceDO> roleResourceDOs = roleResourceMapper.selectListByRoleIds(roleIds);
if (CollectionUtil.isEmpty(roleResourceDOs)) {
return Collections.emptyList();
}
Set<Integer> resourceIds = CollectionUtil.convertSet(roleResourceDOs, RoleResourceDO::getResourceId);
// 查询对应资源列表
return resourceService.getResources(new ResourceGetListDTO().setIds(resourceIds).setType(getResourcesByAccountIdDTO.getType()));
}
@Override
public Map<Integer, Set<RoleBO>> getRoleMapByAccountIds(AuthorizationGetRoleMapByAccountIdsDTO getRoleMapByAccountIdsDTO) {
return null;
}
// @Override
// public Map<Integer, Set<RoleBO>> getRoleIdMapByAccountIds(AuthorizationGetRoleMapByAccountIdsDTO getRoleMapByAccountIdsDTO) {
// // 查询管理员拥有的角色关联数据
// List<AccountRoleDO> accountRoleDOs = accountRoleMapper.selectListByAccountIds(getRoleMapByAccountIdsDTO.getAccountIds());
// if (CollectionUtil.isEmpty(accountRoleDOs)) {
// return Collections.emptyMap();
// }
// // 构建结果
// Map<Integer, Set<Integer>> accountRoleMap = CollectionUtil.convertMultiMap2(accountRoleDOs,
// AccountRoleDO::getAccountId, AccountRoleDO::getRoleId);
// getRoleMapByAccountIdsDTO.getAccountIds().forEach(accountId -> accountRoleMap.putIfAbsent(accountId, Collections.emptySet()));
// return accountRoleMap;
// }
@Override
public Set<Integer> getRoleResources(AuthorizationGetRoleResourcesDTO getRoleResourcesDTO) {
Set<Integer> roleIds = Collections.singleton(getRoleResourcesDTO.getRoleId());
// 判断是否为超管若是超管默认有所有权限
if (roleService.hasSuperAdmin(roleIds)) {
return CollectionUtil.convertSet(resourceService.getResources(new ResourceGetListDTO()), ResourceBO::getId);
}
// 查询角色拥有的资源关联数据
List<RoleResourceDO> 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());

View File

@ -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<ResourceBO> getResourcesByPermissions(Collection<String> permissions);
List<ResourceBO> getResources(ResourceGetListDTO getListDTO);
int countResource(ResourceCountDTO countDTO);
}

View File

@ -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<ResourceBO> getResourcesByPermissions(Collection<String> permissions) {
List<ResourceDO> resourceDOs = resourceMapper.selectListByPermissions(permissions);
return ResourceConvert.INSTANCE.convertList(resourceDOs);
}
@Override
public List<ResourceBO> getResources(ResourceGetListDTO getListDTO) {
List<ResourceDO> resourceDOs = resourceMapper.selectListByIdsAndType(getListDTO.getIds(), getListDTO.getType());
return ResourceConvert.INSTANCE.convertList(resourceDOs);
}
}

View File

@ -42,45 +42,6 @@ public class AdminsAuthorizationController {
@Autowired
private RoleService roleService;
@GetMapping("/menu-resource-tree")
@ApiOperation(value = "获得当前账号的菜单资源树", notes = "以树结构返回")
public CommonResult<List<AdminsAuthorizationMenuTreeResponse>> menuResourceTree() {
List<ResourceTreeNodeBO> 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<Set<String>> resourcePermissions() {
List<ResourceBO> 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<List<AdminsAuthorizationRoleResourceTreeResponse>> roleResourceTree(@RequestParam("roleId") Integer roleId) {
// 1. 获得完整的资源树
List<ResourceTreeNodeBO> resourceTreeNodeBOs = resourceService.getResourceTree(new ResourceGetTreeDTO());
// 2. 获得角色拥有的子树
Set<Integer> 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<Boolean> 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")

View File

@ -1,4 +0,0 @@
/**
* 提供 system 服务的 RPC 接口的实现提供内部调用
*/
package cn.iocoder.mall.system.rpc;

View File

@ -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<OAuth2AccessTokenResponse> authenticate(OAuth2AccessTokenAuthenticateRequest authenticateRequest) {
// 执行认证
OAuth2AccessTokenAuthenticateDTO authenticateDTO = OAuth2Convert.INSTANCE.convert(authenticateRequest);
OAuth2AuthenticateBO accessTokenBO = oauth2Service.authenticate(authenticateDTO);
// 返回结果
OAuth2AccessTokenResponse accessTokenResponse = OAuth2Convert.INSTANCE.convert(accessTokenBO);
return CommonResult.success(accessTokenResponse);
}
}