From cff1e55c52042aa15b30db24150b0f91152bb5ff Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 14 Jun 2024 21:10:40 +0800 Subject: [PATCH] test . --- .../Request/DevicePermissionSaveRequest.cs | 7 ++++ .../Implements/DevicePermissionService.cs | 41 ++++++++++++++++--- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveRequest.cs b/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveRequest.cs index e786e3f8..604bb6e1 100644 --- a/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DevicePermissionSaveRequest.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using Dlhis.Entity.Device.Enums; using Dlhis.Entity.Sys.Enums; using Kurisu.AspNetCore.Utils.Extensions; @@ -36,6 +37,12 @@ public class DevicePermissionSaveRequest : IValidatableObject /// AssignType == AssignTypeEnumType.Department 需要传入 /// public string TenantId { get; set; } + + /// + /// 设备类型 + /// + [EnumDataType(typeof(DeviceTypeEnumType))] + public DeviceTypeEnumType Type { get; set; } public IEnumerable Validate(ValidationContext validationContext) { diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index fc67e71d..ffc594f7 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -7,6 +7,7 @@ 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; @@ -32,17 +33,24 @@ public class DevicePermissionService : IDevicePermissionService public async Task AssignAsync(DevicePermissionSaveRequest request) { - throw new Exception("系统维护中,暂不可操作"); + if (_currentUser.GetStringSubjectId() != "14") + { + throw new Exception("系统维护中,暂不可操作"); + } + var tenantId = request.AssignType == AssignTypeEnumType.Department ? request.TenantId : _currentUser.GetStringTenantId(); await GenerateDeviceTasksAsync(async () => { + var values = await GetUniqueValuesAsync(request.Type, request.UniqueType); + //删除当前匹配的基地权限 var p = await _dbContext.Queryable() .Where(x => x.AssignType == request.AssignType) .Where(x => x.AssignValue == request.AssignValue) .Where(x => x.UniqueType == request.UniqueType) + .WhereIF(values.Any(), x => values.Contains(x.UniqueValue)) .Where(x => x.TenantId == tenantId) .ToListAsync(); @@ -65,6 +73,29 @@ public class DevicePermissionService : IDevicePermissionService }, null); } + private async Task> GetUniqueValuesAsync(DeviceTypeEnumType? type, DeviceAssignmentTypeEnumType assignmentType) + { + if (!type.HasValue) + { + return new List(); + } + + if (assignmentType == DeviceAssignmentTypeEnumType.BusinessPlace) + { + return new List(); + } + else if (assignmentType == DeviceAssignmentTypeEnumType.Device) + { + return await _dbContext.Queryable().Where(x => x.Enable).Where(x => x.Type == type).Select(x => x.Code).ToListAsync(); + } + else if (assignmentType == DeviceAssignmentTypeEnumType.Group) + { + return await _dbContext.Queryable().Where(x => x.Type == type).Select(x => x.Code).ToListAsync(); + } + + throw new UserFriendlyException("不支持当前操作"); + } + public async Task AssignToUniqueAsync(DevicePermissionsAssignToDeviceRequest request) { var tenantId = request.AssignType == AssignTypeEnumType.Department ? request.TenantId : _currentUser.GetStringTenantId(); @@ -242,10 +273,10 @@ public class DevicePermissionService : IDevicePermissionService } _logger.LogInformation("任务产生数量{count}", waitTasks.Count); - if (waitTasks.Any()) - { - await _dbContext.InsertAsync(waitTasks); - } + // if (waitTasks.Any()) + // { + // await _dbContext.InsertAsync(waitTasks); + // } } public async Task GetPermissionUsersInfoAsync(List userNos)