@ -1,6 +1,7 @@
using JetBrains.Annotations ;
using JetBrains.Annotations ;
using LINGYUN.Abp.BackgroundTasks.Activities ;
using LINGYUN.Abp.BackgroundTasks.Activities ;
using LINGYUN.Abp.BackgroundTasks.Localization ;
using LINGYUN.Abp.BackgroundTasks.Localization ;
using LINGYUN.Abp.BackgroundTasks.Notifications.Templates ;
using LINGYUN.Abp.Notifications ;
using LINGYUN.Abp.Notifications ;
using Microsoft.Extensions.Localization ;
using Microsoft.Extensions.Localization ;
using System ;
using System ;
@ -16,10 +17,13 @@ namespace LINGYUN.Abp.BackgroundTasks.Notifications;
public abstract class NotificationJobExecutedProvider : JobExecutedProvider , ITransientDependency
public abstract class NotificationJobExecutedProvider : JobExecutedProvider , ITransientDependency
{
{
public abstract string DefaultNotificationName { get ; }
public readonly static IList < JobActionParamter > Paramters = new List < JobActionParamter >
public readonly static IList < JobActionParamter > Paramters = new List < JobActionParamter >
{
{
new JobActionParamter ( PropertyPushProvider , L ( "DisplayName:PushProvider" ) , L ( "Description:PushProvider" ) ) ,
new JobActionParamter ( PropertyPushProvider , L ( "DisplayName:PushProvider" ) , L ( "Description:PushProvider" ) ) ,
new JobActionParamter ( PropertyUseTemplate , L ( "DisplayName:Template" ) , L ( "Description:Template" ) ) ,
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 ( PropertyContent , L ( "DisplayName:Content" ) , L ( "Description:Content" ) ) ,
new JobActionParamter ( PropertyCulture , L ( "DisplayName:Culture" ) , L ( "Description:Culture" ) ) ,
new JobActionParamter ( PropertyCulture , L ( "DisplayName:Culture" ) , L ( "Description:Culture" ) ) ,
} ;
} ;
@ -33,6 +37,10 @@ public abstract class NotificationJobExecutedProvider : JobExecutedProvider, ITr
/// </summary>
/// </summary>
public const string PropertyUseTemplate = "use-template" ;
public const string PropertyUseTemplate = "use-template" ;
/// <summary>
/// <summary>
/// 使用自定义通知
/// </summary>
public const string PropertyNotificationName = "notification-name" ;
/// <summary>
/// 通知内容, 不使用模板时必须
/// 通知内容, 不使用模板时必须
/// </summary>
/// </summary>
public const string PropertyContent = "content" ;
public const string PropertyContent = "content" ;
@ -66,7 +74,9 @@ public abstract class NotificationJobExecutedProvider : JobExecutedProvider, ITr
var useProvider = context . Action . Paramters . GetOrDefault ( PropertyPushProvider ) ? . ToString ( ) ? ? "" ;
var useProvider = context . Action . Paramters . GetOrDefault ( PropertyPushProvider ) ? . ToString ( ) ? ? "" ;
var content = context . Action . Paramters . GetOrDefault ( PropertyContent ) ? . ToString ( ) ? ? "" ;
var content = context . Action . Paramters . GetOrDefault ( PropertyContent ) ? . ToString ( ) ? ? "" ;
var templateName = context . Action . Paramters . GetOrDefault ( PropertyUseTemplate ) ? . 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 ( ) )
if ( content . IsNullOrWhiteSpace ( ) & & ! templateName . IsNullOrWhiteSpace ( ) )
{
{
@ -97,14 +107,14 @@ public abstract class NotificationJobExecutedProvider : JobExecutedProvider, ITr
formUser : "BackgroundTasks Engine" ) ;
formUser : "BackgroundTasks Engine" ) ;
await NotificationSender . SendNofiterAsync (
await NotificationSender . SendNofiterAsync (
Backgrou ndTasksN otificationNames . JobExecuteSucceeded ,
notificationName ,
notificationData ,
notificationData ,
tenantId : CurrentTenant . Id ,
tenantId : CurrentTenant . Id ,
severity : severity ,
severity : severity ,
useProviders : useProvider . Split ( ';' ) ) ;
useProviders : useProvider . Split ( ';' ) ) ;
}
}
protected string GetTitleColor ( NotificationSeverity severity = NotificationSeverity . Info )
private static string GetTitleColor ( NotificationSeverity severity = NotificationSeverity . Info )
{
{
return severity switch
return severity switch
{
{