feat:添加数据权限搭建,准备完成数据权限过滤
This commit is contained in:
@@ -8,6 +8,6 @@ namespace Yi.Furion.Application.Rbac.Services
|
||||
/// </summary>
|
||||
public interface IDeptService : ICrudAppService<DeptGetOutputDto, DeptGetListOutputDto, long, DeptGetListInputVo, DeptCreateInputVo, DeptUpdateInputVo>
|
||||
{
|
||||
Task<List<long>> GetChiIds(long deptId);
|
||||
Task<List<long>> GetChildListAsync(long deptId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Yi.Furion.Application.Rbac.Services.Impl
|
||||
IDeptService, ITransient, IDynamicApiController
|
||||
{
|
||||
[NonAction]
|
||||
public async Task<List<long>> GetChiIds(long deptId)
|
||||
public async Task<List<long>> GetChildListAsync(long deptId)
|
||||
{
|
||||
var entities= await _DbQueryable.ToChildListAsync(x=>x.ParentId,deptId);
|
||||
return entities.Select(x => x.Id).ToList();
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
using Furion.DatabaseAccessor;
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Infrastructure.Ddd.Dtos;
|
||||
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
||||
using Yi.Framework.Infrastructure.Ddd.Services;
|
||||
using Yi.Framework.Infrastructure.Helper;
|
||||
using Yi.Furion.Application.Rbac.Domain;
|
||||
using Yi.Furion.Core.Rbac.Dtos.Role;
|
||||
using Yi.Furion.Core.Rbac.Entities;
|
||||
using Yi.Furion.Core.Rbac.Enums;
|
||||
|
||||
namespace Yi.Furion.Application.Rbac.Services.Impl
|
||||
{
|
||||
@@ -13,13 +17,34 @@ namespace Yi.Furion.Application.Rbac.Services.Impl
|
||||
public class RoleService : CrudAppService<RoleEntity, RoleGetOutputDto, RoleGetListOutputDto, long, RoleGetListInputVo, RoleCreateInputVo, RoleUpdateInputVo>,
|
||||
IRoleService, ITransient, IDynamicApiController
|
||||
{
|
||||
public RoleService(RoleManager roleManager) =>
|
||||
_roleManager =
|
||||
roleManager;
|
||||
public RoleService(RoleManager roleManager, IRepository<RoleDeptEntity> roleDeptRepository) =>
|
||||
(_roleManager, _roleDeptRepository) =
|
||||
(roleManager, roleDeptRepository);
|
||||
private RoleManager _roleManager { get; set; }
|
||||
|
||||
private IRepository<RoleDeptEntity> _roleDeptRepository;
|
||||
|
||||
|
||||
public async Task<List<long>> GetDeptIdsAsync(long roleId)
|
||||
{
|
||||
var entities = await _roleDeptRepository.GetListAsync(x => x.RoleId == roleId);
|
||||
return entities.Select(x => x.DeptId).ToList();
|
||||
|
||||
}
|
||||
|
||||
[UnitOfWork]
|
||||
public async Task UpdateDataScpoceAsync(UpdateDataScpoceInput input)
|
||||
{
|
||||
//只有自定义的需要特殊处理
|
||||
if (input.DataScope == DataScopeEnum.CUSTOM)
|
||||
{
|
||||
await _roleDeptRepository.DeleteAsync(x => x.RoleId == input.RoleId);
|
||||
var insertEntities = input.DeptIds.Select(x => new RoleDeptEntity {Id=SnowflakeHelper.NextId, DeptId = x, RoleId = input.RoleId }).ToList();
|
||||
await _roleDeptRepository.InsertRangeAsync(insertEntities);
|
||||
}
|
||||
await _repository._Db.Updateable(new RoleEntity() { Id = input.RoleId, DataScope = input.DataScope }).UpdateColumns(x => x.DataScope).ExecuteCommandAsync();
|
||||
|
||||
}
|
||||
|
||||
public override async Task<PagedResultDto<RoleGetListOutputDto>> GetListAsync(RoleGetListInputVo input)
|
||||
{
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Yi.Furion.Application.Rbac.Services.Impl
|
||||
List<long> deptIds = null;
|
||||
if (input.DeptId is not null)
|
||||
{
|
||||
deptIds= await _deptService.GetChiIds(input.DeptId ?? 0);
|
||||
deptIds= await _deptService.GetChildListAsync(input.DeptId ?? 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user