diff --git a/WorkFlowCore/Commons/Common.BackgroundWorker/QuartzImplement/CustomerJob.cs b/WorkFlowCore/Commons/Common.BackgroundWorker/QuartzImplement/CustomerJob.cs index 61ee086e801d4f2298a9d13a3025bdd45c84df14..3951e427e236349fd7bdd6faadeaa0a843ed85f1 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 0000000000000000000000000000000000000000..8b960c939b35f3cd2a8a63c00d1e1168467f32fd --- /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 0000000000000000000000000000000000000000..be5c8990bccbcf693c132b6eb21503f320acea35 --- /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 27677cfa1b9cfcc99172725720e3f5255fb5867c..336493a743a721230b963fcff5189ce53f7b763f 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 4db67dd11b77abab647f0a982a8cb8ef238c1251..ed113ea804f8a21d018a1d103d9123e5e2102d0d 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 9dbe9b79c1e74b1e20fb786ec14427003d5da91a..4183cd97e21726950b23207595335bb556765d79 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 dbd4c6cd5ef7897320de821c3c1dd724aa06ec3e..861f09b79c6ffbd4a41fe6f26abae08659cdc706 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 a44db002c25ee69e8248c9f8f6c4a248b1b10e5d..a068550dfa6c836160d738581c7cba3c5669feae 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 431e5efab2e889e9bed0e5aced9a61d9dd5dfa41..9dd1e0ddb82545ac0ba98a191ae5375d58869acd 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 fcec2713451f3d168f449971aef6c2ee178ff143..ca5b2e7d67b97e34df09a9328a9eca1f234c6d63 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 ec769451ca12879e48bbc62857373760135a038c..d9e266694f479592229e0e6cb14c8a42db060795 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 7fc358e3c4956056d47004b91e56e28b272468b9..9474aa81ba7ffc02e43582cd2594991eb1103031 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 e4bc2445924947f4db20b3838657a8fd16c8745a..a9248e4c7623b9685f221dba3987ac298f7005de 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 60b52e0a882b68837236adfddca49f46c45b25c9..a3e0560ac0fa7428407dad0138ebd7e368c19b45 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 bcff8706e3703f74eb197cace85c81d9567daca7..0000000000000000000000000000000000000000 --- 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 794e99c6b4e2f986d26455b59279229608b0e1cc..b60b9e0d6989ac85f127fa1f10e66a09240c7682 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 0000000000000000000000000000000000000000..25c6b535db89e6054dc9d0d22f1ae1e910ddbc60 --- /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 ab1bad2991fe9ae1701143d1a494d46987f16a78..5b53275306225858e47c875fe38071774de5bf20 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 5123d9003355bf95577da2d425bbb3dc76825b29..e0315aa2a6cad2aceefe95e2a73c0a6bbd9883fd 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 0ecada50a6ff097193c930c57cc4ecd5a842e607..21f8436c63fc146c894de18ff574beae39e7af8d 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 4751d0cbb6ad79a55e74171910eff82189767d6c..2cfcd0baa329ea6e95c5cd8c15a64c7b890081e0 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 350affed78ccf8eda7a71b23ff029eb0e46994c7..3567ff6f7328b8fc51a253a887884dec13682e54 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 29b305ad1822accbbd8617ceb0d0ff354c518c1c..3990460791a7538a213f9ed45071d40dfe1209fb 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 13d2933d6c4387d259e68c73b2a07f70e236855b..2a1c588db28efaebfdccc3c7c9180c2763bd010f 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 5a3a5b9d34b06d53988168b040603f1e18fde189..155d28e62b0fcfd938670cbfec80bdd5408dc3c4 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 bffe70987133e6f7b8105837fff22afd6db7036f..b5b2c998f2782c584ac4f0c66a5424979edf981e 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 6e3a5e675553302c9826e9051a6cd58fe9780a9f..6265bb7bfaff927b19fc28ad8d717b6a6325cb52 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 9ae9ba69f5e09f0933d6283b3ab348b5f3a29f95..0120be88291dc7de687d3f0e5d44069b0b946494 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 0000000000000000000000000000000000000000..81e50d74fdb916f4cacfddbcff6bc895c6cfba02 --- /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 f22afca8d1260dbbd1901e997863c673e42c4953..364b676049ab6b4d8af33ad268c7ec451d6e08a0 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 443984bc2a89bd53e787acc3f498b82f33f6c989..6bfcb33abb0ee0edcd0f60f5faa19b18a794404f 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 5e0a624e07ca0482aca01afa642ba714aa390a6e..ebbf4e5c552848a8fcfdb003cf46b01d09f53818 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 507d827aae21bcf06dd98c06c54c05eaf5149f02..a08b61eef343aa93616f062d16ea768ea1c44304 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 0000000000000000000000000000000000000000..266b42dae0d17e72168ed4c9254ccad5000865a5 --- /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 fd391819378b7b29dc67fd2a8e79c41f9b53e3cf..822a527feaab5406cd0ba133a752d9e1ab30182a 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 9658d895b9b3d94c54b9d61fb87b7f15f632f875..3f6571921488f66e9df34e041206e4cb94266d48 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 cce2bffae99afbf75e99c2616ebc8d0a9ab58686..c76bdce7d77eb2a044aafcb14467f8dc9b35274b 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 f33336b1b576b53eb606c78d203ead4ae1d1100d..5e8505fa2b46bfce0e468c9e672960a9d7c9756e 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 598e3fae1758017220868908c19813f79ff22c49..f9023cb2ffdf5c2d613725299c107876753c85bd 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 3b60eb44849cab326f39aff2c5bd508905ddf60b..f5a5b43981fd9425734c112b6c38d7a847b01293 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 598e3fae1758017220868908c19813f79ff22c49..f9023cb2ffdf5c2d613725299c107876753c85bd 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 996fb7ff30e1f3b2aa56e34d7e522ef53a67d57b..229d98983310e80c26e298163132d58355797049 100644 --- a/docker-compose-environment-dev.yaml +++ b/docker-compose-environment-dev.yaml @@ -1,5 +1,4 @@ version: '3' -name: 'environment' services: mysql: