diff --git a/OpenAuth.App/AppManager.cs b/OpenAuth.App/AppManager.cs
index 506183d6..083abbd4 100644
--- a/OpenAuth.App/AppManager.cs
+++ b/OpenAuth.App/AppManager.cs
@@ -13,7 +13,7 @@ namespace OpenAuth.App
///
/// 分类管理
///
- public class AppManager : BaseApp
+ public class AppManager : BaseStringApp
{
public void Add(Application Application)
{
diff --git a/OpenAuth.App/AuthStrategies/NormalAuthStrategy.cs b/OpenAuth.App/AuthStrategies/NormalAuthStrategy.cs
index 05aae88f..f0ef8abe 100644
--- a/OpenAuth.App/AuthStrategies/NormalAuthStrategy.cs
+++ b/OpenAuth.App/AuthStrategies/NormalAuthStrategy.cs
@@ -28,7 +28,7 @@ namespace OpenAuth.App
///
/// 普通用户授权策略
///
- public class NormalAuthStrategy :BaseApp, IAuthStrategy
+ public class NormalAuthStrategy :BaseStringApp, IAuthStrategy
{
protected User _user;
diff --git a/OpenAuth.App/AuthStrategies/SystemAuthStrategy.cs b/OpenAuth.App/AuthStrategies/SystemAuthStrategy.cs
index 4f4dd06d..87d90d02 100644
--- a/OpenAuth.App/AuthStrategies/SystemAuthStrategy.cs
+++ b/OpenAuth.App/AuthStrategies/SystemAuthStrategy.cs
@@ -30,7 +30,7 @@ namespace OpenAuth.App
/// 超级管理员权限
/// 超级管理员使用guid.empty为ID,可以根据需要修改
///
- public class SystemAuthStrategy : BaseApp, IAuthStrategy
+ public class SystemAuthStrategy : BaseStringApp, IAuthStrategy
{
protected User _user;
private DbExtension _dbExtension;
diff --git a/OpenAuth.App/Base/BaseApp.cs b/OpenAuth.App/Base/BaseApp.cs
index 35c32765..97549e3b 100644
--- a/OpenAuth.App/Base/BaseApp.cs
+++ b/OpenAuth.App/Base/BaseApp.cs
@@ -9,12 +9,7 @@ using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
- ///
- /// 业务层基类,UnitWork用于事务操作,Repository用于普通的数据库操作
- /// 如用户管理:Class UserManagerApp:BaseApp
- ///
- ///
- public class BaseApp where T : StringEntity where TDbContext: DbContext
+ public abstract class BaseApp where T : class where TDbContext: DbContext
{
///
/// 用于普通的数据库操作
@@ -70,21 +65,7 @@ namespace OpenAuth.App
return UnitWork.Find(null).GenerateFilter(parametername,
JsonHelper.Instance.Deserialize(rule.PrivilegeRules));
}
-
- ///
- /// 按id批量删除
- ///
- ///
- public virtual void Delete(string[] ids)
- {
- Repository.Delete(u => ids.Contains(u.Id));
- }
-
- public T Get(string id)
- {
- return Repository.FirstOrDefault(u => u.Id == id);
- }
-
+
///
/// 计算实体更新的层级信息
///
diff --git a/OpenAuth.App/Base/BaseIntAutoGenApp.cs b/OpenAuth.App/Base/BaseIntAutoGenApp.cs
new file mode 100644
index 00000000..88437679
--- /dev/null
+++ b/OpenAuth.App/Base/BaseIntAutoGenApp.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Linq;
+using Infrastructure;
+using Microsoft.EntityFrameworkCore;
+using OpenAuth.App.Interface;
+using OpenAuth.Repository.Core;
+using OpenAuth.Repository.Domain;
+using OpenAuth.Repository.Interface;
+
+namespace OpenAuth.App
+{
+ ///
+ /// 数据库Id为numberic且为数据库自动生成的业务类型
+ /// 该场景通常为SqlServer的自动增长类型和Oracle自带的Sequence
+ /// 业务层基类,UnitWork用于事务操作,Repository用于普通的数据库操作
+ ///
+ ///
+ public class BaseIntAutoGenApp :BaseApp where T : IntAutoGenEntity where TDbContext: DbContext
+ {
+ public BaseIntAutoGenApp(IUnitWork unitWork, IRepository repository, IAuth auth) : base(unitWork, repository, auth)
+ {
+ UnitWork = unitWork;
+ Repository = repository;
+ _auth = auth;
+ }
+
+ ///
+ /// 按id批量删除
+ ///
+ ///
+ public void Delete(int[] ids)
+ {
+ Repository.Delete(u => ids.Contains(u.Id));
+ }
+
+ public T Get(int id)
+ {
+ return Repository.FirstOrDefault(u => u.Id == id);
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenAuth.App/Base/BaseLongApp.cs b/OpenAuth.App/Base/BaseLongApp.cs
index 5ca20d03..48ca2af9 100644
--- a/OpenAuth.App/Base/BaseLongApp.cs
+++ b/OpenAuth.App/Base/BaseLongApp.cs
@@ -12,10 +12,9 @@ namespace OpenAuth.App
///
/// ⭐⭐数据库Id为numberic类型的数据表相关业务使用该基类⭐⭐
/// 业务层基类,UnitWork用于事务操作,Repository用于普通的数据库操作
- /// 如用户管理:Class UserManagerApp:BaseApp
///
///
- public class BaseLongApp where T : LongEntity where TDbContext: DbContext
+ public class BaseLongApp :BaseApp where T : LongEntity where TDbContext: DbContext
{
///
/// 用于普通的数据库操作
@@ -30,53 +29,19 @@ namespace OpenAuth.App
protected IAuth _auth;
- public BaseLongApp(IUnitWork unitWork, IRepository repository, IAuth auth)
+ public BaseLongApp(IUnitWork unitWork, IRepository repository, IAuth auth) : base(unitWork, repository,auth)
{
UnitWork = unitWork;
Repository = repository;
_auth = auth;
}
-
- ///
- /// 获取当前登录用户的数据访问权限
- ///
- /// linq表达式参数的名称,如u=>u.name中的"u"
- ///
- protected IQueryable GetDataPrivilege(string parametername)
- {
- var loginUser = _auth.GetCurrentUser();
- if (loginUser.User.Account == Define.SYSTEM_USERNAME) return UnitWork.Find(null); //超级管理员特权
-
- var moduleName = typeof(T).Name;
- var rule = UnitWork.FirstOrDefault(u => u.SourceCode == moduleName);
- if (rule == null) return UnitWork.Find(null); //没有设置数据规则,那么视为该资源允许被任何主体查看
- if (rule.PrivilegeRules.Contains(Define.DATAPRIVILEGE_LOGINUSER) ||
- rule.PrivilegeRules.Contains(Define.DATAPRIVILEGE_LOGINROLE)||
- rule.PrivilegeRules.Contains(Define.DATAPRIVILEGE_LOGINORG))
- {
-
- //即把{loginUser} =='xxxxxxx'换为 loginUser.User.Id =='xxxxxxx',从而把当前登录的用户名与当时设计规则时选定的用户id对比
- rule.PrivilegeRules = rule.PrivilegeRules.Replace(Define.DATAPRIVILEGE_LOGINUSER, loginUser.User.Id);
-
- var roles = loginUser.Roles.Select(u => u.Id).ToList();
- roles.Sort(); //按字母排序,这样可以进行like操作
- rule.PrivilegeRules = rule.PrivilegeRules.Replace(Define.DATAPRIVILEGE_LOGINROLE,
- string.Join(',',roles));
-
- var orgs = loginUser.Orgs.Select(u => u.Id).ToList();
- orgs.Sort();
- rule.PrivilegeRules = rule.PrivilegeRules.Replace(Define.DATAPRIVILEGE_LOGINORG,
- string.Join(',',orgs));
- }
- return UnitWork.Find(null).GenerateFilter(parametername,
- JsonHelper.Instance.Deserialize(rule.PrivilegeRules));
- }
+
///
/// 按id批量删除
///
///
- public virtual void Delete(long[] ids)
+ public void Delete(long[] ids)
{
Repository.Delete(u => ids.Contains(u.Id));
}
@@ -85,44 +50,5 @@ namespace OpenAuth.App
{
return Repository.FirstOrDefault(u => u.Id == id);
}
-
- ///
- /// 计算实体更新的层级信息
- ///
- /// U必须是一个继承TreeEntity的结构
- ///
- public void CaculateCascade(U entity) where U : TreeEntity
- {
- if (entity.ParentId == "") entity.ParentId = null;
- string cascadeId;
- int currentCascadeId = 1; //当前结点的级联节点最后一位
- var sameLevels = UnitWork.Find(o => o.ParentId == entity.ParentId && o.Id != entity.Id);
- foreach (var obj in sameLevels)
- {
- int objCascadeId = int.Parse(obj.CascadeId.TrimEnd('.').Split('.').Last());
- if (currentCascadeId <= objCascadeId) currentCascadeId = objCascadeId + 1;
- }
-
- if (!string.IsNullOrEmpty(entity.ParentId))
- {
- var parentOrg = UnitWork.FirstOrDefault(o => o.Id == entity.ParentId);
- if (parentOrg != null)
- {
- cascadeId = parentOrg.CascadeId + currentCascadeId + ".";
- entity.ParentName = parentOrg.Name;
- }
- else
- {
- throw new Exception("未能找到该组织的父节点信息");
- }
- }
- else
- {
- cascadeId = ".0." + currentCascadeId + ".";
- entity.ParentName = "根节点";
- }
-
- entity.CascadeId = cascadeId;
- }
}
}
\ No newline at end of file
diff --git a/OpenAuth.App/Base/BaseStringApp.cs b/OpenAuth.App/Base/BaseStringApp.cs
new file mode 100644
index 00000000..b3e4c668
--- /dev/null
+++ b/OpenAuth.App/Base/BaseStringApp.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Linq;
+using Infrastructure;
+using Microsoft.EntityFrameworkCore;
+using OpenAuth.App.Interface;
+using OpenAuth.Repository.Core;
+using OpenAuth.Repository.Domain;
+using OpenAuth.Repository.Interface;
+
+namespace OpenAuth.App
+{
+ ///
+ /// 业务层基类,UnitWork用于事务操作,Repository用于普通的数据库操作
+ /// 如用户管理:Class UserManagerApp:BaseApp
+ ///
+ ///
+ public class BaseStringApp :BaseApp where T : StringEntity where TDbContext: DbContext
+ {
+ ///
+ /// 用于普通的数据库操作
+ ///
+ protected IRepository Repository;
+
+ ///
+ /// 用于事务操作
+ /// 使用详见:http://doc.openauth.me/core/unitwork.html
+ ///
+ protected IUnitWork UnitWork;
+
+ protected IAuth _auth;
+
+ public BaseStringApp(IUnitWork unitWork, IRepository repository, IAuth auth) : base(unitWork, repository, auth)
+ {
+ UnitWork = unitWork;
+ Repository = repository;
+ _auth = auth;
+ }
+
+ ///
+ /// 按id批量删除
+ ///
+ ///
+ public virtual void Delete(string[] ids)
+ {
+ Repository.Delete(u => ids.Contains(u.Id));
+ }
+
+ public T Get(string id)
+ {
+ return Repository.FirstOrDefault(u => u.Id == id);
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/OpenAuth.App/Base/BaseTreeApp.cs b/OpenAuth.App/Base/BaseTreeApp.cs
index 099b3c89..7d75aa61 100644
--- a/OpenAuth.App/Base/BaseTreeApp.cs
+++ b/OpenAuth.App/Base/BaseTreeApp.cs
@@ -10,7 +10,7 @@ namespace OpenAuth.App
/// 树状结构处理
///
///
- public class BaseTreeApp :BaseApp where T : TreeEntity where TDbContext :DbContext
+ public class BaseTreeApp :BaseStringApp where T : TreeEntity where TDbContext :DbContext
{
diff --git a/OpenAuth.App/BuilderTableApp.cs b/OpenAuth.App/BuilderTableApp.cs
index de1c8b7f..ca0bef82 100644
--- a/OpenAuth.App/BuilderTableApp.cs
+++ b/OpenAuth.App/BuilderTableApp.cs
@@ -24,7 +24,7 @@ using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
- public class BuilderTableApp : BaseApp
+ public class BuilderTableApp : BaseStringApp
{
private BuilderTableColumnApp _builderTableColumnApp;
private CategoryApp _categoryApp;
diff --git a/OpenAuth.App/BuilderTableColumnApp.cs b/OpenAuth.App/BuilderTableColumnApp.cs
index 3dce69ac..4b4839ed 100644
--- a/OpenAuth.App/BuilderTableColumnApp.cs
+++ b/OpenAuth.App/BuilderTableColumnApp.cs
@@ -13,7 +13,7 @@ using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
- public class BuilderTableColumnApp : BaseApp
+ public class BuilderTableColumnApp : BaseStringApp
{
public BuilderTableColumnApp(IUnitWork unitWork, IRepository repository,
IAuth auth) : base(unitWork, repository,auth)
diff --git a/OpenAuth.App/CategoryApp.cs b/OpenAuth.App/CategoryApp.cs
index cd8bb5e1..382cdbde 100644
--- a/OpenAuth.App/CategoryApp.cs
+++ b/OpenAuth.App/CategoryApp.cs
@@ -13,7 +13,7 @@ using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
- public class CategoryApp : BaseApp
+ public class CategoryApp : BaseStringApp
{
///
/// 加载列表
diff --git a/OpenAuth.App/CategoryTypeApp.cs b/OpenAuth.App/CategoryTypeApp.cs
index 079a2084..851bc443 100644
--- a/OpenAuth.App/CategoryTypeApp.cs
+++ b/OpenAuth.App/CategoryTypeApp.cs
@@ -13,7 +13,7 @@ using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
- public class CategoryTypeApp : BaseApp
+ public class CategoryTypeApp : BaseStringApp
{
private RevelanceManagerApp _revelanceApp;
diff --git a/OpenAuth.App/DataPrivilegeRuleApp.cs b/OpenAuth.App/DataPrivilegeRuleApp.cs
index 87544f5c..76d0d4c4 100644
--- a/OpenAuth.App/DataPrivilegeRuleApp.cs
+++ b/OpenAuth.App/DataPrivilegeRuleApp.cs
@@ -12,7 +12,7 @@ using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
- public class DataPrivilegeRuleApp : BaseApp
+ public class DataPrivilegeRuleApp : BaseStringApp
{
private RevelanceManagerApp _revelanceApp;
///
diff --git a/OpenAuth.App/FileApp.cs b/OpenAuth.App/FileApp.cs
index 14b68273..cbe8db2b 100644
--- a/OpenAuth.App/FileApp.cs
+++ b/OpenAuth.App/FileApp.cs
@@ -21,7 +21,7 @@ namespace OpenAuth.App
///
/// 文件管理
///
- public class FileApp : BaseApp
+ public class FileApp : BaseStringApp
{
private ILogger _logger;
private string _filePath;
diff --git a/OpenAuth.App/FlowInstanceApp.cs b/OpenAuth.App/FlowInstanceApp.cs
index e3b3870e..36bf4b98 100644
--- a/OpenAuth.App/FlowInstanceApp.cs
+++ b/OpenAuth.App/FlowInstanceApp.cs
@@ -33,7 +33,7 @@ namespace OpenAuth.App
///
/// 工作流实例表操作
///
- public class FlowInstanceApp : BaseApp
+ public class FlowInstanceApp : BaseStringApp
{
private RevelanceManagerApp _revelanceApp;
private FlowSchemeApp _flowSchemeApp;
diff --git a/OpenAuth.App/FlowSchemeApp.cs b/OpenAuth.App/FlowSchemeApp.cs
index a2578ecc..a320e19f 100644
--- a/OpenAuth.App/FlowSchemeApp.cs
+++ b/OpenAuth.App/FlowSchemeApp.cs
@@ -10,7 +10,7 @@ using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
- public class FlowSchemeApp :BaseApp
+ public class FlowSchemeApp :BaseStringApp
{
public void Add(FlowScheme flowScheme)
{
diff --git a/OpenAuth.App/FormApp.cs b/OpenAuth.App/FormApp.cs
index 2b180a7a..e87ef975 100644
--- a/OpenAuth.App/FormApp.cs
+++ b/OpenAuth.App/FormApp.cs
@@ -13,7 +13,7 @@ using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
- public class FormApp : BaseApp