From 74667f7d391ab0742e445891f4ea54e5863c66d8 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 11 Jun 2025 17:03:07 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E5=B7=B2=E7=9F=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/AppointmentService.cs | 32 +++++--- .../Device/Controllers/DevicesController.cs | 74 ------------------- .../IDevicePermissionAnalyzeService.cs | 2 +- .../DevicePermissionAnalyzeService.cs | 5 ++ .../Controllers/GainfoFacesController.cs | 36 +-------- .../Request/FaceValidationRequest.cs | 3 + .../Request/GainfoResignRequest.cs | 6 -- .../Implements/GainfoOutsourceService.cs | 3 +- .../Services/Implements/GainfoService.cs | 8 +- .../Request/WorkGridTimePeriodSaveRequest.cs | 21 +++++- .../Jobs/AutoRemoveAppointmentJob.cs | 7 +- 11 files changed, 62 insertions(+), 135 deletions(-) diff --git a/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs b/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs index 56f10e8c..61ca2bbd 100644 --- a/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs +++ b/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs @@ -185,6 +185,7 @@ public class AppointmentService : IAppointmentService var detail = await _dbContext.Queryable().Where(x => x.Id == id).SingleAsync(); detail.ThrowIfNull("数据不存在"); + //Wait->obsolete; Arrived->FocusLeave if (detail.IsEnterDoorArea && detail.DoorStatus == VisitorAppointmentDetailStatusEnumType.Arrived) detail.DoorStatus = VisitorAppointmentDetailStatusEnumType.FocusLeave; @@ -198,9 +199,10 @@ public class AppointmentService : IAppointmentService detail.WorkplaceStatus = VisitorAppointmentDetailStatusEnumType.Obsolete; detail.FocusLeaveDateTime = DateTime.Now; - detail.Remark += "强制离场原因:" + reason; + detail.Remark += "强制离场:" + reason; - await GenerateDeviceTasksAsync(detail, true, DeviceTaskEnumType.Delete, "访客手动强制离场"); + await GenerateDeviceTasksAsync(detail, true, DeviceTaskEnumType.Delete, $"强制离场:{reason}"); + await _dbContext.UpdateAsync(detail); } public async Task> GetRecordPageByIdNoAsync(AppointmentIdNoPageRequest request) @@ -345,7 +347,8 @@ public class AppointmentService : IAppointmentService /// public async Task AutoResignAsync() { - var outsources = await _dbContext.Queryable() + //获取外部人员 + var externals = await _dbContext.Queryable() .Where(x => x.Type == GainfoUserTypeEnumType.External) .Select(x => new { x.Id, x.Code, x.Factory, x.CreateTime }) .ToListAsync(); @@ -357,23 +360,25 @@ public class AppointmentService : IAppointmentService //todo 临时处理循环依赖 var gainfoService = _serviceProvider.GetService(); - foreach (var grp in outsources.GroupBy(x => x.Factory)) + //人员分组,key为factory + foreach (var grp in externals.GroupBy(x => x.Factory)) { + //factory的设置 var setting = settings.First(x => x.Factory == grp.Key); if (setting.NoRecordAutoResignExternalDays == 0) { continue; } - foreach (var outsource in grp) + foreach (var ext in grp) { var raiseDateTime = await _dbContext.Queryable() - .Where(x => x.UserUniqueNo == outsource.Code) + .Where(x => x.UserUniqueNo == ext.Code) .GroupBy(x => x.UserUniqueNo) - .Select(x => SqlFunc.IsNull(SqlFunc.AggregateMax(x.RaiseDateTime), outsource.CreateTime)) + .Select(x => SqlFunc.IsNull(SqlFunc.AggregateMax(x.RaiseDateTime), ext.CreateTime)) .SingleAsync(); - raiseDateTime = raiseDateTime == nullDateTime ? outsource.CreateTime : raiseDateTime; + raiseDateTime = raiseDateTime == nullDateTime ? ext.CreateTime : raiseDateTime; if (raiseDateTime.AddDays(setting.NoRecordAutoResignExternalDays) < DateTime.Now) { @@ -381,10 +386,9 @@ public class AppointmentService : IAppointmentService { await gainfoService.ResignAsync(new GainfoResignRequest { - Id = outsource.Id, + Id = ext.Id, Reason = $"{setting.NoRecordAutoResignExternalDays}天无通行记录", - Date = DateTime.Now, - IsOutsource = true + Date = DateTime.Now }); } catch (Exception e) @@ -432,6 +436,12 @@ public class AppointmentService : IAppointmentService }).ToList()); } + /// + /// 获取有效的区域编码 + /// + /// + /// + /// private static IEnumerable GetValidAreaCodes(VisitorAppointmentDetailEntity detail, bool withWorkplace) { if (detail.IsEnterDoorArea) diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs index 3bb389f1..026481d4 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs @@ -1,13 +1,8 @@ using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Dlhis.Basic.Device.Services; -using Dlhis.Entity.Basic.Entity; -using Dlhis.Entity.Basic.Enums; -using Dlhis.Entity.Device.Entities; -using Dlhis.Entity.Device.Enums; using Kurisu.AspNetCore.DataAccess.Dto; using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; -using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; using Kurisu.AspNetCore.UnifyResultAndValidation.Aop; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -24,18 +19,15 @@ public class DevicesController : ControllerBase { private readonly IDeviceService _deviceService; private readonly IDeviceTemplateService _deviceTemplateService; - private readonly IDbContext _dbContext; private readonly IDeviceConnectService _deviceConnectService; private readonly IConfiguration _configuration; public DevicesController(IDeviceService deviceService, IDeviceTemplateService deviceTemplateService, - IDbContext dbContext, IDeviceConnectService deviceConnectService, IConfiguration configuration) { _deviceService = deviceService; _deviceTemplateService = deviceTemplateService; - _dbContext = dbContext; _deviceConnectService = deviceConnectService; _configuration = configuration; } @@ -170,70 +162,4 @@ public class DevicesController : ControllerBase { await _deviceService.ImportAsync(request); } - - [HttpPost("test")] - [IgnoreTenant] - [AllowAnonymous] - public async Task Test() - { - var tasks = new List(); - - var devices = await _dbContext.Queryable().Where(x => x.TenantId == "2401").Where(x => x.Type == DeviceTypeEnumType.Meal).ToListAsync(); - - var gainfos = await _dbContext.Queryable() - .Where(x => x.Type == GainfoUserTypeEnumType.External || x.Type == GainfoUserTypeEnumType.Outsource) - .Where(x => x.Factory == "2401") - .ToListAsync(); - - var gainfoLeaves = await _dbContext.Queryable() - .Where(x => x.Type == GainfoUserTypeEnumType.External || x.Type == GainfoUserTypeEnumType.Outsource) - .Where(x => x.Factory == "2401") - .ToListAsync(); - - foreach (var device in devices) - { - foreach (var gainfo in gainfos) - { - tasks.Add(new DeviceTaskEntity - { - Type = DeviceTaskEnumType.Delete, - DeviceType = DeviceTypeEnumType.Meal, - UserId = gainfo.Id, - UserNo = gainfo.No, - DeviceUniqueNo = device.UniqueNo, - Status = DeviceTaskStatusEnumType.Wait, - Version = 0, - ResultMessage = null, - Source = "主动删除2401异常餐饮人员", - Priority = 0, - TenantId = device.TenantId - }); - } - - foreach (var gainfo in gainfoLeaves) - { - tasks.Add(new DeviceTaskEntity - { - Type = DeviceTaskEnumType.Delete, - DeviceType = DeviceTypeEnumType.Meal, - UserId = gainfo.IdentityUserId, - UserNo = gainfo.No, - DeviceUniqueNo = device.UniqueNo, - Status = DeviceTaskStatusEnumType.Wait, - Version = 0, - ResultMessage = null, - Source = "主动删除2401异常餐饮人员", - Priority = 0, - TenantId = device.TenantId - }); - } - } - - foreach (var items in tasks.Chunk(1000)) - { - await _dbContext.InsertAsync(items); - } - - return tasks.Count; - } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Device/Services/IDevicePermissionAnalyzeService.cs b/Src/Dlhis.Basic/Device/Services/IDevicePermissionAnalyzeService.cs index dc6eb6ea..44dc1d74 100644 --- a/Src/Dlhis.Basic/Device/Services/IDevicePermissionAnalyzeService.cs +++ b/Src/Dlhis.Basic/Device/Services/IDevicePermissionAnalyzeService.cs @@ -43,7 +43,7 @@ public interface IDevicePermissionAnalyzeService : IScopeDependency /// 获取人员权限(人员--(厂区--分配方式--设备codes)) /// /// - /// + /// 忽略设备/设备组; /// /// /// diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionAnalyzeService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionAnalyzeService.cs index 68f40647..e247a849 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionAnalyzeService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionAnalyzeService.cs @@ -168,8 +168,12 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService var deviceDtos = new List(); var uniqueTypes = new[] { DeviceAssignmentTypeEnumType.Device, DeviceAssignmentTypeEnumType.Group }; + //根据权限分配类型 foreach (var assignType in new[] { AssignTypeEnumType.User, AssignTypeEnumType.Group, AssignTypeEnumType.Department, AssignTypeEnumType.Tenant }) { + //二选一移除当前类型的权限,差异分析使用 + //eg: 按人分配,移除A设备,只需要查看其他3个类型是否存在A设备而进行删除任务生成 + // 按部门分配,移除A设备,需要查看部门上顶级部门是否存在A设备,则通过IgnoreAssignValue移除当前部门其他权限(分组同理) if (analyzePack.IgnoreAssignTypes.Contains(assignType) && analyzePack.IgnoreAssignValue.IsEmpty()) { continue; @@ -197,6 +201,7 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService }; var data = assignValues.SelectMany(x => uniqueTypes.Select(p => new { assignValue = x, uniqueType = p })).ToList(); + //移除IgnoreAssignValue的数据,对应以上说明 var needRemove = data.Where(x => x.assignValue == analyzePack.IgnoreAssignValue && x.uniqueType == analyzePack.IgnoreUniqueType); data = data.ExceptBy(needRemove, x => new { x.assignValue, x.uniqueType }).ToList(); diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfoFacesController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfoFacesController.cs index 31451e6d..2d4244f4 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfoFacesController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfoFacesController.cs @@ -1,10 +1,7 @@ -using System.Text; -using Dlhis.Basic.Organization.Request; +using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; using Dlhis.Basic.Organization.Services; -using HttpUtil; using Kurisu.AspNetCore.DataAccess.Dto; -using Kurisu.AspNetCore.Utils.Extensions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -19,12 +16,10 @@ namespace Dlhis.Basic.Organization.Controllers; public class GainfoFacesController : ControllerBase { private readonly IGainfoFaceService _gainfoFaceService; - private readonly IHttpClientFactory _httpClientFactory; - public GainfoFacesController(IGainfoFaceService gainfoFaceService, IHttpClientFactory httpClientFactory) + public GainfoFacesController(IGainfoFaceService gainfoFaceService) { _gainfoFaceService = gainfoFaceService; - _httpClientFactory = httpClientFactory; } /// @@ -48,31 +43,4 @@ public class GainfoFacesController : ControllerBase { return await _gainfoFaceService.GetUploadPageRecordsAsync(request); } - - [AllowAnonymous] - [HttpPost("test")] - public async Task> TestAsync(GainfoFaceValidateRequest request) - { - var client = _httpClientFactory.CreateClient("hik-openapi"); - var body = request.ToJson(JsonExtensions.DefaultSetting); - var url = "/artemis/api/frs/v1/application/oneToOne"; - var key = "27390082"; - var secret = "MLl7Dv7p5Pgc9XYI3r4O"; - - HttpUtillib.SetPlatformInfo(key, secret, "10.32.0.10"); - var r = HttpUtillib.HttpPost(url, body, 15); - return Encoding.UTF8.GetString(r).ToObject>(); - - // var headers = InitRequest(url, body, key, secret); - // client.DefaultRequestHeaders.Accept.Clear(); - // client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(headers["Accept"])); - // var content = new StringContent(body, Encoding.UTF8, "application/json"); - // foreach (var item in headers.Where(x => x.Key != "Accept").Where(x => x.Key != "Content-Type")) - // { - // content.Headers.Add(item.Key, item.Value); - // } - // - // var r = await client.PostAsync(url, content); - // return await r.Content.ReadAsStringAsync(); - } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Organization/Request/FaceValidationRequest.cs b/Src/Dlhis.Basic/Organization/Request/FaceValidationRequest.cs index e591f2b0..f4afde3a 100644 --- a/Src/Dlhis.Basic/Organization/Request/FaceValidationRequest.cs +++ b/Src/Dlhis.Basic/Organization/Request/FaceValidationRequest.cs @@ -4,6 +4,9 @@ namespace Dlhis.Basic.Organization.Request { public class FaceValidationRequest : PageDto { + /// + /// 显示成功与否.null全部 + /// public bool? IsSuccess { get; set; } } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Organization/Request/GainfoResignRequest.cs b/Src/Dlhis.Basic/Organization/Request/GainfoResignRequest.cs index c05768ef..bfbdd54d 100644 --- a/Src/Dlhis.Basic/Organization/Request/GainfoResignRequest.cs +++ b/Src/Dlhis.Basic/Organization/Request/GainfoResignRequest.cs @@ -15,12 +15,6 @@ public class GainfoResignRequest : IValidatableObject public DateTime Date { get; set; } = DateTime.Now; - /// - /// 是否外包 - /// - public bool IsOutsource { get; set; } = true; - - public IEnumerable Validate(ValidationContext validationContext) { if (Date < DateTime.Now.Date) diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoOutsourceService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoOutsourceService.cs index 984ba015..26b76f4a 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoOutsourceService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoOutsourceService.cs @@ -150,8 +150,7 @@ public class GainfoOutsourceService : IGainfoOutsourceService { Id = outsource.Id, Reason = $"{setting.NoRecordAutoResignOutsourceDays}天无通行记录", - Date = DateTime.Now, - IsOutsource = true + Date = DateTime.Now }); } catch (Exception e) diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index 3f8874e6..a72862b5 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -267,15 +267,13 @@ public class GainfoService : IGainfoService if (gainfo.Type == GainfoUserTypeEnumType.External) { + //获取人员所有的访客申请 var visitorAppointmentDetails = await _dbContext.Queryable() .Where(x => x.UserNo == gainfo.No) - .Where(x => x.DoorStatus == VisitorAppointmentDetailStatusEnumType.Wait - || x.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Wait - || x.DoorStatus == VisitorAppointmentDetailStatusEnumType.Arrived - || x.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Arrived) + .Where(x => (x.IsEnterDoorArea && x.DoorStatus != VisitorAppointmentDetailStatusEnumType.Leave) + || (x.IsEnterWorkplace && x.WorkplaceStatus != VisitorAppointmentDetailStatusEnumType.Leave)) .ToListAsync(); - foreach (var visitorAppointment in visitorAppointmentDetails) { await _appointmentService.FocusLeaveAsync(visitorAppointment.Id, request.Reason); diff --git a/Src/Dlhis.Basic/WorkGrids/Request/WorkGridTimePeriodSaveRequest.cs b/Src/Dlhis.Basic/WorkGrids/Request/WorkGridTimePeriodSaveRequest.cs index 85bcc07a..c2ccef6c 100644 --- a/Src/Dlhis.Basic/WorkGrids/Request/WorkGridTimePeriodSaveRequest.cs +++ b/Src/Dlhis.Basic/WorkGrids/Request/WorkGridTimePeriodSaveRequest.cs @@ -1,9 +1,10 @@ using System.ComponentModel.DataAnnotations; using Dlhis.Entity.Basic.Enums; +using Kurisu.AspNetCore.Utils.Extensions; namespace Dlhis.Basic.WorkGrids.Request; -public class WorkGridTimePeriodSaveRequest +public class WorkGridTimePeriodSaveRequest : IValidatableObject { public long? Id { get; set; } @@ -33,4 +34,22 @@ public class WorkGridTimePeriodSaveRequest /// 结束时间 /// public TimeOnly End { get; set; } + + /// + public IEnumerable Validate(ValidationContext validationContext) + { + if (Type != WorkGridTimePeriodEnumType.Day) + { + yield break; + } + + var today = DateTime.Today; + var start = today.Add(Start.AddMinutes(-Before).ToTimeSpan()); + var end = today.Add(End.AddMinutes(After).ToTimeSpan()); + + if (start.Date != end.Date) + { + yield return new ValidationResult(WorkGridTimePeriodEnumType.Day.GetDescription() + "禁止跨天", new[] { nameof(Type) }); + } + } } \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/Jobs/AutoRemoveAppointmentJob.cs b/Src/Dlhis.ScheduledTask/Jobs/AutoRemoveAppointmentJob.cs index 8faf467c..883e0723 100644 --- a/Src/Dlhis.ScheduledTask/Jobs/AutoRemoveAppointmentJob.cs +++ b/Src/Dlhis.ScheduledTask/Jobs/AutoRemoveAppointmentJob.cs @@ -57,7 +57,7 @@ public class AutoRemoveAppointmentJob : BaseJob Type = DeviceTaskEnumType.Delete, Priority = 100, TenantId = x.TenantId, - Source = "定时任务判断触发移除", + Source = "访客时间到期自动移除", Version = 0 }).ToList()); @@ -76,6 +76,11 @@ public class AutoRemoveAppointmentJob : BaseJob } + /// + /// 获取有效的区域编码,需要根据申请时间和当前时间判断 + /// + /// + /// private static IEnumerable GetValidAreaCodes(VisitorAppointmentDetailEntity detail) { var now = DateTime.Now;