fix 获取部门权限分配
This commit is contained in:
@@ -68,9 +68,9 @@ public class DevicePermissionsController : ControllerBase
|
||||
[HttpGet("assignments")]
|
||||
public async Task<List<Guid>> GetAssignmentsAsync([FromQuery] DeviceGetAssignmentsRequest request)
|
||||
{
|
||||
return await _devicePermissionService.GetAssignmentsAsync(request.UniqueType, request.AssignType, request.AssignValue);
|
||||
return await _devicePermissionService.GetAssignmentsAsync(request);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当前类型的权限分配
|
||||
/// </summary>
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using Dlhis.Entity.Sys.Enums;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Basic.Device.Request;
|
||||
|
||||
public class DeviceGetAssignmentsRequest
|
||||
public class DeviceGetAssignmentsRequest : IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 权限分配类型 DeviceAssignmentTypeEnumType
|
||||
@@ -27,6 +28,22 @@ public class DeviceGetAssignmentsRequest
|
||||
/// 设备类型
|
||||
/// </summary>
|
||||
public DeviceTypeEnumType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// AssignType == AssignTypeEnumType.Department 需要传入
|
||||
/// </summary>
|
||||
public string TenantId { get; set; }
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (AssignType == AssignTypeEnumType.Department)
|
||||
{
|
||||
if (TenantId.IsEmpty())
|
||||
{
|
||||
yield return new ValidationResult("请明确具体的厂区", new[] { nameof(TenantId) });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class DeviceGetAssignmentUniquesRequest
|
||||
|
||||
@@ -28,11 +28,8 @@ public interface IDevicePermissionService : IScopeDependency
|
||||
/// <summary>
|
||||
/// 获取分配的权限
|
||||
/// </summary>
|
||||
/// <param name="uniqueType"></param>
|
||||
/// <param name="assignValue"></param>
|
||||
/// <param name="assignType"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<Guid>> GetAssignmentsAsync(DeviceAssignmentTypeEnumType uniqueType, AssignTypeEnumType assignType, string assignValue);
|
||||
Task<List<Guid>> GetAssignmentsAsync(DeviceGetAssignmentsRequest request);
|
||||
|
||||
Task<List<GainfoDto>> GetAssignmentUniqueAsync(DeviceGetAssignmentUniquesRequest request);
|
||||
|
||||
|
||||
@@ -175,12 +175,14 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<Guid>> GetAssignmentsAsync(DeviceAssignmentTypeEnumType uniqueType, AssignTypeEnumType assignType, string assignValue)
|
||||
public async Task<List<Guid>> GetAssignmentsAsync(DeviceGetAssignmentsRequest request)
|
||||
{
|
||||
var devicePermissions = await _dbContext.Queryable<DevicePermissionEntity>().ToListAsync();
|
||||
var devicePermissions = await _dbContext.Queryable<DevicePermissionEntity>()
|
||||
.WhereIF(request.TenantId.IsPresent(), x => x.TenantId == request.TenantId)
|
||||
.ToListAsync();
|
||||
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().ToListAsync();
|
||||
|
||||
var result = GetAssignCodesInternal(devicePermissions, deviceGroups, uniqueType, assignType, assignValue);
|
||||
var result = GetAssignCodesInternal(devicePermissions, deviceGroups, request.UniqueType, request.AssignType, request.AssignValue);
|
||||
return result.FirstOrDefault(x => x.Tenant == _currentUser.GetStringTenantId())?.Codes;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Basic.Device.Services;
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
@@ -189,13 +190,20 @@ public class GainfoPermissionService : IGainfoPermissionService
|
||||
|
||||
public async Task<List<DeviceGroupTreeResponse>> GetAssignGroupAsync(string userNo)
|
||||
{
|
||||
var groups = await _devicePermissionService.GetAssignmentsAsync(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo);
|
||||
//(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo
|
||||
var groups = await _devicePermissionService.GetAssignmentsAsync(new DeviceGetAssignmentsRequest
|
||||
{
|
||||
UniqueType = DeviceAssignmentTypeEnumType.Group,
|
||||
AssignType = AssignTypeEnumType.User,
|
||||
AssignValue = userNo
|
||||
});
|
||||
|
||||
return await _dbContext.Queryable<DeviceGroupEntity>()
|
||||
.Where(x => groups.Contains(x.Code))
|
||||
.Select<DeviceGroupTreeResponse>()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
//**********************************************************************************************************************************************
|
||||
|
||||
private static IEnumerable<Guid> RecursionGetNext(DeviceGroupEntity current, List<DeviceGroupEntity> deviceGroups)
|
||||
|
||||
Reference in New Issue
Block a user