diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecuteCompletedNotificationProvider.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecuteCompletedNotificationProvider.cs index 18777d119..610dbbf3c 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecuteCompletedNotificationProvider.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecuteCompletedNotificationProvider.cs @@ -12,6 +12,7 @@ namespace LINGYUN.Abp.BackgroundTasks.Notifications; public class JobExecuteCompletedNotificationProvider : NotificationJobExecutedProvider { public const string Name = "JobExecutedCompletedNofiter"; + public override string DefaultNotificationName => BackgroundTasksNotificationNames.JobExecuteCompleted; public JobExecuteCompletedNotificationProvider( ICurrentTenant currentTenant, @@ -24,7 +25,7 @@ public class JobExecuteCompletedNotificationProvider : NotificationJobExecutedPr public async override Task NotifyComplateAsync([NotNull] JobActionExecuteContext context) { - var title = StringLocalizer["JobExecutedCompleted"].Value; + var title = StringLocalizer["Notifications:JobExecuteCompleted"].Value; await SendNofiterAsync(context, title, NotificationSeverity.Info); } diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecuteFailedNotificationProvider.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecuteFailedNotificationProvider.cs index ad707865e..94ae28234 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecuteFailedNotificationProvider.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecuteFailedNotificationProvider.cs @@ -12,6 +12,7 @@ namespace LINGYUN.Abp.BackgroundTasks.Notifications; public class JobExecuteFailedNotificationProvider : NotificationJobExecutedProvider { public const string Name = "JobExecutedFailedNofiter"; + public override string DefaultNotificationName => BackgroundTasksNotificationNames.JobExecuteFailed; public JobExecuteFailedNotificationProvider( ICurrentTenant currentTenant, @@ -24,7 +25,7 @@ public class JobExecuteFailedNotificationProvider : NotificationJobExecutedProvi public async override Task NotifyErrorAsync([NotNull] JobActionExecuteContext context) { - var title = StringLocalizer["JobExecutedFailed"].Value; + var title = StringLocalizer["Notifications:JobExecuteFailed"].Value; await SendNofiterAsync(context, title, NotificationSeverity.Error); } diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecutedSuccessedNotificationProvider.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecutedSuccessedNotificationProvider.cs index fa6e334a6..d202ee18d 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecutedSuccessedNotificationProvider.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecutedSuccessedNotificationProvider.cs @@ -12,6 +12,7 @@ namespace LINGYUN.Abp.BackgroundTasks.Notifications; public class JobExecutedSuccessedNotificationProvider : NotificationJobExecutedProvider { public const string Name = "JobExecutedSuccessedNofiter"; + public override string DefaultNotificationName => BackgroundTasksNotificationNames.JobExecuteSucceeded; public JobExecutedSuccessedNotificationProvider( ICurrentTenant currentTenant, @@ -24,7 +25,7 @@ public class JobExecutedSuccessedNotificationProvider : NotificationJobExecutedP public async override Task NotifySuccessAsync([NotNull] JobActionExecuteContext context) { - var title = StringLocalizer["JobExecutedSucceeded"].Value; + var title = StringLocalizer["Notifications:JobExecuteSucceeded"].Value; await SendNofiterAsync(context, title, NotificationSeverity.Success); } diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources/en.json b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources/en.json index 2039ad2e3..63a71f754 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources/en.json +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources/en.json @@ -8,6 +8,8 @@ "Notifications:JobExecuteFailedDesc": "Notification push after the execution of a background job failed.", "Notifications:JobExecuteCompleted": "Job Completed Notification", "Notifications:JobExecuteCompletedDesc": "After the background job is complated, the notification is pushed.", + "DisplayName:NotificationName": "Notification Name", + "Description:NotificationName": "If a notification name is specified, the message will be sent using the corresponding notification name.", "DisplayName:PushProvider": "Push Service Provider", "Description:PushProvider": "If a push program is specified, the application will select it to push messages. The optional list is :SignalR(real-time notification), Sms(Sms notification), Emailing(email notification), wecht.miniprogram (WeChat MiniProgram), WxPusher(WxPusher WeChat push service), PushPlus (PushPlus multi-platform push service).", "DisplayName:Template": "Template", diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources/zh-Hans.json b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources/zh-Hans.json index e24b3f5d3..260191d8e 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources/zh-Hans.json +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources/zh-Hans.json @@ -8,6 +8,8 @@ "Notifications:JobExecuteFailedDesc": "后台作业执行失败后通知推送.", "Notifications:JobExecuteCompleted": "作业完成通知", "Notifications:JobExecuteCompletedDesc": "后台作业执行完成后通知推送.", + "DisplayName:NotificationName": "通知名称", + "Description:NotificationName": "如果指定通知名称,将使用对应通知名称发送消息.", "DisplayName:PushProvider": "推送程序", "Description:PushProvider": "如果指定推送程序,应用将选择它进行消息推送,多个提供者用;分隔,可选列表:SignalR(实时通知)、Sms(短信通知)、Emailing(邮件通知)、WeChat.MiniProgram(微信小程序)、WxPusher(WxPusher微信推送服务)、PushPlus(PushPlus多平台推送服务)", "DisplayName:Template": "模板名称", diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/NotificationJobExecutedProvider.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/NotificationJobExecutedProvider.cs index a7edfb8b1..330bcebe3 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/NotificationJobExecutedProvider.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/NotificationJobExecutedProvider.cs @@ -1,6 +1,7 @@ using JetBrains.Annotations; using LINGYUN.Abp.BackgroundTasks.Activities; using LINGYUN.Abp.BackgroundTasks.Localization; +using LINGYUN.Abp.BackgroundTasks.Notifications.Templates; using LINGYUN.Abp.Notifications; using Microsoft.Extensions.Localization; using System; @@ -16,10 +17,13 @@ namespace LINGYUN.Abp.BackgroundTasks.Notifications; public abstract class NotificationJobExecutedProvider : JobExecutedProvider, ITransientDependency { + public abstract string DefaultNotificationName { get; } + public readonly static IList Paramters = new List { new JobActionParamter(PropertyPushProvider, L("DisplayName:PushProvider"), L("Description:PushProvider")), new JobActionParamter(PropertyUseTemplate, L("DisplayName:Template"), L("Description:Template")), + new JobActionParamter(PropertyNotificationName, L("DisplayName:NotificationName"), L("Description:NotificationName")), new JobActionParamter(PropertyContent, L("DisplayName:Content"), L("Description:Content")), new JobActionParamter(PropertyCulture, L("DisplayName:Culture"), L("Description:Culture")), }; @@ -33,6 +37,10 @@ public abstract class NotificationJobExecutedProvider : JobExecutedProvider, ITr /// public const string PropertyUseTemplate = "use-template"; /// + /// 使用自定义通知 + /// + public const string PropertyNotificationName = "notification-name"; + /// /// 通知内容, 不使用模板时必须 /// public const string PropertyContent = "content"; @@ -66,7 +74,9 @@ public abstract class NotificationJobExecutedProvider : JobExecutedProvider, ITr var useProvider = context.Action.Paramters.GetOrDefault(PropertyPushProvider)?.ToString() ?? ""; var content = context.Action.Paramters.GetOrDefault(PropertyContent)?.ToString() ?? ""; var templateName = context.Action.Paramters.GetOrDefault(PropertyUseTemplate)?.ToString() - ?? BackgroundTasksNotificationNames.JobExecuteSucceeded; + ?? BackgroundTasksNotificationTemplates.JobExecutedNotification; + var notificationName = context.Action.Paramters.GetOrDefault(PropertyUseTemplate)?.ToString() + ?? DefaultNotificationName; if (content.IsNullOrWhiteSpace() && !templateName.IsNullOrWhiteSpace()) { @@ -97,14 +107,14 @@ public abstract class NotificationJobExecutedProvider : JobExecutedProvider, ITr formUser: "BackgroundTasks Engine"); await NotificationSender.SendNofiterAsync( - BackgroundTasksNotificationNames.JobExecuteSucceeded, + notificationName, notificationData, tenantId: CurrentTenant.Id, severity: severity, useProviders: useProvider.Split(';')); } - protected string GetTitleColor(NotificationSeverity severity = NotificationSeverity.Info) + private static string GetTitleColor(NotificationSeverity severity = NotificationSeverity.Info) { return severity switch {