1. 迁移角色相关逻辑

2. admin-web 接入角色新接口
This commit is contained in:
YunaiV
2020-04-29 00:42:33 +08:00
parent 4e5b6ff2cf
commit 0763551d6d
16 changed files with 174 additions and 126 deletions

View File

@@ -4,7 +4,7 @@ import lombok.Data;
import lombok.experimental.Accessors;
/**
* 账号信息 BO
* 账号模块 - 账号信息 BO
*/
@Data
@Accessors(chain = true)

View File

@@ -0,0 +1,18 @@
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

@@ -4,7 +4,7 @@ import cn.iocoder.mall.system.biz.bo.account.AccountBO;
import cn.iocoder.mall.system.biz.dto.account.AccountCreateDTO;
/**
* 账号 Service 接口
* 账号模块 - Service 接口
*/
public interface AccountService {

View File

@@ -5,8 +5,10 @@ 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.AuthorizationCheckPermissionsDTO;
import cn.iocoder.mall.system.biz.dto.authorization.AuthorizationGetResourcesByAccountIdDTO;
import cn.iocoder.mall.system.biz.dto.authorization.AuthorizationGetRoleResourcesDTO;
import java.util.List;
import java.util.Set;
/**
* 授权模块 - Service 接口
@@ -40,4 +42,12 @@ public interface AuthorizationService {
*/
List<ResourceTreeNodeBO> getResourceTreeByAccountId(AuthorizationGetResourcesByAccountIdDTO getResourceTreeByAccountIdDTO);
/**
* 获得指定角色拥有的资源编号集合
*
* @param getRoleResourcesDTO 查询条件 DTO
* @return 资源编号数集合
*/
Set<Integer> getRoleResources(AuthorizationGetRoleResourcesDTO getRoleResourcesDTO);
}

View File

@@ -8,20 +8,14 @@ import cn.iocoder.mall.system.biz.dao.authorization.AccountRoleMapper;
import cn.iocoder.mall.system.biz.dao.authorization.RoleResourceMapper;
import cn.iocoder.mall.system.biz.dataobject.authorization.AccountRoleDO;
import cn.iocoder.mall.system.biz.dataobject.authorization.RoleResourceDO;
import cn.iocoder.mall.system.biz.dto.authorization.AuthorizationCheckPermissionsDTO;
import cn.iocoder.mall.system.biz.dto.authorization.AuthorizationGetResourcesByAccountIdDTO;
import cn.iocoder.mall.system.biz.dto.authorization.ResourceGetListDTO;
import cn.iocoder.mall.system.biz.dto.authorization.ResourceGetTreeDTO;
import cn.iocoder.mall.system.biz.dto.authorization.*;
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.event.EventListener;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import static cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum.AUTHORIZATION_PERMISSION_DENY;
@@ -119,6 +113,21 @@ public class AuthorizationServiceImpl implements AuthorizationService {
return resourceService.getResourceTree(new ResourceGetTreeDTO().setIds(resourceIds).setType(getResourcesByAccountIdDTO.getType()));
}
@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

@@ -17,6 +17,12 @@ public interface ResourceService {
List<ResourceBO> getResources(ResourceGetListDTO getListDTO);
/**
* 获得资源树
*
* @param getTreeDTO 查询条件
* @return 资源树
*/
List<ResourceTreeNodeBO> getResourceTree(ResourceGetTreeDTO getTreeDTO);
Integer addResource(ResourceAddDTO addDTO);