diff --git a/OpenAuth.App/AuthStrategies/NormalAuthStrategy.cs b/OpenAuth.App/AuthStrategies/NormalAuthStrategy.cs index d35a491b..e6248ab2 100644 --- a/OpenAuth.App/AuthStrategies/NormalAuthStrategy.cs +++ b/OpenAuth.App/AuthStrategies/NormalAuthStrategy.cs @@ -43,7 +43,7 @@ namespace OpenAuth.App get { var moduleIds = SugarClient.Queryable().Where( u => - u.Key == Define.ROLEMODULE && _userRoleIds.Contains(u.FirstId)).Select(u => u.SecondId).ToList(); + u.RelKey == Define.ROLEMODULE && _userRoleIds.Contains(u.FirstId)).Select(u => u.SecondId).ToList(); var elementIds = GetElementIds(); return SugarClient.Queryable().Where(m =>moduleIds.Contains(m.Id)) @@ -70,7 +70,7 @@ namespace OpenAuth.App { var elementIds = SugarClient.Queryable().Where( u => - u.Key == Define.ROLEELEMENT && _userRoleIds.Contains(u.FirstId)).Select(u => u.SecondId).ToList(); + u.RelKey == Define.ROLEELEMENT && _userRoleIds.Contains(u.FirstId)).Select(u => u.SecondId).ToList(); return elementIds; } @@ -85,7 +85,7 @@ namespace OpenAuth.App { var resourceIds = SugarClient.Queryable().Where( u => - u.Key == Define.ROLERESOURCE && _userRoleIds.Contains(u.FirstId)).Select(u => u.SecondId).ToList(); + u.RelKey == Define.ROLERESOURCE && _userRoleIds.Contains(u.FirstId)).Select(u => u.SecondId).ToList(); return SugarClient.Queryable().Where(u => resourceIds.Contains(u.Id)).ToList(); } } @@ -95,7 +95,7 @@ namespace OpenAuth.App get { var orgids = SugarClient.Queryable().Where( - u =>u.FirstId == _user.Id && u.Key == Define.USERORG).Select(u => u.SecondId).ToList(); + u =>u.FirstId == _user.Id && u.RelKey == Define.USERORG).Select(u => u.SecondId).ToList(); return SugarClient.Queryable().Where(org =>orgids.Contains(org.Id)) .LeftJoin((org, user) => org.ChairmanId ==user.Id) .Select((org,user)=>new OrgView @@ -112,7 +112,7 @@ namespace OpenAuth.App set { _user = value; - _userRoleIds = SugarClient.Queryable().Where(u => u.FirstId == _user.Id && u.Key == Define.USERROLE) + _userRoleIds = SugarClient.Queryable().Where(u => u.FirstId == _user.Id && u.RelKey == Define.USERROLE) .Select(u => u.SecondId).ToList(); } } @@ -142,7 +142,7 @@ namespace OpenAuth.App } var props =SugarClient.Queryable().Where(u => - u.Key == Define.ROLEDATAPROPERTY && _userRoleIds.Contains(u.FirstId) && u.SecondId == moduleCode) + u.RelKey == Define.ROLEDATAPROPERTY && _userRoleIds.Contains(u.FirstId) && u.SecondId == moduleCode) .Select(u => u.ThirdId).ToList(); return allprops.Where(u => props.Contains(u.ColumnName)).ToList(); @@ -160,7 +160,7 @@ namespace OpenAuth.App } var props =SugarClient.Queryable().Where(u => - u.Key == Define.ROLEDATAPROPERTY && _userRoleIds.Contains(u.FirstId) && u.SecondId == moduleCode) + u.RelKey == Define.ROLEDATAPROPERTY && _userRoleIds.Contains(u.FirstId) && u.SecondId == moduleCode) .Select(u => u.ThirdId).ToList(); return allprops.Where(u => props.Contains(u.ColumnName)).ToList(); diff --git a/OpenAuth.App/Flow/FlowRuntime.cs b/OpenAuth.App/Flow/FlowRuntime.cs index deb7478e..478cec7d 100644 --- a/OpenAuth.App/Flow/FlowRuntime.cs +++ b/OpenAuth.App/Flow/FlowRuntime.cs @@ -761,14 +761,18 @@ namespace OpenAuth.App.Flow /// /// 替换SQL中的权限占位符 + /// 如:select id from sysuser where parentId = {loginUser} + /// 替换后:select id from sysuser where parentId = '123' + /// 如:select id from sysuser where parentId = {loginUser} + /// 替换后:select id from sysuser where parentId = '123' /// /// /// private string ReplaceSql(string sql){ var loginUser = AutofacContainerModule.GetService().GetCurrentUser(); - var res = sql.Replace(Define.DATAPRIVILEGE_LOGINUSER, loginUser.User.Id); - res = res.Replace(Define.DATAPRIVILEGE_LOGINROLE, string.Join(',', loginUser.Roles.Select(u => u.Id))); - res = res.Replace(Define.DATAPRIVILEGE_LOGINORG, string.Join(',', loginUser.Orgs.Select(u => u.Id))); + var res = sql.Replace(Define.DATAPRIVILEGE_LOGINUSER, $"'{loginUser.User.Id}'"); + res = res.Replace(Define.DATAPRIVILEGE_LOGINROLE, string.Join(',', loginUser.Roles.Select(u => $"'{u.Id}'"))); + res = res.Replace(Define.DATAPRIVILEGE_LOGINORG, string.Join(',', loginUser.Orgs.Select(u => $"'{u.Id}'"))); return res; } diff --git a/OpenAuth.App/FlowInstance/FlowInstanceApp.cs b/OpenAuth.App/FlowInstance/FlowInstanceApp.cs index c5302dae..e200ccf4 100644 --- a/OpenAuth.App/FlowInstance/FlowInstanceApp.cs +++ b/OpenAuth.App/FlowInstance/FlowInstanceApp.cs @@ -792,17 +792,17 @@ namespace OpenAuth.App select distinct FirstId as InstanceId from Relevance rel inner join FlowInstance flow on rel.FirstId = flow.Id and flow.IsFinish = 1 - where `key` = '{Define.INSTANCE_NOTICE_USER}' + where RelKey = '{Define.INSTANCE_NOTICE_USER}' and SecondId = '{user.User.Id}' union select distinct a.FirstId as InstanceId from Relevance a inner join (select SecondId as RoleId from Relevance - where `key` = 'UserRole' + where RelKey = 'UserRole' and FirstId = '{user.User.Id}') b on a.SecondId = b.RoleId inner join FlowInstance flow on a.FirstId = flow.Id and flow.IsFinish = 1 - where a.`key` = '{Define.INSTANCE_NOTICE_ROLE}') UniqueInstanceIds + where a.RelKey = '{Define.INSTANCE_NOTICE_ROLE}') UniqueInstanceIds ON fi.Id = UniqueInstanceIds.InstanceId "; } @@ -810,15 +810,8 @@ namespace OpenAuth.App switch (SugarClient.CurrentConnectionConfig.DbType) { case DbType.SqlServer: - sql = sql.Replace("`key`", "[Key]"); sql = sql.Replace("from dual", ""); break; - case DbType.Oracle: - sql = sql.Replace("`key`", "\"KEY\""); - break; - case DbType.PostgreSQL: - sql = sql.Replace("`key`", "key"); - break; } var finalQuery = SugarClient.SqlQueryable(sql) diff --git a/OpenAuth.App/ModuleManager/ModuleManagerApp.cs b/OpenAuth.App/ModuleManager/ModuleManagerApp.cs index b18dd383..a9b0b673 100644 --- a/OpenAuth.App/ModuleManager/ModuleManagerApp.cs +++ b/OpenAuth.App/ModuleManager/ModuleManagerApp.cs @@ -52,7 +52,7 @@ namespace OpenAuth.App /// The role unique identifier. public IEnumerable LoadForRole(string roleId) { - var moduleIds = UnitWork.Find(u => u.FirstId == roleId && u.Key == Define.ROLEMODULE) + var moduleIds = UnitWork.Find(u => u.FirstId == roleId && u.RelKey == Define.ROLEMODULE) .Select(u => u.SecondId); return UnitWork.Find(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo); } diff --git a/OpenAuth.App/OrgManager/OrgManagerApp.cs b/OpenAuth.App/OrgManager/OrgManagerApp.cs index 515c1a44..11690d72 100644 --- a/OpenAuth.App/OrgManager/OrgManagerApp.cs +++ b/OpenAuth.App/OrgManager/OrgManagerApp.cs @@ -71,7 +71,7 @@ namespace OpenAuth.App delOrgIds.AddRange(UnitWork.Find(u=>u.CascadeId.Contains(cascadeId)).Select(u =>u.Id).ToArray()); } - UnitWork.Delete(u =>u.Key == Define.USERORG && delOrgIds.Contains(u.SecondId)); + UnitWork.Delete(u =>u.RelKey == Define.USERORG && delOrgIds.Contains(u.SecondId)); UnitWork.Delete(u => delOrgIds.Contains(u.Id)); UnitWork.Save(); @@ -85,7 +85,7 @@ namespace OpenAuth.App { var result = from userorg in UnitWork.Find(null) join org in UnitWork.Find(null) on userorg.SecondId equals org.Id - where userorg.FirstId == userId && userorg.Key == Define.USERORG + where userorg.FirstId == userId && userorg.RelKey == Define.USERORG select org; return result.ToList(); } diff --git a/OpenAuth.App/Relevance/RevelanceManagerApp.cs b/OpenAuth.App/Relevance/RevelanceManagerApp.cs index 378b8ade..32992ef7 100644 --- a/OpenAuth.App/Relevance/RevelanceManagerApp.cs +++ b/OpenAuth.App/Relevance/RevelanceManagerApp.cs @@ -41,7 +41,7 @@ namespace OpenAuth.App from value in sameVals select new Relevance { - Key = key, + RelKey = key, FirstId = sameVals.Key, SecondId = value, OperateTime = DateTime.Now @@ -81,7 +81,7 @@ namespace OpenAuth.App _logger.LogInformation($"start=> delete {key} {sameVals.Key} {value}"); try { - UnitWork.Delete(u => u.Key == key && u.FirstId == sameVals.Key && u.SecondId == value); + UnitWork.Delete(u => u.RelKey == key && u.FirstId == sameVals.Key && u.SecondId == value); } catch (Exception e) { @@ -94,7 +94,7 @@ namespace OpenAuth.App public void DeleteBy(string key, params string[] firstIds) { - UnitWork.Delete(u => firstIds.Contains(u.FirstId) && u.Key == key); + UnitWork.Delete(u => firstIds.Contains(u.FirstId) && u.RelKey == key); } @@ -109,12 +109,12 @@ namespace OpenAuth.App { if (returnSecondIds) { - return Repository.Find(u => u.Key == key + return Repository.Find(u => u.RelKey == key && ids.Contains(u.FirstId)).Select(u => u.SecondId).ToList(); } else { - return Repository.Find(u => u.Key == key + return Repository.Find(u => u.RelKey == key && ids.Contains(u.SecondId)).Select(u => u.FirstId).ToList(); } } @@ -128,7 +128,7 @@ namespace OpenAuth.App /// public List Get(string key, string firstId, string secondId) { - return Repository.Find(u => u.Key == key && u.FirstId == firstId && u.SecondId == secondId) + return Repository.Find(u => u.RelKey == key && u.FirstId == firstId && u.SecondId == secondId) .Select(u => u.ThirdId).ToList(); } @@ -148,7 +148,7 @@ namespace OpenAuth.App { relevances.Add(new Relevance { - Key = Define.ROLEDATAPROPERTY, + RelKey = Define.ROLEDATAPROPERTY, FirstId = request.RoleId, SecondId = request.ModuleCode, ThirdId = requestProperty, @@ -181,7 +181,7 @@ namespace OpenAuth.App { foreach (var property in request.Properties) { - UnitWork.Delete(u => u.Key == Define.ROLEDATAPROPERTY + UnitWork.Delete(u => u.RelKey == Define.ROLEDATAPROPERTY && u.FirstId == request.RoleId && u.SecondId == request.ModuleCode && u.ThirdId == property); @@ -198,12 +198,12 @@ namespace OpenAuth.App UnitWork.ExecuteWithTransaction(() => { //删除以前的所有用户 - UnitWork.Delete(u => u.SecondId == request.RoleId && u.Key == Define.USERROLE); + UnitWork.Delete(u => u.SecondId == request.RoleId && u.RelKey == Define.USERROLE); //批量分配用户角色 UnitWork.BatchAdd((from firstId in request.UserIds select new Relevance { - Key = Define.USERROLE, + RelKey = Define.USERROLE, FirstId = firstId, SecondId = request.RoleId, OperateTime = DateTime.Now @@ -221,12 +221,12 @@ namespace OpenAuth.App UnitWork.ExecuteWithTransaction(() => { //删除以前的所有用户 - UnitWork.Delete(u => u.SecondId == request.OrgId && u.Key == Define.USERORG); + UnitWork.Delete(u => u.SecondId == request.OrgId && u.RelKey == Define.USERORG); //批量分配用户角色 UnitWork.BatchAdd((from firstId in request.UserIds select new Relevance { - Key = Define.USERORG, + RelKey = Define.USERORG, FirstId = firstId, SecondId = request.OrgId, OperateTime = DateTime.Now @@ -244,12 +244,12 @@ namespace OpenAuth.App UnitWork.ExecuteWithTransaction(() => { //删除以前的所有资源 - UnitWork.Delete(u => u.FirstId == request.RoleId && u.Key == Define.ROLERESOURCE); + UnitWork.Delete(u => u.FirstId == request.RoleId && u.RelKey == Define.ROLERESOURCE); //批量分配角色资源 UnitWork.BatchAdd((from firstId in request.ResourceIds select new Relevance { - Key = Define.ROLERESOURCE, + RelKey = Define.ROLERESOURCE, FirstId = request.RoleId, SecondId = firstId, OperateTime = DateTime.Now diff --git a/OpenAuth.App/RoleManager/RoleApp.cs b/OpenAuth.App/RoleManager/RoleApp.cs index c0a5d26d..242e43cd 100644 --- a/OpenAuth.App/RoleManager/RoleApp.cs +++ b/OpenAuth.App/RoleManager/RoleApp.cs @@ -88,8 +88,8 @@ namespace OpenAuth.App { UnitWork.ExecuteWithTransaction(() => { - UnitWork.Delete(u=>(u.Key == Define.ROLEMODULE || u.Key == Define.ROLEELEMENT) && ids.Contains(u.FirstId)); - UnitWork.Delete(u=>u.Key == Define.USERROLE && ids.Contains(u.SecondId)); + UnitWork.Delete(u=>(u.RelKey == Define.ROLEMODULE || u.RelKey == Define.ROLEELEMENT) && ids.Contains(u.FirstId)); + UnitWork.Delete(u=>u.RelKey == Define.USERROLE && ids.Contains(u.SecondId)); UnitWork.Delete(u =>ids.Contains(u.Id)); UnitWork.Save(); }); diff --git a/OpenAuth.App/UserManager/UserManagerApp.cs b/OpenAuth.App/UserManager/UserManagerApp.cs index 4444396b..fc40c9a1 100644 --- a/OpenAuth.App/UserManager/UserManagerApp.cs +++ b/OpenAuth.App/UserManager/UserManagerApp.cs @@ -44,7 +44,7 @@ namespace OpenAuth.App join user2 in UnitWork.Find(null) on user.ParentId equals user2.Id into tempuser from u in tempuser.DefaultIfEmpty() - join relevance in UnitWork.Find(u => u.Key == "UserOrg") + join relevance in UnitWork.Find(u => u.RelKey == "UserOrg") on user.Id equals relevance.FirstId into temp from r in temp.DefaultIfEmpty() join org in UnitWork.Find(null) @@ -64,7 +64,7 @@ namespace OpenAuth.App user.TypeName, user.ParentId, ParentName = u.Name, //直属上级 - r.Key, + Key = r.RelKey, r.SecondId, OrgId = o.Id, OrgName = o.Name @@ -122,7 +122,7 @@ namespace OpenAuth.App join user2 in UnitWork.Find(null) on user.ParentId equals user2.Id into tempuser from u in tempuser.DefaultIfEmpty() - join relevance in UnitWork.Find(u => u.Key == "UserOrg") + join relevance in UnitWork.Find(u => u.RelKey == "UserOrg") on user.Id equals relevance.FirstId into temp from r in temp.DefaultIfEmpty() join org in UnitWork.Find(null) @@ -142,7 +142,7 @@ namespace OpenAuth.App user.TypeName, user.ParentId, ParentName = u.Name, //直属上级 - r.Key, + Key = r.RelKey, r.SecondId, OrgId = o.Id, OrgName = o.Name @@ -230,7 +230,7 @@ namespace OpenAuth.App { UnitWork.ExecuteWithTransaction(() => { - UnitWork.Delete(u =>(u.Key == Define.USERROLE || u.Key == Define.USERORG) + UnitWork.Delete(u =>(u.RelKey == Define.USERROLE || u.RelKey == Define.USERORG) && ids.Contains(u.FirstId)); UnitWork.Delete(u => ids.Contains(u.Id)); UnitWork.Save(); @@ -255,7 +255,7 @@ namespace OpenAuth.App public async Task LoadByRole(QueryUserListByRoleReq request) { var users = from userRole in UnitWork.Find(u => - u.SecondId == request.roleId && u.Key == Define.USERROLE) + u.SecondId == request.roleId && u.RelKey == Define.USERROLE) join user in UnitWork.Find(null) on userRole.FirstId equals user.Id into temp from c in temp.Where(u =>u.Id != null) select c; @@ -273,7 +273,7 @@ namespace OpenAuth.App public async Task LoadByOrg(QueryUserListByOrgReq request) { var users = from userOrg in UnitWork.Find(u => - u.SecondId == request.orgId && u.Key == Define.USERORG) + u.SecondId == request.orgId && u.RelKey == Define.USERORG) join user in UnitWork.Find(null) on userOrg.FirstId equals user.Id into temp from c in temp.Where(u =>u.Id != null) select c; @@ -327,30 +327,16 @@ namespace OpenAuth.App from sysuser u join (select distinct SecondId as UserId from Relevance - where `key` = '{Define.INSTANCE_NOTICE_USER}' + where RelKey = '{Define.INSTANCE_NOTICE_USER}' and FirstId = '{instanceId}' union select distinct FirstId as UserId from Relevance a inner join (select SecondId as RoleId from Relevance - where `key` = '{Define.INSTANCE_NOTICE_ROLE}' + where RelKey = '{Define.INSTANCE_NOTICE_ROLE}' and FirstId = '{instanceId}') b on a.SecondId = b.RoleId - where `key` = 'UserRole') userids on u.Id = userids.UserId"; - - if (UnitWork.GetDbContext().Database.GetDbConnection().GetType().Name == "SqlConnection") - { - sql = sql.Replace("`key`", "[Key]"); - } - else if (UnitWork.GetDbContext().Database.GetDbConnection().GetType().Name == "OracleConnection") - { - sql = sql.Replace("`key`", "\"KEY\""); - } - else if (UnitWork.GetDbContext().Database.GetDbConnection().GetType().Name == "NpgsqlConnection") - { - sql = sql.Replace("`key`", "\"key\""); - } - + where RelKey = 'UserRole') userids on u.Id = userids.UserId"; var users = UnitWork.FromSql(sql); return users.Select(u=>u.Id).ToList(); } diff --git a/OpenAuth.Repository/Domain/Relevance.cs b/OpenAuth.Repository/Domain/Relevance.cs index 1d0b6f80..8e3fdd9d 100644 --- a/OpenAuth.Repository/Domain/Relevance.cs +++ b/OpenAuth.Repository/Domain/Relevance.cs @@ -23,7 +23,7 @@ namespace OpenAuth.Repository.Domain public Relevance() { this.Description= string.Empty; - this.Key= string.Empty; + this.RelKey= string.Empty; this.Status= 0; this.OperateTime= DateTime.Now; this.OperatorId= string.Empty; @@ -42,7 +42,7 @@ namespace OpenAuth.Repository.Domain /// 映射标识 /// [Description("映射标识")] - public string Key { get; set; } + public string RelKey { get; set; } /// /// 状态 ///