增加管理员拥有的菜单列表

This commit is contained in:
YunaiV
2020-07-08 20:21:55 +08:00
parent e4d3254869
commit 6bddebafff
28 changed files with 288 additions and 442 deletions

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 AuthorizationGetResourceTreeByAccountIdDTO {
@NotNull(message = "账号编号不能为空")
private Integer accountId;
/**
* 资源类型
*/
private Integer type;
}

View File

@@ -122,18 +122,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
return Collections.emptyList();
}
Set<Integer> roleIds = CollectionUtil.convertSet(accountRoleDOs, AccountRoleDO::getRoleId);
// 判断是否为超管。若是超管,默认有所有权限
if (roleService.hasSuperAdmin(roleIds)) {
return resourceService.getResourceTree(new ResourceGetTreeDTO().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.getResourceTree(new ResourceGetTreeDTO().setIds(resourceIds).setType(getResourcesByAccountIdDTO.getType()));
}
@Override

View File

@@ -53,30 +53,7 @@ public class ResourceServiceImpl implements ResourceService {
// 获得对应的资源列表
List<ResourceDO> resourceDOs = resourceMapper.selectListByIdsAndType(getTreeDTO.getIds(), getTreeDTO.getType());
// 拼装成树
// 使用 LinkedHashMap 的原因,是为了排序 。实际也可以用 Stream API ,就是太丑了。
Map<Integer, ResourceTreeNodeBO> treeNodeMap = new LinkedHashMap<>();
resourceDOs.stream().sorted(Comparator.comparing(ResourceDO::getSort))
.forEach(resourceDO -> treeNodeMap.put(resourceDO.getId(), ResourceConvert.INSTANCE.convertTreeNode(resourceDO)));
// 处理父子关系
treeNodeMap.values().stream()
.filter(node -> !node.getNode().getPid().equals(ResourceIdEnum.ROOT.getId()))
.forEach((childNode) -> {
// 获得父节点
ResourceTreeNodeBO parentNode = treeNodeMap.get(childNode.getNode().getPid());
if (parentNode == null) {
log.error("[getResourceTree][resource({}) 找不到父资源({})]", childNode.getNode().getId(), childNode.getNode().getPid());
return;
}
if (parentNode.getChildren() == null) { // 初始化 children 数组
parentNode.setChildren(new ArrayList<>());
}
// 将自己添加到父节点中
parentNode.getChildren().add(childNode);
});
// 获得到所有的根节点
return treeNodeMap.values().stream()
.filter(node -> node.getNode().getPid().equals(ResourceIdEnum.ROOT.getId()))
.collect(Collectors.toList());
}
}

View File

@@ -1,39 +0,0 @@
package cn.iocoder.mall.system.biz.service.authorization;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.system.biz.bo.authorization.RoleBO;
import cn.iocoder.mall.system.biz.dto.authorization.RoleAddDTO;
import cn.iocoder.mall.system.biz.dto.authorization.RoleDeleteDTO;
import cn.iocoder.mall.system.biz.dto.authorization.RolePageDTO;
import cn.iocoder.mall.system.biz.dto.authorization.RoleUpdateDTO;
import cn.iocoder.mall.system.biz.dto.authorization.RoleGetListDTO;
import java.util.Collection;
import java.util.List;
/**
* 角色模块 - Service 接口
*/
public interface RoleService {
RoleBO getRole(Integer id);
List<RoleBO> getRoleList(RoleGetListDTO getListDTO);
PageResult<RoleBO> getRolePage(RolePageDTO pageDTO);
/**
* 判断指定角色是否包含超级管理员角色
*
* @param ids 角色编号数组
* @return 是否有超级管理员角色
*/
boolean hasSuperAdmin(Collection<Integer> ids);
Integer addRole(RoleAddDTO roleAddDTO);
void updateRole(RoleUpdateDTO roleUpdateDTO);
void deleteRole(RoleDeleteDTO roleDeleteDTO);
}

View File

@@ -1,50 +0,0 @@
package cn.iocoder.mall.system.biz.service.authorization;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.util.StringUtils;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum;
import cn.iocoder.mall.system.biz.bo.authorization.RoleBO;
import cn.iocoder.mall.system.biz.convert.authorization.RoleConvert;
import cn.iocoder.mall.system.biz.dao.authorization.RoleMapper;
import cn.iocoder.mall.system.biz.dataobject.authorization.RoleDO;
import cn.iocoder.mall.system.biz.dto.authorization.*;
import cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum;
import cn.iocoder.mall.system.biz.enums.authorization.RoleCodeEnum;
import cn.iocoder.mall.system.biz.enums.authorization.RoleTypeEnum;
import cn.iocoder.mall.system.biz.event.authorization.ResourceDeleteEvent;
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.Collection;
import java.util.Date;
import java.util.List;
@Service
public class RoleServiceImpl implements RoleService {
@Autowired
private ApplicationEventPublisher eventPublisher;
@Autowired
private RoleMapper roleMapper;
@Override
public PageResult<RoleBO> getRolePage(RolePageDTO pageDTO) {
return RoleConvert.INSTANCE.convertPage(roleMapper.selectPage(pageDTO));
}
@Override
public boolean hasSuperAdmin(Collection<Integer> ids) {
List<RoleDO> roleDOs = roleMapper.selectBatchIds(ids);
for (RoleDO roleDO : roleDOs) {
if (RoleCodeEnum.SUPER_ADMIN.getCode().equals(roleDO.getCode())) {
return true;
}
}
return false;
}
}