feature:根据区域获取授权数据
This commit is contained in:
16
Api/Ewide.Core/Service/Role/ISysRoleAreaService.cs
Normal file
16
Api/Ewide.Core/Service/Role/ISysRoleAreaService.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
65
Api/Ewide.Core/Service/Role/SysRoleAreaServic.cs
Normal file
65
Api/Ewide.Core/Service/Role/SysRoleAreaServic.cs
Normal 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();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user