Browse Source

Merge pull request #1484 from colinin/calendar

Add the dependency of the notification workday interceptor module
pull/1492/head
yx lin 3 months ago
committed by GitHub
parent
commit
9c4afce097
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      aspnet-core/LINGYUN.MicroService.All.slnx
  2. 1
      aspnet-core/LINGYUN.MicroService.Aspire.slnx
  3. 4
      aspnet-core/LINGYUN.MicroService.SingleProject.slnx
  4. 1
      aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/LINGYUN.Abp.MicroService.MessageService.csproj
  5. 2
      aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/MessageServiceModule.cs
  6. 4
      aspnet-core/framework/calendars/LINGYUN.Abp.Calendar/LINGYUN/Abp/Calendar/WorkdayCalendarService.cs
  7. 3
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/FodyWeavers.xml
  8. 22
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN.Abp.Notifications.Calendar.csproj
  9. 16
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN/Abp/Notifications/Calendar/AbpNotificationsCalendarModule.cs
  10. 65
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN/Abp/Notifications/Calendar/WorkdayCalendarPublishInterceptor.cs
  11. 15
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/README.md
  12. 20
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationPublishInterceptor.cs
  13. 77
      aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationPublishProvider.cs
  14. 1
      aspnet-core/services/LY.MicroService.Applications.Single/LY.MicroService.Applications.Single.csproj
  15. 3
      aspnet-core/services/LY.MicroService.Applications.Single/MicroServiceApplicationsSingleModule.cs
  16. 1
      aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/LY.MicroService.RealtimeMessage.HttpApi.Host.csproj
  17. 2
      aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/RealtimeMessageHttpApiHostModule.cs

4
aspnet-core/LINGYUN.MicroService.All.slnx

@ -105,6 +105,9 @@
<Folder Name="/framework/authorization/">
<Project Path="framework/authorization/LINGYUN.Abp.Authorization.OrganizationUnits/LINGYUN.Abp.Authorization.OrganizationUnits.csproj" />
</Folder>
<Folder Name="/framework/calendars/">
<Project Path="framework/calendars/LINGYUN.Abp.Calendar/LINGYUN.Abp.Calendar.csproj" />
</Folder>
<Folder Name="/framework/cli/">
<Project Path="framework/cli/LINGYUN.Abp.Cli/LINGYUN.Abp.Cli.csproj" />
</Folder>
@ -433,6 +436,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" />
<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" />

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" />

4
aspnet-core/LINGYUN.MicroService.SingleProject.slnx

@ -36,6 +36,9 @@
<Project Path="modules/task-management/LINGYUN.Abp.Quartz.SqlInstaller/LINGYUN.Abp.Quartz.SqlInstaller.csproj" />
<Project Path="modules/task-management/LINGYUN.Abp.Quartz.SqlServerInstaller/LINGYUN.Abp.Quartz.SqlServerInstaller.csproj" />
</Folder>
<Folder Name="/framework/calendars/">
<Project Path="framework/calendars/LINGYUN.Abp.Calendar/LINGYUN.Abp.Calendar.csproj" />
</Folder>
<Folder Name="/framework/cap/">
<Project Path="framework/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.csproj" />
</Folder>
@ -96,6 +99,7 @@
<Project Path="framework/common/LINGYUN.Abp.RealTime/LINGYUN.Abp.RealTime.csproj" />
<Project Path="modules/realtime-message/LINGYUN.Abp.IM.SignalR/LINGYUN.Abp.IM.SignalR.csproj" />
<Project Path="modules/realtime-message/LINGYUN.Abp.IM/LINGYUN.Abp.IM.csproj" />
<Project Path="modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN.Abp.Notifications.Calendar.csproj" />
<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.Emailing/LINGYUN.Abp.Notifications.Emailing.csproj" />

1
aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/LINGYUN.Abp.MicroService.MessageService.csproj

