From a90e47393b9545cb85585b49701cb68f09961f78 Mon Sep 17 00:00:00 2001
From: cKey <35512826+colinin@users.noreply.github.com>
Date: Sat, 10 Oct 2020 23:01:19 +0800
Subject: [PATCH] rules engine module
---
aspnet-core/LINGYUN.MicroService.sln | 19 +-
.../AbpNRulesModule.cs | 31 ++++
.../LINGYUN.Abp.Rules.NRules.csproj} | 7 +-
.../LINGYUN/Abp/Rules/AbpNRulesOptions.cs | 14 ++
.../LINGYUN/Abp/Rules/AbpRuleRepository.cs | 44 +++++
.../LINGYUN/Abp/Rules/DependencyResolver.cs | 20 +++
.../LINGYUN/Abp/Rules/INRulesRepository.cs | 20 +++
.../Abp/Rules/NRulesEntityRuleContributor.cs | 60 +++++++
.../LINGYUN/Abp/Rules/RuleActivator.cs | 24 +++
.../NRulesServiceCollectionExtensions.cs | 55 ++++++
.../NRules/RuleRepositoryExtensions.cs | 15 ++
.../LINGYUN/Abp/Rules/Rule.cs | 28 +--
.../LINGYUN/Abp/Rules/RuleGroup.cs | 22 ++-
.../LINGYUN/Abp/Rules/RuleNameAttribute.cs | 35 ++++
.../LINGYUN/Abp/Rules/RuleParam.cs | 6 +-
.../Abp/RulesEngine/AbpRulesEngineModule.cs | 22 ---
.../RulesEngine/MsEntityRuleContributor.cs | 50 ------
.../RulesEngine/MsRulesEngineMapperProfile.cs | 27 ---
.../common/LINGYUN.Abp.RulesEngine/README.md | 7 -
.../Class1.cs | 8 +
...lesManagement.Application.Contracts.csproj | 18 ++
.../Class1.cs | 8 +
...YUN.Abp.RulesManagement.Application.csproj | 18 ++
...N.Abp.RulesManagement.Domain.Shared.csproj | 19 ++
.../AbpRulesManagementDomainSharedModule.cs | 28 +++
.../Abp/RulesManagement/EntityRuleConsts.cs | 11 ++
.../Abp/RulesManagement/EntityRuleEto.cs | 18 ++
.../RulesManagement/EntityRuleGroupConsts.cs | 9 +
.../Abp/RulesManagement/EntityRuleGroupEto.cs | 18 ++
.../RulesManagement/EntityRuleParamConsts.cs | 8 +
.../Localization/RulesResource.cs | 9 +
.../LINGYUN.Abp.RulesManagement.Domain.csproj | 20 +++
.../AbpRulesManagementDomainModule.cs | 31 ++++
.../LINGYUN/Abp/RulesManagement/EntityRule.cs | 163 ++++++++++++++++++
.../RulesManagement/EntityRuleDataSeeder.cs | 34 ++++
.../Abp/RulesManagement/EntityRuleFinder.cs | 131 ++++++++++++++
.../Abp/RulesManagement/EntityRuleGroup.cs | 103 +++++++++++
.../Abp/RulesManagement/EntityRuleInGroup.cs | 35 ++++
.../Abp/RulesManagement/EntityRuleInject.cs | 39 +++++
.../Abp/RulesManagement/EntityRuleParam.cs | 44 +++++
.../Abp/RulesManagement/EntitySubRule.cs | 35 ++++
.../RulesManagement/IEntityRuleDataSeeder.cs | 9 +
.../IEntityRuleGroupRepository.cs | 40 +++++
.../RulesManagement/IEntityRuleRepository.cs | 35 ++++
.../RulesManagementDbProperties.cs | 13 ++
.../RulesManagementMapperProfile.cs | 22 +++
...RulesManagement.EntityFrameworkCore.csproj | 18 ++
...ulesManagementEntityFrameworkCoreModule.cs | 21 +++
.../EfCoreEntityRuleGroupRepository.cs | 98 +++++++++++
.../EfCoreEntityRuleRepository.cs | 76 ++++++++
.../IRulesManagementDbContext.cs | 13 ++
.../RulesManagementDbContext.cs | 25 +++
...nagementDbContextModelBuilderExtensions.cs | 81 +++++++++
...ulesManagementEfCoreQueryableExtensions.cs | 32 ++++
...agementModelBuilderConfigurationOptions.cs | 15 ++
.../Class1.cs | 8 +
....Abp.RulesManagement.HttpApi.Client.csproj | 18 ++
.../Class1.cs | 8 +
...LINGYUN.Abp.RulesManagement.HttpApi.csproj | 18 ++
.../modules/rules-management/README.md | 9 +
60 files changed, 1738 insertions(+), 134 deletions(-)
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/AbpNRulesModule.cs
rename aspnet-core/modules/common/{LINGYUN.Abp.RulesEngine/LINGYUN.Abp.RulesEngine.csproj => LINGYUN.Abp.Rules.NRules/LINGYUN.Abp.Rules.NRules.csproj} (71%)
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/AbpNRulesOptions.cs
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/AbpRuleRepository.cs
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/DependencyResolver.cs
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/INRulesRepository.cs
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/NRulesEntityRuleContributor.cs
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/RuleActivator.cs
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/Microsoft/Extensions/DependencyInjection/NRulesServiceCollectionExtensions.cs
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/NRules/RuleRepositoryExtensions.cs
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Rules/LINGYUN/Abp/Rules/RuleNameAttribute.cs
delete mode 100644 aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/LINGYUN/Abp/RulesEngine/AbpRulesEngineModule.cs
delete mode 100644 aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/LINGYUN/Abp/RulesEngine/MsEntityRuleContributor.cs
delete mode 100644 aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/LINGYUN/Abp/RulesEngine/MsRulesEngineMapperProfile.cs
delete mode 100644 aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/README.md
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Application.Contracts/Class1.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Application.Contracts/LINGYUN.Abp.RulesManagement.Application.Contracts.csproj
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Application/Class1.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Application/LINGYUN.Abp.RulesManagement.Application.csproj
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN.Abp.RulesManagement.Domain.Shared.csproj
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/AbpRulesManagementDomainSharedModule.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleConsts.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleEto.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleGroupConsts.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleGroupEto.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleParamConsts.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/Localization/RulesResource.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN.Abp.RulesManagement.Domain.csproj
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/AbpRulesManagementDomainModule.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRule.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleDataSeeder.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleFinder.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleGroup.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleInGroup.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleInject.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleParam.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntitySubRule.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/IEntityRuleDataSeeder.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/IEntityRuleGroupRepository.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/IEntityRuleRepository.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/RulesManagementDbProperties.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/RulesManagementMapperProfile.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN.Abp.RulesManagement.EntityFrameworkCore.csproj
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/AbpRulesManagementEntityFrameworkCoreModule.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/EfCoreEntityRuleGroupRepository.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/EfCoreEntityRuleRepository.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/IRulesManagementDbContext.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/RulesManagementDbContext.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/RulesManagementDbContextModelBuilderExtensions.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/RulesManagementEfCoreQueryableExtensions.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/RulesManagementModelBuilderConfigurationOptions.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.HttpApi.Client/Class1.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.HttpApi.Client/LINGYUN.Abp.RulesManagement.HttpApi.Client.csproj
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.HttpApi/Class1.cs
create mode 100644 aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.HttpApi/LINGYUN.Abp.RulesManagement.HttpApi.csproj
create mode 100644 aspnet-core/modules/rules-management/README.md
diff --git a/aspnet-core/LINGYUN.MicroService.sln b/aspnet-core/LINGYUN.MicroService.sln
index 2bb914e1a..aa0f04ae8 100644
--- a/aspnet-core/LINGYUN.MicroService.sln
+++ b/aspnet-core/LINGYUN.MicroService.sln
@@ -241,7 +241,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Auditing.HttpAp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Rules", "modules\common\LINGYUN.Abp.Rules\LINGYUN.Abp.Rules.csproj", "{8ACB30CF-2311-4C0A-AE79-92C1A7667353}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.RulesEngine", "modules\common\LINGYUN.Abp.RulesEngine\LINGYUN.Abp.RulesEngine.csproj", "{FD007B55-A0F1-4EF8-9CFD-6D8AD1B61B65}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Rules.NRules", "modules\common\LINGYUN.Abp.Rules.NRules\LINGYUN.Abp.Rules.NRules.csproj", "{0BA9FF71-C55E-483B-B83A-6B4BD8ABBBB1}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.RulesEngine", "modules\common\LINGYUN.Abp.RulesEngine\LINGYUN.Abp.RulesEngine.csproj", "{E796CB81-8F94-40C4-87B3-FA9FBAD3F54E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -641,10 +643,14 @@ Global
{8ACB30CF-2311-4C0A-AE79-92C1A7667353}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8ACB30CF-2311-4C0A-AE79-92C1A7667353}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8ACB30CF-2311-4C0A-AE79-92C1A7667353}.Release|Any CPU.Build.0 = Release|Any CPU
- {FD007B55-A0F1-4EF8-9CFD-6D8AD1B61B65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {FD007B55-A0F1-4EF8-9CFD-6D8AD1B61B65}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {FD007B55-A0F1-4EF8-9CFD-6D8AD1B61B65}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {FD007B55-A0F1-4EF8-9CFD-6D8AD1B61B65}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0BA9FF71-C55E-483B-B83A-6B4BD8ABBBB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0BA9FF71-C55E-483B-B83A-6B4BD8ABBBB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0BA9FF71-C55E-483B-B83A-6B4BD8ABBBB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0BA9FF71-C55E-483B-B83A-6B4BD8ABBBB1}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E796CB81-8F94-40C4-87B3-FA9FBAD3F54E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E796CB81-8F94-40C4-87B3-FA9FBAD3F54E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E796CB81-8F94-40C4-87B3-FA9FBAD3F54E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E796CB81-8F94-40C4-87B3-FA9FBAD3F54E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -766,7 +772,8 @@ Global
{AC3C8985-73C2-472A-8E76-A0B8786FEC3F} = {67DAB2A0-D407-4CAB-8414-AE3D0AC52FC4}
{07E19CA8-671D-4D58-9FED-5FEE9AE01A2F} = {67DAB2A0-D407-4CAB-8414-AE3D0AC52FC4}
{8ACB30CF-2311-4C0A-AE79-92C1A7667353} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E}
- {FD007B55-A0F1-4EF8-9CFD-6D8AD1B61B65} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E}
+ {0BA9FF71-C55E-483B-B83A-6B4BD8ABBBB1} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E}
+ {E796CB81-8F94-40C4-87B3-FA9FBAD3F54E} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C95FDF91-16F2-4A8B-A4BE-0E62D1B66718}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/AbpNRulesModule.cs b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/AbpNRulesModule.cs
new file mode 100644
index 000000000..c42aecd61
--- /dev/null
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/AbpNRulesModule.cs
@@ -0,0 +1,31 @@
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using Volo.Abp.Modularity;
+using NRule = NRules.Fluent.Dsl.Rule;
+
+namespace LINGYUN.Abp.Rules.NRules
+{
+ [DependsOn(
+ typeof(AbpRulesModule)
+ )]
+ public class AbpNRulesModule : AbpModule
+ {
+ private readonly AbpNRulesOptions options = new AbpNRulesOptions();
+ public override void PreConfigureServices(ServiceConfigurationContext context)
+ {
+ context.Services.AddObjectAccessor(options);
+ context.Services.OnRegistred(ctx =>
+ {
+ if (ctx.ImplementationType.IsAssignableTo(typeof(NRule)))
+ {
+ options.Rules.AddIfNotContains(ctx.ImplementationType);
+ }
+ });
+ }
+ public override void ConfigureServices(ServiceConfigurationContext context)
+ {
+ context.Services.AddNRules(options);
+ }
+ }
+}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/LINGYUN.Abp.RulesEngine.csproj b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN.Abp.Rules.NRules.csproj
similarity index 71%
rename from aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/LINGYUN.Abp.RulesEngine.csproj
rename to aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN.Abp.Rules.NRules.csproj
index 127be1177..0e5a7a1ea 100644
--- a/aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/LINGYUN.Abp.RulesEngine.csproj
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN.Abp.Rules.NRules.csproj
@@ -8,12 +8,15 @@
-
-
+
+
+
+
+
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/AbpNRulesOptions.cs b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/AbpNRulesOptions.cs
new file mode 100644
index 000000000..0fb5079a6
--- /dev/null
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/AbpNRulesOptions.cs
@@ -0,0 +1,14 @@
+using Volo.Abp.Collections;
+using NRule = NRules.Fluent.Dsl.Rule;
+
+namespace LINGYUN.Abp.Rules
+{
+ public class AbpNRulesOptions
+ {
+ public ITypeList Rules { get; }
+ public AbpNRulesOptions()
+ {
+ Rules = new TypeList();
+ }
+ }
+}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/AbpRuleRepository.cs b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/AbpRuleRepository.cs
new file mode 100644
index 000000000..89ff7f9eb
--- /dev/null
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/AbpRuleRepository.cs
@@ -0,0 +1,44 @@
+using NRules.RuleModel;
+using System;
+using System.Collections.Generic;
+
+namespace LINGYUN.Abp.Rules
+{
+ public class AbpRuleRepository : INRulesRepository
+ {
+ public void Add(IRuleSet ruleSet)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IEnumerable GetRuleSets()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Remove(string ruleSetName)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Remove(IRuleSet ruleSet)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IRuleSet GetRuleSet(string ruleSetName)
+ {
+ return new RuleSet(ruleSetName);
+ }
+
+ public IRuleSet GetRuleSet(RuleGroup group)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IEnumerable GetRuleSets(IEnumerable groups)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/DependencyResolver.cs b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/DependencyResolver.cs
new file mode 100644
index 000000000..d898645e0
--- /dev/null
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/DependencyResolver.cs
@@ -0,0 +1,20 @@
+using Microsoft.Extensions.DependencyInjection;
+using NRules.Extensibility;
+using System;
+
+namespace LINGYUN.Abp.Rules
+{
+ public class DependencyResolver : IDependencyResolver
+ {
+ protected IServiceProvider ServiceProvider { get; }
+ public DependencyResolver(IServiceProvider serviceProvider)
+ {
+ ServiceProvider = serviceProvider;
+ }
+
+ public virtual object Resolve(IResolutionContext context, Type serviceType)
+ {
+ return ServiceProvider.GetRequiredService(serviceType);
+ }
+ }
+}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/INRulesRepository.cs b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/INRulesRepository.cs
new file mode 100644
index 000000000..67b10fcd8
--- /dev/null
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/INRulesRepository.cs
@@ -0,0 +1,20 @@
+using NRules.RuleModel;
+using System.Collections.Generic;
+
+namespace LINGYUN.Abp.Rules
+{
+ public interface INRulesRepository : IRuleRepository
+ {
+ void Add(IRuleSet ruleSet);
+
+ void Remove(string ruleSetName);
+
+ void Remove(IRuleSet ruleSet);
+
+ IRuleSet GetRuleSet(string ruleSetName);
+
+ IRuleSet GetRuleSet(RuleGroup group);
+
+ IEnumerable GetRuleSets(IEnumerable groups);
+ }
+}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/NRulesEntityRuleContributor.cs b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/NRulesEntityRuleContributor.cs
new file mode 100644
index 000000000..308f315cb
--- /dev/null
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/NRulesEntityRuleContributor.cs
@@ -0,0 +1,60 @@
+using Microsoft.Extensions.DependencyInjection;
+using NRules.RuleModel;
+using NRules.RuleModel.Builders;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Dynamic.Core;
+using System.Linq.Expressions;
+using System.Threading.Tasks;
+using Volo.Abp.DependencyInjection;
+
+namespace LINGYUN.Abp.Rules
+{
+ [Dependency(ServiceLifetime.Transient, ReplaceServices = true)]
+ [ExposeServices(typeof(IEntityRuleContributor))]
+ public class NRulesEntityRuleContributor : IEntityRuleContributor
+ {
+ protected INRulesRepository Repository { get; }
+ public Task ApplyAsync(EntityRuleContext context)
+ {
+ var entityType = context.Entity.GetType();
+ var entityRuleName = RuleNameAttribute.GetRuleName(entityType);
+
+
+
+ IEnumerable groupRuleSets = new List();
+
+ groupRuleSets = Repository.GetRuleSets(context.Groups);
+
+ var sessionFactory = Repository.Compile(context.Groups);
+ var session = sessionFactory.CreateSession();
+ session.Insert(context.Entity);
+
+ session.Fire();
+
+ foreach (var groupRuleSet in groupRuleSets)
+ {
+ }
+
+ foreach (var group in context.Groups)
+ {
+ var groupRuleSet = new RuleSet(group.Name);
+
+ Repository.GetRuleSet(group.Name);
+
+ foreach (var rule in group.Rules)
+ {
+ var builder = new RuleBuilder();
+ builder.Name(rule.Name);
+
+ PatternBuilder thisRulePattern = builder.LeftHandSide().Pattern(entityType, entityRuleName);
+ ParameterExpression thisRuleParameter = thisRulePattern.Declaration.ToParameterExpression();
+ var ruleCondition = Expression.Lambda(DynamicExpressionParser.ParseLambda(typeof(bool), rule.Expression), thisRuleParameter);
+ thisRulePattern.Condition(ruleCondition);
+ }
+ }
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/RuleActivator.cs b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/RuleActivator.cs
new file mode 100644
index 000000000..4777a20d6
--- /dev/null
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/LINGYUN/Abp/Rules/RuleActivator.cs
@@ -0,0 +1,24 @@
+using Microsoft.Extensions.DependencyInjection;
+using NRules.Fluent;
+using System;
+using System.Collections.Generic;
+using Volo.Abp.DependencyInjection;
+using NRule = NRules.Fluent.Dsl.Rule;
+
+namespace LINGYUN.Abp.Rules
+{
+ [Dependency(ServiceLifetime.Transient, ReplaceServices = true)]
+ [ExposeServices(typeof(IRuleActivator))]
+ public class RuleActivator : IRuleActivator
+ {
+ protected IServiceProvider ServiceProvider { get; }
+ public RuleActivator(IServiceProvider serviceProvider)
+ {
+ ServiceProvider = serviceProvider;
+ }
+ public virtual IEnumerable Activate(Type type)
+ {
+ return (IEnumerable)ServiceProvider.GetServices(type);
+ }
+ }
+}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/Microsoft/Extensions/DependencyInjection/NRulesServiceCollectionExtensions.cs b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/Microsoft/Extensions/DependencyInjection/NRulesServiceCollectionExtensions.cs
new file mode 100644
index 000000000..2097719c5
--- /dev/null
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/Microsoft/Extensions/DependencyInjection/NRulesServiceCollectionExtensions.cs
@@ -0,0 +1,55 @@
+using LINGYUN.Abp.Rules;
+using NRules;
+using NRules.Fluent;
+using NRules.RuleModel;
+using System;
+
+namespace Microsoft.Extensions.DependencyInjection
+{
+ public static class NRulesServiceCollectionExtensions
+ {
+ public static IServiceCollection AddNRules(this IServiceCollection services, AbpNRulesOptions options)
+ {
+ services.RegisterRepository();
+ services.RegisterSessionFactory();
+ services.RegisterSession();
+
+ return services;
+ }
+
+ public static IServiceCollection RegisterRepository(this IServiceCollection services)
+ {
+ services.AddSingleton();
+
+ services.AddSingleton();
+ services.AddSingleton();
+
+ return services;
+ }
+
+ public static IServiceCollection RegisterSessionFactory(this IServiceCollection services)
+ {
+ services.RegisterSessionFactory((provider) => provider.GetRequiredService().Compile());
+
+ return services;
+ }
+
+ public static IServiceCollection RegisterSessionFactory(this IServiceCollection services, Func compileFunc)
+ {
+ services.AddSingleton();
+ services.AddSingleton(compileFunc);
+
+ return services;
+ }
+
+ public static IServiceCollection RegisterSession(this IServiceCollection services)
+ {
+ return services.RegisterSession((provider) => provider.GetRequiredService().CreateSession());
+ }
+
+ public static IServiceCollection RegisterSession(this IServiceCollection services, Func factoryFunc)
+ {
+ return services.AddScoped(factoryFunc);
+ }
+ }
+}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/NRules/RuleRepositoryExtensions.cs b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/NRules/RuleRepositoryExtensions.cs
new file mode 100644
index 000000000..2f29b2f7f
--- /dev/null
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Rules.NRules/NRules/RuleRepositoryExtensions.cs
@@ -0,0 +1,15 @@
+using NRules;
+using System.Collections.Generic;
+
+namespace LINGYUN.Abp.Rules
+{
+ public static class RuleRepositoryExtensions
+ {
+ public static ISessionFactory Compile(this INRulesRepository repository, IEnumerable groups)
+ {
+ var compiler = new RuleCompiler();
+ ISessionFactory factory = compiler.Compile(repository.GetRuleSets(groups));
+ return factory;
+ }
+ }
+}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Rules/LINGYUN/Abp/Rules/Rule.cs b/aspnet-core/modules/common/LINGYUN.Abp.Rules/LINGYUN/Abp/Rules/Rule.cs
index f35e5b054..4d18e8d5a 100644
--- a/aspnet-core/modules/common/LINGYUN.Abp.Rules/LINGYUN/Abp/Rules/Rule.cs
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Rules/LINGYUN/Abp/Rules/Rule.cs
@@ -11,21 +11,21 @@ namespace LINGYUN.Abp.Rules
public class Rule
{
[NotNull]
- public string Name { get; }
- public string Operator { get; }
- public string ErrorMessage { get; }
- public DateTime CreationTime { get; }
- public ErrorType ErrorType { get; }
- public ExpressionType? ExpressionType { get; }
- public List Rules { get; }
- public List InjectRules { get; }
- public List Params { get; }
- public string Expression { get; }
- public string SuccessEvent { get; }
-
+ public string Name { get; set; }
+ public string Operator { get; set; }
+ public string ErrorMessage { get; set; }
+ public DateTime CreationTime { get; set; }
+ public ErrorType ErrorType { get; set; }
+ public ExpressionType? ExpressionType { get; set; }
+ public List Rules { get; set; }
+ public List InjectRules { get; set; }
+ public List Params { get; set; }
+ public string Expression { get; set; }
+ public string SuccessEvent { get; set; }
+ protected Rule() { }
public Rule(
[NotNull] string name,
- string @operator,
+ string operation,
DateTime creationTime,
string expression = null,
string successEvent = null,
@@ -35,7 +35,7 @@ namespace LINGYUN.Abp.Rules
Check.NotNullOrWhiteSpace(name, nameof(name));
Name = name;
- Operator = @operator;
+ Operator = operation;
CreationTime = creationTime;
Expression = expression;
SuccessEvent = successEvent;
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Rules/LINGYUN/Abp/Rules/RuleGroup.cs b/aspnet-core/modules/common/LINGYUN.Abp.Rules/LINGYUN/Abp/Rules/RuleGroup.cs
index c6447a204..f426a5a03 100644
--- a/aspnet-core/modules/common/LINGYUN.Abp.Rules/LINGYUN/Abp/Rules/RuleGroup.cs
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Rules/LINGYUN/Abp/Rules/RuleGroup.cs
@@ -7,10 +7,10 @@ namespace LINGYUN.Abp.Rules
public class RuleGroup
{
[NotNull]
- public string Name { get; }
- public List InjectRules { get; }
+ public string Name { get; set; }
+ public List InjectRules { get; set; }
public List Rules { get; }
-
+ protected RuleGroup() { }
public RuleGroup(
[NotNull] string name)
{
@@ -22,18 +22,32 @@ namespace LINGYUN.Abp.Rules
InjectRules = new List();
}
- public RuleGroup InjectRule(string ruleName)
+ public RuleGroup WithInjectRule(string ruleName)
{
InjectRules.AddIfNotContains(ruleName);
return this;
}
+ public RuleGroup WithInjectRule(IEnumerable ruleNames)
+ {
+ InjectRules.AddIfNotContains(ruleNames);
+
+ return this;
+ }
+
public RuleGroup WithRule(Rule rule)
{
Rules.AddIfNotContains(rule);
return this;
}
+
+ public RuleGroup WithRule(IEnumerable rules)
+ {
+ Rules.AddIfNotContains(rules);
+
+ return this;
+ }
}
}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Rules/LINGYUN/Abp/Rules/RuleNameAttribute.cs b/aspnet-core/modules/common/LINGYUN.Abp.Rules/LINGYUN/Abp/Rules/RuleNameAttribute.cs
new file mode 100644
index 000000000..532acde00
--- /dev/null
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Rules/LINGYUN/Abp/Rules/RuleNameAttribute.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Reflection;
+
+namespace LINGYUN.Abp.Rules
+{
+ public class RuleNameAttribute : Attribute
+ {
+ public string Name { get; }
+ public RuleNameAttribute(string name)
+ {
+ Name = name;
+ }
+
+ public virtual string GetRuleNameForType(Type ruleType)
+ {
+ return Name;
+ }
+
+ public static string GetRuleName()
+ {
+ return GetRuleName(typeof(TEntity));
+ }
+
+ public static string GetRuleName(Type entityType)
+ {
+ var ruleAttribute = entityType.GetSingleAttributeOrNull();
+ if (ruleAttribute != null)
+ {
+ return ruleAttribute.GetRuleNameForType(entityType);
+ }
+
+ return entityType.Name.RemovePostFix("Rule").ToKebabCase();
+ }
+ }
+}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Rules/LINGYUN/Abp/Rules/RuleParam.cs b/aspnet-core/modules/common/LINGYUN.Abp.Rules/LINGYUN/Abp/Rules/RuleParam.cs
index 2601e4c47..086d945b1 100644
--- a/aspnet-core/modules/common/LINGYUN.Abp.Rules/LINGYUN/Abp/Rules/RuleParam.cs
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Rules/LINGYUN/Abp/Rules/RuleParam.cs
@@ -6,10 +6,12 @@ namespace LINGYUN.Abp.Rules
public class RuleParam
{
[NotNull]
- public string Name { get; }
+ public string Name { get; set; }
[NotNull]
- public string Expression { get; }
+ public string Expression { get; set; }
+
+ protected RuleParam() { }
public RuleParam(
[NotNull] string name,
[NotNull] string expression)
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/LINGYUN/Abp/RulesEngine/AbpRulesEngineModule.cs b/aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/LINGYUN/Abp/RulesEngine/AbpRulesEngineModule.cs
deleted file mode 100644
index 09234aa58..000000000
--- a/aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/LINGYUN/Abp/RulesEngine/AbpRulesEngineModule.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using LINGYUN.Abp.Rules;
-using Microsoft.Extensions.DependencyInjection;
-using Volo.Abp.AutoMapper;
-using Volo.Abp.Modularity;
-
-namespace LINGYUN.Abp.RulesEngine
-{
- [DependsOn(
- typeof(AbpRulesModule),
- typeof(AbpAutoMapperModule))]
- public class AbpRulesEngineModule : AbpModule
- {
- public override void ConfigureServices(ServiceConfigurationContext context)
- {
- context.Services.AddAutoMapperObjectMapper();
- Configure(options =>
- {
- options.AddProfile(validate: true);
- });
- }
- }
-}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/LINGYUN/Abp/RulesEngine/MsEntityRuleContributor.cs b/aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/LINGYUN/Abp/RulesEngine/MsEntityRuleContributor.cs
deleted file mode 100644
index b59b621bb..000000000
--- a/aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/LINGYUN/Abp/RulesEngine/MsEntityRuleContributor.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-using LINGYUN.Abp.Rules;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Logging;
-using RulesEngine.Extensions;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using Volo.Abp.DependencyInjection;
-using Volo.Abp.ObjectMapping;
-using MsRulesEngine = RulesEngine.RulesEngine;
-using MsWorkflowRules = RulesEngine.Models.WorkflowRules;
-
-namespace LINGYUN.Abp.RulesEngine
-{
- [Dependency(ServiceLifetime.Transient, ReplaceServices = true)]
- [ExposeServices(typeof(IEntityRuleContributor))]
- public class MsEntityRuleContributor : IEntityRuleContributor
- {
- protected ILogger Logger { get; }
- protected IObjectMapper ObjectMapper { get; }
- public MsEntityRuleContributor(
- IObjectMapper objectMapper,
- ILogger logger)
- {
- Logger = logger;
- ObjectMapper = objectMapper;
- }
-
- public Task ApplyAsync(EntityRuleContext context)
- {
- var workflowRules = ObjectMapper.Map, List>(context.Groups);
-
- var rulesEngine = new MsRulesEngine(workflowRules.ToArray(), Logger);
-
- foreach(var workflow in workflowRules)
- {
- var ruleRsults = rulesEngine.ExecuteRule(workflow.WorkflowName, context.Entity);
- ruleRsults.OnSuccess((eventName) =>
- {
- Logger.LogDebug($"{workflow.WorkflowName} evaluation resulted in succees - {eventName}");
- });
- ruleRsults.OnFail(() =>
- {
- Logger.LogWarning($"{workflow.WorkflowName} evaluation resulted in failure");
- });
- }
-
- return Task.CompletedTask;
- }
- }
-}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/LINGYUN/Abp/RulesEngine/MsRulesEngineMapperProfile.cs b/aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/LINGYUN/Abp/RulesEngine/MsRulesEngineMapperProfile.cs
deleted file mode 100644
index deffe9a2f..000000000
--- a/aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/LINGYUN/Abp/RulesEngine/MsRulesEngineMapperProfile.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using AutoMapper;
-using LINGYUN.Abp.Rules;
-using MsExpressionType = RulesEngine.Models.RuleExpressionType;
-using MsRule = RulesEngine.Models.Rule;
-using MsRuleErrorType = RulesEngine.Models.ErrorType;
-using MsRuleParam = RulesEngine.Models.LocalParam;
-using MsWorkflowRules = RulesEngine.Models.WorkflowRules;
-
-namespace LINGYUN.Abp.RulesEngine
-{
- public class MsRulesEngineMapperProfile : Profile
- {
- public MsRulesEngineMapperProfile()
- {
- CreateMap();
- CreateMap()
- .ForMember(r => r.LocalParams, map => map.MapFrom(m => m.Params))
- .ForMember(r => r.WorkflowRulesToInject, map => map.MapFrom(m => m.InjectRules))
- .ForMember(r => r.ErrorType, map => map.MapFrom(m => (MsRuleErrorType)m.ErrorType.GetHashCode()))
- .ForMember(r => r.RuleExpressionType, map => map.MapFrom(m => (MsExpressionType)m.ExpressionType.GetHashCode()));
- CreateMap()
- .ForMember(wr => wr.WorkflowName, map => map.MapFrom(m => m.Name))
- .ForMember(wr => wr.Rules, map => map.MapFrom(m => m.Rules))
- .ForMember(wr => wr.WorkflowRulesToInject, map => map.MapFrom(m => m.InjectRules));
- }
- }
-}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/README.md b/aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/README.md
deleted file mode 100644
index b50241c85..000000000
--- a/aspnet-core/modules/common/LINGYUN.Abp.RulesEngine/README.md
+++ /dev/null
@@ -1,7 +0,0 @@
-# LINGYUN.Abp.RulesEngine
-
-规则引擎 [microsoft/RulesEngine](https://github.com/microsoft/RulesEngine) (RulesEngine) 实现
-
-## 配置使用
-
-待完善
\ No newline at end of file
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Application.Contracts/Class1.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Application.Contracts/Class1.cs
new file mode 100644
index 000000000..8b700dfdf
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Application.Contracts/Class1.cs
@@ -0,0 +1,8 @@
+using System;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ public class Class1
+ {
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Application.Contracts/LINGYUN.Abp.RulesManagement.Application.Contracts.csproj b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Application.Contracts/LINGYUN.Abp.RulesManagement.Application.Contracts.csproj
new file mode 100644
index 000000000..3dfa487fc
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Application.Contracts/LINGYUN.Abp.RulesManagement.Application.Contracts.csproj
@@ -0,0 +1,18 @@
+
+
+
+
+
+ netstandard2.0
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Application/Class1.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Application/Class1.cs
new file mode 100644
index 000000000..718346007
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Application/Class1.cs
@@ -0,0 +1,8 @@
+using System;
+
+namespace LINGYUN.Abp.RulesManagement.Application
+{
+ public class Class1
+ {
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Application/LINGYUN.Abp.RulesManagement.Application.csproj b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Application/LINGYUN.Abp.RulesManagement.Application.csproj
new file mode 100644
index 000000000..0e9183995
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Application/LINGYUN.Abp.RulesManagement.Application.csproj
@@ -0,0 +1,18 @@
+
+
+
+
+
+ netstandard2.0
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN.Abp.RulesManagement.Domain.Shared.csproj b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN.Abp.RulesManagement.Domain.Shared.csproj
new file mode 100644
index 000000000..b8a1e7e64
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN.Abp.RulesManagement.Domain.Shared.csproj
@@ -0,0 +1,19 @@
+
+
+
+
+
+ netstandard2.0
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/AbpRulesManagementDomainSharedModule.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/AbpRulesManagementDomainSharedModule.cs
new file mode 100644
index 000000000..f319b81f7
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/AbpRulesManagementDomainSharedModule.cs
@@ -0,0 +1,28 @@
+using LINGYUN.Abp.RulesManagement.Localization;
+using Volo.Abp.Localization;
+using Volo.Abp.Modularity;
+using Volo.Abp.Validation;
+using Volo.Abp.VirtualFileSystem;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ [DependsOn(
+ typeof(AbpValidationModule))]
+ public class AbpRulesManagementDomainSharedModule : AbpModule
+ {
+ public override void ConfigureServices(ServiceConfigurationContext context)
+ {
+ Configure(options =>
+ {
+ options.FileSets.AddEmbedded();
+ });
+
+ Configure(options =>
+ {
+ options.Resources
+ .Add()
+ .AddVirtualJson("/LINGYUN/Abp/RulesManagement/Localization/Resources");
+ });
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleConsts.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleConsts.cs
new file mode 100644
index 000000000..caeb998ae
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleConsts.cs
@@ -0,0 +1,11 @@
+namespace LINGYUN.Abp.RulesManagement
+{
+ public static class EntityRuleConsts
+ {
+ public static int MaxNameLength { get; set; } = 64;
+ public static int MaxDisplayNameLength { get; set; } = 256;
+ public static int MaxOperatorLength { get; set; } = 64;
+ public static int MaxErrorMessageLength { get; set; } = 256;
+ public static int MaxExpressionLength { get; set; } = 1024;
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleEto.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleEto.cs
new file mode 100644
index 000000000..815308bee
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleEto.cs
@@ -0,0 +1,18 @@
+using System;
+using Volo.Abp.Auditing;
+using Volo.Abp.MultiTenancy;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ public class EntityRuleEto : IMultiTenant, ICreationAuditedObject, IModificationAuditedObject
+ {
+ public Guid Id { get; set; }
+ public Guid? TenantId { get; set; }
+ public string Name { get; set; }
+ public string DisplayName { get; set; }
+ public Guid? LastModifierId { get; set; }
+ public DateTime? LastModificationTime { get; set; }
+ public DateTime CreationTime { get; set; }
+ public Guid? CreatorId { get; set; }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleGroupConsts.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleGroupConsts.cs
new file mode 100644
index 000000000..0387ba93b
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleGroupConsts.cs
@@ -0,0 +1,9 @@
+namespace LINGYUN.Abp.RulesManagement
+{
+ public static class EntityRuleGroupConsts
+ {
+ public static int MaxNameLength { get; set; } = 64;
+ public static int MaxDisplayNameLength { get; set; } = 256;
+ public static int MaxEntiyFullTypeNameLength { get; set; } = 256;
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleGroupEto.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleGroupEto.cs
new file mode 100644
index 000000000..efac1832c
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleGroupEto.cs
@@ -0,0 +1,18 @@
+using System;
+using Volo.Abp.Auditing;
+using Volo.Abp.MultiTenancy;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ public class EntityRuleGroupEto : IMultiTenant, ICreationAuditedObject, IModificationAuditedObject
+ {
+ public Guid Id { get; set; }
+ public Guid? TenantId { get; set; }
+ public string Name { get; set; }
+ public string DisplayName { get; set; }
+ public Guid? LastModifierId { get; set; }
+ public DateTime? LastModificationTime { get; set; }
+ public DateTime CreationTime { get; set; }
+ public Guid? CreatorId { get; set; }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleParamConsts.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleParamConsts.cs
new file mode 100644
index 000000000..e05e38304
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/EntityRuleParamConsts.cs
@@ -0,0 +1,8 @@
+namespace LINGYUN.Abp.RulesManagement
+{
+ public static class EntityRuleParamConsts
+ {
+ public static int MaxNameLength { get; set; } = 64;
+ public static int MaxExpressionLength { get; set; } = 1024;
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/Localization/RulesResource.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/Localization/RulesResource.cs
new file mode 100644
index 000000000..b96a397f6
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain.Shared/LINGYUN/Abp/RulesManagement/Localization/RulesResource.cs
@@ -0,0 +1,9 @@
+using Volo.Abp.Localization;
+
+namespace LINGYUN.Abp.RulesManagement.Localization
+{
+ [LocalizationResourceName("AbpRulesManagement")]
+ public class RulesResource
+ {
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN.Abp.RulesManagement.Domain.csproj b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN.Abp.RulesManagement.Domain.csproj
new file mode 100644
index 000000000..79235b9d8
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN.Abp.RulesManagement.Domain.csproj
@@ -0,0 +1,20 @@
+
+
+
+
+
+ netstandard2.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/AbpRulesManagementDomainModule.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/AbpRulesManagementDomainModule.cs
new file mode 100644
index 000000000..b1d4bdfbe
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/AbpRulesManagementDomainModule.cs
@@ -0,0 +1,31 @@
+using Microsoft.Extensions.DependencyInjection;
+using Volo.Abp.AutoMapper;
+using Volo.Abp.Domain;
+using Volo.Abp.Domain.Entities.Events.Distributed;
+using Volo.Abp.Modularity;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ [DependsOn(
+ typeof(AbpDddDomainModule),
+ typeof(AbpAutoMapperModule),
+ typeof(AbpRulesManagementDomainSharedModule))]
+ public class AbpRulesManagementDomainModule : AbpModule
+ {
+ public override void ConfigureServices(ServiceConfigurationContext context)
+ {
+ context.Services.AddAutoMapperObjectMapper();
+
+ Configure(options =>
+ {
+ options.AddProfile(validate: true);
+ });
+
+ Configure(options =>
+ {
+ options.EtoMappings.Add(typeof(AbpRulesManagementDomainModule));
+ options.EtoMappings.Add(typeof(AbpRulesManagementDomainModule));
+ });
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRule.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRule.cs
new file mode 100644
index 000000000..4a2512eab
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRule.cs
@@ -0,0 +1,163 @@
+using JetBrains.Annotations;
+using LINGYUN.Abp.Rules;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using Volo.Abp;
+using Volo.Abp.Domain.Entities.Auditing;
+using Volo.Abp.Guids;
+using Volo.Abp.MultiTenancy;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ public class EntityRule : FullAuditedAggregateRoot, IMultiTenant
+ {
+ public virtual Guid? TenantId { get; protected set; }
+ ///
+ /// 规则名称
+ ///
+ public virtual string Name { get; protected set; }
+ ///
+ /// 显示名称
+ ///
+ public virtual string DisplayName { get; protected set; }
+ ///
+ /// 操作类型
+ ///
+ public virtual string Operator { get; protected set; }
+ ///
+ /// 错误提示
+ ///
+ public virtual string ErrorMessage { get; protected set; }
+ ///
+ /// 错误类型
+ ///
+ public virtual ErrorType ErrorType { get; protected set; }
+ ///
+ /// 表达式类型
+ ///
+ public virtual ExpressionType? ExpressionType { get; set; }
+ ///
+ /// 所属规则
+ ///
+ public virtual Guid? ParentId { get; protected set; }
+
+ public virtual ICollection SubRules { get; protected set; }
+ public virtual ICollection InjectRules { get; protected set; }
+ public virtual ICollection Params { get; protected set; }
+ public virtual string Expression { get; protected set; }
+
+ protected EntityRule()
+ {
+ }
+
+ public EntityRule(
+ [NotNull] Guid id,
+ [NotNull] string name,
+ [CanBeNull] string operation,
+ [CanBeNull] string displayName,
+ [CanBeNull] Guid? parentId = null,
+ [CanBeNull] Guid? tenantId = null)
+ {
+ Check.NotNull(id, nameof(id));
+ Check.NotNullOrWhiteSpace(name, nameof(name), EntityRuleConsts.MaxNameLength);
+
+ Id = id;
+ Name = name;
+ Operator = operation;
+ DisplayName = displayName;
+ ParentId = parentId;
+ TenantId = tenantId;
+
+ ExpressionType = Abp.Rules.ExpressionType.LambdaExpression;
+
+ Params = new Collection();
+ SubRules = new Collection();
+ InjectRules = new Collection();
+ ExtraProperties = new Dictionary();
+ }
+
+ public virtual void SetErrorInfomation(string errorMessage, ErrorType errorType = ErrorType.Warning)
+ {
+ ErrorType = errorType;
+ ErrorMessage = errorMessage;
+ }
+
+ public virtual void AddParamter([NotNull] IGuidGenerator guidGenerator, [NotNull] string name, [NotNull] string expression)
+ {
+ Check.NotNull(guidGenerator, nameof(guidGenerator));
+
+ if (Params.Any(p => p.Name == name))
+ {
+ return;
+ }
+ Params.Add(new EntityRuleParam(guidGenerator.Create(), Id, name, expression, TenantId));
+ }
+
+ public virtual void RemoveParamter([NotNull] string name)
+ {
+ Check.NotNullOrWhiteSpace(name, nameof(name));
+
+ Params.RemoveAll(p => p.Name == name);
+ }
+
+ public virtual void AddInjectRule([NotNull] EntityRule rule)
+ {
+ Check.NotNull(rule, nameof(rule));
+ if (IsInjectRule(rule.Id))
+ {
+ return;
+ }
+ InjectRules.Add(new EntityRuleInject(rule.Id, Id, TenantId));
+ }
+
+ public virtual void RemoveInjectRule([NotNull] Guid ruleId)
+ {
+ Check.NotNull(ruleId, nameof(ruleId));
+ if (IsInjectRule(ruleId))
+ {
+ return;
+ }
+ InjectRules.RemoveAll(rule => rule.RuleId == ruleId);
+ }
+
+ public virtual bool IsInjectRule([NotNull] Guid ruleId)
+ {
+ Check.NotNull(ruleId, nameof(ruleId));
+
+ return InjectRules.Any(rule => rule.RuleId == ruleId);
+ }
+
+
+ public virtual void AddSubRule([NotNull] EntityRule rule)
+ {
+ Check.NotNull(rule, nameof(rule));
+
+ if (IsInRule(rule.Id))
+ {
+ return;
+ }
+ SubRules.Add(new EntitySubRule(Id, rule.Id, TenantId));
+ }
+
+ public virtual void RemoveSubRule([NotNull] Guid ruleId)
+ {
+ Check.NotNull(ruleId, nameof(ruleId));
+
+ if (!IsInRule(ruleId))
+ {
+ return;
+ }
+
+ SubRules.RemoveAll(r => r.SubId == ruleId);
+ }
+
+ public virtual bool IsInRule([NotNull] Guid ruleId)
+ {
+ Check.NotNull(ruleId, nameof(ruleId));
+
+ return SubRules.Any(r => r.SubId == ruleId);
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleDataSeeder.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleDataSeeder.cs
new file mode 100644
index 000000000..99dbee17e
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleDataSeeder.cs
@@ -0,0 +1,34 @@
+using System.Threading.Tasks;
+using Volo.Abp.DependencyInjection;
+using Volo.Abp.Guids;
+using Volo.Abp.MultiTenancy;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ public class EntityRuleDataSeeder : IEntityRuleDataSeeder, ITransientDependency
+ {
+ protected IGuidGenerator GuidGenerator { get; }
+ protected ICurrentTenant CurrentTenant { get; }
+ protected IEntityRuleGroupRepository Repository { get; }
+
+ public EntityRuleDataSeeder(
+ IGuidGenerator guidGenerator,
+ ICurrentTenant currentTenant,
+ IEntityRuleGroupRepository repository)
+ {
+ GuidGenerator = guidGenerator;
+ CurrentTenant = currentTenant;
+ Repository = repository;
+ }
+
+ public virtual async Task SeedAsync(EntityRuleInGroup group)
+ {
+ var findGroup = await Repository.GetByNameAsync(group.Name);
+ if (findGroup != null)
+ {
+ return;
+ }
+ await Repository.InsertAsync(group);
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleFinder.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleFinder.cs
new file mode 100644
index 000000000..fc7364688
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleFinder.cs
@@ -0,0 +1,131 @@
+using LINGYUN.Abp.Rules;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Volo.Abp.DependencyInjection;
+using Volo.Abp.Domain.Services;
+using Volo.Abp.ObjectMapping;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ [Dependency(ServiceLifetime.Transient, ReplaceServices = true)]
+ [ExposeServices(typeof(IRuleFinder))]
+ public class EntityRuleFinder : DomainService, IRuleFinder
+ {
+ private IObjectMapper _objectMapper;
+ protected IObjectMapper ObjectMapper => LazyGetRequiredService(ref _objectMapper);
+
+ private IEntityRuleGroupRepository _ruleGroupRepository;
+ protected IEntityRuleGroupRepository RuleGroupRepository => LazyGetRequiredService(ref _ruleGroupRepository);
+
+ private IEntityRuleRepository _rruleRepository;
+ protected IEntityRuleRepository RuleRepository => LazyGetRequiredService(ref _rruleRepository);
+
+ public virtual async Task> GetRuleGroupsAsync(Type entityType)
+ {
+ var entityFullTypeName = entityType.FullName;
+ if (entityType.IsGenericType)
+ {
+ entityFullTypeName = entityType.GetGenericTypeDefinition().FullName;
+ }
+ else if (entityType.IsArray)
+ {
+ entityFullTypeName = entityType.GetElementType().FullName;
+ }
+ var entityRuleGroups = await RuleGroupRepository.GetListByTypeAsync(entityFullTypeName, includeDetails: true);
+
+ var ruleGroups = ObjectMapper.Map, List>(entityRuleGroups);
+
+ foreach(var group in ruleGroups)
+ {
+ var entityRuleGroup = entityRuleGroups.Find(g => g.Name.Equals(group.Name));
+ if (entityRuleGroup != null)
+ {
+ foreach(var ruleInGroup in entityRuleGroup.Rules)
+ {
+ await AddRuleAsync(group, ruleInGroup.RuleId);
+ }
+
+ foreach(var ruleInject in entityRuleGroup.InjectRules)
+ {
+ await AddToInjectRuleAsync(group, ruleInject.RuleId);
+ }
+ }
+ }
+
+ return ruleGroups;
+ }
+
+ protected virtual async Task AddRuleAsync(RuleGroup ruleGroup, Guid ruleId)
+ {
+ var entityRule = await RuleRepository.FindAsync(ruleId);
+ if (entityRule == null)
+ {
+ return;
+ }
+ var rule = ObjectMapper.Map(entityRule);
+ ruleGroup.WithRule(rule);
+
+ foreach (var subEntityRule in entityRule.SubRules)
+ {
+ await AddSubRuleAsync(rule, subEntityRule.SubId);
+ }
+
+ foreach (var ruleInject in entityRule.InjectRules)
+ {
+ // 如果依赖于某个规则,需要把此规则添加到集合
+ await AddRuleAsync(ruleGroup, ruleInject.InjectId);
+
+ // 添加依赖规则
+ await AddToInjectRuleAsync(ruleGroup, ruleInject.InjectId);
+ }
+ }
+
+ protected virtual async Task AddSubRuleAsync(Rule rule, Guid subRuleId)
+ {
+ var entityRule = await RuleRepository.FindAsync(subRuleId);
+ if (entityRule == null)
+ {
+ return;
+ }
+ var subRule = ObjectMapper.Map(entityRule);
+ rule.CreateChildren(subRule);
+ foreach (var subEntityRule in entityRule.SubRules)
+ {
+ await AddSubRuleAsync(subRule, subEntityRule.SubId);
+ }
+ }
+
+ protected virtual async Task AddToInjectRuleAsync(RuleGroup group, Guid ruleId)
+ {
+ var entityRule = await RuleRepository.FindAsync(ruleId);
+ if (entityRule == null)
+ {
+ return;
+ }
+ group.WithInjectRule(entityRule.Name);
+ foreach (var injectRule in entityRule.InjectRules)
+ {
+ await AddToInjectRuleAsync(group, injectRule.InjectId);
+ }
+ }
+
+ protected virtual async Task AddToInjectRuleAsync(Rule rule, Guid ruleId)
+ {
+ var entityRule = await RuleRepository.FindAsync(ruleId);
+ if (entityRule == null)
+ {
+ return;
+ }
+ var injectRule = ObjectMapper.Map(entityRule);
+ rule.CreateChildren(injectRule);
+ rule.InjectRule(entityRule.Name);
+ foreach (var injectSubRule in entityRule.InjectRules)
+ {
+ await AddToInjectRuleAsync(injectRule, injectSubRule.InjectId);
+ }
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleGroup.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleGroup.cs
new file mode 100644
index 000000000..e1ab00217
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleGroup.cs
@@ -0,0 +1,103 @@
+using JetBrains.Annotations;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using Volo.Abp;
+using Volo.Abp.Domain.Entities.Auditing;
+using Volo.Abp.MultiTenancy;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ public class EntityRuleGroup : FullAuditedAggregateRoot, IMultiTenant
+ {
+ public virtual Guid? TenantId { get; protected set; }
+ public virtual string Name { get; protected set; }
+ public virtual string DisplayName { get; protected set; }
+ public virtual string EntityFullTypeName { get; protected set; }
+ public virtual ICollection Rules { get; protected set; }
+ public virtual ICollection InjectRules { get; protected set; }
+ protected EntityRuleGroup()
+ {
+ }
+
+ public EntityRuleGroup(
+ [NotNull] Guid id,
+ [NotNull] string name,
+ [NotNull] string entiyFullTypeName,
+ [CanBeNull] string displayName,
+ [CanBeNull] Guid? tenantId = null)
+ {
+ Check.NotNull(id, nameof(id));
+ Check.NotNullOrWhiteSpace(name, nameof(name), EntityRuleGroupConsts.MaxNameLength);
+ Check.NotNullOrWhiteSpace(entiyFullTypeName, nameof(entiyFullTypeName), EntityRuleGroupConsts.MaxEntiyFullTypeNameLength);
+
+ Id = id;
+ Name = name;
+ DisplayName = displayName;
+ TenantId = tenantId;
+
+ Rules = new Collection();
+ InjectRules = new Collection();
+ ExtraProperties = new Dictionary();
+ }
+
+ public virtual void AddInjectRule([NotNull] EntityRule rule)
+ {
+ Check.NotNull(rule, nameof(rule));
+ if (IsInjectRule(rule.Id))
+ {
+ return;
+ }
+ InjectRules.Add(new EntityRuleInject(rule.Id, Id, TenantId));
+ }
+
+ public virtual void RemoveInjectRule([NotNull] Guid ruleId)
+ {
+ Check.NotNull(ruleId, nameof(ruleId));
+ if (IsInjectRule(ruleId))
+ {
+ return;
+ }
+ InjectRules.RemoveAll(rule => rule.RuleId == ruleId);
+ }
+
+ public virtual bool IsInjectRule([NotNull] Guid ruleId)
+ {
+ Check.NotNull(ruleId, nameof(ruleId));
+
+ return InjectRules.Any(rule => rule.RuleId == ruleId);
+ }
+
+
+ public virtual void AddRule([NotNull] EntityRule rule)
+ {
+ Check.NotNull(rule, nameof(rule));
+
+ if (IsInRule(rule.Id))
+ {
+ return;
+ }
+ Rules.Add(new EntityRuleInGroup(rule.Id, Id, TenantId));
+ }
+
+ public virtual void RemoveRule([NotNull] Guid ruleId)
+ {
+ Check.NotNull(ruleId, nameof(ruleId));
+
+ if (!IsInRule(ruleId))
+ {
+ return;
+ }
+
+ Rules.RemoveAll(r => r.RuleId == ruleId);
+ }
+
+ public virtual bool IsInRule([NotNull] Guid ruleId)
+ {
+ Check.NotNull(ruleId, nameof(ruleId));
+
+ return Rules.Any(r => r.RuleId == ruleId);
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleInGroup.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleInGroup.cs
new file mode 100644
index 000000000..276ae1d69
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleInGroup.cs
@@ -0,0 +1,35 @@
+using JetBrains.Annotations;
+using System;
+using Volo.Abp;
+using Volo.Abp.Domain.Entities;
+using Volo.Abp.MultiTenancy;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ public class EntityRuleInGroup : Entity, IMultiTenant
+ {
+ public virtual Guid? TenantId { get; protected set; }
+ public virtual Guid RuleId { get; protected set; }
+ public virtual Guid GroupId { get; protected set; }
+ protected EntityRuleInGroup()
+ {
+ }
+
+ public EntityRuleInGroup(
+ [NotNull] Guid ruleId,
+ [NotNull] Guid groupId,
+ [CanBeNull] Guid? tenantId = null)
+ {
+ Check.NotNull(ruleId, nameof(ruleId));
+ Check.NotNull(groupId, nameof(groupId));
+
+ RuleId = ruleId;
+ GroupId = groupId;
+ TenantId = tenantId;
+ }
+ public override object[] GetKeys()
+ {
+ return new object[] { RuleId, GroupId };
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleInject.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleInject.cs
new file mode 100644
index 000000000..719777950
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleInject.cs
@@ -0,0 +1,39 @@
+using JetBrains.Annotations;
+using System;
+using Volo.Abp;
+using Volo.Abp.Domain.Entities;
+using Volo.Abp.MultiTenancy;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ public class EntityRuleInject : Entity, IMultiTenant
+ {
+ public virtual Guid? TenantId { get; protected set; }
+ ///
+ /// 规则标识
+ ///
+ public virtual Guid RuleId { get; protected set; }
+ ///
+ /// 依赖的规则标识
+ ///
+ public virtual Guid InjectId { get; protected set; }
+
+ protected EntityRuleInject() { }
+ public EntityRuleInject(
+ [NotNull] Guid ruleId,
+ [NotNull] Guid injectId,
+ [CanBeNull] Guid? tenantId = null)
+ {
+ Check.NotNull(ruleId, nameof(ruleId));
+ Check.NotNull(injectId, nameof(injectId));
+
+ RuleId = ruleId;
+ InjectId = injectId;
+ TenantId = tenantId;
+ }
+ public override object[] GetKeys()
+ {
+ return new object[] { RuleId , InjectId };
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleParam.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleParam.cs
new file mode 100644
index 000000000..d91d597ab
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntityRuleParam.cs
@@ -0,0 +1,44 @@
+using JetBrains.Annotations;
+using System;
+using System.Collections.Generic;
+using Volo.Abp;
+using Volo.Abp.Data;
+using Volo.Abp.Domain.Entities;
+using Volo.Abp.MultiTenancy;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ public class EntityRuleParam : Entity, IMultiTenant, IHasExtraProperties
+ {
+ public virtual Guid? TenantId { get; protected set; }
+ public virtual Guid RuleId { get; protected set; }
+ public virtual string Name { get; protected set; }
+ public virtual string Expression { get; protected set; }
+
+ public virtual Dictionary ExtraProperties { get; protected set; }
+
+ protected EntityRuleParam()
+ {
+ }
+ public EntityRuleParam(
+ [NotNull] Guid id,
+ [NotNull] Guid ruleId,
+ [NotNull] string name,
+ [NotNull] string expression,
+ [CanBeNull] Guid? tenantId = null)
+ {
+ Check.NotNull(id, nameof(id));
+ Check.NotNull(ruleId, nameof(ruleId));
+ Check.NotNullOrWhiteSpace(name, nameof(name), EntityRuleParamConsts.MaxNameLength);
+ Check.NotNullOrWhiteSpace(expression, nameof(expression), EntityRuleParamConsts.MaxExpressionLength);
+
+ Id = id;
+ RuleId = ruleId;
+ Name = name;
+ Expression = expression;
+ TenantId = tenantId;
+
+ ExtraProperties = new Dictionary();
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntitySubRule.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntitySubRule.cs
new file mode 100644
index 000000000..a2e444f1a
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/EntitySubRule.cs
@@ -0,0 +1,35 @@
+using JetBrains.Annotations;
+using System;
+using Volo.Abp;
+using Volo.Abp.Domain.Entities;
+using Volo.Abp.MultiTenancy;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ public class EntitySubRule : Entity, IMultiTenant
+ {
+ public virtual Guid? TenantId { get; protected set; }
+ public virtual Guid RuleId { get; protected set; }
+ public virtual Guid SubId { get; protected set; }
+ protected EntitySubRule()
+ {
+ }
+
+ public EntitySubRule(
+ [NotNull] Guid ruleId,
+ [NotNull] Guid subId,
+ [CanBeNull] Guid? tenantId = null)
+ {
+ Check.NotNull(ruleId, nameof(ruleId));
+ Check.NotNull(subId, nameof(subId));
+
+ RuleId = ruleId;
+ SubId = subId;
+ TenantId = tenantId;
+ }
+ public override object[] GetKeys()
+ {
+ return new object[] { RuleId, SubId };
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/IEntityRuleDataSeeder.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/IEntityRuleDataSeeder.cs
new file mode 100644
index 000000000..f65b19fc1
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/IEntityRuleDataSeeder.cs
@@ -0,0 +1,9 @@
+using System.Threading.Tasks;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ public interface IEntityRuleDataSeeder
+ {
+ Task SeedAsync(EntityRuleInGroup group);
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/IEntityRuleGroupRepository.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/IEntityRuleGroupRepository.cs
new file mode 100644
index 000000000..bfd11e89e
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/IEntityRuleGroupRepository.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using Volo.Abp.Domain.Repositories;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ public interface IEntityRuleGroupRepository : IBasicRepository
+ {
+ Task GetByNameAsync(
+ string name,
+ bool includeDetails = false,
+ CancellationToken cancellationToken = default
+ );
+ Task> GetListByTypeAsync(
+ string entityFullTypeName,
+ string sorting = null,
+ bool includeDetails = false,
+ CancellationToken cancellationToken = default);
+
+ Task> GetRulesAsync(
+ Guid groupId,
+ bool includeDetails = false,
+ CancellationToken cancellationToken = default);
+
+
+ Task GetCountAsync(
+ string filter = null,
+ CancellationToken cancellationToken = default);
+
+ Task> GetListAsync(
+ string filter = null,
+ string sorting = null,
+ int skipCount = 1,
+ int maxResultCount = 10,
+ bool includeDetails = false,
+ CancellationToken cancellationToken = default);
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/IEntityRuleRepository.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/IEntityRuleRepository.cs
new file mode 100644
index 000000000..328069f5d
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/IEntityRuleRepository.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using Volo.Abp.Domain.Repositories;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ public interface IEntityRuleRepository : IBasicRepository
+ {
+ Task> GetInjectRuleNamesAsync(
+ Guid ruleId,
+ bool includeDetails = false,
+ CancellationToken cancellationToken = default
+ );
+
+ Task> GetInjectRulesAsync(
+ Guid ruleId,
+ bool includeDetails = false,
+ CancellationToken cancellationToken = default
+ );
+
+ Task GetCountAsync(
+ string filter = null,
+ CancellationToken cancellationToken = default);
+
+ Task> GetListAsync(
+ string filter = null,
+ string sorting = null,
+ int skipCount = 1,
+ int maxResultCount = 10,
+ bool includeDetails = false,
+ CancellationToken cancellationToken = default);
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/RulesManagementDbProperties.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/RulesManagementDbProperties.cs
new file mode 100644
index 000000000..4d17f2d08
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/RulesManagementDbProperties.cs
@@ -0,0 +1,13 @@
+using Volo.Abp.Data;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ public static class RulesManagementDbProperties
+ {
+ public static string DbTablePrefix { get; set; } = "App";
+
+ public static string DbSchema { get; set; } = AbpCommonDbProperties.DbSchema;
+
+ public const string ConnectionStringName = "AppRulesManagement";
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/RulesManagementMapperProfile.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/RulesManagementMapperProfile.cs
new file mode 100644
index 000000000..9b777112b
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.Domain/LINGYUN/Abp/RulesManagement/RulesManagementMapperProfile.cs
@@ -0,0 +1,22 @@
+using AutoMapper;
+using LINGYUN.Abp.Rules;
+
+namespace LINGYUN.Abp.RulesManagement
+{
+ public class RulesManagementMapperProfile : Profile
+ {
+ public RulesManagementMapperProfile()
+ {
+ CreateMap();
+ CreateMap()
+ .ForMember(rule => rule.InjectRules, map => map.Ignore())
+ .ForMember(rule => rule.Rules, map => map.Ignore());
+ CreateMap()
+ .ForMember(rule => rule.InjectRules, map => map.Ignore())
+ .ForMember(rule => rule.Rules, map => map.Ignore());
+
+ CreateMap();
+ CreateMap();
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN.Abp.RulesManagement.EntityFrameworkCore.csproj b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN.Abp.RulesManagement.EntityFrameworkCore.csproj
new file mode 100644
index 000000000..754a0bc46
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN.Abp.RulesManagement.EntityFrameworkCore.csproj
@@ -0,0 +1,18 @@
+
+
+
+
+
+ netstandard2.0
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/AbpRulesManagementEntityFrameworkCoreModule.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/AbpRulesManagementEntityFrameworkCoreModule.cs
new file mode 100644
index 000000000..12ed7a034
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/AbpRulesManagementEntityFrameworkCoreModule.cs
@@ -0,0 +1,21 @@
+using Microsoft.Extensions.DependencyInjection;
+using Volo.Abp.EntityFrameworkCore;
+using Volo.Abp.Modularity;
+
+namespace LINGYUN.Abp.RulesManagement.EntityFrameworkCore
+{
+ [DependsOn(
+ typeof(AbpRulesManagementDomainModule),
+ typeof(AbpEntityFrameworkCoreModule))]
+ public class AbpRulesManagementEntityFrameworkCoreModule : AbpModule
+ {
+ public override void ConfigureServices(ServiceConfigurationContext context)
+ {
+ context.Services.AddAbpDbContext(options =>
+ {
+ options.AddRepository();
+ options.AddRepository();
+ });
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/EfCoreEntityRuleGroupRepository.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/EfCoreEntityRuleGroupRepository.cs
new file mode 100644
index 000000000..bf3ea09a1
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/EfCoreEntityRuleGroupRepository.cs
@@ -0,0 +1,98 @@
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Dynamic.Core;
+using System.Threading;
+using System.Threading.Tasks;
+using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
+using Volo.Abp.EntityFrameworkCore;
+
+namespace LINGYUN.Abp.RulesManagement.EntityFrameworkCore
+{
+ public class EfCoreEntityRuleGroupRepository : EfCoreRepository, IEntityRuleGroupRepository
+ {
+ public EfCoreEntityRuleGroupRepository(
+ IDbContextProvider dbContextProvider)
+ : base(dbContextProvider)
+ {
+ }
+
+ public virtual async Task GetByNameAsync(
+ string name,
+ bool includeDetails = false,
+ CancellationToken cancellationToken = default)
+ {
+ return await this
+ .Where(ug => ug.Name.Equals(name))
+ .FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
+ }
+
+ public virtual async Task> GetRulesAsync(
+ Guid groupId,
+ bool includeDetails = false,
+ CancellationToken cancellationToken = default)
+ {
+ var query = from ruleGroup in DbContext.Set()
+ join rule in DbContext.EntityRules.IncludeDetails(includeDetails) on ruleGroup.RuleId equals rule.Id
+ where ruleGroup.GroupId == groupId
+ select rule;
+
+ return await query.ToListAsync(GetCancellationToken(cancellationToken));
+ }
+
+ public virtual async Task GetCountAsync(
+ string filter = null,
+ CancellationToken cancellationToken = default)
+ {
+ return await this.WhereIf(
+ !filter.IsNullOrWhiteSpace(),
+ rg =>
+ rg.Name.Contains(filter) ||
+ rg.DisplayName.Contains(filter) ||
+ rg.EntityFullTypeName.Contains(filter)
+ )
+ .LongCountAsync(GetCancellationToken(cancellationToken));
+ }
+
+ public virtual async Task> GetListByTypeAsync(
+ string entityFullTypeName,
+ string sorting = null,
+ bool includeDetails = false,
+ CancellationToken cancellationToken = default)
+ {
+ return await DbSet
+ .IncludeDetails(includeDetails)
+ .Where(ug => ug.EntityFullTypeName.Equals(entityFullTypeName))
+ .OrderBy(sorting ?? nameof(EntityRuleGroup.CreationTime))
+ .ToListAsync(GetCancellationToken(cancellationToken));
+ }
+
+ public virtual async Task> GetListAsync(
+ string filter = null,
+ string sorting = null,
+ int skipCount = 1,
+ int maxResultCount = 10,
+ bool includeDetails = false,
+ CancellationToken cancellationToken = default)
+ {
+ return await DbSet
+ .IncludeDetails(includeDetails)
+ .WhereIf(
+ !filter.IsNullOrWhiteSpace(),
+ rg =>
+ rg.Name.Contains(filter) ||
+ rg.DisplayName.Contains(filter) ||
+ rg.EntityFullTypeName.Contains(filter)
+ )
+ .OrderBy(sorting ?? nameof(EntityRuleGroup.CreationTime))
+ .PageBy(skipCount, maxResultCount)
+ .ToListAsync(GetCancellationToken(cancellationToken));
+ }
+
+ public override IQueryable WithDetails()
+ {
+ return GetQueryable().IncludeDetails();
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/EfCoreEntityRuleRepository.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/EfCoreEntityRuleRepository.cs
new file mode 100644
index 000000000..e06fb3352
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/EfCoreEntityRuleRepository.cs
@@ -0,0 +1,76 @@
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Dynamic.Core;
+using System.Threading;
+using System.Threading.Tasks;
+using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
+using Volo.Abp.EntityFrameworkCore;
+
+namespace LINGYUN.Abp.RulesManagement.EntityFrameworkCore
+{
+ public class EfCoreEntityRuleRepository : EfCoreRepository, IEntityRuleRepository
+ {
+ public EfCoreEntityRuleRepository(
+ IDbContextProvider dbContextProvider)
+ : base(dbContextProvider)
+ {
+ }
+
+ public virtual async Task> GetInjectRulesAsync(
+ Guid ruleId,
+ bool includeDetails = false,
+ CancellationToken cancellationToken = default
+ )
+ {
+ var query = from injectRule in DbContext.Set()
+ join rule in DbContext.EntityRules.IncludeDetails(includeDetails) on injectRule.InjectId equals rule.Id
+ where injectRule.RuleId == ruleId
+ select rule;
+
+ return await query.ToListAsync(GetCancellationToken(cancellationToken));
+ }
+
+ public virtual async Task GetCountAsync(
+ string filter = null,
+ CancellationToken cancellationToken = default)
+ {
+ return await this
+ .WhereIf(
+ !filter.IsNullOrWhiteSpace(),
+ rg =>
+ rg.Name.Contains(filter) ||
+ rg.DisplayName.Contains(filter) ||
+ rg.Operator.Contains(filter)
+ )
+ .LongCountAsync(GetCancellationToken(cancellationToken));
+ }
+
+ public virtual async Task> GetListAsync(
+ string filter = null,
+ string sorting = null,
+ int skipCount = 1,
+ int maxResultCount = 10,
+ bool includeDetails = false,
+ CancellationToken cancellationToken = default)
+ {
+ return await this
+ .WhereIf(
+ !filter.IsNullOrWhiteSpace(),
+ rg =>
+ rg.Name.Contains(filter) ||
+ rg.DisplayName.Contains(filter) ||
+ rg.Operator.Contains(filter)
+ )
+ .OrderBy(sorting ?? nameof(EntityRule.CreationTime))
+ .PageBy(skipCount, maxResultCount)
+ .ToListAsync(GetCancellationToken(cancellationToken));
+ }
+
+ public override IQueryable WithDetails()
+ {
+ return GetQueryable().IncludeDetails();
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/IRulesManagementDbContext.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/IRulesManagementDbContext.cs
new file mode 100644
index 000000000..b8381df99
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/IRulesManagementDbContext.cs
@@ -0,0 +1,13 @@
+using Microsoft.EntityFrameworkCore;
+using Volo.Abp.Data;
+using Volo.Abp.EntityFrameworkCore;
+
+namespace LINGYUN.Abp.RulesManagement.EntityFrameworkCore
+{
+ [ConnectionStringName(RulesManagementDbProperties.ConnectionStringName)]
+ public interface IRulesManagementDbContext : IEfCoreDbContext
+ {
+ DbSet EntityRules { get; set; }
+ DbSet EntityRuleGroups { get; set; }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/RulesManagementDbContext.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/RulesManagementDbContext.cs
new file mode 100644
index 000000000..af6df87ee
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/RulesManagementDbContext.cs
@@ -0,0 +1,25 @@
+using Microsoft.EntityFrameworkCore;
+using Volo.Abp.Data;
+using Volo.Abp.EntityFrameworkCore;
+
+namespace LINGYUN.Abp.RulesManagement.EntityFrameworkCore
+{
+ [ConnectionStringName(RulesManagementDbProperties.ConnectionStringName)]
+ public class RulesManagementDbContext : AbpDbContext, IRulesManagementDbContext
+ {
+ public DbSet EntityRules { get; set; }
+ public DbSet EntityRuleGroups { get; set; }
+
+ public RulesManagementDbContext(
+ DbContextOptions options) : base(options)
+ {
+ }
+
+ protected override void OnModelCreating(ModelBuilder builder)
+ {
+ base.OnModelCreating(builder);
+
+ builder.ConfigureRulesManagement();
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/RulesManagementDbContextModelBuilderExtensions.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/RulesManagementDbContextModelBuilderExtensions.cs
new file mode 100644
index 000000000..01b48b017
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/RulesManagementDbContextModelBuilderExtensions.cs
@@ -0,0 +1,81 @@
+using JetBrains.Annotations;
+using Microsoft.EntityFrameworkCore;
+using System;
+using Volo.Abp;
+using Volo.Abp.EntityFrameworkCore.Modeling;
+
+namespace LINGYUN.Abp.RulesManagement.EntityFrameworkCore
+{
+ public static class RulesManagementDbContextModelBuilderExtensions
+ {
+ public static void ConfigureRulesManagement(
+ [NotNull] this ModelBuilder builder,
+ [CanBeNull] Action optionsAction = null)
+ {
+ Check.NotNull(builder, nameof(builder));
+
+ var options = new RulesManagementModelBuilderConfigurationOptions(
+ RulesManagementDbProperties.DbTablePrefix,
+ RulesManagementDbProperties.DbSchema
+ );
+
+ optionsAction?.Invoke(options);
+
+ builder.Entity(b =>
+ {
+ b.ToTable(options.TablePrefix + "EntityRuleParams", options.Schema);
+
+ b.ConfigureMultiTenant();
+ b.ConfigureExtraProperties();
+
+ b.Property(x => x.Id).ValueGeneratedNever();
+
+ b.Property(rp => rp.Name).HasMaxLength(EntityRuleParamConsts.MaxNameLength).IsRequired();
+ b.Property(rp => rp.Expression).HasMaxLength(EntityRuleParamConsts.MaxExpressionLength).IsRequired();
+
+ b.HasIndex(rp => rp.Name);
+ });
+
+ builder.Entity(b =>
+ {
+ b.ToTable(options.TablePrefix + "EntityRules", options.Schema);
+
+ b.ConfigureByConvention();
+
+ b.Property(x => x.Id).ValueGeneratedNever();
+
+ b.Property(r => r.Name).HasMaxLength(EntityRuleConsts.MaxNameLength).IsRequired();
+ b.Property(r => r.Expression).HasMaxLength(EntityRuleConsts.MaxExpressionLength).IsRequired();
+
+ b.Property(r => r.Operator).HasMaxLength(EntityRuleConsts.MaxOperatorLength);
+ b.Property(r => r.DisplayName).HasMaxLength(EntityRuleConsts.MaxDisplayNameLength);
+ b.Property(r => r.ErrorMessage).HasMaxLength(EntityRuleConsts.MaxErrorMessageLength);
+
+ b.HasMany(r => r.SubRules).WithOne().HasForeignKey(r => r.RuleId).IsRequired();
+ b.HasMany(r => r.InjectRules).WithOne().HasForeignKey(r => r.InjectId).IsRequired();
+ b.HasMany(r => r.Params).WithOne().HasForeignKey(r => r.RuleId).IsRequired();
+
+ b.HasIndex(r => r.Name);
+ });
+
+ builder.Entity(b =>
+ {
+ b.ToTable(options.TablePrefix + "EntityRuleGroups", options.Schema);
+
+ b.ConfigureByConvention();
+
+ b.Property(x => x.Id).ValueGeneratedNever();
+
+ b.Property(rg => rg.Name).HasMaxLength(EntityRuleGroupConsts.MaxNameLength).IsRequired();
+ b.Property(rg => rg.EntityFullTypeName).HasMaxLength(EntityRuleGroupConsts.MaxEntiyFullTypeNameLength).IsRequired();
+
+ b.Property(rg => rg.DisplayName).HasMaxLength(EntityRuleGroupConsts.MaxDisplayNameLength);
+
+ b.HasMany(rg => rg.Rules).WithOne().HasForeignKey(rg => rg.GroupId).IsRequired();
+ b.HasMany(rg => rg.InjectRules).WithOne().HasForeignKey(rg => rg.InjectId).IsRequired();
+
+ b.HasIndex(uc => uc.Name);
+ });
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/RulesManagementEfCoreQueryableExtensions.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/RulesManagementEfCoreQueryableExtensions.cs
new file mode 100644
index 000000000..8d1d04b57
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/RulesManagementEfCoreQueryableExtensions.cs
@@ -0,0 +1,32 @@
+using Microsoft.EntityFrameworkCore;
+using System.Linq;
+
+namespace LINGYUN.Abp.RulesManagement.EntityFrameworkCore
+{
+ public static class RulesManagementEfCoreQueryableExtensions
+ {
+ public static IQueryable IncludeDetails(this IQueryable queryable, bool include = true)
+ {
+ if (!include)
+ {
+ return queryable;
+ }
+
+ return queryable
+ .Include(x => x.Rules)
+ .Include(x => x.InjectRules);
+ }
+
+ public static IQueryable IncludeDetails(this IQueryable queryable, bool include = true)
+ {
+ if (!include)
+ {
+ return queryable;
+ }
+
+ return queryable
+ .Include(x => x.InjectRules)
+ .Include(x => x.Params);
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/RulesManagementModelBuilderConfigurationOptions.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/RulesManagementModelBuilderConfigurationOptions.cs
new file mode 100644
index 000000000..487335f4a
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.EntityFrameworkCore/LINGYUN/Abp/RulesManagement/EntityFrameworkCore/RulesManagementModelBuilderConfigurationOptions.cs
@@ -0,0 +1,15 @@
+using JetBrains.Annotations;
+using Volo.Abp.EntityFrameworkCore.Modeling;
+
+namespace LINGYUN.Abp.RulesManagement.EntityFrameworkCore
+{
+ public class RulesManagementModelBuilderConfigurationOptions : AbpModelBuilderConfigurationOptions
+ {
+ public RulesManagementModelBuilderConfigurationOptions(
+ [NotNull] string tablePrefix,
+ [CanBeNull] string schema)
+ : base(tablePrefix, schema)
+ {
+ }
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.HttpApi.Client/Class1.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.HttpApi.Client/Class1.cs
new file mode 100644
index 000000000..7a72d8e6b
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.HttpApi.Client/Class1.cs
@@ -0,0 +1,8 @@
+using System;
+
+namespace LINGYUN.Abp.RulesManagement.HttpApi.Client
+{
+ public class Class1
+ {
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.HttpApi.Client/LINGYUN.Abp.RulesManagement.HttpApi.Client.csproj b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.HttpApi.Client/LINGYUN.Abp.RulesManagement.HttpApi.Client.csproj
new file mode 100644
index 000000000..d51795862
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.HttpApi.Client/LINGYUN.Abp.RulesManagement.HttpApi.Client.csproj
@@ -0,0 +1,18 @@
+
+
+
+
+
+ netstandard2.0
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.HttpApi/Class1.cs b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.HttpApi/Class1.cs
new file mode 100644
index 000000000..c31d24e5a
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.HttpApi/Class1.cs
@@ -0,0 +1,8 @@
+using System;
+
+namespace LINGYUN.Abp.RulesManagement.HttpApi
+{
+ public class Class1
+ {
+ }
+}
diff --git a/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.HttpApi/LINGYUN.Abp.RulesManagement.HttpApi.csproj b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.HttpApi/LINGYUN.Abp.RulesManagement.HttpApi.csproj
new file mode 100644
index 000000000..aa4f9a3d3
--- /dev/null
+++ b/aspnet-core/modules/rules-management/LINGYUN.Abp.RulesManagement.HttpApi/LINGYUN.Abp.RulesManagement.HttpApi.csproj
@@ -0,0 +1,18 @@
+
+
+
+
+
+ netcoreapp3.1
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/aspnet-core/modules/rules-management/README.md b/aspnet-core/modules/rules-management/README.md
new file mode 100644
index 000000000..104f3341d
--- /dev/null
+++ b/aspnet-core/modules/rules-management/README.md
@@ -0,0 +1,9 @@
+# LINGYUN.Abp.RulesManagement
+
+规则引擎管理
+
+想法很美好,现实很残酷,.NET平台还没有Java阵营那么强大的规则引擎,目前还在研究NRules.Language库,这个库应该可以实现简单的规则动态管理
+
+## 配置使用
+
+待完善
\ No newline at end of file