Browse Source

optimize background task notification.

pull/668/head
cKey 3 years ago
parent
commit
ae9d2516fe
  1. 2
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources/zh-Hans.json
  2. 18
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/NotificationJobExecutedProvider.cs
  3. 34
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Templates/BackgroundTasksNotificationTemplateDefinitionProvider.cs
  4. 6
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Templates/BackgroundTasksNotificationTemplates.cs
  5. 14
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Templates/JobExecutedNotification.tpl

2
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": "上下文参数",

18
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)

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

6
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";
}

14
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Templates/JobExecutedNotification.tpl

@ -0,0 +1,14 @@
### <font color="{{ model.color }}" size=3>{{ model.title }}</font>
---
{{ 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"}}**: <font color="#1E90FF ">{{ model.triggertime }}</font>
---
{{ if model.error }}
{{ model.errormessage }}
{{ end }}
Loading…
Cancel
Save