diff --git a/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs b/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs index 2617df28..ff3cae07 100644 --- a/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs +++ b/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs @@ -85,12 +85,15 @@ public class AppointmentService : IAppointmentService var detail = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync(); detail.ThrowIfNull("预约信息不存在"); - detail.DoorStatus = VisitorAppointmentDetailStatusEnumType.Arrived; - detail.WorkplaceStatus = VisitorAppointmentDetailStatusEnumType.Arrived; - detail.ArrivedTime = DateTime.Now; - - await _dbContext.UpdateAsync(detail); await GenerateTaskAndUpdateFaceAsync(detail.Id, request.Base64Image, DeviceTaskEnumType.Add); + + if (detail.DoorStatus == VisitorAppointmentDetailStatusEnumType.Wait) + { + detail.DoorStatus = VisitorAppointmentDetailStatusEnumType.Arrived; + } + + detail.ArrivedTime = DateTime.Now; + await _dbContext.UpdateAsync(detail); } public async Task GenerateTaskAndUpdateFaceAsync(long detailId, string base64, DeviceTaskEnumType deviceTaskType) @@ -120,7 +123,7 @@ public class AppointmentService : IAppointmentService Priority = 100, TenantId = x.TenantId, Source = DeviceTaskSourceEnumType.Appointment, - Version = 0, + Version = 0 }).ToList()); await _gainfoFaceService.UploadExternalFaceAsync(new GainfoUploadFaceRequest @@ -137,14 +140,6 @@ public class AppointmentService : IAppointmentService { yield return detail.ApplyDoorArea; } - - if (detail.IsEnterWorkplace) - { - foreach (var item in detail.ApplyWorkplaceAreas) - { - yield return item; - } - } } diff --git a/Src/Dlhis.External/Appointment/Services/Implements/AppointmentService.cs b/Src/Dlhis.External/Appointment/Services/Implements/AppointmentService.cs index ff689b9f..5e5a516b 100644 --- a/Src/Dlhis.External/Appointment/Services/Implements/AppointmentService.cs +++ b/Src/Dlhis.External/Appointment/Services/Implements/AppointmentService.cs @@ -61,24 +61,25 @@ public class AppointmentService : IAppointmentService IdNo = item.IdNo, Name = item.Name, Source = request.Source, - Phone = item.Phone + Phone = item.Phone, + Factory = mst.Factory }; await _dbContext.InsertAsync(gainfo); } else { + (gainfo.Type != GainfoUserTypeEnumType.External && item.IsEnterDoorArea).ThrowIfTrue("内部人员无法发起门岗预约"); + if (gainfo.Type == GainfoUserTypeEnumType.External) { gainfo.Source = request.Source; gainfo.Phone = item.Phone; + gainfo.Factory = mst.Factory; await _dbContext.UpdateAsync(gainfo); } } - //todo - //(gainfo.Type == GainfoUserTypeEnumType.External && item.IsEnterWorkplace && item.ImageUrl.IsEmpty()).ThrowIfTrue($"{item.Name}的社保照片不可为空"); - var detail = new VisitorAppointmentDetailEntity { UserNo = gainfo.No, diff --git a/Src/Dlhis.ScheduledTask/Jobs/AutoConfirmAppointmentJob.cs b/Src/Dlhis.ScheduledTask/Jobs/AutoConfirmAppointmentJob.cs new file mode 100644 index 00000000..a584ce6f --- /dev/null +++ b/Src/Dlhis.ScheduledTask/Jobs/AutoConfirmAppointmentJob.cs @@ -0,0 +1,82 @@ +using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Basic.Enums; +using Dlhis.Entity.Device.Entities; +using Dlhis.Entity.Device.Enums; +using Dlhis.Entity.Visitor.Entity; +using Dlhis.Entity.Visitor.Enums; +using Dlhis.ScheduledTask.Attributes; + +namespace Dlhis.ScheduledTask.Jobs; + +/// +/// 访客预约移除 +/// +[RecurringJob(nameof(AutoConfirmAppointmentJob), "0 0/5 * * * ?", Name = "访客预约自动处理车间")] +public class AutoConfirmAppointmentJob : BaseJob +{ + /// + public AutoConfirmAppointmentJob(IServiceProvider serviceProvider) : base(serviceProvider) + { + } + + /// + protected override async Task RunAsync(IServiceProvider serviceProvider) + { + var details = await DbContext.Queryable() + .Where(x => x.DoorStatus == VisitorAppointmentDetailStatusEnumType.Wait || x.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Wait) + .ToListAsync(); + + foreach (var detail in details) + { + var gainfo = await DbContext.Queryable().Where(x => x.No == detail.No).SingleAsync(); + var isExternal = gainfo.Type == GainfoUserTypeEnumType.External; + + var areaCodes = GetValidAreaCodes(isExternal, detail); + var existsAreaCodes = await DbContext.Queryable().Where(x => areaCodes.Contains(x.CustomCode)).Select(x => x.CustomCode).ToListAsync(); + + //当前分配的设备组code + var deviceGroupCodes = await DbContext.Queryable() + .Where(x => existsAreaCodes.Contains(x.CustomCode)) + .Select(x => x.DeviceGroupCode) + .ToListAsync(); + + var deviceCodes = await DbContext.Queryable().Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToListAsync(); + var deviceUniqueNos = await DbContext.Queryable().Where(x => deviceCodes.Contains(x.Code)).Select(x => new { x.UniqueNo, x.TenantId }).ToListAsync(); + + await DbContext.InsertAsync(deviceUniqueNos.Select(x => new DeviceTaskEntity + { + DeviceType = DeviceTypeEnumType.Door, + DeviceUniqueNo = x.UniqueNo, + Status = DeviceTaskStatusEnumType.Wait, + UserNo = detail.UserNo, + Type = DeviceTaskEnumType.Add, + Priority = 100, + TenantId = x.TenantId, + Source = DeviceTaskSourceEnumType.Appointment, + Version = 0 + }).ToList()); + + + if (detail.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Arrived) + { + detail.WorkplaceStatus = VisitorAppointmentDetailStatusEnumType.Leave; + } + + await DbContext.UpdateAsync(detail); + } + } + + + private static IEnumerable GetValidAreaCodes(bool isExternal, VisitorAppointmentDetailEntity detail) + { + var now = DateTime.Now; + + if (detail.IsEnterWorkplace && detail.WorkplaceEnd >= now) + { + foreach (var item in detail.ApplyWorkplaceAreas) + { + yield return item; + } + } + } +} \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/Jobs/AutoRemoveAppointmentJob.cs b/Src/Dlhis.ScheduledTask/Jobs/AutoRemoveAppointmentJob.cs new file mode 100644 index 00000000..d7987e8d --- /dev/null +++ b/Src/Dlhis.ScheduledTask/Jobs/AutoRemoveAppointmentJob.cs @@ -0,0 +1,87 @@ +using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Device.Entities; +using Dlhis.Entity.Device.Enums; +using Dlhis.Entity.Visitor.Entity; +using Dlhis.Entity.Visitor.Enums; +using Dlhis.ScheduledTask.Attributes; + +namespace Dlhis.ScheduledTask.Jobs; + +/// +/// 访客预约移除 +/// +[RecurringJob(nameof(AutoRemoveAppointmentJob), "0 0/5 * * * ?", Name = "访客预约移除")] +public class AutoRemoveAppointmentJob : BaseJob +{ + /// + public AutoRemoveAppointmentJob(IServiceProvider serviceProvider) : base(serviceProvider) + { + } + + /// + protected override async Task RunAsync(IServiceProvider serviceProvider) + { + var details = await DbContext.Queryable() + .Where(x => x.DoorStatus == VisitorAppointmentDetailStatusEnumType.Arrived || x.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Arrived) + .ToListAsync(); + + foreach (var detail in details) + { + var areaCodes = GetValidAreaCodes(detail); + var existsAreaCodes = await DbContext.Queryable().Where(x => areaCodes.Contains(x.CustomCode)).Select(x => x.CustomCode).ToListAsync(); + + //当前分配的设备组code + var deviceGroupCodes = await DbContext.Queryable() + .Where(x => existsAreaCodes.Contains(x.CustomCode)) + .Select(x => x.DeviceGroupCode) + .ToListAsync(); + + var deviceCodes = await DbContext.Queryable().Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToListAsync(); + var deviceUniqueNos = await DbContext.Queryable().Where(x => deviceCodes.Contains(x.Code)).Select(x => new { x.UniqueNo, x.TenantId }).ToListAsync(); + + await DbContext.InsertAsync(deviceUniqueNos.Select(x => new DeviceTaskEntity + { + DeviceType = DeviceTypeEnumType.Door, + DeviceUniqueNo = x.UniqueNo, + Status = DeviceTaskStatusEnumType.Wait, + UserNo = detail.UserNo, + Type = DeviceTaskEnumType.Delete, + Priority = 100, + TenantId = x.TenantId, + Source = DeviceTaskSourceEnumType.Appointment, + Version = 0 + }).ToList()); + + if (detail.DoorStatus == VisitorAppointmentDetailStatusEnumType.Arrived) + { + detail.DoorStatus = VisitorAppointmentDetailStatusEnumType.Leave; + } + + if (detail.WorkplaceStatus == VisitorAppointmentDetailStatusEnumType.Arrived) + { + detail.WorkplaceStatus = VisitorAppointmentDetailStatusEnumType.Leave; + } + + await DbContext.UpdateAsync(detail); + } + } + + + private static IEnumerable GetValidAreaCodes(VisitorAppointmentDetailEntity detail) + { + var now = DateTime.Now; + + if (detail.IsEnterDoorArea && detail.DoorEnd >= now) + { + yield return detail.ApplyDoorArea; + } + + if (detail.IsEnterWorkplace && detail.WorkplaceEnd >= now) + { + foreach (var item in detail.ApplyWorkplaceAreas) + { + yield return item; + } + } + } +} \ No newline at end of file