fix 分配/获取权限需要根据数据权限处理
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Sys.Entities;
|
||||
using Dlhis.Entity.Sys.Enums;
|
||||
@@ -91,3 +92,24 @@ public class GetDataPermissionService : IGetDataPermissions, ISingletonDependenc
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IMyDataPermissionService : IScopeDependency
|
||||
{
|
||||
List<Guid> GetMyDeviceCodes();
|
||||
}
|
||||
|
||||
public class MyDataPermissionService : IMyDataPermissionService
|
||||
{
|
||||
private readonly IGetDataPermissions _getDataPermissions;
|
||||
|
||||
public MyDataPermissionService(IGetDataPermissions getDataPermissions)
|
||||
{
|
||||
_getDataPermissions = getDataPermissions;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<Guid> GetMyDeviceCodes()
|
||||
{
|
||||
return _getDataPermissions.GetData<DeviceEntity>().FirstOrDefault().Value ?? new List<Guid>();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Basic.Device.Dtos;
|
||||
using Dlhis.Basic.DataPermissions;
|
||||
using Dlhis.Basic.Device.Dtos;
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Organization.Dto;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
@@ -7,7 +8,6 @@ using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Entity.Sys.Entities;
|
||||
using Dlhis.Entity.Sys.Enums;
|
||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||
using Kurisu.AspNetCore.CustomClass;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
@@ -20,13 +20,15 @@ namespace Dlhis.Basic.Device.Services.Implements;
|
||||
public class DevicePermissionService : IDevicePermissionService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly IMyDataPermissionService _myDataPermissionService;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly ILogger<DevicePermissionService> _logger;
|
||||
|
||||
public DevicePermissionService(IDbContext dbContext,
|
||||
public DevicePermissionService(IDbContext dbContext, IMyDataPermissionService myDataPermissionService,
|
||||
ICurrentUser currentUser, ILogger<DevicePermissionService> logger)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_myDataPermissionService = myDataPermissionService;
|
||||
_currentUser = currentUser;
|
||||
_logger = logger;
|
||||
}
|
||||
@@ -37,15 +39,12 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
|
||||
await GenerateDeviceTasksAsync(async () =>
|
||||
{
|
||||
var values = await GetUniqueValuesAsync(request.Type, request.UniqueType);
|
||||
|
||||
//删除当前匹配的基地权限
|
||||
var p = await _dbContext.Queryable<DevicePermissionEntity>()
|
||||
.Where(x => x.AssignType == request.AssignType)
|
||||
.Where(x => x.AssignValue == request.AssignValue)
|
||||
.Where(x => x.UniqueType == request.UniqueType)
|
||||
.Where(x => x.Type == request.Type)
|
||||
.WhereIF(values.Any(), x => values.Contains(x.UniqueValue))
|
||||
.Where(x => x.TenantId == tenantId)
|
||||
.ToListAsync();
|
||||
|
||||
@@ -69,38 +68,17 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
}, null);
|
||||
}
|
||||
|
||||
private async Task<List<Guid>> GetUniqueValuesAsync(DeviceTypeEnumType? type, DeviceAssignmentTypeEnumType assignmentType)
|
||||
{
|
||||
if (!type.HasValue)
|
||||
{
|
||||
return new List<Guid>();
|
||||
}
|
||||
|
||||
if (assignmentType == DeviceAssignmentTypeEnumType.BusinessPlace)
|
||||
{
|
||||
return new List<Guid>();
|
||||
}
|
||||
else if (assignmentType == DeviceAssignmentTypeEnumType.Device)
|
||||
{
|
||||
return await _dbContext.Queryable<DeviceEntity>().Where(x => x.Enable).Where(x => x.Type == type).Select(x => x.Code).ToListAsync();
|
||||
}
|
||||
else if (assignmentType == DeviceAssignmentTypeEnumType.Group)
|
||||
{
|
||||
return await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.Type == type).Select(x => x.Code).ToListAsync();
|
||||
}
|
||||
|
||||
throw new UserFriendlyException("不支持当前操作");
|
||||
}
|
||||
|
||||
public async Task AssignToUniqueAsync(DevicePermissionsAssignToDeviceRequest request)
|
||||
{
|
||||
await GenerateDeviceTasksAsync(async () =>
|
||||
{
|
||||
var tenantId = _currentUser.GetStringTenantId();
|
||||
var deviceCodes = _myDataPermissionService.GetMyDeviceCodes();
|
||||
|
||||
//删除当前匹配的基地权限
|
||||
var p = await _dbContext.Queryable<DevicePermissionEntity>()
|
||||
.Where(x => x.UniqueType == request.UniqueType)
|
||||
.WhereIF(request.UniqueType == DeviceAssignmentTypeEnumType.Device, x => deviceCodes.Contains(x.UniqueValue))
|
||||
.Where(x => x.UniqueValue == request.UniqueValue)
|
||||
.Where(x => x.AssignType == request.AssignType)
|
||||
.Where(x => x.Type == request.Type)
|
||||
@@ -136,11 +114,13 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
|
||||
public async Task<List<Guid>> GetAssignmentsAsync(DeviceGetAssignmentsRequest request)
|
||||
{
|
||||
var deviceCodes = _myDataPermissionService.GetMyDeviceCodes();
|
||||
return await _dbContext.Queryable<DevicePermissionEntity>()
|
||||
.WhereIF(request.TenantId.IsPresent() && request.AssignType == AssignTypeEnumType.Department, x => x.TenantId == request.TenantId)
|
||||
.Where(x => x.AssignType == request.AssignType)
|
||||
.Where(x => x.AssignValue == request.AssignValue)
|
||||
.Where(x => x.UniqueType == request.UniqueType)
|
||||
.WhereIF(request.UniqueType == DeviceAssignmentTypeEnumType.Device, x => deviceCodes.Contains(x.UniqueValue))
|
||||
.Where(x => x.Type == request.Type)
|
||||
.Select(x => x.UniqueValue)
|
||||
.ToListAsync();
|
||||
|
||||
Reference in New Issue
Block a user