fix 权限数据优化
This commit is contained in:
@@ -56,14 +56,18 @@ public class GetDataPermissionService : IGetDataPermissions, ISingletonDependenc
|
||||
if (deviceGroupCodes.Any())
|
||||
{
|
||||
var data = db.Queryable<DeviceGroupEntity>().ToList();
|
||||
//开始递归处理
|
||||
var tops = data.Where(x => !x.PCode.HasValue).ToList();
|
||||
tops.ForEach(x => { DeviceGroupRecursionGetNext(x, data, deviceGroupCodes, deviceGroupCodes.Contains(x.Code)); });
|
||||
deviceGroupCodes = deviceGroupCodes.Distinct().ToList();
|
||||
|
||||
var myDeviceGroupCodes = new List<Guid>();
|
||||
foreach (Guid deviceGroupCode in deviceGroupCodes)
|
||||
{
|
||||
myDeviceGroupCodes.AddRange(RecursionHelper.HandlerDeviceGroupNextCodes(deviceGroupCode, data));
|
||||
}
|
||||
|
||||
myDeviceGroupCodes = myDeviceGroupCodes.Distinct().ToList();
|
||||
|
||||
if (deviceCodeProperty != null)
|
||||
{
|
||||
deviceCodes = db.Queryable<DeviceGroupRelationshipEntity>().Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToList();
|
||||
deviceCodes = db.Queryable<DeviceGroupRelationshipEntity>().Where(x => myDeviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToList();
|
||||
}
|
||||
|
||||
if (deviceGroupCodeProperty != null)
|
||||
@@ -82,39 +86,50 @@ public class GetDataPermissionService : IGetDataPermissions, ISingletonDependenc
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
static void DeviceGroupRecursionGetNext(DeviceGroupEntity current, List<DeviceGroupEntity> data, List<Guid> result, bool add)
|
||||
{
|
||||
var next = data.Where(x => x.PCode == current.Code).ToList();
|
||||
foreach (var item in next)
|
||||
{
|
||||
if (add)
|
||||
{
|
||||
result.Add(item.Code);
|
||||
}
|
||||
|
||||
DeviceGroupRecursionGetNext(item, data, result, result.Contains(item.Code));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IMyDataPermissionService : IScopeDependency
|
||||
{
|
||||
List<Guid> GetMyDeviceCodes();
|
||||
(bool, List<Guid>) GetMyDeviceCodes();
|
||||
(bool, List<Guid>) GetMyDeviceGroupCodes();
|
||||
}
|
||||
|
||||
public class MyDataPermissionService : IMyDataPermissionService
|
||||
{
|
||||
private readonly IGetDataPermissions _getDataPermissions;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
|
||||
public MyDataPermissionService(IGetDataPermissions getDataPermissions)
|
||||
public MyDataPermissionService(IGetDataPermissions getDataPermissions, ICurrentUser currentUser)
|
||||
{
|
||||
_getDataPermissions = getDataPermissions;
|
||||
_currentUser = currentUser;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<Guid> GetMyDeviceCodes()
|
||||
public (bool, List<Guid>) GetMyDeviceCodes()
|
||||
{
|
||||
return _getDataPermissions.GetData<DeviceEntity>().FirstOrDefault().Value ?? new List<Guid>();
|
||||
var codes = new List<Guid>();
|
||||
|
||||
var disableFilter = _currentUser.GetRole() is "admin" or "tenant-admin";
|
||||
if (!disableFilter)
|
||||
{
|
||||
codes = _getDataPermissions.GetData<DeviceEntity>().FirstOrDefault().Value ?? new List<Guid>();
|
||||
}
|
||||
|
||||
return (!disableFilter, codes);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public (bool, List<Guid>) GetMyDeviceGroupCodes()
|
||||
{
|
||||
var codes = new List<Guid>();
|
||||
|
||||
var disableFilter = _currentUser.GetRole() is "admin" or "tenant-admin";
|
||||
if (!disableFilter)
|
||||
{
|
||||
codes = _getDataPermissions.GetData<DeviceGroupEntity>().FirstOrDefault().Value ?? new List<Guid>();
|
||||
}
|
||||
|
||||
return (!disableFilter, codes);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user