From 726e62d032b1042b44bae08093d70cb68e2ef0fa Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 9 Dec 2025 11:16:09 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E8=AE=BF=E5=AE=A2=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E7=A6=BB=E5=9C=BA=E9=80=9A=E7=9F=A5,=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E7=A6=BB=E5=9C=BA=E5=A2=9E=E5=8A=A0=E8=8A=82=E5=81=87=E6=97=A5?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Response/AppointmentDetailResponse.cs | 4 +- .../Services/Implements/AppointmentService.cs | 92 +++++++++++++++++-- .../Services/Implements/HolidayService.cs | 16 ++-- .../Message/Controller/MessagesController.cs | 6 ++ .../Message/Services/IJinkoApiService.cs | 1 + .../Services/Implements/JinkoApiService.cs | 7 +- .../GetDataPermissionService.cs | 1 + 7 files changed, 107 insertions(+), 20 deletions(-) diff --git a/Src/Dlhis.Basic/Appointment/Response/AppointmentDetailResponse.cs b/Src/Dlhis.Basic/Appointment/Response/AppointmentDetailResponse.cs index 8163846f..13351b85 100644 --- a/Src/Dlhis.Basic/Appointment/Response/AppointmentDetailResponse.cs +++ b/Src/Dlhis.Basic/Appointment/Response/AppointmentDetailResponse.cs @@ -1,5 +1,5 @@ -using Dlhis.Entity.Visitor.Enums; -using Kurisu.AspNetCore.Utils.Extensions; +using Dlhis.Basic.Utils; +using Dlhis.Entity.Visitor.Enums; using Newtonsoft.Json; namespace Dlhis.Basic.Appointment.Response; diff --git a/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs b/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs index ff03760b..12b9e3ae 100644 --- a/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs +++ b/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs @@ -1,5 +1,7 @@ using Dlhis.Basic.Appointment.Request; using Dlhis.Basic.Appointment.Response; +using Dlhis.Basic.Common.Message.Requests; +using Dlhis.Basic.Common.Message.Services; using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Services; using Dlhis.Dh.Api; @@ -27,6 +29,7 @@ public class AppointmentService : IAppointmentService private readonly IDataProtectionProvider _dataProtectionProvider; private readonly ICurrentUser _currentUser; private readonly IDhApi _dhApi; + private readonly IJinkoApiService _jinkoApiService; private readonly IFactorySettingService _factorySettingService; private readonly ILogger _logger; private readonly IGainfoFaceService _gainfoFaceService; @@ -36,15 +39,18 @@ public class AppointmentService : IAppointmentService IDataProtectionProvider dataProtectionProvider, ICurrentUser currentUser, IDhApi dhApi, + IJinkoApiService jinkoApiService, IFactorySettingService factorySettingService, IGainfoFaceService gainfoFaceService, IServiceProvider serviceProvider, + ILogger logger) { _dbContext = dbContext; _dataProtectionProvider = dataProtectionProvider; _currentUser = currentUser; _dhApi = dhApi; + _jinkoApiService = jinkoApiService; _factorySettingService = factorySettingService; _logger = logger; _gainfoFaceService = gainfoFaceService; @@ -196,6 +202,13 @@ public class AppointmentService : IAppointmentService // 生成设备任务并更新数据库 await GenerateDeviceTasksAsync(detail, true, DeviceTaskEnumType.Delete, $"强制离场:{reason}"); await _dbContext.UpdateAsync(detail); + + var appointment = await _dbContext.Queryable().Where(x => x.No == detail.No).SingleAsync(); + await _jinkoApiService.SendWorkMessageAsync(new DingTalkWorkMessageRequest + { + WorkCodes = new List { appointment.Code }, + Content = $"您的访客预约《{appointment.Title}》中的访客{detail.Name}已被强制离场,原因:{reason}。" + }); } public async Task> GetRecordPageByIdNoAsync(AppointmentIdNoPageRequest request) @@ -355,6 +368,21 @@ public class AppointmentService : IAppointmentService //todo 临时处理循环依赖 var gainfoService = _serviceProvider.GetService(); + var holidaies = await _dbContext + .Queryable() + .Select(x => new + { + x.Type, + Period = new DatePeriod + { + Start = x.Start, + End = x.End + } + }) + .ToListAsync(); + + + var weekends = new List() { DayOfWeek.Saturday, DayOfWeek.Sunday }; //人员分组,key为factory foreach (var exts in externals.GroupBy(x => x.Factory)) { @@ -375,29 +403,73 @@ public class AppointmentService : IAppointmentService .SingleAsync(); // 如果最近通行时间存在且超出未通行天数阈值,则自动归档该外部人员 - if (raiseDateTime.HasValue && raiseDateTime.Value.AddDays(setting.NoRecordAutoResignExternalDays) < DateTime.Now) + if (raiseDateTime.HasValue) { - try + var checkDates = GetDaysUntilToday(raiseDateTime.Value); + var days = checkDates.Count; + foreach (var date in checkDates) { - await gainfoService.ResignAsync(new GainfoResignRequest + //date.DayOfWeek + foreach (var holiday in holidaies) { - Id = ext.Id, - Reason = $"{setting.NoRecordAutoResignExternalDays}天无通行记录", - Date = DateTime.Now - }); + var isPresent = date >= holiday.Period.Start && date <= holiday.Period.Start; + if (isPresent) + { + if (holiday.Type == HolidayEnumType.Rest) + { + days--; + } + } + else + { + if (weekends.Contains(date.DayOfWeek)) + { + days--; + } + } + } } - catch (Exception e) + + if (days >= setting.NoRecordAutoResignExternalDays) { - // 记录自动归档异常日志 - _logger.LogError(e, "自动归档外部人员异常:{msg}", e.Message); + try + { + await gainfoService.ResignAsync(new GainfoResignRequest + { + Id = ext.Id, + Reason = $"{setting.NoRecordAutoResignExternalDays}天无通行记录", + Date = DateTime.Now + }); + } + catch (Exception e) + { + // 记录自动归档异常日志 + _logger.LogError(e, "自动归档外部人员异常:{msg}", e.Message); + } } } } } } + //********************************************************************************************************************* + private List GetDaysUntilToday(DateTime begin) + { + var start = DateOnly.FromDateTime(begin.Date); + var today = DateOnly.FromDateTime(DateTime.Today); + if (start > today) return new List(); + + var days = new List(); + for (var d = start; d <= today; d = d.AddDays(1)) + { + days.Add(d); + } + + return days; + } + private async Task GenerateDeviceTasksAsync(VisitorAppointmentDetailEntity detail, bool withWorkplace, DeviceTaskEnumType deviceTaskType, string source) { diff --git a/Src/Dlhis.Basic/Common/Holiday/Services/Implements/HolidayService.cs b/Src/Dlhis.Basic/Common/Holiday/Services/Implements/HolidayService.cs index 7c3aa067..e8ec04e1 100644 --- a/Src/Dlhis.Basic/Common/Holiday/Services/Implements/HolidayService.cs +++ b/Src/Dlhis.Basic/Common/Holiday/Services/Implements/HolidayService.cs @@ -28,7 +28,7 @@ public class HolidayService : IHolidayService var exists = await _dbContext.Queryable() .WhereIF(req.Id.HasValue, x => x.Id != req.Id) .Where(x => x.Year == req.Year) - .Where(x => x.Start < req.End && req.Start < x.End) + .Where(x => x.Start <= req.End && req.Start <= x.End) .Where(x => x.Type != req.Type) .AnyAsync(); @@ -36,20 +36,22 @@ public class HolidayService : IHolidayService if (!req.Id.HasValue) { - await _dbContext.InsertAsync(req.Adapt()); + var holiday = req.Adapt(); + await _dbContext.InsertAsync(holiday); } else { - var entity = await _dbContext.Queryable().SingleAsync(x => x.Id == req.Id); - entity.ThrowIfNull("节假日数据不存在"); + var holiday = await _dbContext.Queryable().SingleAsync(x => x.Id == req.Id); + holiday.ThrowIfNull("节假日数据不存在"); - req.Adapt(entity); - await _dbContext.UpdateAsync(entity); + req.Adapt(holiday); + await _dbContext.UpdateAsync(holiday); } } public async Task DeleteAsync(long id) { - await _dbContext.Deleteable().Where(x => x.Id == id).ExecuteCommandAsync(); + var holiday = await _dbContext.Queryable().Where(x => x.Id == id).SingleAsync(); + await _dbContext.DeleteReallyAsync(holiday); } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Common/Message/Controller/MessagesController.cs b/Src/Dlhis.Basic/Common/Message/Controller/MessagesController.cs index dd3ce314..14a022bf 100644 --- a/Src/Dlhis.Basic/Common/Message/Controller/MessagesController.cs +++ b/Src/Dlhis.Basic/Common/Message/Controller/MessagesController.cs @@ -22,4 +22,10 @@ public class MessagesController : ControllerBase { await _jinkoApiService.SendWorkMessageAsync(request); } + + [HttpPost("dingtalk/workgrid/workmessage")] + public async Task SendWorkMessageByWorkGridAsync(DingTalkWorkMessageRequest request) + { + await _jinkoApiService.SendWorkMessageByWorkGridAsync(request); + } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Common/Message/Services/IJinkoApiService.cs b/Src/Dlhis.Basic/Common/Message/Services/IJinkoApiService.cs index 2efc0314..f04efc0a 100644 --- a/Src/Dlhis.Basic/Common/Message/Services/IJinkoApiService.cs +++ b/Src/Dlhis.Basic/Common/Message/Services/IJinkoApiService.cs @@ -5,4 +5,5 @@ namespace Dlhis.Basic.Common.Message.Services; public interface IJinkoApiService : ISingletonDependency { Task SendWorkMessageAsync(DingTalkWorkMessageRequest request); + Task SendWorkMessageByWorkGridAsync(DingTalkWorkMessageRequest request); } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Common/Message/Services/Implements/JinkoApiService.cs b/Src/Dlhis.Basic/Common/Message/Services/Implements/JinkoApiService.cs index d8bec022..4444f3b5 100644 --- a/Src/Dlhis.Basic/Common/Message/Services/Implements/JinkoApiService.cs +++ b/Src/Dlhis.Basic/Common/Message/Services/Implements/JinkoApiService.cs @@ -81,7 +81,12 @@ public class JinkoApiService : IJinkoApiService var jsonResponse = await response.Content.ReadAsStringAsync(); var jObject = JObject.Parse(jsonResponse); - (jObject.Value("errcode") == "0").ThrowIfFalse(jObject.Value("errmsg")); + (jObject.Value("errcode") == "0").ThrowIfFalse(jObject.Value("errmsg")); + } + + public async Task SendWorkMessageByWorkGridAsync(DingTalkWorkMessageRequest request) + { + await SendWorkMessageAsync(request); using var scope = _serviceProvider.CreateScope(); var ol = scope.ServiceProvider.GetService(); diff --git a/Src/Dlhis.Basic/DataPermissions/GetDataPermissionService.cs b/Src/Dlhis.Basic/DataPermissions/GetDataPermissionService.cs index f74f765e..1dbf5bf8 100644 --- a/Src/Dlhis.Basic/DataPermissions/GetDataPermissionService.cs +++ b/Src/Dlhis.Basic/DataPermissions/GetDataPermissionService.cs @@ -1,3 +1,4 @@ +using Dlhis.Basic.Utils; using Dlhis.DataPermission.Model; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities;