From 126810550708cb0141d872b7353c81d0d7aaa28f Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 10 Oct 2025 11:26:15 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E7=94=B5=E5=AD=90=E5=9B=B4=E6=A0=8F?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=83=A8=E7=BD=B2=E6=96=B9=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WorkGrids/Request/EFenceSaveRequest.cs | 4 +++ .../WorkGrids/Response/EFencePageResponse.cs | 7 +++++ .../Services/Implements/EFenceService.cs | 4 +-- .../Device/Entities/EFenceEntity.cs | 8 ++++++ .../Implements/DeviceUploadLogService.cs | 27 ++++++++++++++----- 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/Src/Dlhis.Basic/WorkGrids/Request/EFenceSaveRequest.cs b/Src/Dlhis.Basic/WorkGrids/Request/EFenceSaveRequest.cs index ec4edf77..450f930e 100644 --- a/Src/Dlhis.Basic/WorkGrids/Request/EFenceSaveRequest.cs +++ b/Src/Dlhis.Basic/WorkGrids/Request/EFenceSaveRequest.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using Dlhis.Entity.Device.Enums; namespace Dlhis.Basic.WorkGrids.Request; @@ -10,4 +11,7 @@ public class EFenceSaveRequest public string Name { get; set; } public string Description { get; set; } + + [EnumDataType(typeof(DeviceDeployDirectionEnumType))] + public DeviceDeployDirectionEnumType DirectionType { get; set; } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/WorkGrids/Response/EFencePageResponse.cs b/Src/Dlhis.Basic/WorkGrids/Response/EFencePageResponse.cs index 3630748d..dae3eaf3 100644 --- a/Src/Dlhis.Basic/WorkGrids/Response/EFencePageResponse.cs +++ b/Src/Dlhis.Basic/WorkGrids/Response/EFencePageResponse.cs @@ -1,3 +1,6 @@ +using Dlhis.Entity.Device.Enums; +using Kurisu.AspNetCore.Utils.Extensions; + namespace Dlhis.Basic.WorkGrids.Response; public class EFencePageResponse @@ -20,4 +23,8 @@ public class EFencePageResponse /// 设备数量 /// public int DeviceCount { get; set; } + + public DeviceDeployDirectionEnumType DirectionType { get; set; } + + public string DirectionTypeDesc => DirectionType.GetDescription(); } \ No newline at end of file diff --git a/Src/Dlhis.Basic/WorkGrids/Services/Implements/EFenceService.cs b/Src/Dlhis.Basic/WorkGrids/Services/Implements/EFenceService.cs index a0630a04..a7196650 100644 --- a/Src/Dlhis.Basic/WorkGrids/Services/Implements/EFenceService.cs +++ b/Src/Dlhis.Basic/WorkGrids/Services/Implements/EFenceService.cs @@ -49,6 +49,7 @@ public class EFenceService : IEFenceService Code = x.Code, Name = x.Name, Description = x.Description, + DirectionType = x.DirectionType, DeviceCount = SqlFunc.Subqueryable().Where(p => p.EFenceCode == x.Code).Count(), }) .ToPageListAsync(request); @@ -81,9 +82,8 @@ public class EFenceService : IEFenceService //查询设备 var devices = await _dbContext.Queryable() .Where(d => deviceCodes.Contains(d.Code)) - .Where(d => d.DeployDirection.HasValue) .Where(d => SqlFunc.Subqueryable() - .Where(p => p.EFenceCode == fence.Code && p.DeviceCode == d.Code) + .Where(p => p.DeviceCode == d.Code) .NotAny() //不可重复分配 ) .ToListAsync(); diff --git a/Src/Dlhis.Entity/Device/Entities/EFenceEntity.cs b/Src/Dlhis.Entity/Device/Entities/EFenceEntity.cs index 36266fc0..60d52077 100644 --- a/Src/Dlhis.Entity/Device/Entities/EFenceEntity.cs +++ b/Src/Dlhis.Entity/Device/Entities/EFenceEntity.cs @@ -1,6 +1,8 @@ +using Dlhis.Entity.Device.Enums; using Kurisu.AspNetCore.DataAccess.SqlSugar; using Mapster; using SqlSugar; +using SqlSugar.DbConvert; namespace Dlhis.Entity.Device.Entities; @@ -25,4 +27,10 @@ public class EFenceEntity : SugarBaseEntity /// [SugarColumn(IsNullable = true, Length = 1000)] public string Description { get; set; } + + /// + /// 部署方向 + /// + [SugarColumn(IsNullable = false, ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert))] + public DeviceDeployDirectionEnumType DirectionType { get; set; } } \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs index 3e1fa1e6..92a49050 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs @@ -50,11 +50,9 @@ public class DeviceUploadLogService : IDeviceUploadLogService { var deviceUniqueNos = requests.Select(x => x.DeviceUniqueNo).Distinct().ToList(); var devices = await _dbContext.Queryable().Where(x => deviceUniqueNos.Contains(x.UniqueNo)).ToListAsync(); - var existsDeviceUniqueNos = devices.Select(x => x.UniqueNo).ToList(); + var existsDeviceUniqueNos = devices.Select(x => x.UniqueNo).ToList(); - var deviceCodes = devices.Where(x => x.DeployDirection.HasValue).Select(x => x.Code).Distinct().ToList(); - var eFenceDeviceRelations = await _dbContext.Queryable().Where(x => deviceCodes.Contains(x.DeviceCode)).ToListAsync(); - var eFenceDeviceMap = eFenceDeviceRelations.ToDictionary(x => x.DeviceCode, x => x.EFenceCode); + var deviceCodeInEFenceMap = await GetDeviceCodeInEFencesAsync(devices.Select(x => x.Code).ToList()); var userCodes = requests.Where(x => x.UserUniqueNo.IsPresent()).Select(x => x.UserUniqueNo).Distinct().ToList(); var gainfo1 = await _dbContext.Queryable().Where(x => userCodes.Contains(x.Code)).Select(x => new { x.Code, x.Name, x.Type }).ToListAsync(); @@ -121,9 +119,9 @@ public class DeviceUploadLogService : IDeviceUploadLogService ? DeviceUploadLogTypeEnumType.Attendance : DeviceUploadLogTypeEnumType.Door; - if (eFenceDeviceMap.TryGetValue(device.Code, out var eFenceCore)) + if (deviceCodeInEFenceMap.TryGetValue(device.Code, out var fence)) { - await HandlerPowerSwitchAsync(eFenceCore, request.UserUniqueNo, device.DeployDirection.Value); + await HandlerPowerSwitchAsync(fence.Code, request.UserUniqueNo, fence.DirectionType); } var workGridInfo = new WorkGridInfo(); @@ -278,6 +276,23 @@ public class DeviceUploadLogService : IDeviceUploadLogService } + private async Task> GetDeviceCodeInEFencesAsync(List deviceCodes) + { + var eFenceDeviceRelations = await _dbContext.Queryable() + .Where(x => deviceCodes.Contains(x.DeviceCode)) + .ToListAsync(); + + var eFenceCodes = eFenceDeviceRelations.Select(x => x.DeviceCode).Distinct().ToList(); + var eFences = await _dbContext.Queryable().Where(x => eFenceCodes.Contains(x.Code)).ToListAsync(); + + //二次过滤 + var eFenceCodesNew = eFences.Select(x => x.Code).Distinct().ToList(); + eFenceDeviceRelations = eFenceDeviceRelations.Where(x => eFenceCodesNew.Contains(x.EFenceCode)).ToList(); + + + return eFenceDeviceRelations.ToDictionary(x => x.DeviceCode, x => eFences.First(y => y.Code == x.EFenceCode)); + } + /// /// 宿舍只能空开触发 ///