feature:根据区域获取授权数据

This commit is contained in:
2021-04-27 10:21:25 +08:00
parent d62ca5759b
commit d93ca8b235
18 changed files with 15248 additions and 55 deletions

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ewide.Core.Service.Role
{
public interface ISysRoleAreaService
{
Task DeleteRoleAreaListByAreaCodeList(List<string> areaCodeList);
Task DeleteRoleAreaListByRoleId(string roleId);
Task<List<string>> GetRoleAreaCodeList(List<string> roleIdList);
Task GrantArea(UpdateRoleInput input);
}
}

View File

@@ -0,0 +1,65 @@
using Ewide.Core.Entity;
using Ewide.Core.Service.User;
using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ewide.Core.Service.Role
{
public class SysRoleAreaServic : ISysRoleAreaService
{
public readonly IRepository<SysRoleArea> _sysRoleAreaRep;
public SysRoleAreaServic(IRepository<SysRoleArea> sysRolleAreaRep)
{
_sysRoleAreaRep = sysRolleAreaRep;
}
public async Task DeleteRoleAreaListByAreaCodeList(List<string> areaCodeList)
{
var dataScopes = await _sysRoleAreaRep.DetachedEntities.Where(u => areaCodeList.Contains(u.AreaNumberCode)).ToListAsync();
dataScopes.ForEach(u =>
{
u.Delete();
});
}
public async Task DeleteRoleAreaListByRoleId(string roleId)
{
var dataScopes = await _sysRoleAreaRep.DetachedEntities.Where(u => roleId==u.SysRoleId).ToListAsync();
dataScopes.ForEach(u =>
{
u.Delete();
});
}
public async Task<List<string>> GetRoleAreaCodeList(List<string> roleIdList)
{
return await _sysRoleAreaRep.DetachedEntities.Where(u => roleIdList.Contains(u.SysRoleId)).Select(u=>u.AreaNumberCode).Distinct().ToListAsync();
}
public async Task GrantArea(UpdateRoleInput input)
{
var dataScopes = await _sysRoleAreaRep.Where(u => u.SysRoleId == input.Id).ToListAsync();
dataScopes.ForEach(u =>
{
u.Delete();
});
input.GrantAreaCodeList.ForEach(u =>
{
new SysRoleArea
{
SysRoleId = input.Id,
AreaNumberCode = u
}.Insert();
});
}
}
}

View File

@@ -243,6 +243,7 @@ namespace Ewide.Core.Service
{
// 定义角色中最大数据范围的类型目前按最大范围策略来如果你同时拥有ALL和SELF的权限最后按ALL返回
int strongerDataScopeType = (int)DataScopeType.SELF;
int strongerAreaType = (int)DataScopeType.SELF;
var customDataScopeRoleIdList = new List<string>();
if (roleIdList != null && roleIdList.Count > 0)
@@ -252,6 +253,10 @@ namespace Ewide.Core.Service
{
if (u.DataScopeType == (int)DataScopeType.DEFINE)
customDataScopeRoleIdList.Add(u.Id);
if ((u.DataScopeType == (int)DataScopeType.AREA || u.DataScopeType == (int)DataScopeType.AREA_WITH_CHILD) && strongerAreaType < u.DataScopeType)
{
strongerDataScopeType = u.DataScopeType;
}
else if (u.DataScopeType <= strongerDataScopeType)
strongerDataScopeType = u.DataScopeType;
});
@@ -262,8 +267,9 @@ namespace Ewide.Core.Service
// 角色中拥有最大数据范围类型的数据范围
var dataScopeIdList = await _sysOrgService.GetDataScopeListByDataScopeType(strongerDataScopeType, orgId);
return roleDataScopeIdList.Concat(dataScopeIdList).Distinct().ToList(); //并集
//角色区域数据范围
var areaOrgIdList = await _sysOrgService.GetAreaDataScopeIdList(strongerAreaType, orgId);
return roleDataScopeIdList.Concat(dataScopeIdList).Concat(areaOrgIdList).Distinct().ToList(); //并集
}
/// <summary>