@ -55,6 +55,7 @@
<ProjectReference Include="..\..\framework\wechat\LINGYUN.Abp.Identity.WeChat\LINGYUN.Abp.Identity.WeChat.csproj" />
<ProjectReference Include="..\..\framework\wechat\LINGYUN.Abp.WeChat.Official.Handlers\LINGYUN.Abp.WeChat.Official.Handlers.csproj" />
<ProjectReference Include="..\..\framework\wechat\LINGYUN.Abp.WeChat.Work.Handlers\LINGYUN.Abp.WeChat.Work.Handlers.csproj" />
<ProjectReference Include="..\..\modules\realtime-notifications\LINGYUN.Abp.Notifications.Calendar\LINGYUN.Abp.Notifications.Calendar.csproj" />
</ItemGroup>
<ItemGroup>

2
aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/MessageServiceModule.cs

@ -23,6 +23,7 @@ using LINGYUN.Abp.LocalizationManagement.EntityFrameworkCore;
using LINGYUN.Abp.MessageService;
using LINGYUN.Abp.MessageService.EntityFrameworkCore;
using LINGYUN.Abp.Notifications;
using LINGYUN.Abp.Notifications.Calendar;
using LINGYUN.Abp.Notifications.Common;
using LINGYUN.Abp.Notifications.Emailing;
using LINGYUN.Abp.Notifications.EntityFrameworkCore;
@ -102,6 +103,7 @@ namespace LINGYUN.Abp.MicroService.MessageService;
typeof(AbpNotificationsWeChatWorkModule),
typeof(AbpNotificationsExceptionHandlingModule),
typeof(AbpNotificationsTemplatingModule),
typeof(AbpNotificationsCalendarModule),
typeof(AbpWeChatWorkHandlersModule),
typeof(AbpWeChatOfficialHandlersModule),
typeof(AbpIdentityNotificationsModule),

4
aspnet-core/framework/calendars/LINGYUN.Abp.Calendar/LINGYUN/Abp/Calendar/WorkdayCalendarService.cs

@ -87,7 +87,7 @@ public class WorkdayCalendarService : IWorkdayCalendarService, ITransientDepende
return false;
}
if (_options.EnableWorkTimeRestriction &&
!_options.DefaultWorkTimes.Any(timeRange => timeRange.StartTime >= time.TimeOfDay && timeRange.EndTime <= time.TimeOfDay))
!_options.DefaultWorkTimes.Any(timeRange => time.TimeOfDay >= timeRange.StartTime && time.TimeOfDay <= timeRange.EndTime))
{
return false;
}
@ -109,7 +109,7 @@ public class WorkdayCalendarService : IWorkdayCalendarService, ITransientDepende
if (calendar.EnableWorkTimeRestriction &&
calendar.WorkTimes != null)
{
return calendar.WorkTimes.Any(x => x.StartTime >= time.TimeOfDay && x.EndTime <= time.TimeOfDay);
return calendar.WorkTimes.Any(timeRange => time.TimeOfDay >= timeRange.StartTime && time.TimeOfDay <= timeRange.EndTime);
}
return false;

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>();
}
}

65
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications.Calendar/LINGYUN/Abp/Notifications/Calendar/WorkdayCalendarPublishInterceptor.cs

