feat(role): 添加角色菜单和部门树获取功能
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Volo.Abp.Application.Services;
|
using Volo.Abp.Application.Services;
|
||||||
using Yi.Framework.Ddd.Application.Contracts;
|
using Yi.Framework.Ddd.Application.Contracts;
|
||||||
using Yi.Framework.Rbac.Application.Contracts.Dtos.Role;
|
using Yi.Framework.Rbac.Application.Contracts.Dtos.Role;
|
||||||
@@ -9,6 +10,18 @@ namespace Yi.Framework.Rbac.Application.Contracts.IServices
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IRoleService : IYiCrudAppService<RoleGetOutputDto, RoleGetListOutputDto, Guid, RoleGetListInputVo, RoleCreateInputVo, RoleUpdateInputVo>
|
public interface IRoleService : IYiCrudAppService<RoleGetOutputDto, RoleGetListOutputDto, Guid, RoleGetListInputVo, RoleCreateInputVo, RoleUpdateInputVo>
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取角色菜单树
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId">角色ID</param>
|
||||||
|
/// <returns>角色菜单树数据,包含已选中的菜单ID和菜单树结构</returns>
|
||||||
|
Task<ActionResult> GetMenuTreeAsync(Guid roleId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取角色部门树
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId">角色ID</param>
|
||||||
|
/// <returns>角色部门树数据,包含已选中的部门ID和部门树结构</returns>
|
||||||
|
Task<ActionResult> GetDeptTreeAsync(Guid roleId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,10 +26,12 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
|||||||
{
|
{
|
||||||
public RoleService(RoleManager roleManager, ISqlSugarRepository<RoleDeptEntity> roleDeptRepository,
|
public RoleService(RoleManager roleManager, ISqlSugarRepository<RoleDeptEntity> roleDeptRepository,
|
||||||
ISqlSugarRepository<UserRoleEntity> userRoleRepository,
|
ISqlSugarRepository<UserRoleEntity> userRoleRepository,
|
||||||
ISqlSugarRepository<RoleAggregateRoot, Guid> repository) : base(repository)
|
ISqlSugarRepository<RoleAggregateRoot, Guid> repository,
|
||||||
|
ISqlSugarRepository<MenuAggregateRoot, Guid> menuRepository,
|
||||||
|
ISqlSugarRepository<DeptAggregateRoot, Guid> deptRepository) : base(repository)
|
||||||
{
|
{
|
||||||
(_roleManager, _roleDeptRepository, _userRoleRepository, _repository) =
|
(_roleManager, _roleDeptRepository, _userRoleRepository, _repository, _menuRepository, _deptRepository) =
|
||||||
(roleManager, roleDeptRepository, userRoleRepository, repository);
|
(roleManager, roleDeptRepository, userRoleRepository, repository, menuRepository, deptRepository);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ISqlSugarRepository<RoleAggregateRoot, Guid> _repository;
|
private ISqlSugarRepository<RoleAggregateRoot, Guid> _repository;
|
||||||
@@ -38,6 +40,10 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
|||||||
private ISqlSugarRepository<RoleDeptEntity> _roleDeptRepository;
|
private ISqlSugarRepository<RoleDeptEntity> _roleDeptRepository;
|
||||||
|
|
||||||
private ISqlSugarRepository<UserRoleEntity> _userRoleRepository;
|
private ISqlSugarRepository<UserRoleEntity> _userRoleRepository;
|
||||||
|
|
||||||
|
private ISqlSugarRepository<MenuAggregateRoot, Guid> _menuRepository;
|
||||||
|
|
||||||
|
private ISqlSugarRepository<DeptAggregateRoot, Guid> _deptRepository;
|
||||||
|
|
||||||
public async Task UpdateDataScopeAsync(UpdateDataScopeInput input)
|
public async Task UpdateDataScopeAsync(UpdateDataScopeInput input)
|
||||||
{
|
{
|
||||||
@@ -215,5 +221,45 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
|||||||
.ExecuteCommandAsync();
|
.ExecuteCommandAsync();
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取角色菜单树
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<ActionResult> GetMenuTreeAsync(Guid roleId)
|
||||||
|
{
|
||||||
|
var checkedKeys = await _menuRepository._DbQueryable
|
||||||
|
.Where(m => SqlFunc.Subqueryable<RoleMenuEntity>().Where(rm => rm.RoleId == roleId && rm.MenuId == m.Id).Any())
|
||||||
|
.Select(x => x.Id).ToListAsync();
|
||||||
|
var menus = await _menuRepository._DbQueryable.ToListAsync();
|
||||||
|
var menuTrees = menus.TreeDtoBuild();
|
||||||
|
return new JsonResult(new
|
||||||
|
{
|
||||||
|
checkedKeys,
|
||||||
|
menus = menuTrees
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取角色部门树
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<ActionResult> GetDeptTreeAsync(Guid roleId)
|
||||||
|
{
|
||||||
|
var checkedKeys = await _deptRepository._DbQueryable
|
||||||
|
.Where(d => SqlFunc.Subqueryable<RoleDeptEntity>().Where(rd => rd.RoleId == roleId && rd.DeptId == d.Id).Any())
|
||||||
|
.Select(x => x.Id).ToListAsync();
|
||||||
|
var deptList = await _deptRepository._DbQueryable
|
||||||
|
.Where(x => x.State == true)
|
||||||
|
.OrderBy(x => x.OrderNum, OrderByType.Asc)
|
||||||
|
.ToListAsync();
|
||||||
|
return new JsonResult(new
|
||||||
|
{
|
||||||
|
checkedKeys,
|
||||||
|
depts = deptList.DeptTreeBuild()
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user