Browse Source

feat: Implement the notification workday check interceptor

pull/1484/head
colin 5 months ago
parent
commit
24dad660f8
  1. 1
      aspnet-core/LINGYUN.MicroService.Aspire.slnx
  2. 3
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/FodyWeavers.xml
  3. 22
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN.Abp.Notifications.Calendar.csproj
  4. 16
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN/Abp/Notifications/Calendar/AbpNotificationsCalendarModule.cs
  5. 66
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN/Abp/Notifications/Calendar/WorkdayCalendarPublishInterceptor.cs
  6. 15
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/README.md

1
aspnet-core/LINGYUN.MicroService.Aspire.slnx

@ -448,6 +448,7 @@
<Project Path="modules/realtime-notifications/LINGYUN.Abp.ExceptionHandling.Notifications/LINGYUN.Abp.ExceptionHandling.Notifications.csproj" />
<Project Path="modules/realtime-notifications/LINGYUN.Abp.Notifications.Application.Contracts/LINGYUN.Abp.Notifications.Application.Contracts.csproj" />
<Project Path="modules/realtime-notifications/LINGYUN.Abp.Notifications.Application/LINGYUN.Abp.Notifications.Application.csproj" />
<Project Path="modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN.Abp.Notifications.Calendar.csproj" Id="afef5b69-ebbf-454c-8783-027dde6e5970" />
<Project Path="modules/realtime-notifications/LINGYUN.Abp.Notifications.Common/LINGYUN.Abp.Notifications.Common.csproj" />
<Project Path="modules/realtime-notifications/LINGYUN.Abp.Notifications.Core/LINGYUN.Abp.Notifications.Core.csproj" />
<Project Path="modules/realtime-notifications/LINGYUN.Abp.Notifications.Domain.Shared/LINGYUN.Abp.Notifications.Domain.Shared.csproj" />

3
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/FodyWeavers.xml

@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait ContinueOnCapturedContext="false" />
</Weavers>

22
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN.Abp.Notifications.Calendar.csproj

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\..\configureawait.props" />
<Import Project="..\..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<AssemblyName>LINGYUN.Abp.Notifications.Calendar</AssemblyName>
<PackageId>LINGYUN.Abp.Notifications.Calendar</PackageId>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Nullable>enable</Nullable>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\framework\calendars\LINGYUN.Abp.Calendar\LINGYUN.Abp.Calendar.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.Notifications\LINGYUN.Abp.Notifications.csproj" />
</ItemGroup>
</Project>

16
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<INotificationPublishInterceptor, WorkdayCalendarPublishInterceptor>();
}
}

66
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;
/// <summary>
/// 工作日通知发布拦截器
/// </summary>
public class WorkdayCalendarPublishInterceptor : INotificationPublishInterceptor, ITransientDependency
{
private readonly IClock _clock;
private readonly ICurrentTenant _currentTenant;
private readonly IWorkdayCalendarService _workdayCalendarService;
public ILogger<WorkdayCalendarPublishInterceptor> Logger { protected get; set; }
public WorkdayCalendarPublishInterceptor(
IClock clock,
ICurrentTenant currentTenant,
IWorkdayCalendarService workdayCalendarService)
{
_clock = clock;
_currentTenant = currentTenant;
_workdayCalendarService = workdayCalendarService;
Logger = NullLogger<WorkdayCalendarPublishInterceptor>.Instance;
}
public int Priority => 100;
public async Task<bool> 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;
}
}
}

15
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/README.md

@ -0,0 +1,15 @@
# LINGYUN.Abp.Notifications.Calendar
通知发布提供程序的工作日检查拦截器, 非系统定义工作日时不发布通知.
#### 注意
## 功能特性
## 配置使用
## 更多信息
Loading…
Cancel
Save