From 8cd3dbc754dd08614ad8537a03760712f8ad33d0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 23 Oct 2022 14:11:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E6=80=BB=E7=BA=BF=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../QuartzImplement/CustomerJob.cs | 6 +- .../Common.Caching/Common.Caching.csproj | 12 + .../Common.Caching/IDistributedCache.cs | 340 ++++++++++++++++++ .../UnitOfWorkApiInterceptor.cs | 8 +- ...tEventBus.cs => DefaultEventBusManager.cs} | 8 +- .../DefaultEventBusModule.cs | 6 +- ...kaEventBus.cs => IKafkaEventBusManager.cs} | 2 +- ...fkaEventBus.cs => KafkaEventBusManager.cs} | 16 +- .../KafkaEventBusModule.cs | 8 +- ...mainEventBusService.cs => BaseEventBus.cs} | 10 +- .../Common.EventBus/CommonEventBusConfig.cs | 10 +- .../Common.EventBus/CommonEventBusModule.cs | 42 ++- .../Common.EventBus/DomainEventBusManager.cs | 6 +- .../Common.EventBus/EventBusMiddleware.cs | 2 +- .../Commons/Common.EventBus/EventBusModule.cs | 41 --- .../Commons/Common.EventBus/IEventBus.cs | 7 +- .../Common.EventBus/IEventBusManager.cs | 15 + .../Clients/WebApiClient.cs | 1 + .../Common.MicroService/Registers/Consul.cs | 4 +- .../UnitOfWork4EF.cs | 3 +- .../DynamicFormAppModule.cs | 2 +- .../TaskStateChangeEventHandler.cs | 2 +- .../Workflows/WorkflowAdapter.cs | 7 + .../appsettings.Development.json | 2 +- .../OrganizationAppModule.cs | 2 +- .../Organization.Core/Users/UserManager.cs | 4 +- .../appsettings.Development.json | 2 +- WorkFlowCore/WorkFlowCore.sln | 7 + .../AutoHandleStepsEventHandler.cs | 29 ++ .../WorkFlowCoreAppModule.cs | 4 +- .../WorkFlowCores/WorkFlowAppService.cs | 2 +- .../Workflow/WorkFlowCore.Host/Startup.cs | 2 +- .../appsettings.Development.json | 2 +- .../EventData/AutoHandleStepsEventData.cs | 16 + .../Users/SyncUserBackgroundWorker.cs | 2 +- .../WorkFlowCore/Users/UserInterface.cs | 1 + .../WorkFlowCore/WorkTasks/WorkTaskManager.cs | 82 +++-- .../WorkFlowCore/Workflows/WorkflowManager.cs | 8 +- .../views/workflows/formInstance/viewForm.vue | 2 +- .../workflows/myFormInstance/editForm.vue | 3 +- .../workflows/myFormInstance/viewForm.vue | 2 +- docker-compose-environment-dev.yaml | 1 - 42 files changed, 569 insertions(+), 162 deletions(-) create mode 100644 WorkFlowCore/Commons/Common.Caching/Common.Caching.csproj create mode 100644 WorkFlowCore/Commons/Common.Caching/IDistributedCache.cs rename WorkFlowCore/Commons/Common.EventBus.Default/{DefaultEventBus.cs => DefaultEventBusManager.cs} (97%) rename WorkFlowCore/Commons/Common.EventBus.Kafka/{IKafkaEventBus.cs => IKafkaEventBusManager.cs} (66%) rename WorkFlowCore/Commons/Common.EventBus.Kafka/{KafkaEventBus.cs => KafkaEventBusManager.cs} (93%) rename WorkFlowCore/Commons/Common.EventBus/{DomainEventBusService.cs => BaseEventBus.cs} (86%) delete mode 100644 WorkFlowCore/Commons/Common.EventBus/EventBusModule.cs create mode 100644 WorkFlowCore/Commons/Common.EventBus/IEventBusManager.cs create mode 100644 WorkFlowCore/Workflow/WorkFlowCore.AppService/EventHandlers/AutoHandleStepsEventHandler.cs create mode 100644 WorkFlowCore/Workflow/WorkFlowCore/EventData/AutoHandleStepsEventData.cs diff --git a/WorkFlowCore/Commons/Common.BackgroundWorker/QuartzImplement/CustomerJob.cs b/WorkFlowCore/Commons/Common.BackgroundWorker/QuartzImplement/CustomerJob.cs index 61ee086..3951e42 100644 --- a/WorkFlowCore/Commons/Common.BackgroundWorker/QuartzImplement/CustomerJob.cs +++ b/WorkFlowCore/Commons/Common.BackgroundWorker/QuartzImplement/CustomerJob.cs @@ -20,7 +20,7 @@ namespace Common.BackgroundWorker.QuartzImplement private readonly DistributiveLock redisClient; private readonly IJob job; private readonly IUnitOfWork unitOfWork; - private readonly DomainEventBusService? domainEventBusService; + private readonly IEventBus eventBus; private readonly IServiceProvider serviceProvider; public CustomerJob(IJob job, IServiceProvider serviceProvider) @@ -29,7 +29,7 @@ namespace Common.BackgroundWorker.QuartzImplement this.job = job; this.redisClient = serviceProvider.GetService(); this.unitOfWork = serviceProvider.GetService(); - this.domainEventBusService = serviceProvider.GetService(); + this.eventBus = serviceProvider.GetService(); } public async Task Execute(IJobExecutionContext context) @@ -41,7 +41,7 @@ namespace Common.BackgroundWorker.QuartzImplement try { await job.Execute(context); - if (unitOfWork==null||unitOfWork.Commit()) domainEventBusService?.Trigger(); + if (unitOfWork==null||unitOfWork.Commit()) eventBus?.Trigger(); } catch (Exception ex) { diff --git a/WorkFlowCore/Commons/Common.Caching/Common.Caching.csproj b/WorkFlowCore/Commons/Common.Caching/Common.Caching.csproj new file mode 100644 index 0000000..8b960c9 --- /dev/null +++ b/WorkFlowCore/Commons/Common.Caching/Common.Caching.csproj @@ -0,0 +1,12 @@ + + + + netcoreapp3.1 + + + + + + + + diff --git a/WorkFlowCore/Commons/Common.Caching/IDistributedCache.cs b/WorkFlowCore/Commons/Common.Caching/IDistributedCache.cs new file mode 100644 index 0000000..be5c899 --- /dev/null +++ b/WorkFlowCore/Commons/Common.Caching/IDistributedCache.cs @@ -0,0 +1,340 @@ +using System; +using JetBrains.Annotations; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Collections.Generic; +using Microsoft.Extensions.Caching.Distributed; + +namespace Common.Caching +{ + //这个接口借鉴 abp + + /// + /// Represents a distributed cache of type. + /// + /// The type of cache item being cached. + public interface IDistributedCache : IDistributedCache + where TCacheItem : class + { + } + + /// + /// Represents a distributed cache of type. + /// Uses a generic cache key type of type. + /// + /// The type of cache item being cached. + /// The type of cache key being used. + public interface IDistributedCache + where TCacheItem : class + { + /// + /// Gets a cache item with the given key. If no cache item is found for the given key then returns null. + /// + /// The key of cached item to be retrieved from the cache. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. + /// The cache item, or null. + TCacheItem Get( + TCacheKey key, + bool? hideErrors = null, + bool considerUow = false + ); + + /// + /// Gets multiple cache items with the given keys. + /// + /// The returned list contains exactly the same count of items specified in the given keys. + /// An item in the return list can not be null, but an item in the list has null value + /// if the related key not found in the cache. + /// + /// The keys of cached items to be retrieved from the cache. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. + /// List of cache items. + KeyValuePair[] GetMany( + IEnumerable keys, + bool? hideErrors = null, + bool considerUow = false + ); + + /// + /// Gets multiple cache items with the given keys. + /// + /// The returned list contains exactly the same count of items specified in the given keys. + /// An item in the return list can not be null, but an item in the list has null value + /// if the related key not found in the cache. + /// + /// + /// The keys of cached items to be retrieved from the cache. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. + /// /// The for the task. + /// List of cache items. + Task[]> GetManyAsync( + IEnumerable keys, + bool? hideErrors = null, + bool considerUow = false, + CancellationToken token = default + ); + + /// + /// Gets a cache item with the given key. If no cache item is found for the given key then returns null. + /// + /// The key of cached item to be retrieved from the cache. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. + /// The for the task. + /// The cache item, or null. + Task GetAsync( + [NotNull] TCacheKey key, + bool? hideErrors = null, + bool considerUow = false, + CancellationToken token = default + ); + + /// + /// Gets or Adds a cache item with the given key. If no cache item is found for the given key then adds a cache item + /// provided by delegate and returns the provided cache item. + /// + /// The key of cached item to be retrieved from the cache. + /// The factory delegate is used to provide the cache item when no cache item is found for the given . + /// The cache options for the factory delegate. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. + /// The cache item. + TCacheItem GetOrAdd( + TCacheKey key, + Func factory, + Func optionsFactory = null, + bool? hideErrors = null, + bool considerUow = false + ); + + /// + /// Gets or Adds a cache item with the given key. If no cache item is found for the given key then adds a cache item + /// provided by delegate and returns the provided cache item. + /// + /// The key of cached item to be retrieved from the cache. + /// The factory delegate is used to provide the cache item when no cache item is found for the given . + /// The cache options for the factory delegate. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. + /// The for the task. + /// The cache item. + Task GetOrAddAsync( + [NotNull] TCacheKey key, + Func> factory, + Func optionsFactory = null, + bool? hideErrors = null, + bool considerUow = false, + CancellationToken token = default + ); + + /// + /// Gets or Adds multiple cache items with the given keys. If any cache items not found for the given keys then adds cache items + /// provided by delegate and returns the provided cache items. + /// + /// The keys of cached items to be retrieved from the cache. + /// The factory delegate is used to provide the cache items when no cache items are found for the given . + /// The cache options for the factory delegate. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. + /// The cache items. + KeyValuePair[] GetOrAddMany( + IEnumerable keys, + Func, List>> factory, + Func optionsFactory = null, + bool? hideErrors = null, + bool considerUow = false + ); + + /// + /// Gets or Adds multiple cache items with the given keys. If any cache items not found for the given keys then adds cache items + /// provided by delegate and returns the provided cache items. + /// + /// The keys of cached items to be retrieved from the cache. + /// The factory delegate is used to provide the cache items when no cache items are found for the given . + /// The cache options for the factory delegate. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. + /// The for the task. + /// The cache items. + Task[]> GetOrAddManyAsync( + IEnumerable keys, + Func, Task>>> factory, + Func optionsFactory = null, + bool? hideErrors = null, + bool considerUow = false, + CancellationToken token = default + ); + + /// + /// Sets the cache item value for the provided key. + /// + /// The key of cached item to be retrieved from the cache. + /// The cache item value to set in the cache. + /// The cache options for the value. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. + void Set( + TCacheKey key, + TCacheItem value, + DistributedCacheEntryOptions options = null, + bool? hideErrors = null, + bool considerUow = false + ); + + /// + /// Sets the cache item value for the provided key. + /// + /// The key of cached item to be retrieved from the cache. + /// The cache item value to set in the cache. + /// The cache options for the value. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. + /// The for the task. + /// The indicating that the operation is asynchronous. + Task SetAsync( + [NotNull] TCacheKey key, + [NotNull] TCacheItem value, + [CanBeNull] DistributedCacheEntryOptions options = null, + bool? hideErrors = null, + bool considerUow = false, + CancellationToken token = default + ); + + /// + /// Sets multiple cache items. + /// Based on the implementation, this can be more efficient than setting multiple items individually. + /// + /// Items to set on the cache + /// The cache options for the value. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. + void SetMany( + IEnumerable> items, + DistributedCacheEntryOptions options = null, + bool? hideErrors = null, + bool considerUow = false + ); + + /// + /// Sets multiple cache items. + /// Based on the implementation, this can be more efficient than setting multiple items individually. + /// + /// Items to set on the cache + /// The cache options for the value. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. + /// The for the task. + /// The indicating that the operation is asynchronous. + Task SetManyAsync( + IEnumerable> items, + DistributedCacheEntryOptions options = null, + bool? hideErrors = null, + bool considerUow = false, + CancellationToken token = default + ); + + /// + /// Refreshes the cache value of the given key, and resets its sliding expiration timeout. + /// + /// The key of cached item to be retrieved from the cache. + /// Indicates to throw or hide the exceptions for the distributed cache. + void Refresh( + TCacheKey key, + bool? hideErrors = null + ); + + /// + /// Refreshes the cache value of the given key, and resets its sliding expiration timeout. + /// + /// The key of cached item to be retrieved from the cache. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// The for the task. + /// The indicating that the operation is asynchronous. + Task RefreshAsync( + TCacheKey key, + bool? hideErrors = null, + CancellationToken token = default + ); + + /// + /// Refreshes the cache value of the given keys, and resets their sliding expiration timeout. + /// Based on the implementation, this can be more efficient than setting multiple items individually. + /// + /// The keys of cached items to be retrieved from the cache. + /// Indicates to throw or hide the exceptions for the distributed cache. + void RefreshMany( + IEnumerable keys, + bool? hideErrors = null); + + /// + /// Refreshes the cache value of the given keys, and resets their sliding expiration timeout. + /// Based on the implementation, this can be more efficient than setting multiple items individually. + /// + /// The keys of cached items to be retrieved from the cache. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// The for the task. + /// The indicating that the operation is asynchronous. + Task RefreshManyAsync( + IEnumerable keys, + bool? hideErrors = null, + CancellationToken token = default); + + /// + /// Removes the cache item for given key from cache. + /// + /// The key of cached item to be retrieved from the cache. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. + void Remove( + TCacheKey key, + bool? hideErrors = null, + bool considerUow = false + ); + + /// + /// Removes the cache item for given key from cache. + /// + /// The key of cached item to be retrieved from the cache. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. + /// The for the task. + /// The indicating that the operation is asynchronous. + Task RemoveAsync( + TCacheKey key, + bool? hideErrors = null, + bool considerUow = false, + CancellationToken token = default + ); + + /// + /// Removes the cache items for given keys from cache. + /// + /// The keys of cached items to be retrieved from the cache. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. + void RemoveMany( + IEnumerable keys, + bool? hideErrors = null, + bool considerUow = false + ); + + /// + /// Removes the cache items for given keys from cache. + /// + /// The keys of cached items to be retrieved from the cache. + /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. + /// The for the task. + /// The indicating that the operation is asynchronous. + Task RemoveManyAsync( + IEnumerable keys, + bool? hideErrors = null, + bool considerUow = false, + CancellationToken token = default + ); + } +} diff --git a/WorkFlowCore/Commons/Common.DynamicApi/DynamicApiInterceptors/UnitOfWorkApiInterceptor.cs b/WorkFlowCore/Commons/Common.DynamicApi/DynamicApiInterceptors/UnitOfWorkApiInterceptor.cs index 27677cf..336493a 100644 --- a/WorkFlowCore/Commons/Common.DynamicApi/DynamicApiInterceptors/UnitOfWorkApiInterceptor.cs +++ b/WorkFlowCore/Commons/Common.DynamicApi/DynamicApiInterceptors/UnitOfWorkApiInterceptor.cs @@ -10,12 +10,12 @@ namespace Common.DynamicApi.DynamicApiInterceptors public class UnitOfWorkApiInterceptor : IDynamicApiInterceptor { private readonly IUnitOfWork unitOfWork; - private readonly DomainEventBusService domainEventBusService; + private readonly IEventBus eventBus; - public UnitOfWorkApiInterceptor(IUnitOfWork unitOfWork, DomainEventBusService domainEventBusService) + public UnitOfWorkApiInterceptor(IUnitOfWork unitOfWork, IEventBus eventBus) { this.unitOfWork = unitOfWork; - this.domainEventBusService = domainEventBusService; + this.eventBus = eventBus; } public void BeforeExecute() @@ -26,7 +26,7 @@ namespace Common.DynamicApi.DynamicApiInterceptors public void Executed() { - //if (unitOfWork.Commit()) domainEventBusService.Trigger(); + //if (unitOfWork.Commit()) eventBus.Trigger(); } } } diff --git a/WorkFlowCore/Commons/Common.EventBus.Default/DefaultEventBus.cs b/WorkFlowCore/Commons/Common.EventBus.Default/DefaultEventBusManager.cs similarity index 97% rename from WorkFlowCore/Commons/Common.EventBus.Default/DefaultEventBus.cs rename to WorkFlowCore/Commons/Common.EventBus.Default/DefaultEventBusManager.cs index 4db67dd..ed113ea 100644 --- a/WorkFlowCore/Commons/Common.EventBus.Default/DefaultEventBus.cs +++ b/WorkFlowCore/Commons/Common.EventBus.Default/DefaultEventBusManager.cs @@ -10,7 +10,7 @@ using System.Text; namespace Common.EventBus.Default { - public class DefaultEventBus : IEventBus + public class DefaultEventBusManager : IEventBusManager { private class ConsumerInfo { @@ -40,13 +40,13 @@ namespace Common.EventBus.Default private IServiceProvider serviceProvider; private static object objLock = new object(); - public DefaultEventBus(IServiceProvider serviceProvider) + public DefaultEventBusManager(IServiceProvider serviceProvider) { this.serviceProvider = serviceProvider; } private static Dictionary> eventSubscribes; - static DefaultEventBus() + static DefaultEventBusManager() { eventSubscribes = new Dictionary>(); } @@ -174,7 +174,7 @@ namespace Common.EventBus.Default //统一工作单元提交,无需事件单独处理 var unitOfWork = scope.ServiceProvider.GetService(); - var domainEventBusService = scope.ServiceProvider.GetService(); + var domainEventBusService = scope.ServiceProvider.GetService(); if (unitOfWork==null||unitOfWork.Commit()) domainEventBusService?.Trigger(); } diff --git a/WorkFlowCore/Commons/Common.EventBus.Default/DefaultEventBusModule.cs b/WorkFlowCore/Commons/Common.EventBus.Default/DefaultEventBusModule.cs index 9dbe9b7..4183cd9 100644 --- a/WorkFlowCore/Commons/Common.EventBus.Default/DefaultEventBusModule.cs +++ b/WorkFlowCore/Commons/Common.EventBus.Default/DefaultEventBusModule.cs @@ -11,11 +11,11 @@ namespace Common.EventBus.Default { public static IServiceCollection AddDefautEventBus(this IServiceCollection services, params Assembly[] assemblies) { - services.AddSingleton(typeof(IEventBus), typeof(DefaultEventBus)); - services.AddSingleton(typeof(DefaultEventBus)); + services.AddSingleton(typeof(IEventBusManager), typeof(DefaultEventBusManager)); + services.AddSingleton(typeof(DefaultEventBusManager),provider=>provider.GetService()); foreach (var assembly in assemblies) { - DefaultEventBus.RegistSubscriptions(assembly); + DefaultEventBusManager.RegistSubscriptions(assembly); } services.AddEventBus(); return services; diff --git a/WorkFlowCore/Commons/Common.EventBus.Kafka/IKafkaEventBus.cs b/WorkFlowCore/Commons/Common.EventBus.Kafka/IKafkaEventBusManager.cs similarity index 66% rename from WorkFlowCore/Commons/Common.EventBus.Kafka/IKafkaEventBus.cs rename to WorkFlowCore/Commons/Common.EventBus.Kafka/IKafkaEventBusManager.cs index dbd4c6c..861f09b 100644 --- a/WorkFlowCore/Commons/Common.EventBus.Kafka/IKafkaEventBus.cs +++ b/WorkFlowCore/Commons/Common.EventBus.Kafka/IKafkaEventBusManager.cs @@ -4,7 +4,7 @@ using System.Text; namespace Common.EventBus.Kafka { - public interface IKafkaEventBus: IEventBus + public interface IKafkaEventBusManager: IEventBusManager { } } diff --git a/WorkFlowCore/Commons/Common.EventBus.Kafka/KafkaEventBus.cs b/WorkFlowCore/Commons/Common.EventBus.Kafka/KafkaEventBusManager.cs similarity index 93% rename from WorkFlowCore/Commons/Common.EventBus.Kafka/KafkaEventBus.cs rename to WorkFlowCore/Commons/Common.EventBus.Kafka/KafkaEventBusManager.cs index a44db00..a068550 100644 --- a/WorkFlowCore/Commons/Common.EventBus.Kafka/KafkaEventBus.cs +++ b/WorkFlowCore/Commons/Common.EventBus.Kafka/KafkaEventBusManager.cs @@ -13,14 +13,14 @@ using System.Threading.Tasks; namespace Common.EventBus.Kafka { - public class KafkaEventBus : IKafkaEventBus + public class KafkaEventBusManager : IKafkaEventBusManager { private IServiceProvider serviceProvider; private readonly KafkaEventConfig eventConfig; - private readonly ILogger logger; + private readonly ILogger logger; private static object objLock = new object(); - public KafkaEventBus(IServiceProvider serviceProvider, KafkaEventConfig eventConfig,ILogger logger) + public KafkaEventBusManager(IServiceProvider serviceProvider, KafkaEventConfig eventConfig,ILogger logger) { this.serviceProvider = serviceProvider; this.eventConfig = eventConfig; @@ -30,7 +30,7 @@ namespace Common.EventBus.Kafka private static Dictionary> eventSubscribes; private static Dictionary eventSubscribeCancellationTokenSources; - static KafkaEventBus() + static KafkaEventBusManager() { eventSubscribes = new Dictionary>(); eventSubscribeCancellationTokenSources = new Dictionary(); @@ -59,8 +59,9 @@ namespace Common.EventBus.Kafka } var groupIdAttr = handlerType.GetCustomAttribute(); - if (groupIdAttr == null) return; - var groupId = string.IsNullOrEmpty(groupIdAttr.GroupId) ? handlerType.FullName : groupIdAttr.GroupId; + //去掉标记限制,统一使用分布式 + //if (groupIdAttr == null) return; + var groupId = string.IsNullOrEmpty(groupIdAttr?.GroupId) ? handlerType.FullName : groupIdAttr.GroupId; var conf = new ConsumerConfig { GroupId = groupId, @@ -94,6 +95,7 @@ namespace Common.EventBus.Kafka { //统一工作单元提交,无需事件单独处理 var unitOfWork = scope.ServiceProvider.GetService(); + unitOfWork.Enabled(); var handler = scope.ServiceProvider.GetService(handlerType); try { @@ -106,7 +108,7 @@ namespace Common.EventBus.Kafka unitOfWork.Rollback(); } - var domainEventBusService = scope.ServiceProvider.GetService(); + var domainEventBusService = scope.ServiceProvider.GetService(); if (unitOfWork == null || unitOfWork.HasCommitted()) domainEventBusService?.Trigger(); } diff --git a/WorkFlowCore/Commons/Common.EventBus.Kafka/KafkaEventBusModule.cs b/WorkFlowCore/Commons/Common.EventBus.Kafka/KafkaEventBusModule.cs index 431e5ef..9dd1e0d 100644 --- a/WorkFlowCore/Commons/Common.EventBus.Kafka/KafkaEventBusModule.cs +++ b/WorkFlowCore/Commons/Common.EventBus.Kafka/KafkaEventBusModule.cs @@ -11,9 +11,9 @@ namespace Common.EventBus.Kafka { public static IServiceCollection AddKafkaEventBus(this IServiceCollection services, Action options) { - services.AddSingleton(typeof(IKafkaEventBus), typeof(KafkaEventBus)); - services.AddSingleton(typeof(IEventBus), typeof(KafkaEventBus)); - services.AddSingleton(typeof(KafkaEventBus)); + services.AddSingleton(typeof(IKafkaEventBusManager), typeof(KafkaEventBusManager)); + services.AddSingleton(typeof(IEventBusManager), provider => provider.GetService()); + services.AddSingleton(typeof(KafkaEventBusManager), provider => provider.GetService()); var config = new KafkaEventConfig(); options?.Invoke(config); //注册配置到服务,以便注入 @@ -24,7 +24,7 @@ namespace Common.EventBus.Kafka public static IApplicationBuilder RunKafkaEventBus(this IApplicationBuilder app) { //注册kafka作为分布式事件 - var kafkaEventBus = app.ApplicationServices.GetService(); + var kafkaEventBus = app.ApplicationServices.GetService(); var config = app.ApplicationServices.GetService(); var configuration = app.ApplicationServices.GetService(); Console.WriteLine("servers:" + configuration["KafkaBootstrapServers"]); diff --git a/WorkFlowCore/Commons/Common.EventBus/DomainEventBusService.cs b/WorkFlowCore/Commons/Common.EventBus/BaseEventBus.cs similarity index 86% rename from WorkFlowCore/Commons/Common.EventBus/DomainEventBusService.cs rename to WorkFlowCore/Commons/Common.EventBus/BaseEventBus.cs index fcec271..ca5b2e7 100644 --- a/WorkFlowCore/Commons/Common.EventBus/DomainEventBusService.cs +++ b/WorkFlowCore/Commons/Common.EventBus/BaseEventBus.cs @@ -6,20 +6,20 @@ using System.Text; namespace Common.EventBus { - public class DomainEventBusService + public class BaseEventBus: IEventBus { private readonly IServiceProvider serviceProvider; private List baseEventDatas; private readonly IEventDataRepository eventDataRepository; - public DomainEventBusService(IServiceProvider serviceProvider) + public BaseEventBus(IServiceProvider serviceProvider) { this.serviceProvider = serviceProvider; baseEventDatas = new List(); this.eventDataRepository = serviceProvider.GetService(); } - public void Publish(TData data) where TData : BaseEventData + public virtual void Publish(TData data) where TData : BaseEventData { if (data == null) return; //保存到数据库 @@ -27,11 +27,11 @@ namespace Common.EventBus eventDataRepository.InsertAsync(EventData.CreateEventData(data)); baseEventDatas.Add(data); } - public void Trigger() + public virtual void Trigger() { if(baseEventDatas== null|| baseEventDatas.Count==0) return; - var services = serviceProvider.GetServices(); + var services = serviceProvider.GetServices(); foreach (var service in services) { try diff --git a/WorkFlowCore/Commons/Common.EventBus/CommonEventBusConfig.cs b/WorkFlowCore/Commons/Common.EventBus/CommonEventBusConfig.cs index ec76945..d9e2666 100644 --- a/WorkFlowCore/Commons/Common.EventBus/CommonEventBusConfig.cs +++ b/WorkFlowCore/Commons/Common.EventBus/CommonEventBusConfig.cs @@ -7,10 +7,10 @@ namespace Common.EventBus { public class CommonEventBusConfig { - internal Type EventDataRepositoryType; - public void ReEventDataRepository()where TEventDataRepository : IEventDataRepository - { - EventDataRepositoryType = typeof(IEventDataRepository); - } + //internal Type EventDataRepositoryType; + //public void ReEventDataRepository()where TEventDataRepository : IEventDataRepository + //{ + // EventDataRepositoryType = typeof(IEventDataRepository); + //} } } diff --git a/WorkFlowCore/Commons/Common.EventBus/CommonEventBusModule.cs b/WorkFlowCore/Commons/Common.EventBus/CommonEventBusModule.cs index 7fc358e..9474aa8 100644 --- a/WorkFlowCore/Commons/Common.EventBus/CommonEventBusModule.cs +++ b/WorkFlowCore/Commons/Common.EventBus/CommonEventBusModule.cs @@ -1,26 +1,42 @@ -using Common.EventBus.IRepositories; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; +using System.Reflection; using System.Text; namespace Common.EventBus { public static class CommonEventBusModule { - //public static IServiceCollection AddEventBus(this IServiceCollection services,Action options=null ) - //{ - // if(options==null)return services; + public static IServiceCollection AddEventBus(this IServiceCollection services) + { + services.AddSingleton(); + services.AddScoped(); - // var config = new CommonEventBusConfig(); - // options.Invoke(config); - // if(config.EventDataRepositoryType!=null) - // { - // services.AddScoped(typeof(IEventDataRepository), config.EventDataRepositoryType); - // } - // return services; - //} + return services; + } - + public static IApplicationBuilder RunEventBus(this IApplicationBuilder app) + { + //注册普通事件,该事件订阅在单应用有效无法分布式 + DomainEventBusManager.Init(app.ApplicationServices); + return app; + + } + /// + /// 在 UseUnitOfWork之前执行; + /// + /// + /// + public static IApplicationBuilder UseEventBus(this IApplicationBuilder app) + { + //注册普通事件,该事件订阅在单应用有效无法分布式 + DomainEventBusManager.Init(app.ApplicationServices); + app.UseMiddleware(); + return app; + + } } } diff --git a/WorkFlowCore/Commons/Common.EventBus/DomainEventBusManager.cs b/WorkFlowCore/Commons/Common.EventBus/DomainEventBusManager.cs index e4bc244..a9248e4 100644 --- a/WorkFlowCore/Commons/Common.EventBus/DomainEventBusManager.cs +++ b/WorkFlowCore/Commons/Common.EventBus/DomainEventBusManager.cs @@ -8,7 +8,7 @@ namespace Common.EventBus /// /// 全局静态事件帮助类,便于在其它非注入渠道发起事件 /// - internal class DomainEventBusManager + public class DomainEventBusManager { private static IServiceProvider serviceProvider; internal static void Init(IServiceProvider serviceProvider) @@ -16,9 +16,9 @@ namespace Common.EventBus DomainEventBusManager.serviceProvider = serviceProvider; } - public static DomainEventBusService EventBusInstance() + public static IEventBus EventBusInstance() { - return serviceProvider.CreateScope().ServiceProvider.GetService(); + return serviceProvider.CreateScope().ServiceProvider.GetService(); } } } diff --git a/WorkFlowCore/Commons/Common.EventBus/EventBusMiddleware.cs b/WorkFlowCore/Commons/Common.EventBus/EventBusMiddleware.cs index 60b52e0..a3e0560 100644 --- a/WorkFlowCore/Commons/Common.EventBus/EventBusMiddleware.cs +++ b/WorkFlowCore/Commons/Common.EventBus/EventBusMiddleware.cs @@ -16,7 +16,7 @@ namespace Common.EventBus this.next = next; } - public async Task Invoke(HttpContext context,IUnitOfWork unitOfWork, DomainEventBusService domainEventBusService) + public async Task Invoke(HttpContext context,IUnitOfWork unitOfWork, IEventBus domainEventBusService) { await next(context); if (unitOfWork.HasCommitted()) domainEventBusService.Trigger(); diff --git a/WorkFlowCore/Commons/Common.EventBus/EventBusModule.cs b/WorkFlowCore/Commons/Common.EventBus/EventBusModule.cs deleted file mode 100644 index bcff870..0000000 --- a/WorkFlowCore/Commons/Common.EventBus/EventBusModule.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Text; - -namespace Common.EventBus -{ - public static class EventBusModule - { - public static IServiceCollection AddEventBus(this IServiceCollection services) - { - services.AddSingleton(); - services.AddScoped(); - return services; - } - - public static IApplicationBuilder RunEventBus(this IApplicationBuilder app) - { - //注册普通事件,该事件订阅在单应用有效无法分布式 - DomainEventBusManager.Init(app.ApplicationServices); - return app; - - } - /// - /// 在 UseUnitOfWork之前执行; - /// - /// - /// - public static IApplicationBuilder UseEventBus(this IApplicationBuilder app) - { - //注册普通事件,该事件订阅在单应用有效无法分布式 - DomainEventBusManager.Init(app.ApplicationServices); - app.UseMiddleware(); - return app; - - } - } -} diff --git a/WorkFlowCore/Commons/Common.EventBus/IEventBus.cs b/WorkFlowCore/Commons/Common.EventBus/IEventBus.cs index 794e99c..b60b9e0 100644 --- a/WorkFlowCore/Commons/Common.EventBus/IEventBus.cs +++ b/WorkFlowCore/Commons/Common.EventBus/IEventBus.cs @@ -6,10 +6,7 @@ namespace Common.EventBus { public interface IEventBus { - void SubscribeEventHandler(Type eventDataType, Type handlerType); - void UnsubscribeEventHandler(Type eventDataType, Type handlerType); - void SubscribeEventHandler() where THandler : IEventHandler where TData : BaseEventData; - void UnsubscribeEventHandler() where THandler : IEventHandler where TData : BaseEventData; - void Trigger(TData data) where TData:new (); + void Publish(TData data) where TData : BaseEventData; + void Trigger(); } } diff --git a/WorkFlowCore/Commons/Common.EventBus/IEventBusManager.cs b/WorkFlowCore/Commons/Common.EventBus/IEventBusManager.cs new file mode 100644 index 0000000..25c6b53 --- /dev/null +++ b/WorkFlowCore/Commons/Common.EventBus/IEventBusManager.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Common.EventBus +{ + public interface IEventBusManager + { + void SubscribeEventHandler(Type eventDataType, Type handlerType); + void UnsubscribeEventHandler(Type eventDataType, Type handlerType); + void SubscribeEventHandler() where THandler : IEventHandler where TData : BaseEventData; + void UnsubscribeEventHandler() where THandler : IEventHandler where TData : BaseEventData; + void Trigger(TData data) where TData:new (); + } +} diff --git a/WorkFlowCore/Commons/Common.MicroService/Clients/WebApiClient.cs b/WorkFlowCore/Commons/Common.MicroService/Clients/WebApiClient.cs index ab1bad2..5b53275 100644 --- a/WorkFlowCore/Commons/Common.MicroService/Clients/WebApiClient.cs +++ b/WorkFlowCore/Commons/Common.MicroService/Clients/WebApiClient.cs @@ -41,6 +41,7 @@ namespace Common.MicroService.Clients clientHeaders.TryAddWithoutValidation(header.Key, new string[] { header.Value }); } } + httpClient.Timeout = TimeSpan.FromSeconds(12000); return httpClient; } diff --git a/WorkFlowCore/Commons/Common.MicroService/Registers/Consul.cs b/WorkFlowCore/Commons/Common.MicroService/Registers/Consul.cs index 5123d90..e0315aa 100644 --- a/WorkFlowCore/Commons/Common.MicroService/Registers/Consul.cs +++ b/WorkFlowCore/Commons/Common.MicroService/Registers/Consul.cs @@ -58,10 +58,10 @@ namespace Common.MicroService.Registers Port = int.Parse(port), Check = new AgentServiceCheck { - Interval = TimeSpan.FromSeconds(10), + Interval = TimeSpan.FromSeconds(5), HTTP = $"http://{ipAddress}:{port}/api/Health/", Timeout = TimeSpan.FromSeconds(5), - DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(30) + DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(10) } }; diff --git a/WorkFlowCore/Commons/Common.UnitOfWork4EntityFramework/UnitOfWork4EF.cs b/WorkFlowCore/Commons/Common.UnitOfWork4EntityFramework/UnitOfWork4EF.cs index 0ecada5..21f8436 100644 --- a/WorkFlowCore/Commons/Common.UnitOfWork4EntityFramework/UnitOfWork4EF.cs +++ b/WorkFlowCore/Commons/Common.UnitOfWork4EntityFramework/UnitOfWork4EF.cs @@ -97,7 +97,8 @@ namespace Common.UnitOfWork4EntityFramework public void Rollback() { //回滚 - dbContextTransaction.Rollback(); + if(isActive&&dbContextTransaction!=null) + dbContextTransaction.Rollback(); isActive = false; } } diff --git a/WorkFlowCore/DynamicForm/DynamicForm.AppService/DynamicFormAppModule.cs b/WorkFlowCore/DynamicForm/DynamicForm.AppService/DynamicFormAppModule.cs index 4751d0c..2cfcd0b 100644 --- a/WorkFlowCore/DynamicForm/DynamicForm.AppService/DynamicFormAppModule.cs +++ b/WorkFlowCore/DynamicForm/DynamicForm.AppService/DynamicFormAppModule.cs @@ -27,7 +27,7 @@ namespace DynamicForm.AppService services.AddMapster(Assembly.GetExecutingAssembly()); services.AddDynamicFormAppContracts(); services.AddDependencyServices(Assembly.GetExecutingAssembly()); - services.AddDefautEventBus(Assembly.GetExecutingAssembly(), typeof(DynamicFormCoreModule).Assembly); + ////services.AddDefautEventBus(Assembly.GetExecutingAssembly(), typeof(DynamicFormCoreModule).Assembly); services.AddKafkaEventBus(config => { config.Servers = serviceConfig.KafkaBootstrapServers; diff --git a/WorkFlowCore/DynamicForm/DynamicForm.AppService/EventHandlers/TaskStateChangeEventHandler.cs b/WorkFlowCore/DynamicForm/DynamicForm.AppService/EventHandlers/TaskStateChangeEventHandler.cs index 350affe..3567ff6 100644 --- a/WorkFlowCore/DynamicForm/DynamicForm.AppService/EventHandlers/TaskStateChangeEventHandler.cs +++ b/WorkFlowCore/DynamicForm/DynamicForm.AppService/EventHandlers/TaskStateChangeEventHandler.cs @@ -28,7 +28,7 @@ namespace DynamicForm.Core.EventHandlers { logger.LogInformation($"同步流程状态事件:{JsonConvert.SerializeObject(data)}"); - if (!typeof(FormInstance).FullName.Equals(data.WorkTask.EntityFullName)) return; + if (!typeof(FormInstance).FullName.Replace(".","_").Equals(data.WorkTask.EntityFullName)) return; formInstanceInterface.UpdateformInstance(Guid.Parse(data.WorkTask.EntityKeyValue), data.WorkTaskStatus).Wait(); } } diff --git a/WorkFlowCore/DynamicForm/DynamicForm.Core/Workflows/WorkflowAdapter.cs b/WorkFlowCore/DynamicForm/DynamicForm.Core/Workflows/WorkflowAdapter.cs index 29b305a..3990460 100644 --- a/WorkFlowCore/DynamicForm/DynamicForm.Core/Workflows/WorkflowAdapter.cs +++ b/WorkFlowCore/DynamicForm/DynamicForm.Core/Workflows/WorkflowAdapter.cs @@ -37,6 +37,13 @@ namespace DynamicForm.Core.Workflows if (result == null || !result.IsSucced) throw new Exception(result?.Msg ?? "创建工作流任务失败!"); + + var startResult = await webApiClient.PostAsync, object>("workflow/api/workflow/StartWorkTask", new + { + WorktaskId = result.Data.id.ToString(), + }, false); ; + + return true; } diff --git a/WorkFlowCore/DynamicForm/DynamicForm.Host/appsettings.Development.json b/WorkFlowCore/DynamicForm/DynamicForm.Host/appsettings.Development.json index 13d2933..2a1c588 100644 --- a/WorkFlowCore/DynamicForm/DynamicForm.Host/appsettings.Development.json +++ b/WorkFlowCore/DynamicForm/DynamicForm.Host/appsettings.Development.json @@ -22,7 +22,7 @@ "Port": "${port}|5200", "Name": "${servicename}|dynamicform" }, - "Gateway": "${Gateway}|http://localhost:7001/", + "Gateway": "${Gateway}|http://localhost:5400/", "Kafka": { "BootstrapServers": "${KafkaBootstrapServers}|kafka1:9092" //本地跑需在hosts 增加 127.0.0.1 映射到 kafka1 }, diff --git a/WorkFlowCore/UserOrganization/Organization.AppService/OrganizationAppModule.cs b/WorkFlowCore/UserOrganization/Organization.AppService/OrganizationAppModule.cs index 5a3a5b9..155d28e 100644 --- a/WorkFlowCore/UserOrganization/Organization.AppService/OrganizationAppModule.cs +++ b/WorkFlowCore/UserOrganization/Organization.AppService/OrganizationAppModule.cs @@ -27,7 +27,7 @@ namespace Organization.AppService services.AddOrganizationAppContracts(); services.AddDependencyServices(Assembly.GetExecutingAssembly()); - services.AddDefautEventBus(Assembly.GetExecutingAssembly(), typeof(OrganizationCoreModule).Assembly); + //services.AddDefautEventBus(Assembly.GetExecutingAssembly(), typeof(OrganizationCoreModule).Assembly); services.AddKafkaEventBus(config => { config.Servers = serviceConfig.KafkaBootstrapServers; diff --git a/WorkFlowCore/UserOrganization/Organization.Core/Users/UserManager.cs b/WorkFlowCore/UserOrganization/Organization.Core/Users/UserManager.cs index bffe709..b5b2c99 100644 --- a/WorkFlowCore/UserOrganization/Organization.Core/Users/UserManager.cs +++ b/WorkFlowCore/UserOrganization/Organization.Core/Users/UserManager.cs @@ -15,11 +15,11 @@ namespace Organization.Core.Users public class UserManager : IScopedService { private readonly IBasicRepository userRepository; - private readonly DomainEventBusService eventBus; + private readonly IEventBus eventBus; private readonly OrganizationInterface organizationInterface; private readonly RoleInterface roleInterface; - public UserManager(IBasicRepository userRepository, DomainEventBusService eventBus, OrganizationInterface organizationInterface, RoleInterface roleInterface) + public UserManager(IBasicRepository userRepository, IEventBus eventBus, OrganizationInterface organizationInterface, RoleInterface roleInterface) { this.userRepository = userRepository; this.eventBus = eventBus; diff --git a/WorkFlowCore/UserOrganization/Organization.Host/appsettings.Development.json b/WorkFlowCore/UserOrganization/Organization.Host/appsettings.Development.json index 6e3a5e6..6265bb7 100644 --- a/WorkFlowCore/UserOrganization/Organization.Host/appsettings.Development.json +++ b/WorkFlowCore/UserOrganization/Organization.Host/appsettings.Development.json @@ -22,7 +22,7 @@ "Port": "${port}|5100", "Name": "${servicename}|organisation" }, - "Gateway": "${Gateway}|http://localhost:7001/", + "Gateway": "${Gateway}|http://localhost:5400", "Kafka": { "BootstrapServers": "${KafkaBootstrapServers}|kafka1:9092" //本地跑需在hosts 增加 127.0.0.1 映射到 kafka1 }, diff --git a/WorkFlowCore/WorkFlowCore.sln b/WorkFlowCore/WorkFlowCore.sln index 9ae9ba6..0120be8 100644 --- a/WorkFlowCore/WorkFlowCore.sln +++ b/WorkFlowCore/WorkFlowCore.sln @@ -85,6 +85,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common.SimplePluginLoader", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.EventBus.Repository4EF", "Commons\Common.EventBus.Repository4EF\Common.EventBus.Repository4EF.csproj", "{519E4805-268B-409C-9167-45A5DF4B8F69}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Caching", "Commons\Common.Caching\Common.Caching.csproj", "{A556C938-F98C-4E93-AE37-159C5DFACC0D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -235,6 +237,10 @@ Global {519E4805-268B-409C-9167-45A5DF4B8F69}.Debug|Any CPU.Build.0 = Debug|Any CPU {519E4805-268B-409C-9167-45A5DF4B8F69}.Release|Any CPU.ActiveCfg = Release|Any CPU {519E4805-268B-409C-9167-45A5DF4B8F69}.Release|Any CPU.Build.0 = Release|Any CPU + {A556C938-F98C-4E93-AE37-159C5DFACC0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A556C938-F98C-4E93-AE37-159C5DFACC0D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A556C938-F98C-4E93-AE37-159C5DFACC0D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A556C938-F98C-4E93-AE37-159C5DFACC0D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -276,6 +282,7 @@ Global {3C37AF32-C83D-4C54-8F17-74DD0584BC50} = {3EF58BFB-DEAB-4607-9C83-3D0B0BF0CFFA} {038F8892-EDB7-4091-AC59-D21DC44033E0} = {3EF58BFB-DEAB-4607-9C83-3D0B0BF0CFFA} {519E4805-268B-409C-9167-45A5DF4B8F69} = {3EF58BFB-DEAB-4607-9C83-3D0B0BF0CFFA} + {A556C938-F98C-4E93-AE37-159C5DFACC0D} = {3EF58BFB-DEAB-4607-9C83-3D0B0BF0CFFA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2B47C6B7-D14F-4E7A-AC89-493A7F10350B} diff --git a/WorkFlowCore/Workflow/WorkFlowCore.AppService/EventHandlers/AutoHandleStepsEventHandler.cs b/WorkFlowCore/Workflow/WorkFlowCore.AppService/EventHandlers/AutoHandleStepsEventHandler.cs new file mode 100644 index 0000000..81e50d7 --- /dev/null +++ b/WorkFlowCore/Workflow/WorkFlowCore.AppService/EventHandlers/AutoHandleStepsEventHandler.cs @@ -0,0 +1,29 @@ +using Common.DependencyInjection; +using Common.EventBus; +using System; +using System.Collections.Generic; +using System.Text; +using WorkFlowCore.EventData; +using WorkFlowCore.WorkTasks; + +namespace WorkFlowCore.AppService.EventHandlers +{ + public class AutoHandleStepsEventHandler : IEventHandler, IScopedService + { + private readonly WorkTaskManager workTaskManager; + + public AutoHandleStepsEventHandler(WorkTaskManager workTaskManager) + { + this.workTaskManager = workTaskManager; + } + + public void Handle(AutoHandleStepsEventData data) + { + if (data == null || data.Steps == null) return; + foreach (var step in data.Steps) + { + workTaskManager.PassApprove(step.Id, data.Comment, string.Empty).Wait(); + } + } + } +} diff --git a/WorkFlowCore/Workflow/WorkFlowCore.AppService/WorkFlowCoreAppModule.cs b/WorkFlowCore/Workflow/WorkFlowCore.AppService/WorkFlowCoreAppModule.cs index f22afca..364b676 100644 --- a/WorkFlowCore/Workflow/WorkFlowCore.AppService/WorkFlowCoreAppModule.cs +++ b/WorkFlowCore/Workflow/WorkFlowCore.AppService/WorkFlowCoreAppModule.cs @@ -26,9 +26,7 @@ namespace WorkFlowCore.AppService services.AddDependencyServices(Assembly.GetExecutingAssembly()); services.AddWorkFlowCoreAppContracts(); - - - services.AddDefautEventBus(Assembly.GetExecutingAssembly(), typeof(WorkFlowCoreModule).Assembly); + //services.AddDefautEventBus(Assembly.GetExecutingAssembly(), typeof(WorkFlowCoreModule).Assembly); services.AddKafkaEventBus(config => { config.Servers = serviceConfig.KafkaBootstrapServers; diff --git a/WorkFlowCore/Workflow/WorkFlowCore.AppService/WorkFlowCores/WorkFlowAppService.cs b/WorkFlowCore/Workflow/WorkFlowCore.AppService/WorkFlowCores/WorkFlowAppService.cs index 443984b..6bfcb33 100644 --- a/WorkFlowCore/Workflow/WorkFlowCore.AppService/WorkFlowCores/WorkFlowAppService.cs +++ b/WorkFlowCore/Workflow/WorkFlowCore.AppService/WorkFlowCores/WorkFlowAppService.cs @@ -195,7 +195,7 @@ namespace WorkFlowCore.AppService.WorkFlows public async Task CreateAndStartWorkTask(CreateWorkTaskInput input) { var worktask = await workTaskManager.CreateWorkTask(input.WorkflowId, input.Name, input.FormData, input.EntityFullName, input.EntityKeyValue, input.CreatedUserId); - await workTaskManager.WorkTaskStart(worktask.Id); + //await workTaskManager.WorkTaskStart(worktask.Id); return worktask; } diff --git a/WorkFlowCore/Workflow/WorkFlowCore.Host/Startup.cs b/WorkFlowCore/Workflow/WorkFlowCore.Host/Startup.cs index 5e0a624..ebbf4e5 100644 --- a/WorkFlowCore/Workflow/WorkFlowCore.Host/Startup.cs +++ b/WorkFlowCore/Workflow/WorkFlowCore.Host/Startup.cs @@ -45,7 +45,7 @@ namespace WorkFlowCore.Host options.KafkaBootstrapServers = Configuration.GetValueFromManyChanels("Kafka:BootstrapServers"); }); - services.AddDynamicControllers(typeof(WorkFlowCoreModule).Assembly); + services.AddDynamicControllers(typeof(WorkFlowCoreAppModule).Assembly); services.AddWorkFlowCore(options => { options.MicroServiceGateway = Configuration.GetValueFromManyChanels("Gateway"); diff --git a/WorkFlowCore/Workflow/WorkFlowCore.Host/appsettings.Development.json b/WorkFlowCore/Workflow/WorkFlowCore.Host/appsettings.Development.json index 507d827..a08b61e 100644 --- a/WorkFlowCore/Workflow/WorkFlowCore.Host/appsettings.Development.json +++ b/WorkFlowCore/Workflow/WorkFlowCore.Host/appsettings.Development.json @@ -22,7 +22,7 @@ "Port": "${port}|5000", "Name": "${servicename}|workflow" }, - "Gateway": "${Gateway}|http://localhost:7001/", + "Gateway": "${Gateway}|http://localhost:5400/", "Kafka": { "BootstrapServers": "${KafkaBootstrapServers}|kafka1:9092" //本地跑需在hosts 增加 127.0.0.1 映射到 kafka1 } diff --git a/WorkFlowCore/Workflow/WorkFlowCore/EventData/AutoHandleStepsEventData.cs b/WorkFlowCore/Workflow/WorkFlowCore/EventData/AutoHandleStepsEventData.cs new file mode 100644 index 0000000..266b42d --- /dev/null +++ b/WorkFlowCore/Workflow/WorkFlowCore/EventData/AutoHandleStepsEventData.cs @@ -0,0 +1,16 @@ +using Common.EventBus; +using System; +using System.Collections.Generic; +using System.Text; + +namespace WorkFlowCore.EventData +{ + /// + /// 自动处理节点事件 + /// + public class AutoHandleStepsEventData : BaseEventData + { + public List Steps { get; set; } + public string Comment { get; set; } + } +} diff --git a/WorkFlowCore/Workflow/WorkFlowCore/Users/SyncUserBackgroundWorker.cs b/WorkFlowCore/Workflow/WorkFlowCore/Users/SyncUserBackgroundWorker.cs index fd39181..822a527 100644 --- a/WorkFlowCore/Workflow/WorkFlowCore/Users/SyncUserBackgroundWorker.cs +++ b/WorkFlowCore/Workflow/WorkFlowCore/Users/SyncUserBackgroundWorker.cs @@ -31,7 +31,7 @@ namespace WorkFlowCore.Users logger.LogInformation($"同步用户数据"); var users = await userAdapter.GetAllUserList(); //这里同步的数据可能会有点多,所以同步时,每一条数据直接 更新,userRepository操作的 autosave 设为 true - await userInterface.UpdateUser(users.ToArray()); + await userInterface.UpdateUser(users?.ToArray()); logger.LogInformation($"本次同步 {users?.Count ?? 0} 条数据"); } } diff --git a/WorkFlowCore/Workflow/WorkFlowCore/Users/UserInterface.cs b/WorkFlowCore/Workflow/WorkFlowCore/Users/UserInterface.cs index 9658d89..3f65719 100644 --- a/WorkFlowCore/Workflow/WorkFlowCore/Users/UserInterface.cs +++ b/WorkFlowCore/Workflow/WorkFlowCore/Users/UserInterface.cs @@ -18,6 +18,7 @@ namespace WorkFlowCore.Users public async Task UpdateUser(params User[] user) { + if (user == null) return; foreach (var data in user) { var newUserId = data.Id; diff --git a/WorkFlowCore/Workflow/WorkFlowCore/WorkTasks/WorkTaskManager.cs b/WorkFlowCore/Workflow/WorkFlowCore/WorkTasks/WorkTaskManager.cs index cce2bff..c76bdce 100644 --- a/WorkFlowCore/Workflow/WorkFlowCore/WorkTasks/WorkTaskManager.cs +++ b/WorkFlowCore/Workflow/WorkFlowCore/WorkTasks/WorkTaskManager.cs @@ -25,7 +25,7 @@ namespace WorkFlowCore.WorkTasks private readonly IWorkStepRepository workStepRepository; private readonly ConditionManager conditionManager; private readonly UserSelectorManager userSelectorManager; - private readonly DomainEventBusService eventManager; + private readonly IEventBus eventBus; private readonly WorkflowInterface workflowInterface; private readonly ILogger logger; @@ -35,7 +35,7 @@ namespace WorkFlowCore.WorkTasks , IWorkStepRepository workStepRepository , ConditionManager conditionManager , UserSelectorManager userSelectorManager - , DomainEventBusService eventManager + , IEventBus eventBus , WorkflowInterface workflowInterface , ILogger logger) { @@ -45,7 +45,7 @@ namespace WorkFlowCore.WorkTasks this.workStepRepository = workStepRepository; this.conditionManager = conditionManager; this.userSelectorManager = userSelectorManager; - this.eventManager = eventManager; + this.eventBus = eventBus; this.workflowInterface = workflowInterface; this.logger = logger; } @@ -65,11 +65,12 @@ namespace WorkFlowCore.WorkTasks /// public async Task CreateWorkTask(WorkflowId workflowId, string name, string formData, string entityFullName, string entityKeyValue, string createdUserId) { - - var worktaskInfo = await workTaskRepository.GetAsync(w => w.EntityFullName == entityFullName && w.EntityKeyValue == entityKeyValue && w.WorkflowId_Id == workflowId.Id && w.WorkflowId_VersionId == workflowId.VersionId); + + var worktaskInfo = await workTaskRepository.GetAsync(w => (w.EntityFullName == entityFullName) && w.EntityKeyValue == entityKeyValue && w.WorkflowId_Id == workflowId.Id && w.WorkflowId_VersionId == workflowId.VersionId); if (worktaskInfo == null) { + entityFullName = entityFullName.Replace(".", "_"); var worktask = new WorkTask(Guid.NewGuid(), workflowId, name, formData, entityFullName, entityKeyValue, createdUserId); worktaskInfo = worktask.ToWorkTaskInfo(); await workTaskRepository.InsertAsync(worktaskInfo); @@ -88,7 +89,7 @@ namespace WorkFlowCore.WorkTasks /// public async Task CreateSimulationWorkTask(WorkflowId workflowId, string name, string formData, string entityFullName, string entityKeyValue, string createdUserId) { - + entityFullName = entityFullName.Replace(".", "_"); var worktask = new WorkTask(Guid.NewGuid(), workflowId, name, formData, entityFullName, entityKeyValue, createdUserId); worktask.AsSimulation(); await workTaskRepository.InsertAsync(worktask.ToWorkTaskInfo()); @@ -273,19 +274,21 @@ namespace WorkFlowCore.WorkTasks //自动处理开始节点 - /* - * 这里单独开事务有两个考虑的地方: - * 1.就算这里没自动处理成功,变成人工审批处理也是不影响流程 - * 2.能力有限,默认实现的简易数据持久化仓储以及工作单元无法支持复杂的事务嵌套操作 - */ - var startSteps = new List(); - foreach (var step in steps) - { - var _steps = (await PassApprove(step.Id, "发起审批", string.Empty)).WorkSteps; - if (_steps != null) - startSteps.AddRange(_steps); - } - steps = startSteps; + ///* + // * 这里单独开事务有两个考虑的地方: + // * 1.就算这里没自动处理成功,变成人工审批处理也是不影响流程 + // * 2.能力有限,默认实现的简易数据持久化仓储以及工作单元无法支持复杂的事务嵌套操作 + // */ + //var startSteps = new List(); + //foreach (var step in steps) + //{ + // var _steps = (await PassApprove(step.Id, "发起审批", string.Empty)).WorkSteps; + // if (_steps != null) + // startSteps.AddRange(_steps); + //} + //steps = startSteps; + + eventBus.Publish(new AutoHandleStepsEventData() { Steps = steps, Comment = "发起审批" }); return steps; } @@ -401,18 +404,20 @@ namespace WorkFlowCore.WorkTasks if (nextNodes.Count == 1 && nextNodes[0].NodeType == WorkNodeType.End) { /* - * 这里单独开事务有两个考虑的地方: - * 1.就算这里没自动处理成功,变成人工审批处理也是不影响流程 - * 2.默认实现的简易数据持久化仓储以及工作单元无法支持复杂的事务嵌套操作 - */ - var startSteps = new List(); - foreach (var step in steps) - { - var _steps = (await PassApprove(step.Id, "审批结束", string.Empty)).WorkSteps; - if (_steps != null) - startSteps.AddRange(_steps); - } - steps = startSteps; + // * 这里单独开事务有两个考虑的地方: + // * 1.就算这里没自动处理成功,变成人工审批处理也是不影响流程 + // * 2.默认实现的简易数据持久化仓储以及工作单元无法支持复杂的事务嵌套操作 + // */ + //var startSteps = new List(); + //foreach (var step in steps) + //{ + // var _steps = (await PassApprove(step.Id, "审批结束", string.Empty)).WorkSteps; + // if (_steps != null) + // startSteps.AddRange(_steps); + //} + //steps = startSteps; + + eventBus.Publish(new AutoHandleStepsEventData() { Steps = steps, Comment = "审批结束" }); } @@ -576,7 +581,7 @@ namespace WorkFlowCore.WorkTasks { workTask.SetPending(); await workTaskRepository.UpdateAsync(workTask.ToWorkTaskInfo(workTaskInfo)); - eventManager.Publish(new TaskStateChangeEventData + eventBus.Publish(new TaskStateChangeEventData { WorkTask = workTask, WorkTaskStatus = workTask.WorkTaskStatus, @@ -599,7 +604,7 @@ namespace WorkFlowCore.WorkTasks { workTask.SetProcessing(); await workTaskRepository.UpdateAsync(workTask.ToWorkTaskInfo(workTaskInfo)); - eventManager.Publish(new TaskStateChangeEventData + eventBus.Publish(new TaskStateChangeEventData { WorkTask = workTask, WorkTaskStatus = workTask.WorkTaskStatus, @@ -622,13 +627,13 @@ namespace WorkFlowCore.WorkTasks workTask.SetProcessed(); await workTaskRepository.UpdateAsync(workTask.ToWorkTaskInfo(workTaskInfo)); - eventManager.Publish(new TaskFinishedEventData + eventBus.Publish(new TaskFinishedEventData { WorkTask = workTask }); - eventManager.Publish(new TaskStateChangeEventData + eventBus.Publish(new TaskStateChangeEventData { WorkTask = workTask, WorkTaskStatus = workTask.WorkTaskStatus, @@ -789,7 +794,7 @@ namespace WorkFlowCore.WorkTasks //TODO 发布开启消息 //TODO 考虑增加让步骤保存每次处理的表单信息 } - eventManager.Publish(new SendTaskEventData + eventBus.Publish(new SendTaskEventData { WorkTask = workTask, WorkSteps = workSteps @@ -814,7 +819,10 @@ namespace WorkFlowCore.WorkTasks /// public async Task> GetAllTaskStepsOfWorkTaskByEntityInfoAsync(string entityFullName, string entityKeyValue) { - var worktasks = await workTaskRepository.GetListAsync(t => t.EntityFullName == entityFullName && t.EntityKeyValue == entityKeyValue); + //TODO 修复 数据库 带 . 查询失败问题 + //临时修复查询问题 + var worktasks = await workTaskRepository.GetListAsync(t => t.EntityKeyValue == entityKeyValue); + worktasks = worktasks.Where(w => w.EntityFullName == entityFullName || w.EntityFullName == (entityFullName.Replace(".", "_"))).ToList(); return (await workStepRepository.GetListAsync(ws => worktasks.Select(w => w.Id).Contains(ws.WorkTaskId))).OrderByDescending(ws => ws.CreationTime).Select(s => s.ToWorkStep()).ToList(); } diff --git a/WorkFlowCore/Workflow/WorkFlowCore/Workflows/WorkflowManager.cs b/WorkFlowCore/Workflow/WorkFlowCore/Workflows/WorkflowManager.cs index f33336b..5e8505f 100644 --- a/WorkFlowCore/Workflow/WorkFlowCore/Workflows/WorkflowManager.cs +++ b/WorkFlowCore/Workflow/WorkFlowCore/Workflows/WorkflowManager.cs @@ -18,17 +18,17 @@ namespace WorkFlowCore.Workflows { private readonly IBasicRepository workflowRepository; private readonly IBasicRepository versionRepository; - private readonly DomainEventBusService eventManager; + private readonly IEventBus eventBus; private readonly WorkflowInterface workflowInterface; public WorkflowManager(IBasicRepository workflowRepository , IBasicRepository versionRepository - , DomainEventBusService eventManager + , IEventBus eventBus , WorkflowInterface workflowInterface) { this.workflowRepository = workflowRepository; this.versionRepository = versionRepository; - this.eventManager = eventManager; + this.eventBus = eventBus; this.workflowInterface = workflowInterface; } @@ -186,7 +186,7 @@ namespace WorkFlowCore.Workflows await versionRepository.UpdateAsync(version.ToWorkflowVersionInfo(versionInfo)); } //推送设计流程信息变更事件 - eventManager.Publish(new WorkflowVersionChangeEventData + eventBus.Publish(new WorkflowVersionChangeEventData { Workflow = workflow, WorkflowVersion = version, diff --git a/admin/vue-admin-template/src/views/workflows/formInstance/viewForm.vue b/admin/vue-admin-template/src/views/workflows/formInstance/viewForm.vue index 598e3fa..f9023cb 100644 --- a/admin/vue-admin-template/src/views/workflows/formInstance/viewForm.vue +++ b/admin/vue-admin-template/src/views/workflows/formInstance/viewForm.vue @@ -232,7 +232,7 @@ export default { getAllTaskStepsOfWorkTaskByEntityInfo() { this.$store .dispatch("workflow/getAllTaskStepsOfWorkTaskByEntityInfo", { - entityFullName: "DynamicForm.Core.Forms.FormInstance", + entityFullName: "DynamicForm.Core.FormInstance", entityKeyValue: this.form.id, }) .then((res) => { diff --git a/admin/vue-admin-template/src/views/workflows/myFormInstance/editForm.vue b/admin/vue-admin-template/src/views/workflows/myFormInstance/editForm.vue index 3b60eb4..f5a5b43 100644 --- a/admin/vue-admin-template/src/views/workflows/myFormInstance/editForm.vue +++ b/admin/vue-admin-template/src/views/workflows/myFormInstance/editForm.vue @@ -15,11 +15,10 @@ label-width="0px" class="demo-form" label-position="top" - size="mini" v-loading="loading" > - + diff --git a/admin/vue-admin-template/src/views/workflows/myFormInstance/viewForm.vue b/admin/vue-admin-template/src/views/workflows/myFormInstance/viewForm.vue index 598e3fa..f9023cb 100644 --- a/admin/vue-admin-template/src/views/workflows/myFormInstance/viewForm.vue +++ b/admin/vue-admin-template/src/views/workflows/myFormInstance/viewForm.vue @@ -232,7 +232,7 @@ export default { getAllTaskStepsOfWorkTaskByEntityInfo() { this.$store .dispatch("workflow/getAllTaskStepsOfWorkTaskByEntityInfo", { - entityFullName: "DynamicForm.Core.Forms.FormInstance", + entityFullName: "DynamicForm.Core.FormInstance", entityKeyValue: this.form.id, }) .then((res) => { diff --git a/docker-compose-environment-dev.yaml b/docker-compose-environment-dev.yaml index 996fb7f..229d989 100644 --- a/docker-compose-environment-dev.yaml +++ b/docker-compose-environment-dev.yaml @@ -1,5 +1,4 @@ version: '3' -name: 'environment' services: mysql: -- Gitee