diff --git a/aspnet-core/LINGYUN.MicroService.Aspire.slnx b/aspnet-core/LINGYUN.MicroService.Aspire.slnx index a19022d70..f44c32ec2 100644 --- a/aspnet-core/LINGYUN.MicroService.Aspire.slnx +++ b/aspnet-core/LINGYUN.MicroService.Aspire.slnx @@ -448,6 +448,7 @@ + diff --git a/aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/FodyWeavers.xml b/aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/FodyWeavers.xml new file mode 100644 index 000000000..1715698cc --- /dev/null +++ b/aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN.Abp.Notifications.Calendar.csproj b/aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN.Abp.Notifications.Calendar.csproj new file mode 100644 index 000000000..3715f079e --- /dev/null +++ b/aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN.Abp.Notifications.Calendar.csproj @@ -0,0 +1,22 @@ + + + + + + + net10.0 + LINGYUN.Abp.Notifications.Calendar + LINGYUN.Abp.Notifications.Calendar + false + false + false + enable + + + + + + + + + diff --git a/aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN/Abp/Notifications/Calendar/AbpNotificationsCalendarModule.cs b/aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN/Abp/Notifications/Calendar/AbpNotificationsCalendarModule.cs new file mode 100644 index 000000000..781030660 --- /dev/null +++ b/aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN/Abp/Notifications/Calendar/AbpNotificationsCalendarModule.cs @@ -0,0 +1,16 @@ +using LINGYUN.Abp.Calendar; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.Notifications.Calendar; + +[DependsOn( + typeof(AbpNotificationsModule), + typeof(AbpCalendarModule))] +public class AbpNotificationsCalendarModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddTransient(); + } +} diff --git a/aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN/Abp/Notifications/Calendar/WorkdayCalendarPublishInterceptor.cs b/aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN/Abp/Notifications/Calendar/WorkdayCalendarPublishInterceptor.cs new file mode 100644 index 000000000..a24d997bd --- /dev/null +++ b/aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN/Abp/Notifications/Calendar/WorkdayCalendarPublishInterceptor.cs @@ -0,0 +1,66 @@ +using LINGYUN.Abp.Calendar; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using System; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; +using Volo.Abp.MultiTenancy; +using Volo.Abp.Timing; + +namespace LINGYUN.Abp.Notifications.Calendar; + +/// +/// 工作日通知发布拦截器 +/// +public class WorkdayCalendarPublishInterceptor : INotificationPublishInterceptor, ITransientDependency +{ + private readonly IClock _clock; + private readonly ICurrentTenant _currentTenant; + private readonly IWorkdayCalendarService _workdayCalendarService; + public ILogger Logger { protected get; set; } + + public WorkdayCalendarPublishInterceptor( + IClock clock, + ICurrentTenant currentTenant, + IWorkdayCalendarService workdayCalendarService) + { + _clock = clock; + _currentTenant = currentTenant; + _workdayCalendarService = workdayCalendarService; + + Logger = NullLogger.Instance; + } + + public int Priority => 100; + + public async Task CanPublishAsync(NotificationInfo notification) + { + try + { + using (_currentTenant.Change(notification.TenantId)) + { + var isWorktime = await _workdayCalendarService.IsInWorkTimeAsync(_clock.Now); + + if (!isWorktime) + { + Logger.LogInformation( + "Notification {NotificationName} was blocked during the working time check. Type: {NotificationType}, Time: {Time}.", + notification.Name, + notification.Type, + _clock.Now.ToString("yyyy-MM-dd HH:mm:ss")); + return false; + } + + return true; + } + } + catch (Exception ex) + { + Logger.LogWarning(ex, + "If an abnormality occurs during the working day check, the default setting allows {NotificationName} to be notified to publish.", + notification.Name); + + return true; + } + } +} diff --git a/aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/README.md b/aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/README.md new file mode 100644 index 000000000..8695a85e8 --- /dev/null +++ b/aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/README.md @@ -0,0 +1,15 @@ +# LINGYUN.Abp.Notifications.Calendar + +通知发布提供程序的工作日检查拦截器, 非系统定义工作日时不发布通知. + +#### 注意 + + +## 功能特性 + + +## 配置使用 + + +## 更多信息 +