6 changed files with 123 additions and 0 deletions
@ -0,0 +1,3 @@ |
|||||
|
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
||||
|
<ConfigureAwait ContinueOnCapturedContext="false" /> |
||||
|
</Weavers> |
||||
@ -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> |
||||
@ -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>(); |
||||
|
} |
||||
|
} |
||||
@ -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; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
# LINGYUN.Abp.Notifications.Calendar |
||||
|
|
||||
|
通知发布提供程序的工作日检查拦截器, 非系统定义工作日时不发布通知. |
||||
|
|
||||
|
#### 注意 |
||||
|
|
||||
|
|
||||
|
## 功能特性 |
||||
|
|
||||
|
|
||||
|
## 配置使用 |
||||
|
|
||||
|
|
||||
|
## 更多信息 |
||||
|
|
||||
Loading…
Reference in new issue