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 af4ecfb26..e24b3f5d3 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 @@ -9,7 +9,7 @@ "Notifications:JobExecuteCompleted": "作业完成通知", "Notifications:JobExecuteCompletedDesc": "后台作业执行完成后通知推送.", "DisplayName:PushProvider": "推送程序", - "Description:PushProvider": "如果指定推送程序,应用将选择它进行消息推送,可选列表:SignalR(实时通知)、Sms(短信通知)、Emailing(邮件通知)、WeChat.MiniProgram(微信小程序)、WxPusher(WxPusher微信推送服务)、PushPlus(PushPlus多平台推送服务)", + "Description:PushProvider": "如果指定推送程序,应用将选择它进行消息推送,多个提供者用;分隔,可选列表:SignalR(实时通知)、Sms(短信通知)、Emailing(邮件通知)、WeChat.MiniProgram(微信小程序)、WxPusher(WxPusher微信推送服务)、PushPlus(PushPlus多平台推送服务)", "DisplayName:Template": "模板名称", "Description:Template": "如果指定模板名称,将发送格式化模板消息.", "DisplayName:Context": "上下文参数", 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 10828aa5f..a7edfb8b1 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 @@ -63,6 +63,7 @@ public abstract class NotificationJobExecutedProvider : JobExecutedProvider, ITr [NotNull] string title, NotificationSeverity severity = NotificationSeverity.Info) { + 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; @@ -72,6 +73,7 @@ public abstract class NotificationJobExecutedProvider : JobExecutedProvider, ITr var errorMessage = context.Event.EventData.Exception?.GetBaseException().Message; var model = new { + Color = GetTitleColor(severity), Error = context.Event.EventData.Exception != null, Errormessage = errorMessage, Title = title, @@ -98,7 +100,21 @@ public abstract class NotificationJobExecutedProvider : JobExecutedProvider, ITr BackgroundTasksNotificationNames.JobExecuteSucceeded, notificationData, tenantId: CurrentTenant.Id, - severity: severity); + severity: severity, + useProviders: useProvider.Split(';')); + } + + protected string GetTitleColor(NotificationSeverity severity = NotificationSeverity.Info) + { + return severity switch + { + NotificationSeverity.Success => "#3CB371", + NotificationSeverity.Warn => "#FF4500", + NotificationSeverity.Error => "red", + NotificationSeverity.Info => "#708090", + NotificationSeverity.Fatal => "red", + _ => "#708090" + }; } private static ILocalizableString L(string name) diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Templates/BackgroundTasksNotificationTemplateDefinitionProvider.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Templates/BackgroundTasksNotificationTemplateDefinitionProvider.cs new file mode 100644 index 000000000..9c6e69b95 --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Templates/BackgroundTasksNotificationTemplateDefinitionProvider.cs @@ -0,0 +1,34 @@ +using LINGYUN.Abp.BackgroundTasks.Localization; +using System; +using System.Collections.Generic; +using System.Text; +using Volo.Abp.Localization; +using Volo.Abp.TextTemplating; + +namespace LINGYUN.Abp.BackgroundTasks.Notifications.Templates; +public class BackgroundTasksNotificationTemplateDefinitionProvider : TemplateDefinitionProvider +{ + public override void Define(ITemplateDefinitionContext context) + { + context.Add(GetTemplateDefinitions()); + } + + private static TemplateDefinition[] GetTemplateDefinitions() + { + return new[] + { + new TemplateDefinition( + BackgroundTasksNotificationTemplates.JobExecutedNotification, + displayName: L("TextTemplate:JobExecutedNotification"), + localizationResource: typeof(BackgroundTasksResource) + ).WithVirtualFilePath( + "/LINGYUN/Abp/BackgroundTasks/Notifications/Templates/JobExecutedNotification.tpl", + isInlineLocalized: true) + }; + } + + private static ILocalizableString L(string name) + { + return LocalizableString.Create(name); + } +} diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Templates/BackgroundTasksNotificationTemplates.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Templates/BackgroundTasksNotificationTemplates.cs new file mode 100644 index 000000000..263c4eadf --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Templates/BackgroundTasksNotificationTemplates.cs @@ -0,0 +1,6 @@ +namespace LINGYUN.Abp.BackgroundTasks.Notifications.Templates; + +public static class BackgroundTasksNotificationTemplates +{ + public const string JobExecutedNotification = "Abp.BackgroundTasks.JobExecutedNotification"; +} diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Templates/JobExecutedNotification.tpl b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Templates/JobExecutedNotification.tpl new file mode 100644 index 000000000..691703efd --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Templates/JobExecutedNotification.tpl @@ -0,0 +1,14 @@ +### {{ model.title }} +--- +{{ if model.tenantname }} +* **{{ L "TenantName"}}**: {{ model.tenantname }} +{{ end }} +* **{{ L "JobGroup"}}**: {{ model.group }} +* **{{ L "JobName"}}**: {{ model.name }} +* **{{ L "JobId"}}**: {{ model.id }} +* **{{ L "JobType"}}**: {{ model.type }} +* **{{ L "TriggerTime"}}**: {{ model.triggertime }} +--- +{{ if model.error }} +{{ model.errormessage }} +{{ end }} \ No newline at end of file