diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppNotificationPublishProvider.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppNotificationPublishProvider.cs
index 441086346..e6c21fac6 100644
--- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppNotificationPublishProvider.cs
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppNotificationPublishProvider.cs
@@ -2,6 +2,7 @@
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Threading.Tasks;
namespace LINGYUN.Abp.Notifications.WeChat.WeApp
@@ -12,7 +13,8 @@ namespace LINGYUN.Abp.Notifications.WeChat.WeApp
public class WeChatWeAppNotificationPublishProvider : NotificationPublishProvider
{
public override string Name => "WeChat.WeApp";
-
+ private INotificationSubscriptionManager _notificationSubscriptionManager;
+ protected INotificationSubscriptionManager NotificationSubscriptionManager => LazyGetRequiredService(ref _notificationSubscriptionManager);
protected IWeChatWeAppNotificationSender NotificationSender { get; }
protected AbpWeChatWeAppNotificationOptions Options { get; }
public WeChatWeAppNotificationPublishProvider(
@@ -32,6 +34,16 @@ namespace LINGYUN.Abp.Notifications.WeChat.WeApp
// step2 调用微信消息推送接口
+ // 微信不支持推送到所有用户,需要获取订阅列表再发送
+ // 在小程序里用户订阅消息后通过 api/subscribes/subscribe 接口订阅对应模板消息
+ if (identifiers == null)
+ {
+ var userSubscriptions = await NotificationSubscriptionManager
+ .GetSubscriptionsAsync(notification.TenantId, notification.Name);
+ identifiers = userSubscriptions
+ .Select(us => new UserIdentifier(us.UserId, us.UserName));
+
+ }
foreach (var identifier in identifiers)
{
await SendWeChatTemplateMessagAsync(notification, identifier);
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationCleanupOptions.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationCleanupOptions.cs
new file mode 100644
index 000000000..3c92996b2
--- /dev/null
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationCleanupOptions.cs
@@ -0,0 +1,21 @@
+namespace LINGYUN.Abp.Notifications
+{
+ public class AbpNotificationCleanupOptions
+ {
+ ///
+ /// 是否启用清理任务
+ /// 默认:启用
+ ///
+ public bool IsEnabled { get; set; } = true;
+ ///
+ /// 清理时间间隔
+ /// 默认:300000ms
+ ///
+ public int CleanupPeriod { get; set; } = 300000;
+ ///
+ /// 清理批次
+ /// 默认: 200
+ ///
+ public int CleanupBatchSize { get; set; } = 200;
+ }
+}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationModule.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationModule.cs
index 30bf9376b..f4eeb1ff5 100644
--- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationModule.cs
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationModule.cs
@@ -1,9 +1,11 @@
using LINGYUN.Abp.Notifications.Internal;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using Volo.Abp;
using Volo.Abp.BackgroundJobs;
+using Volo.Abp.BackgroundWorkers;
using Volo.Abp.Json;
using Volo.Abp.Modularity;
@@ -25,6 +27,20 @@ namespace LINGYUN.Abp.Notifications
context.Services.AddTransient();
}
+ public override void OnApplicationInitialization(ApplicationInitializationContext context)
+ {
+ var options = context.ServiceProvider.GetRequiredService>().Value;
+ if (options.IsEnabled)
+ {
+ context.ServiceProvider
+ .GetRequiredService()
+ .Add(
+ context.ServiceProvider
+ .GetRequiredService()
+ );
+ }
+ }
+
private static void AutoAddDefinitionProviders(IServiceCollection services)
{
var definitionProviders = new List();
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationCleanupBackgroundWorker.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationCleanupBackgroundWorker.cs
new file mode 100644
index 000000000..1dd7fb608
--- /dev/null
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationCleanupBackgroundWorker.cs
@@ -0,0 +1,41 @@
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+using System;
+using System.Threading.Tasks;
+using Volo.Abp.BackgroundWorkers;
+using Volo.Abp.Threading;
+
+namespace LINGYUN.Abp.Notifications.Internal
+{
+ internal class NotificationCleanupBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
+ {
+ protected AbpNotificationCleanupOptions Options { get; }
+
+ public NotificationCleanupBackgroundWorker(
+ AbpTimer timer,
+ IServiceScopeFactory serviceScopeFactory,
+ IOptions options)
+ : base(timer, serviceScopeFactory)
+ {
+ Options = options.Value;
+ timer.Period = Options.CleanupPeriod;
+ }
+
+ protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
+ {
+ try
+ {
+ var store = workerContext.ServiceProvider.GetRequiredService();
+ Logger.LogDebug("Before cleanup exprition jobs...");
+ await store.DeleteNotificationAsync(Options.CleanupBatchSize);
+ Logger.LogDebug("Exprition jobs cleanup job was successful...");
+ }
+ catch (Exception ex)
+ {
+ Logger.LogWarning("Exprition jobs cleanup job was failed...");
+ Logger.LogWarning("Error:{0}", ex.Message);
+ }
+ }
+ }
+}
diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN.Abp.MessageService.Application.Contracts.csproj b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN.Abp.MessageService.Application.Contracts.csproj
index 99b0704d5..7dd324638 100644
--- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN.Abp.MessageService.Application.Contracts.csproj
+++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN.Abp.MessageService.Application.Contracts.csproj
@@ -3,8 +3,16 @@
netstandard2.0
+ true
+ 2.9.0
+ LINGYUN
+
+ D:\LocalNuget
+
+
+
diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationContrantsModule.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationContractsModule.cs
similarity index 89%
rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationContrantsModule.cs
rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationContractsModule.cs
index 000532693..d2fc22278 100644
--- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationContrantsModule.cs
+++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationContractsModule.cs
@@ -6,13 +6,13 @@ using Volo.Abp.VirtualFileSystem;
namespace LINGYUN.Abp.MessageService
{
[DependsOn(typeof(AbpMessageServiceDomainSharedModule))]
- public class AbpMessageServiceApplicationContrantsModule : AbpModule
+ public class AbpMessageServiceApplicationContractsModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure(options =>
{
- options.FileSets.AddEmbedded();
+ options.FileSets.AddEmbedded();
});
Configure(options =>
diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN.Abp.MessageService.Application.csproj b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN.Abp.MessageService.Application.csproj
index a158701e2..4d65e3c0e 100644
--- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN.Abp.MessageService.Application.csproj
+++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN.Abp.MessageService.Application.csproj
@@ -3,8 +3,16 @@
netstandard2.0
+ true
+ 2.9.0
+ LINGYUN
+
+ D:\LocalNuget
+
+
+
diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/AbpMessageServiceApplicationModule.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationModule.cs
similarity index 77%
rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/AbpMessageServiceApplicationModule.cs
rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationModule.cs
index 8351d0454..61620440f 100644
--- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/AbpMessageServiceApplicationModule.cs
+++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationModule.cs
@@ -3,7 +3,7 @@
namespace LINGYUN.Abp.MessageService
{
[DependsOn(
- typeof(AbpMessageServiceApplicationContrantsModule),
+ typeof(AbpMessageServiceApplicationContractsModule),
typeof(AbpMessageServiceDomainModule))]
public class AbpMessageServiceApplicationModule : AbpModule
{
diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/Notification.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/Notification.cs
index 75d49b423..947cc3d65 100644
--- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/Notification.cs
+++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/Notification.cs
@@ -19,6 +19,12 @@ namespace LINGYUN.Abp.MessageService.Notifications
public virtual DateTime? ExpirationTime { get; set; }
public virtual DateTime CreationTime { get; set; }
protected Notification(){}
+
+ public Notification(long id)
+ {
+ Id = id;
+ }
+
public Notification(long id, string category, string name, string dataType, string data, NotificationSeverity severity = NotificationSeverity.Info)
{
NotificationId = id;
diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatGroupRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatGroupRepository.cs
index d77b60a04..388afa740 100644
--- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatGroupRepository.cs
+++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatGroupRepository.cs
@@ -1,6 +1,8 @@
using LINGYUN.Abp.IM.Group;
using LINGYUN.Abp.MessageService.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationRepository.cs
index f6fd96e39..c4f698b56 100644
--- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationRepository.cs
+++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationRepository.cs
@@ -20,12 +20,15 @@ namespace LINGYUN.Abp.MessageService.Notifications
public async Task DeleteExpritionAsync(int batchCount)
{
- var notifications = await DbSet
+ var batchDeleteNoticeWithIds = await DbSet
.Where(x => x.ExpirationTime <= DateTime.Now)
.Take(batchCount)
+ .Select(x => new Notification(x.Id))
+ .AsNoTracking()
.ToArrayAsync();
- DbSet.RemoveRange(notifications);
+ DbSet.AttachRange(batchDeleteNoticeWithIds);
+ DbSet.RemoveRange(batchDeleteNoticeWithIds);
}
public async Task GetByIdAsync(long notificationId)
diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi.Client/LINGYUN.Abp.MessageService.HttpApi.Client.csproj b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi.Client/LINGYUN.Abp.MessageService.HttpApi.Client.csproj
new file mode 100644
index 000000000..1ae461b35
--- /dev/null
+++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi.Client/LINGYUN.Abp.MessageService.HttpApi.Client.csproj
@@ -0,0 +1,23 @@
+
+
+
+ netcoreapp3.1
+
+ true
+ 2.9.0
+ LINGYUN
+
+
+
+ D:\LocalNuget
+
+
+
+
+
+
+
+
+
+
+
diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi.Client/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiClientModule.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi.Client/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiClientModule.cs
new file mode 100644
index 000000000..9ecf88a18
--- /dev/null
+++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi.Client/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiClientModule.cs
@@ -0,0 +1,20 @@
+using Microsoft.Extensions.DependencyInjection;
+using Volo.Abp.Http.Client;
+using Volo.Abp.Modularity;
+
+namespace LINGYUN.Abp.MessageService
+{
+ [DependsOn(
+ typeof(AbpMessageServiceApplicationContractsModule),
+ typeof(AbpHttpClientModule))]
+ public class AbpMessageServiceHttpApiClientModule : AbpModule
+ {
+ public override void ConfigureServices(ServiceConfigurationContext context)
+ {
+ context.Services.AddHttpClientProxies(
+ typeof(AbpMessageServiceApplicationContractsModule).Assembly,
+ AbpMessageServiceConsts.RemoteServiceName
+ );
+ }
+ }
+}
diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiModule.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiModule.cs
index d01c83ef2..32d2e9bf0 100644
--- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiModule.cs
+++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiModule.cs
@@ -5,7 +5,7 @@ using Volo.Abp.Modularity;
namespace LINGYUN.Abp.MessageService
{
[DependsOn(
- typeof(AbpMessageServiceApplicationContrantsModule),
+ typeof(AbpMessageServiceApplicationContractsModule),
typeof(AbpAspNetCoreMvcModule)
)]
public class AbpMessageServiceHttpApiModule : AbpModule
diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs
index 4df950c71..e0abc20ae 100644
--- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs
+++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs
@@ -156,13 +156,13 @@ namespace LINGYUN.Abp.MessageService
}
}
- public override void OnPostApplicationInitialization(ApplicationInitializationContext context)
- {
- var backgroundJobManager = context.ServiceProvider.GetRequiredService();
- // 五分钟执行一次的定时任务
- AsyncHelper.RunSync(async () => await
- backgroundJobManager.EnqueueAsync(CronGenerator.Minute(5), new NotificationCleanupExpritionJobArgs(200)));
- }
+ //public override void OnPostApplicationInitialization(ApplicationInitializationContext context)
+ //{
+ // var backgroundJobManager = context.ServiceProvider.GetRequiredService();
+ // // 五分钟执行一次的定时任务
+ // AsyncHelper.RunSync(async () => await
+ // backgroundJobManager.EnqueueAsync(CronGenerator.Minute(5), new NotificationCleanupExpritionJobArgs(200)));
+ //}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs
index d4afc33c3..c026d3afc 100644
--- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs
+++ b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs
@@ -54,7 +54,7 @@ namespace LINGYUN.Platform
typeof(AbpPermissionManagementDomainIdentityModule),
typeof(AbpPermissionManagementDomainIdentityServerModule),
typeof(ApiGatewayApplicationContractsModule),
- typeof(AbpMessageServiceApplicationContrantsModule),
+ typeof(AbpMessageServiceApplicationContractsModule),
typeof(AbpIdentityHttpApiModule),
typeof(AbpIdentityApplicationModule),
typeof(Abp.Account.AbpAccountApplicationModule),