diff --git a/aspnet-core/LINGYUN.MicroService.TaskManagement.sln b/aspnet-core/LINGYUN.MicroService.TaskManagement.sln index 1218fcaf6..c135c6bdf 100644 --- a/aspnet-core/LINGYUN.MicroService.TaskManagement.sln +++ b/aspnet-core/LINGYUN.MicroService.TaskManagement.sln @@ -52,7 +52,21 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BackgroundTasks EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "extend-jobs", "extend-jobs", "{A9536BD2-2573-44CA-B033-DC16B7E345E5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Notifications.Jobs", "modules\common\LINGYUN.Abp.Notifications.Jobs\LINGYUN.Abp.Notifications.Jobs.csproj", "{17D7ED0F-E789-4637-9B06-57DF693C6E1E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Notifications.Jobs", "modules\common\LINGYUN.Abp.Notifications.Jobs\LINGYUN.Abp.Notifications.Jobs.csproj", "{17D7ED0F-E789-4637-9B06-57DF693C6E1E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.BackgroundTasks.Notifications", "modules\task-management\LINGYUN.Abp.BackgroundTasks.Notifications\LINGYUN.Abp.BackgroundTasks.Notifications.csproj", "{1978B64C-B2F5-4F68-9E5C-B45F948E7155}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "realtime", "realtime", "{18918B94-BB48-48F3-874D-B91B0252440A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.RealTime", "modules\common\LINGYUN.Abp.RealTime\LINGYUN.Abp.RealTime.csproj", "{23620224-93A1-4A88-93B7-23D37929FCF7}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Notifications", "modules\common\LINGYUN.Abp.Notifications\LINGYUN.Abp.Notifications.csproj", "{09F7171C-6DA1-4466-AB4A-DC92E93368EC}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dapr", "dapr", "{FA5E30C9-05E3-4E35-AEDD-7DC5534E3A01}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Dapr", "modules\dapr\LINGYUN.Abp.Dapr\LINGYUN.Abp.Dapr.csproj", "{2FA23894-E598-4896-A336-3E7C682699D9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Dapr.Client", "modules\dapr\LINGYUN.Abp.Dapr.Client\LINGYUN.Abp.Dapr.Client.csproj", "{194DAB61-BC3C-4003-BFF0-C87763E7B8B0}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -132,6 +146,26 @@ Global {17D7ED0F-E789-4637-9B06-57DF693C6E1E}.Debug|Any CPU.Build.0 = Debug|Any CPU {17D7ED0F-E789-4637-9B06-57DF693C6E1E}.Release|Any CPU.ActiveCfg = Release|Any CPU {17D7ED0F-E789-4637-9B06-57DF693C6E1E}.Release|Any CPU.Build.0 = Release|Any CPU + {1978B64C-B2F5-4F68-9E5C-B45F948E7155}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1978B64C-B2F5-4F68-9E5C-B45F948E7155}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1978B64C-B2F5-4F68-9E5C-B45F948E7155}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1978B64C-B2F5-4F68-9E5C-B45F948E7155}.Release|Any CPU.Build.0 = Release|Any CPU + {23620224-93A1-4A88-93B7-23D37929FCF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {23620224-93A1-4A88-93B7-23D37929FCF7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {23620224-93A1-4A88-93B7-23D37929FCF7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {23620224-93A1-4A88-93B7-23D37929FCF7}.Release|Any CPU.Build.0 = Release|Any CPU + {09F7171C-6DA1-4466-AB4A-DC92E93368EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {09F7171C-6DA1-4466-AB4A-DC92E93368EC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {09F7171C-6DA1-4466-AB4A-DC92E93368EC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {09F7171C-6DA1-4466-AB4A-DC92E93368EC}.Release|Any CPU.Build.0 = Release|Any CPU + {2FA23894-E598-4896-A336-3E7C682699D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2FA23894-E598-4896-A336-3E7C682699D9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2FA23894-E598-4896-A336-3E7C682699D9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2FA23894-E598-4896-A336-3E7C682699D9}.Release|Any CPU.Build.0 = Release|Any CPU + {194DAB61-BC3C-4003-BFF0-C87763E7B8B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {194DAB61-BC3C-4003-BFF0-C87763E7B8B0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {194DAB61-BC3C-4003-BFF0-C87763E7B8B0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {194DAB61-BC3C-4003-BFF0-C87763E7B8B0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -155,6 +189,11 @@ Global {A817B7B7-A225-404A-A301-B42D400DE4B7} = {C38EB7EF-BAE9-4129-862A-71C652B81775} {3D0A1901-36FB-4DA2-9F8D-05308598E98C} = {C38EB7EF-BAE9-4129-862A-71C652B81775} {17D7ED0F-E789-4637-9B06-57DF693C6E1E} = {A9536BD2-2573-44CA-B033-DC16B7E345E5} + {1978B64C-B2F5-4F68-9E5C-B45F948E7155} = {C38EB7EF-BAE9-4129-862A-71C652B81775} + {23620224-93A1-4A88-93B7-23D37929FCF7} = {18918B94-BB48-48F3-874D-B91B0252440A} + {09F7171C-6DA1-4466-AB4A-DC92E93368EC} = {18918B94-BB48-48F3-874D-B91B0252440A} + {2FA23894-E598-4896-A336-3E7C682699D9} = {FA5E30C9-05E3-4E35-AEDD-7DC5534E3A01} + {194DAB61-BC3C-4003-BFF0-C87763E7B8B0} = {FA5E30C9-05E3-4E35-AEDD-7DC5534E3A01} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E1FD1F4C-D344-408B-97CF-B6F1F6D7D293} diff --git a/aspnet-core/modules/cli/LINGYUN.Abp.Cli/LINGYUN.Abp.Cli.csproj b/aspnet-core/modules/cli/LINGYUN.Abp.Cli/LINGYUN.Abp.Cli.csproj index e9a34c828..e69fbe868 100644 --- a/aspnet-core/modules/cli/LINGYUN.Abp.Cli/LINGYUN.Abp.Cli.csproj +++ b/aspnet-core/modules/cli/LINGYUN.Abp.Cli/LINGYUN.Abp.Cli.csproj @@ -5,7 +5,7 @@ Exe net6.0 - 5.3.2 + 5.3.4 colin Use LINGYUN.MicroService.Templates command line true diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobActionType.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobActionType.cs index 1b4752f04..b9585ef12 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobActionType.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobActionType.cs @@ -4,4 +4,5 @@ public enum JobActionType { Failed = -1, Successed = 0, + Completed = 1, } diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/JobExecutedFailedProvider.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/JobExecutedFailedProvider.cs index 9db8784f6..9573be853 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/JobExecutedFailedProvider.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/JobExecutedFailedProvider.cs @@ -103,7 +103,7 @@ public class JobExecutedFailedProvider : JobExecutedProvider, ITransientDependen Type = context.Event.EventData.Args.GetOrDefault(nameof(JobInfo.Type)) ?? context.Event.EventData.Type.Name, Triggertime = context.Event.EventData.RunTime.ToString("yyyy-MM-dd HH:mm:ss"), Message = errorMessage, - Tenantname = context.Action.Paramters.GetOrDefault(nameof(IMultiTenant.TenantId)), + Tenantname = context.Event.EventData.Args.GetOrDefault(nameof(IMultiTenant.TenantId)), Footer = footer, }; diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/Localization/Resources/zh-Hans.json b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/Localization/Resources/zh-Hans.json index f3dd99963..96c0d8002 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/Localization/Resources/zh-Hans.json +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/Localization/Resources/zh-Hans.json @@ -6,17 +6,17 @@ "DisplayName:To": "收件方", "Description:To": "demo@example.com, 多个接收者以逗号分隔.", "DisplayName:Subject": "邮件标题", - "Description:Subject": "发送邮件的标题", + "Description:Subject": "发送邮件的标题.", "DisplayName:From": "发送方", - "Description:From": "邮件发送方名称", + "Description:From": "邮件发送方名称.", "DisplayName:Body": "内容", "Description:Body": "发送的文本内容.", "DisplayName:Template": "模板名称", - "Description:Template": "如需指定模板内容则指定.", + "Description:Template": "如果指定模板名称,将发送格式化模板消息.", "DisplayName:Context": "上下文参数", - "Description:Context": "格式化模板内容时指定.", + "Description:Context": "格式化模板内容时指定参数.", "DisplayName:Culture": "文化名称", - "Description:Culture": "需要本地化邮件内容指定", + "Description:Culture": "需要本地化内容指定.", "TenantName": "租户名称", "JobGroup": "作业分组", "JobName": "作业名称", diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/README.md b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/README.md index 3cd15a8ea..ff46ee2e0 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/README.md +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/README.md @@ -14,14 +14,14 @@ public class YouProjectModule : AbpModule } ``` -## 先决条件 +## Action参数 ** 在定义作业时在参数中指定如下参数,在作业执行失败时将发送通知 -* exception.to 必须, 接收者邮件地址 -* exception.from 可选, 邮件抬头发送者名称 -* exception.body 可选, 邮件内容(未指定模板名称则为必须参数) -* exception.subject 可选, 邮件标题 -* exception.template 可选, 邮件模板 -* exception.context 可选, 使用模板时的上下文参数 -* exception.culture 可选, 使用模板时的模板区域性 +* to 必须, 接收者邮件地址 +* from 可选, 邮件抬头发送者名称 +* body 可选, 邮件内容(未指定模板名称则为必须参数) +* subject 可选, 邮件标题 +* template 可选, 邮件模板 +* context 可选, 使用模板时的上下文参数 +* culture 可选, 使用模板时的模板区域性 diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/FodyWeavers.xml b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/FodyWeavers.xml new file mode 100644 index 000000000..1715698cc --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/FodyWeavers.xsd b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/FodyWeavers.xsd new file mode 100644 index 000000000..11da52550 --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN.Abp.BackgroundTasks.Notifications.csproj b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN.Abp.BackgroundTasks.Notifications.csproj new file mode 100644 index 000000000..e5c8d893e --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN.Abp.BackgroundTasks.Notifications.csproj @@ -0,0 +1,32 @@ + + + + + + + netstandard2.0 + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/AbpBackgroundTasksNotificationsModule.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/AbpBackgroundTasksNotificationsModule.cs new file mode 100644 index 000000000..7c2bb61fd --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/AbpBackgroundTasksNotificationsModule.cs @@ -0,0 +1,29 @@ +using LINGYUN.Abp.BackgroundTasks.Activities; +using LINGYUN.Abp.BackgroundTasks.Localization; +using LINGYUN.Abp.Notifications; +using Volo.Abp.Localization; +using Volo.Abp.Modularity; +using Volo.Abp.VirtualFileSystem; + +namespace LINGYUN.Abp.BackgroundTasks.Notifications; + +[DependsOn( + typeof(AbpBackgroundTasksActivitiesModule), + typeof(AbpNotificationModule))] +public class AbpBackgroundTasksNotificationsModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + options.FileSets.AddEmbedded(); + }); + + Configure(options => + { + options.Resources + .Get() + .AddVirtualJson("/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources"); + }); + } +} diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/BackgroundTasksNotificationDefinitionProvider.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/BackgroundTasksNotificationDefinitionProvider.cs new file mode 100644 index 000000000..2308946e3 --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/BackgroundTasksNotificationDefinitionProvider.cs @@ -0,0 +1,51 @@ +using LINGYUN.Abp.BackgroundTasks.Localization; +using LINGYUN.Abp.Notifications; +using Volo.Abp.Localization; + +namespace LINGYUN.Abp.BackgroundTasks.Notifications; + +public class BackgroundTasksNotificationDefinitionProvider : NotificationDefinitionProvider +{ + public override void Define(INotificationDefinitionContext context) + { + var backgroundTaskGroup = context.AddGroup( + BackgroundTasksNotificationNames.GroupName, + L("Notifications:BackgroundTasks")); + + backgroundTaskGroup.AddNotification( + BackgroundTasksNotificationNames.JobExecuteSucceeded, + L("Notifications:JobExecuteSucceeded"), + L("Notifications:JobExecuteSucceededDesc"), + notificationType: NotificationType.Application, + lifetime: NotificationLifetime.Persistent, + allowSubscriptionToClients: true) + .WithProviders( + NotificationProviderNames.SignalR, + NotificationProviderNames.Emailing); + backgroundTaskGroup.AddNotification( + BackgroundTasksNotificationNames.JobExecuteFailed, + L("Notifications:JobExecuteFailed"), + L("Notifications:JobExecuteFailedDesc"), + notificationType: NotificationType.Application, + lifetime: NotificationLifetime.Persistent, + allowSubscriptionToClients: true) + .WithProviders( + NotificationProviderNames.SignalR, + NotificationProviderNames.Emailing); + backgroundTaskGroup.AddNotification( + BackgroundTasksNotificationNames.JobExecuteCompleted, + L("Notifications:JobExecuteCompleted"), + L("Notifications:JobExecuteCompletedDesc"), + notificationType: NotificationType.Application, + lifetime: NotificationLifetime.Persistent, + allowSubscriptionToClients: true) + .WithProviders( + NotificationProviderNames.SignalR, + NotificationProviderNames.Emailing); + } + + protected LocalizableString L(string name) + { + return LocalizableString.Create(name); + } +} diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/BackgroundTasksNotificationNames.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/BackgroundTasksNotificationNames.cs new file mode 100644 index 000000000..4ac1009d2 --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/BackgroundTasksNotificationNames.cs @@ -0,0 +1,18 @@ +namespace LINGYUN.Abp.BackgroundTasks.Notifications; + +public static class BackgroundTasksNotificationNames +{ + public const string GroupName = "Abp.Notifications.BackgroundTasks"; + /// + /// 作业执行成功 + /// + public const string JobExecuteSucceeded = GroupName + ".ExecuteSucceeded"; + /// + /// 作业执行失败 + /// + public const string JobExecuteFailed = GroupName + ".ExecuteFailed"; + /// + /// 作业执行完毕 + /// + public const string JobExecuteCompleted = GroupName + ".ExecuteCompleted"; +} 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 new file mode 100644 index 000000000..18777d119 --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecuteCompletedNotificationProvider.cs @@ -0,0 +1,31 @@ +using JetBrains.Annotations; +using LINGYUN.Abp.BackgroundTasks.Activities; +using LINGYUN.Abp.BackgroundTasks.Localization; +using LINGYUN.Abp.Notifications; +using Microsoft.Extensions.Localization; +using System.Threading.Tasks; +using Volo.Abp.MultiTenancy; +using Volo.Abp.TextTemplating; + +namespace LINGYUN.Abp.BackgroundTasks.Notifications; + +public class JobExecuteCompletedNotificationProvider : NotificationJobExecutedProvider +{ + public const string Name = "JobExecutedCompletedNofiter"; + + public JobExecuteCompletedNotificationProvider( + ICurrentTenant currentTenant, + INotificationSender notificationSender, + ITemplateRenderer templateRenderer, + IStringLocalizer stringLocalizer) + : base(currentTenant, notificationSender, templateRenderer, stringLocalizer) + { + } + + public async override Task NotifyComplateAsync([NotNull] JobActionExecuteContext context) + { + var title = StringLocalizer["JobExecutedCompleted"].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 new file mode 100644 index 000000000..ad707865e --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecuteFailedNotificationProvider.cs @@ -0,0 +1,31 @@ +using JetBrains.Annotations; +using LINGYUN.Abp.BackgroundTasks.Activities; +using LINGYUN.Abp.BackgroundTasks.Localization; +using LINGYUN.Abp.Notifications; +using Microsoft.Extensions.Localization; +using System.Threading.Tasks; +using Volo.Abp.MultiTenancy; +using Volo.Abp.TextTemplating; + +namespace LINGYUN.Abp.BackgroundTasks.Notifications; + +public class JobExecuteFailedNotificationProvider : NotificationJobExecutedProvider +{ + public const string Name = "JobExecutedFailedNofiter"; + + public JobExecuteFailedNotificationProvider( + ICurrentTenant currentTenant, + INotificationSender notificationSender, + ITemplateRenderer templateRenderer, + IStringLocalizer stringLocalizer) + : base(currentTenant, notificationSender, templateRenderer, stringLocalizer) + { + } + + public async override Task NotifyErrorAsync([NotNull] JobActionExecuteContext context) + { + var title = StringLocalizer["JobExecutedFailed"].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 new file mode 100644 index 000000000..fa6e334a6 --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecutedSuccessedNotificationProvider.cs @@ -0,0 +1,31 @@ +using JetBrains.Annotations; +using LINGYUN.Abp.BackgroundTasks.Activities; +using LINGYUN.Abp.BackgroundTasks.Localization; +using LINGYUN.Abp.Notifications; +using Microsoft.Extensions.Localization; +using System.Threading.Tasks; +using Volo.Abp.MultiTenancy; +using Volo.Abp.TextTemplating; + +namespace LINGYUN.Abp.BackgroundTasks.Notifications; + +public class JobExecutedSuccessedNotificationProvider : NotificationJobExecutedProvider +{ + public const string Name = "JobExecutedSuccessedNofiter"; + + public JobExecutedSuccessedNotificationProvider( + ICurrentTenant currentTenant, + INotificationSender notificationSender, + ITemplateRenderer templateRenderer, + IStringLocalizer stringLocalizer) + : base(currentTenant, notificationSender, templateRenderer, stringLocalizer) + { + } + + public async override Task NotifySuccessAsync([NotNull] JobActionExecuteContext context) + { + var title = StringLocalizer["JobExecutedSucceeded"].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 new file mode 100644 index 000000000..2039ad2e3 --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources/en.json @@ -0,0 +1,22 @@ +{ + "culture": "en", + "texts": { + "Notifications:BackgroundTasks": "Background job Notification", + "Notifications:JobExecuteSucceeded": "Job Success Notification", + "Notifications:JobExecuteSucceededDesc": "After the background job is successfully executed, the notification is pushed.", + "Notifications:JobExecuteFailed": "Job Failure Notification", + "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: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", + "Description:Template": "If the template content needs to be specified.", + "DisplayName:Context": "Context", + "Description:Context": "Specified when formatting template content.", + "DisplayName:Content": "Content", + "Description:Content": "If you specify the content, a plain text message is sent.", + "DisplayName:Culture": "Culture", + "Description:Culture": "Need to localize the message content specification" + } +} \ No newline at end of file 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 new file mode 100644 index 000000000..af4ecfb26 --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources/zh-Hans.json @@ -0,0 +1,22 @@ +{ + "culture": "zh-Hans", + "texts": { + "Notifications:BackgroundTasks": "后台作业通知", + "Notifications:JobExecuteSucceeded": "作业成功通知", + "Notifications:JobExecuteSucceededDesc": "后台作业执行成功后通知推送.", + "Notifications:JobExecuteFailed": "作业失败通知", + "Notifications:JobExecuteFailedDesc": "后台作业执行失败后通知推送.", + "Notifications:JobExecuteCompleted": "作业完成通知", + "Notifications:JobExecuteCompletedDesc": "后台作业执行完成后通知推送.", + "DisplayName:PushProvider": "推送程序", + "Description:PushProvider": "如果指定推送程序,应用将选择它进行消息推送,可选列表:SignalR(实时通知)、Sms(短信通知)、Emailing(邮件通知)、WeChat.MiniProgram(微信小程序)、WxPusher(WxPusher微信推送服务)、PushPlus(PushPlus多平台推送服务)", + "DisplayName:Template": "模板名称", + "Description:Template": "如果指定模板名称,将发送格式化模板消息.", + "DisplayName:Context": "上下文参数", + "Description:Context": "格式化模板内容时指定参数.", + "DisplayName:Content": "内容", + "Description:Content": "如果指定内容,将发送普通文本消息.", + "DisplayName:Culture": "文化名称", + "Description:Culture": "需要本地化内容指定." + } +} \ No newline at end of file diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/NotificationJobActionDefinitionProvider.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/NotificationJobActionDefinitionProvider.cs new file mode 100644 index 000000000..2ca59adde --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/NotificationJobActionDefinitionProvider.cs @@ -0,0 +1,41 @@ +using LINGYUN.Abp.BackgroundTasks.Activities; +using LINGYUN.Abp.BackgroundTasks.Localization; +using Volo.Abp.Localization; + +namespace LINGYUN.Abp.BackgroundTasks.Notifications; + +public class NotificationJobActionDefinitionProvider : JobActionDefinitionProvider +{ + public override void Define(IJobActionDefinitionContext context) + { + context.Add( + new JobActionDefinition( + JobExecutedSuccessedNotificationProvider.Name, + JobActionType.Successed, + L("Notifications:JobExecuteSucceeded"), + NotificationJobExecutedProvider.Paramters, + L("Notifications:JobExecuteSucceededDesc")) + .WithProvider()); + context.Add( + new JobActionDefinition( + JobExecuteFailedNotificationProvider.Name, + JobActionType.Failed, + L("Notifications:JobExecuteFailed"), + NotificationJobExecutedProvider.Paramters, + L("Notifications:JobExecuteFailedDesc")) + .WithProvider()); + context.Add( + new JobActionDefinition( + JobExecuteCompletedNotificationProvider.Name, + JobActionType.Completed, + L("Notifications:JobExecuteCompleted"), + NotificationJobExecutedProvider.Paramters, + L("Notifications:JobExecuteCompletedDesc")) + .WithProvider()); + } + + 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/NotificationJobExecutedProvider.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/NotificationJobExecutedProvider.cs new file mode 100644 index 000000000..10828aa5f --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/NotificationJobExecutedProvider.cs @@ -0,0 +1,108 @@ +using JetBrains.Annotations; +using LINGYUN.Abp.BackgroundTasks.Activities; +using LINGYUN.Abp.BackgroundTasks.Localization; +using LINGYUN.Abp.Notifications; +using Microsoft.Extensions.Localization; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Localization; +using Volo.Abp.MultiTenancy; +using Volo.Abp.TextTemplating; + +namespace LINGYUN.Abp.BackgroundTasks.Notifications; + +public abstract class NotificationJobExecutedProvider : JobExecutedProvider, ITransientDependency +{ + 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(PropertyContent, L("DisplayName:Content"), L("Description:Content")), + new JobActionParamter(PropertyCulture, L("DisplayName:Culture"), L("Description:Culture")), + }; + + /// + /// 指定发送工具 + /// + public const string PropertyPushProvider = "push-provider"; + /// + /// 使用通知模板 + /// + public const string PropertyUseTemplate = "use-template"; + /// + /// 通知内容, 不使用模板时必须 + /// + public const string PropertyContent = "content"; + /// + /// 可选, 模板消息中的区域性 + /// + public const string PropertyCulture = "culture"; + + protected ICurrentTenant CurrentTenant { get; } + protected INotificationSender NotificationSender { get; } + protected ITemplateRenderer TemplateRenderer { get; } + protected IStringLocalizer StringLocalizer { get; } + + protected NotificationJobExecutedProvider( + ICurrentTenant currentTenant, + INotificationSender notificationSender, + ITemplateRenderer templateRenderer, + IStringLocalizer stringLocalizer) + { + CurrentTenant = currentTenant; + NotificationSender = notificationSender; + TemplateRenderer = templateRenderer; + StringLocalizer = stringLocalizer; + } + + protected async virtual Task SendNofiterAsync( + [NotNull] JobActionExecuteContext context, + [NotNull] string title, + NotificationSeverity severity = NotificationSeverity.Info) + { + var content = context.Action.Paramters.GetOrDefault(PropertyContent)?.ToString() ?? ""; + var templateName = context.Action.Paramters.GetOrDefault(PropertyUseTemplate)?.ToString() + ?? BackgroundTasksNotificationNames.JobExecuteSucceeded; + + if (content.IsNullOrWhiteSpace() && !templateName.IsNullOrWhiteSpace()) + { + var errorMessage = context.Event.EventData.Exception?.GetBaseException().Message; + var model = new + { + Error = context.Event.EventData.Exception != null, + Errormessage = errorMessage, + Title = title, + Id = context.Event.EventData.Key, + Group = context.Event.EventData.Args.GetOrDefault(nameof(JobInfo.Group)) ?? context.Event.EventData.Group, + Name = context.Event.EventData.Args.GetOrDefault(nameof(JobInfo.Name)) ?? context.Event.EventData.Name, + Type = context.Event.EventData.Args.GetOrDefault(nameof(JobInfo.Type)) ?? context.Event.EventData.Type.Name, + Triggertime = context.Event.EventData.RunTime.ToString("yyyy-MM-dd HH:mm:ss"), + Tenantname = context.Event.EventData.Args.GetOrDefault(nameof(IMultiTenant.TenantId)), + }; + var culture = context.Action.Paramters.GetOrDefault(PropertyCulture)?.ToString() ?? CultureInfo.CurrentCulture.Name; + + content = await TemplateRenderer.RenderAsync(templateName, model, culture); + } + + var notificationData = new NotificationData(); + notificationData.WriteStandardData( + title: title, + message: content, + createTime: context.Event.EventData.RunTime, + formUser: "BackgroundTasks Engine"); + + await NotificationSender.SendNofiterAsync( + BackgroundTasksNotificationNames.JobExecuteSucceeded, + notificationData, + tenantId: CurrentTenant.Id, + severity: severity); + } + + private static ILocalizableString L(string name) + { + return LocalizableString.Create(name); + } +} diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/README.md b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/README.md new file mode 100644 index 000000000..90709262f --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/README.md @@ -0,0 +1,24 @@ +# LINGYUN.Abp.BackgroundTasks.Notifications + +后台作业执行后通知事件 + +## 配置使用 + +模块按需引用 + +```csharp +[DependsOn(typeof(AbpBackgroundTasksNotificationsModule))] +public class YouProjectModule : AbpModule +{ + // other +} +``` + +## Action参数 + +** 通知内容格式化参数,在作业后将发送实时通知 + +* push-provider 可选, 用户指定消息推送提供程序; +* use-template 可选, 用于格式化通知内容的模板名称 +* content 可选, 通知内容(未指定模板名称则为必须参数) +* culture 可选, 使用模板时的模板区域性 diff --git a/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/LY.MicroService.TaskManagement.HttpApi.Host.csproj b/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/LY.MicroService.TaskManagement.HttpApi.Host.csproj index b5f017181..e7ffe83e0 100644 --- a/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/LY.MicroService.TaskManagement.HttpApi.Host.csproj +++ b/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/LY.MicroService.TaskManagement.HttpApi.Host.csproj @@ -61,6 +61,7 @@ + diff --git a/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/TaskManagementHttpApiHostModule.cs b/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/TaskManagementHttpApiHostModule.cs index 5a6985c58..c3a245843 100644 --- a/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/TaskManagementHttpApiHostModule.cs +++ b/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/TaskManagementHttpApiHostModule.cs @@ -5,6 +5,7 @@ using LINGYUN.Abp.Authorization.OrganizationUnits; using LINGYUN.Abp.BackgroundTasks.DistributedLocking; using LINGYUN.Abp.BackgroundTasks.ExceptionHandling; using LINGYUN.Abp.BackgroundTasks.Jobs; +using LINGYUN.Abp.BackgroundTasks.Notifications; using LINGYUN.Abp.BackgroundTasks.Quartz; using LINGYUN.Abp.Data.DbMigrator; using LINGYUN.Abp.EventBus.CAP; @@ -55,6 +56,7 @@ namespace LY.MicroService.TaskManagement; typeof(AbpBackgroundTasksQuartzModule), typeof(AbpBackgroundTasksDistributedLockingModule), typeof(AbpBackgroundTasksExceptionHandlingModule), + typeof(AbpBackgroundTasksNotificationsModule), typeof(TaskManagementApplicationModule), typeof(TaskManagementHttpApiModule), typeof(TaskManagementEntityFrameworkCoreModule),