@ -0,0 +1,65 @@
using LINGYUN.Abp.Calendar;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using System;
using System.Threading.Tasks;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Timing;
namespace LINGYUN.Abp.Notifications.Calendar;
/// <summary>
/// 工作日通知发布拦截器
/// </summary>
public class WorkdayCalendarPublishInterceptor : INotificationPublishInterceptor
{
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
通知发布提供程序的工作日检查拦截器, 非系统定义工作日时不发布通知.
#### 注意
## 功能特性
## 配置使用
## 更多信息

20
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationPublishInterceptor.cs

@ -0,0 +1,20 @@
using System.Threading.Tasks;
namespace LINGYUN.Abp.Notifications;
/// <summary>
/// 通知发布拦截器, 实现此接口来增加发布前的自定义检查
/// </summary>
public interface INotificationPublishInterceptor
{
/// <summary>
/// 拦截优先级,数值越小优先级越高
/// </summary>
int Priority { get; }
/// <summary>
/// 在通知发布前执行检查
/// </summary>
/// <param name="notification">通知信息</param>
/// <returns>true-允许发布, false-阻止发布</returns>
Task<bool> CanPublishAsync(NotificationInfo notification);
}

77
aspnet-core/modules/realtime-notifications/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationPublishProvider.cs

@ -1,6 +1,8 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
@ -21,6 +23,11 @@ public abstract class NotificationPublishProvider : INotificationPublishProvider
public ICancellationTokenProvider CancellationTokenProvider => ServiceProvider.LazyGetService<ICancellationTokenProvider>(NullCancellationTokenProvider.Instance);
private IEnumerable<INotificationPublishInterceptor> _interceptors;
protected IEnumerable<INotificationPublishInterceptor> Interceptors =>
_interceptors ??= ServiceProvider.LazyGetService<IEnumerable<INotificationPublishInterceptor>>()
?? Enumerable.Empty<INotificationPublishInterceptor>();
public async virtual Task<bool> CanPublishAsync(NotificationInfo notification)
{
return await CanPublishAsync(notification, GetCancellationToken());
@ -28,9 +35,23 @@ public abstract class NotificationPublishProvider : INotificationPublishProvider
public async Task PublishAsync(NotificationPublishContext context)
{
await PublishAsync(context, GetCancellationToken());
var cancellationToken = GetCancellationToken();
// 通知拦截器检查
if (!await ExecuteInterceptorsAsync(context, cancellationToken))
{
return;
}
await PublishAsync(context, cancellationToken);
}
/// <summary>
/// 是否允许发布通知
/// </summary>
/// <param name="notification"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
protected virtual Task<bool> CanPublishAsync(
NotificationInfo notification,
CancellationToken cancellationToken = default)
@ -38,6 +59,60 @@ public abstract class NotificationPublishProvider : INotificationPublishProvider
return Task.FromResult(true);
}
/// <summary>
/// 执行通知发布拦截器
/// </summary>
/// <param name="context"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
protected virtual async Task<bool> ExecuteInterceptorsAsync(
NotificationPublishContext context,
CancellationToken cancellationToken = default)
{
if (context.Notification.Type == NotificationType.System ||
context.Notification.Type == NotificationType.ServiceCallback)
{
Logger.LogDebug(
"System or service callback notification {NotificationName}, skip all interceptors.",
context.Notification.Name);
return true;
}
if (!Interceptors.Any())
{
Logger.LogDebug("No notification publishing interceptors have been registered.");
return true;
}
var orderedInterceptors = Interceptors.OrderBy(i => i.Priority);
foreach (var interceptor in orderedInterceptors)
{
try
{
if (!await interceptor.CanPublishAsync(context.Notification))
{
var reason = string.Format("The interceptor {0} prevented the publication of the notification {1}.",
interceptor.GetType().Name,
context.Notification.Name);
context.Cancel(reason);
Logger.LogWarning(reason);
return false;
}
}
catch (Exception ex)
{
Logger.LogWarning(ex,
"An exception occurred while executing the interceptor {InterceptorType}. By default, publication is allowed.",
interceptor.GetType().Name);
}
}
return true;
}
protected virtual CancellationToken GetCancellationToken(CancellationToken cancellationToken = default)
{
return CancellationTokenProvider.FallbackToProvider(cancellationToken);

1
aspnet-core/services/LY.MicroService.Applications.Single/LY.MicroService.Applications.Single.csproj

@ -211,6 +211,7 @@
<ProjectReference Include="..\..\modules\realtime-message\LINGYUN.Abp.MessageService.EntityFrameworkCore\LINGYUN.Abp.MessageService.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\modules\realtime-message\LINGYUN.Abp.MessageService.HttpApi\LINGYUN.Abp.MessageService.HttpApi.csproj" />
<ProjectReference Include="..\..\modules\realtime-notifications\LINGYUN.Abp.ExceptionHandling.Notifications\LINGYUN.Abp.ExceptionHandling.Notifications.csproj" />
<ProjectReference Include="..\..\modules\realtime-notifications\LINGYUN.Abp.Notifications.Calendar\LINGYUN.Abp.Notifications.Calendar.csproj" />
<ProjectReference Include="..\..\modules\realtime-notifications\LINGYUN.Abp.Notifications.Common\LINGYUN.Abp.Notifications.Common.csproj" />
<ProjectReference Include="..\..\modules\realtime-notifications\LINGYUN.Abp.Notifications.Core\LINGYUN.Abp.Notifications.Core.csproj" />
<ProjectReference Include="..\..\modules\realtime-notifications\LINGYUN.Abp.Notifications.Emailing\LINGYUN.Abp.Notifications.Emailing.csproj" />

3
aspnet-core/services/LY.MicroService.Applications.Single/MicroServiceApplicationsSingleModule.cs

@ -1,4 +1,5 @@
using LINGYUN.Abp.Exporter.MiniSoftware;
using LINGYUN.Abp.Notifications.Calendar;
namespace LY.MicroService.Applications.Single;
@ -316,6 +317,8 @@ namespace LY.MicroService.Applications.Single;
typeof(AbpNotificationsWeChatMiniProgramModule),
// 通知模块 企业微信
typeof(AbpNotificationsWeChatWorkModule),
// 通知模块 工作日检查拦截器
typeof(AbpNotificationsCalendarModule),
// 多租户模块 版本
typeof(AbpMultiTenancyEditionsModule),

1
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/LY.MicroService.RealtimeMessage.HttpApi.Host.csproj

@ -74,6 +74,7 @@
<ProjectReference Include="..\..\modules\realtime-message\LINGYUN.Abp.IM.SignalR\LINGYUN.Abp.IM.SignalR.csproj" />
<ProjectReference Include="..\..\modules\realtime-notifications\LINGYUN.Abp.ExceptionHandling.Notifications\LINGYUN.Abp.ExceptionHandling.Notifications.csproj" />
<ProjectReference Include="..\..\modules\realtime-notifications\LINGYUN.Abp.Notifications.Application\LINGYUN.Abp.Notifications.Application.csproj" />
<ProjectReference Include="..\..\modules\realtime-notifications\LINGYUN.Abp.Notifications.Calendar\LINGYUN.Abp.Notifications.Calendar.csproj" />
<ProjectReference Include="..\..\modules\realtime-notifications\LINGYUN.Abp.Notifications.Emailing\LINGYUN.Abp.Notifications.Emailing.csproj" />
<ProjectReference Include="..\..\modules\realtime-notifications\LINGYUN.Abp.Notifications.EntityFrameworkCore\LINGYUN.Abp.Notifications.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\modules\realtime-notifications\LINGYUN.Abp.Notifications.HttpApi\LINGYUN.Abp.Notifications.HttpApi.csproj" />

2
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/RealtimeMessageHttpApiHostModule.cs

@ -23,6 +23,7 @@ using LINGYUN.Abp.LocalizationManagement.EntityFrameworkCore;
using LINGYUN.Abp.MessageService;
using LINGYUN.Abp.MessageService.EntityFrameworkCore;
using LINGYUN.Abp.Notifications;
using LINGYUN.Abp.Notifications.Calendar;
using LINGYUN.Abp.Notifications.Common;
using LINGYUN.Abp.Notifications.Emailing;
using LINGYUN.Abp.Notifications.EntityFrameworkCore;
@ -107,6 +108,7 @@ namespace LY.MicroService.RealtimeMessage;
typeof(AbpNotificationsWeChatWorkModule),
typeof(AbpNotificationsExceptionHandlingModule),
typeof(AbpNotificationsTemplatingModule),
typeof(AbpNotificationsCalendarModule),
typeof(AbpWeChatWorkHandlersModule),
typeof(AbpWeChatOfficialHandlersModule),
typeof(AbpIdentityNotificationsModule),

Loading…
Cancel
Save