From 51155a779030af72808859f5be6f927e17082a64 Mon Sep 17 00:00:00 2001 From: wintel Date: Sat, 23 Dec 2023 15:42:50 +0800 Subject: [PATCH] =?UTF-8?q?fix=20issue=20#I80UEX=20=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E4=BA=BA=E5=91=98=E5=8F=AF=E4=BB=A5=E9=80=89=E6=8B=A9=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E4=B8=8A=E7=BA=A7=E5=92=8C=E9=83=A8=E9=97=A8=E8=B4=9F?= =?UTF-8?q?=E8=B4=A3=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AuthStrategies/AuthStrategyContext.cs | 2 +- .../AuthStrategies/NormalAuthStrategy.cs | 85 ++-- .../AuthStrategies/SystemAuthStrategy.cs | 49 +-- OpenAuth.App/Interface/IAuthStrategy.cs | 2 +- .../ModuleManager/Response/ModuleView.cs | 8 +- OpenAuth.App/OrgManager/Response/OrgView.cs | 13 + OpenAuth.App/UserManager/Response/UserView.cs | 5 +- OpenAuth.App/UserManager/UserManagerApp.cs | 14 +- .../Controllers/UserSessionController.cs | 390 +++++++++--------- OpenAuth.Repository/Domain/Org.cs | 220 +++++----- .../Controllers/CheckController.cs | 4 +- 11 files changed, 398 insertions(+), 394 deletions(-) create mode 100644 OpenAuth.App/OrgManager/Response/OrgView.cs diff --git a/OpenAuth.App/AuthStrategies/AuthStrategyContext.cs b/OpenAuth.App/AuthStrategies/AuthStrategyContext.cs index 6be1baba..e6b6735b 100644 --- a/OpenAuth.App/AuthStrategies/AuthStrategyContext.cs +++ b/OpenAuth.App/AuthStrategies/AuthStrategyContext.cs @@ -59,7 +59,7 @@ namespace OpenAuth.App get { return _strategy.Resources; } } - public List Orgs + public List Orgs { get { return _strategy.Orgs; } } diff --git a/OpenAuth.App/AuthStrategies/NormalAuthStrategy.cs b/OpenAuth.App/AuthStrategies/NormalAuthStrategy.cs index 7e8f7f9c..95101c63 100644 --- a/OpenAuth.App/AuthStrategies/NormalAuthStrategy.cs +++ b/OpenAuth.App/AuthStrategies/NormalAuthStrategy.cs @@ -23,13 +23,14 @@ using OpenAuth.App.Response; using OpenAuth.Repository; using OpenAuth.Repository.Domain; using OpenAuth.Repository.Interface; +using SqlSugar; namespace OpenAuth.App { /// /// 普通用户授权策略 /// - public class NormalAuthStrategy :BaseStringApp, IAuthStrategy + public class NormalAuthStrategy : SqlSugarBaseApp, IAuthStrategy { protected User _user; @@ -40,34 +41,12 @@ namespace OpenAuth.App public List Modules { get { - var moduleIds = UnitWork.Find( + var moduleIds = SugarClient.Queryable().Where( u => - (u.Key == Define.ROLEMODULE && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId); - - var modules = (from module in UnitWork.Find(u =>moduleIds.Contains(u.Id)) - select new ModuleView - { - SortNo = module.SortNo, - Name = module.Name, - Code = module.Code, - CascadeId = module.CascadeId, - Id = module.Id, - IconName = module.IconName, - Url = module.Url, - ParentId = module.ParentId, - ParentName = module.ParentName, - IsSys = module.IsSys, - Status = module.Status - }).ToList(); - - var usermoduleelements = ModuleElements; - - foreach (var module in modules) - { - module.Elements =usermoduleelements.Where(u => u.ModuleId == module.Id).ToList(); - } - - return modules; + (u.Key == Define.ROLEMODULE && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList(); + + return SugarClient.Queryable().Where(m =>moduleIds.Contains(m.Id)).Includes(x=>x.Elements).ToList(); + } } @@ -75,37 +54,43 @@ namespace OpenAuth.App { get { - var elementIds = UnitWork.Find( + var elementIds = SugarClient.Queryable().Where( u => - (u.Key == Define.ROLEELEMENT && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId); - var usermoduleelements = UnitWork.Find(u => elementIds.Contains(u.Id)); + (u.Key == Define.ROLEELEMENT && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList(); + var usermoduleelements = SugarClient.Queryable().Where(u => elementIds.Contains(u.Id)); return usermoduleelements.ToList(); } } public List Roles { - get { return UnitWork.Find(u => _userRoleIds.Contains(u.Id)).ToList(); } + get { return SugarClient.Queryable().Where(u => _userRoleIds.Contains(u.Id)).ToList(); } } public List Resources { get { - var resourceIds = UnitWork.Find( + var resourceIds = SugarClient.Queryable().Where( u => - (u.Key == Define.ROLERESOURCE && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId); - return UnitWork.Find(u => resourceIds.Contains(u.Id)).ToList(); + (u.Key == Define.ROLERESOURCE && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList(); + return SugarClient.Queryable().Where(u => resourceIds.Contains(u.Id)).ToList(); } } - public List Orgs + public List Orgs { get { - var orgids = UnitWork.Find( - u =>u.FirstId == _user.Id && u.Key == Define.USERORG).Select(u => u.SecondId); - return UnitWork.Find(u => orgids.Contains(u.Id)).ToList(); + var orgids = SugarClient.Queryable().Where( + u =>u.FirstId == _user.Id && u.Key == 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 + { + Id = org.Id.SelectAll(), + ChairmanName = user.Name + }).ToList(); } } @@ -115,16 +100,18 @@ namespace OpenAuth.App set { _user = value; - _userRoleIds = UnitWork.Find(u => u.FirstId == _user.Id && u.Key == Define.USERROLE).Select(u => u.SecondId).ToList(); + _userRoleIds = SugarClient.Queryable().Where(u => u.FirstId == _user.Id && u.Key == Define.USERROLE) + .Select(u => u.SecondId).ToList(); } } public List GetTableColumns(string moduleCode) { - var allprops = UnitWork.Find(u => u.TableName.ToLower() == moduleCode.ToLower()); + var allprops = SugarClient.Queryable() + .Where(u => u.TableName.ToLower() == moduleCode.ToLower()); //如果是子表,直接返回所有字段 - var builderTable = UnitWork.FirstOrDefault(u => u.TableName.ToLower() == moduleCode.ToLower()); + var builderTable = SugarClient.Queryable().First(u => u.TableName.ToLower() == moduleCode.ToLower()); if (builderTable == null) { throw new Exception($"代码生成器中找不到{moduleCode.ToLower()}的定义"); @@ -136,15 +123,15 @@ namespace OpenAuth.App } //如果是系统模块,直接返回所有字段。防止开发者把模块配置成系统模块,还在外层调用loginContext.GetProperties("xxxx"); - bool? isSysModule = UnitWork.FirstOrDefault(u => u.Code == moduleCode)?.IsSys; + bool? isSysModule = SugarClient.Queryable().First(u => u.Code == moduleCode)?.IsSys; if (isSysModule!= null && isSysModule.Value) { return allprops.ToList(); } - var props =UnitWork.Find(u => + var props =SugarClient.Queryable().Where(u => u.Key == Define.ROLEDATAPROPERTY && _userRoleIds.Contains(u.FirstId) && u.SecondId == moduleCode) - .Select(u => u.ThirdId); + .Select(u => u.ThirdId).ToList(); return allprops.Where(u => props.Contains(u.ColumnName)).ToList(); } @@ -154,22 +141,22 @@ namespace OpenAuth.App var allprops = _dbExtension.GetTableColumnsFromDb(moduleCode); //如果是系统模块,直接返回所有字段。防止开发者把模块配置成系统模块,还在外层调用loginContext.GetProperties("xxxx"); - bool? isSysModule = UnitWork.FirstOrDefault(u => u.Code == moduleCode)?.IsSys; + bool? isSysModule = SugarClient.Queryable().First(u => u.Code == moduleCode)?.IsSys; if (isSysModule!= null && isSysModule.Value) { return allprops.ToList(); } - var props =UnitWork.Find(u => + var props =SugarClient.Queryable().Where(u => u.Key == Define.ROLEDATAPROPERTY && _userRoleIds.Contains(u.FirstId) && u.SecondId == moduleCode) - .Select(u => u.ThirdId); + .Select(u => u.ThirdId).ToList(); return allprops.Where(u => props.Contains(u.ColumnName)).ToList(); } //用户角色 - public NormalAuthStrategy(IUnitWork unitWork, IRepository repository, DbExtension dbExtension) : base(unitWork, repository,null) + public NormalAuthStrategy(ISqlSugarClient client,DbExtension dbExtension) : base(client, null) { _dbExtension = dbExtension; } diff --git a/OpenAuth.App/AuthStrategies/SystemAuthStrategy.cs b/OpenAuth.App/AuthStrategies/SystemAuthStrategy.cs index 9018b90a..5c802dd1 100644 --- a/OpenAuth.App/AuthStrategies/SystemAuthStrategy.cs +++ b/OpenAuth.App/AuthStrategies/SystemAuthStrategy.cs @@ -22,6 +22,7 @@ using OpenAuth.App.Response; using OpenAuth.Repository; using OpenAuth.Repository.Domain; using OpenAuth.Repository.Interface; +using SqlSugar; namespace OpenAuth.App { @@ -30,57 +31,43 @@ namespace OpenAuth.App /// 超级管理员权限 /// 超级管理员使用guid.empty为ID,可以根据需要修改 /// - public class SystemAuthStrategy : BaseStringApp, IAuthStrategy + public class SystemAuthStrategy : SqlSugarBaseApp, IAuthStrategy { protected User _user; private DbExtension _dbExtension; public List Modules { - get { - var modules = (from module in UnitWork.Find(null) - select new ModuleView - { - SortNo = module.SortNo, - Name = module.Name, - Id = module.Id, - CascadeId = module.CascadeId, - Code = module.Code, - IconName = module.IconName, - Url = module.Url, - ParentId = module.ParentId, - ParentName = module.ParentName, - IsSys = module.IsSys, - Status = module.Status - }).ToList(); - - foreach (var module in modules) - { - module.Elements = UnitWork.Find(u => u.ModuleId == module.Id).ToList(); - } - - return modules; + get + { + return SugarClient.Queryable().Includes(x=>x.Elements).ToList(); } } public List Roles { - get { return UnitWork.Find(null).ToList(); } + get { return SugarClient.Queryable().ToList(); } } public List ModuleElements { - get { return UnitWork.Find(null).ToList(); } + get { return SugarClient.Queryable().ToList(); } } public List Resources { - get { return UnitWork.Find(null).ToList(); } + get { return SugarClient.Queryable().ToList(); } } - public List Orgs + public List Orgs { - get { return UnitWork.Find(null).ToList(); } + get { return SugarClient.Queryable() + .LeftJoin((org, user) => org.ChairmanId ==user.Id) + .Select((org,user)=>new OrgView + { + Id = org.Id.SelectAll(), + ChairmanName = user.Name + }).ToList(); } } public User User @@ -95,7 +82,7 @@ namespace OpenAuth.App public List GetTableColumns(string moduleCode) { - return UnitWork.Find(u => u.TableName.ToLower() == moduleCode.ToLower()).ToList(); + return SugarClient.Queryable().Where(u => u.TableName.ToLower() == moduleCode.ToLower()).ToList(); } public List GetTableColumnsFromDb(string moduleCode) @@ -104,7 +91,7 @@ namespace OpenAuth.App } - public SystemAuthStrategy(IUnitWork unitWork, IRepository repository, DbExtension dbExtension) : base(unitWork, repository, null) + public SystemAuthStrategy(ISqlSugarClient client,DbExtension dbExtension) : base(client, null) { _dbExtension = dbExtension; _user = new User diff --git a/OpenAuth.App/Interface/IAuthStrategy.cs b/OpenAuth.App/Interface/IAuthStrategy.cs index 850f756f..1a58edd1 100644 --- a/OpenAuth.App/Interface/IAuthStrategy.cs +++ b/OpenAuth.App/Interface/IAuthStrategy.cs @@ -33,7 +33,7 @@ namespace OpenAuth.App List Resources { get; } - List Orgs { get; } + List Orgs { get; } User User { diff --git a/OpenAuth.App/ModuleManager/Response/ModuleView.cs b/OpenAuth.App/ModuleManager/Response/ModuleView.cs index 70118b82..86a1e372 100644 --- a/OpenAuth.App/ModuleManager/Response/ModuleView.cs +++ b/OpenAuth.App/ModuleManager/Response/ModuleView.cs @@ -1,9 +1,11 @@ using System.Collections.Generic; using Infrastructure; using OpenAuth.Repository.Domain; +using SqlSugar; namespace OpenAuth.App.Response { + [SugarTable("Module")] public class ModuleView { /// @@ -52,10 +54,7 @@ namespace OpenAuth.App.Response /// 当前状态,0:正常,-1:隐藏,不在导航列表中显示 /// public int Status { get; set; } - - - public bool Checked { get; set; } - + /// /// 排序号 /// @@ -68,6 +67,7 @@ namespace OpenAuth.App.Response /// /// 模块中的元素 /// + [Navigate(NavigateType.OneToMany, nameof(ModuleElement.ModuleId),nameof(Id))] public List Elements { get; set; } public static implicit operator ModuleView(Module module) diff --git a/OpenAuth.App/OrgManager/Response/OrgView.cs b/OpenAuth.App/OrgManager/Response/OrgView.cs new file mode 100644 index 00000000..04b867cf --- /dev/null +++ b/OpenAuth.App/OrgManager/Response/OrgView.cs @@ -0,0 +1,13 @@ +using System.ComponentModel; +using OpenAuth.Repository.Domain; + +namespace OpenAuth.App.Response; + +public class OrgView: SysOrg +{ + /// + /// 负责人 + /// + [Description("负责人")] + public string ChairmanName { get; set; } +} \ No newline at end of file diff --git a/OpenAuth.App/UserManager/Response/UserView.cs b/OpenAuth.App/UserManager/Response/UserView.cs index 90d7605b..bf1ae529 100644 --- a/OpenAuth.App/UserManager/Response/UserView.cs +++ b/OpenAuth.App/UserManager/Response/UserView.cs @@ -50,7 +50,10 @@ namespace OpenAuth.App.Response /// public string ParentId { get; set; } - + /// + /// 直接上级 + /// + public string ParentName { get; set; } /// /// 创建时间 diff --git a/OpenAuth.App/UserManager/UserManagerApp.cs b/OpenAuth.App/UserManager/UserManagerApp.cs index eeaaf19a..3076887c 100644 --- a/OpenAuth.App/UserManager/UserManagerApp.cs +++ b/OpenAuth.App/UserManager/UserManagerApp.cs @@ -40,7 +40,10 @@ namespace OpenAuth.App { query = UnitWork.Find(u => u.Name.Contains(request.key) || u.Account.Contains(request.key)); } - var userOrgs = from user in query + var userOrgs = from user in query + 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") on user.Id equals relevance.FirstId into temp from r in temp.DefaultIfEmpty() @@ -60,6 +63,7 @@ namespace OpenAuth.App user.TypeId, user.TypeName, user.ParentId, + ParentName = u.Name, //直属上级 r.Key, r.SecondId, OrgId = o.Id, @@ -86,6 +90,7 @@ namespace OpenAuth.App Id = u.First().Id, Account = u.Key, Name = u.First().Name, + ParentName = u.First().ParentName, Sex = u.First().Sex, Status = u.First().Status, ParentId = u.First().ParentId, @@ -114,6 +119,9 @@ namespace OpenAuth.App query = UnitWork.Find(u => u.Name.Contains(request.key) || u.Account.Contains(request.key)); } var userOrgs = from user in query + 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") on user.Id equals relevance.FirstId into temp from r in temp.DefaultIfEmpty() @@ -132,6 +140,8 @@ namespace OpenAuth.App user.CreateTime, user.TypeId, user.TypeName, + user.ParentId, + ParentName = u.Name, //直属上级 r.Key, r.SecondId, OrgId = o.Id, @@ -151,6 +161,8 @@ namespace OpenAuth.App Status = u.First().Status, CreateTime = u.First().CreateTime, CreateUser = u.First().CreateId, + ParentName = u.First().ParentName, + ParentId = u.First().ParentId, OrganizationIds = string.Join(",", u.Select(x=>x.OrgId)) ,Organizations = string.Join(",", u.Select(x=>x.OrgName)) }); diff --git a/OpenAuth.Mvc/Controllers/UserSessionController.cs b/OpenAuth.Mvc/Controllers/UserSessionController.cs index 61353502..c93e7a32 100644 --- a/OpenAuth.Mvc/Controllers/UserSessionController.cs +++ b/OpenAuth.Mvc/Controllers/UserSessionController.cs @@ -1,196 +1,196 @@ -// *********************************************************************** -// Assembly : OpenAuth.Mvc -// Author : 李玉宝 -// Created : 06-08-2018 -// -// Last Modified By : 李玉宝 -// Last Modified On : 07-04-2018 -// *********************************************************************** -// -// Copyright (c) http://www.openauth.net.cn. All rights reserved. -// -// -// 获取登录用户的全部信息 -// 所有和当前登录用户相关的操作都在这里 -// -// *********************************************************************** - -using System; -using System.Collections.Generic; -using System.Linq; -using Infrastructure; -using Infrastructure.Helpers; -using Microsoft.EntityFrameworkCore.Metadata.Internal; -using OpenAuth.App; -using OpenAuth.App.Interface; -using OpenAuth.App.Response; -using OpenAuth.Repository.Domain; - -namespace OpenAuth.Mvc.Controllers -{ - public class UserSessionController : BaseController - { - private readonly AuthStrategyContext _authStrategyContext; - public UserSessionController(IAuth authUtil) : base(authUtil) - { - _authStrategyContext = _authUtil.GetCurrentUser(); - } - - /// - /// 获取用户资料 - /// - /// - public string GetUserProfile() - { - var resp = new Response(); - try - { - resp.Result = _authStrategyContext.User.MapTo(); - } - catch (Exception e) - { - resp.Code = 500; - resp.Message = e.Message; - } - return JsonHelper.Instance.Serialize(resp); - } - - public string GetUserName() - { - return _authUtil.GetUserName(); - } - /// - /// 获取登录用户可访问的所有模块,及模块的操作菜单 - /// - public string GetModulesTree() - { - var moduleTree = _authStrategyContext.Modules.GenerateTree(u => u.Id, u => u.ParentId); - return JsonHelper.Instance.Serialize(moduleTree); - } - - /// - /// datatable结构的模块列表 - /// - /// - /// - public string GetModulesTable(string pId) - { - string cascadeId = ".0."; - if (!string.IsNullOrEmpty(pId)) - { - var obj = _authStrategyContext.Modules.SingleOrDefault(u => u.Id == pId); - if (obj == null) - throw new Exception("未能找到指定对象信息"); - cascadeId = obj.CascadeId; - } - - var query = _authStrategyContext.Modules.Where(u => u.CascadeId.Contains(cascadeId)); - - return JsonHelper.Instance.Serialize(new TableData - { - data = query.ToList(), - count = query.Count(), - }); - - } - - /// - /// 获取用户可访问的模块列表 - /// - public string GetModules() - { - var resp = new Response>(); - try - { - resp.Result = _authStrategyContext.Modules; - } - catch (Exception e) - { - resp.Code = 500; - resp.Message = e.Message; - } - return JsonHelper.Instance.Serialize(resp); - } - - /// - /// 获取登录用户可访问的所有部门 - /// 用于树状结构 - /// - public string GetOrgs() - { - var resp = new Response>(); - try - { - resp.Result = _authStrategyContext.Orgs; - } - catch (Exception e) - { - resp.Code = 500; - resp.Message = e.Message; - } - return JsonHelper.Instance.Serialize(resp); - } - - /// - /// 获取当前登录用户可访问的字段 - /// - /// 模块的Code,如Category - /// - public string GetProperties(string moduleCode) - { - try - { - if (string.IsNullOrEmpty(moduleCode)) - { - throw new Exception("模块标识为空,不能分配可见字段"); - } - var list = _authStrategyContext.GetTableColumns(moduleCode); - return JsonHelper.Instance.Serialize(new TableData - { - data = list, - count = list.Count(), - }); - } - catch (Exception ex) - { - return JsonHelper.Instance.Serialize(new TableData - { - msg =ex.Message, - code = 500, - }); - } - } - - /// - /// 加载机构的全部下级机构 - /// - /// 机构ID - /// - public string GetSubOrgs(string orgId) - { - string cascadeId = ".0."; - if (!string.IsNullOrEmpty(orgId)) - { - var org = _authStrategyContext.Orgs.SingleOrDefault(u => u.Id == orgId); - if (org == null) - { - return JsonHelper.Instance.Serialize(new TableData - { - msg ="未找到指定的节点", - code = 500, - }); - } - cascadeId = org.CascadeId; - } - - var query = _authStrategyContext.Orgs.Where(u => u.CascadeId.Contains(cascadeId)); - - return JsonHelper.Instance.Serialize(new TableData - { - data = query.ToList(), - count = query.Count(), - }); - } - - } +// *********************************************************************** +// Assembly : OpenAuth.Mvc +// Author : 李玉宝 +// Created : 06-08-2018 +// +// Last Modified By : 李玉宝 +// Last Modified On : 07-04-2018 +// *********************************************************************** +// +// Copyright (c) http://www.openauth.net.cn. All rights reserved. +// +// +// 获取登录用户的全部信息 +// 所有和当前登录用户相关的操作都在这里 +// +// *********************************************************************** + +using System; +using System.Collections.Generic; +using System.Linq; +using Infrastructure; +using Infrastructure.Helpers; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using OpenAuth.App; +using OpenAuth.App.Interface; +using OpenAuth.App.Response; +using OpenAuth.Repository.Domain; + +namespace OpenAuth.Mvc.Controllers +{ + public class UserSessionController : BaseController + { + private readonly AuthStrategyContext _authStrategyContext; + public UserSessionController(IAuth authUtil) : base(authUtil) + { + _authStrategyContext = _authUtil.GetCurrentUser(); + } + + /// + /// 获取用户资料 + /// + /// + public string GetUserProfile() + { + var resp = new Response(); + try + { + resp.Result = _authStrategyContext.User.MapTo(); + } + catch (Exception e) + { + resp.Code = 500; + resp.Message = e.Message; + } + return JsonHelper.Instance.Serialize(resp); + } + + public string GetUserName() + { + return _authUtil.GetUserName(); + } + /// + /// 获取登录用户可访问的所有模块,及模块的操作菜单 + /// + public string GetModulesTree() + { + var moduleTree = _authStrategyContext.Modules.GenerateTree(u => u.Id, u => u.ParentId); + return JsonHelper.Instance.Serialize(moduleTree); + } + + /// + /// datatable结构的模块列表 + /// + /// + /// + public string GetModulesTable(string pId) + { + string cascadeId = ".0."; + if (!string.IsNullOrEmpty(pId)) + { + var obj = _authStrategyContext.Modules.SingleOrDefault(u => u.Id == pId); + if (obj == null) + throw new Exception("未能找到指定对象信息"); + cascadeId = obj.CascadeId; + } + + var query = _authStrategyContext.Modules.Where(u => u.CascadeId.Contains(cascadeId)); + + return JsonHelper.Instance.Serialize(new TableData + { + data = query.ToList(), + count = query.Count(), + }); + + } + + /// + /// 获取用户可访问的模块列表 + /// + public string GetModules() + { + var resp = new Response>(); + try + { + resp.Result = _authStrategyContext.Modules; + } + catch (Exception e) + { + resp.Code = 500; + resp.Message = e.Message; + } + return JsonHelper.Instance.Serialize(resp); + } + + /// + /// 获取登录用户可访问的所有部门 + /// 用于树状结构 + /// + public string GetOrgs() + { + var resp = new Response>(); + try + { + resp.Result = _authStrategyContext.Orgs; + } + catch (Exception e) + { + resp.Code = 500; + resp.Message = e.Message; + } + return JsonHelper.Instance.Serialize(resp); + } + + /// + /// 获取当前登录用户可访问的字段 + /// + /// 模块的Code,如Category + /// + public string GetProperties(string moduleCode) + { + try + { + if (string.IsNullOrEmpty(moduleCode)) + { + throw new Exception("模块标识为空,不能分配可见字段"); + } + var list = _authStrategyContext.GetTableColumns(moduleCode); + return JsonHelper.Instance.Serialize(new TableData + { + data = list, + count = list.Count(), + }); + } + catch (Exception ex) + { + return JsonHelper.Instance.Serialize(new TableData + { + msg =ex.Message, + code = 500, + }); + } + } + + /// + /// 加载机构的全部下级机构 + /// + /// 机构ID + /// + public string GetSubOrgs(string orgId) + { + string cascadeId = ".0."; + if (!string.IsNullOrEmpty(orgId)) + { + var org = _authStrategyContext.Orgs.SingleOrDefault(u => u.Id == orgId); + if (org == null) + { + return JsonHelper.Instance.Serialize(new TableData + { + msg ="未找到指定的节点", + code = 500, + }); + } + cascadeId = org.CascadeId; + } + + var query = _authStrategyContext.Orgs.Where(u => u.CascadeId.Contains(cascadeId)); + + return JsonHelper.Instance.Serialize(new TableData + { + data = query.ToList(), + count = query.Count(), + }); + } + + } } \ No newline at end of file diff --git a/OpenAuth.Repository/Domain/Org.cs b/OpenAuth.Repository/Domain/Org.cs index 5e58212e..997e710d 100644 --- a/OpenAuth.Repository/Domain/Org.cs +++ b/OpenAuth.Repository/Domain/Org.cs @@ -1,110 +1,112 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a CodeSmith Template. -// -// DO NOT MODIFY contents of this file. Changes to this -// file will be lost if the code is regenerated. -// Author:Yubao Li -// -//------------------------------------------------------------------------------ -using System; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations.Schema; -using OpenAuth.Repository.Core; - -namespace OpenAuth.Repository.Domain -{ - /// - /// 组织表 - /// - [Table("Org")] - public partial class SysOrg : TreeEntity - { - public SysOrg() - { - this.CascadeId= string.Empty; - this.Name= string.Empty; - this.HotKey= string.Empty; - this.ParentName= string.Empty; - this.IconName= string.Empty; - this.Status= 0; - this.BizCode= string.Empty; - this.CustomCode= string.Empty; - this.CreateTime= DateTime.Now; - this.CreateId= 0; - this.SortNo= 0; - this.ParentId= null; - this.TypeName= string.Empty; - this.TypeId= string.Empty; - } - - /// - /// 热键 - /// - [Description("热键")] - public string HotKey { get; set; } - - /// - /// 是否叶子节点 - /// - [Description("是否叶子节点")] - public bool IsLeaf { get; set; } - /// - /// 是否自动展开 - /// - [Description("是否自动展开")] - public bool IsAutoExpand { get; set; } - /// - /// 节点图标文件名称 - /// - [Description("节点图标文件名称")] - public string IconName { get; set; } - /// - /// 当前状态 - /// - [Description("当前状态")] - public int Status { get; set; } - /// - /// 业务对照码 - /// - [Description("业务对照码")] - public string BizCode { get; set; } - /// - /// 自定义扩展码 - /// - [Description("自定义扩展码")] - public string CustomCode { get; set; } - /// - /// 创建时间 - /// - [Description("创建时间")] - public System.DateTime CreateTime { get; set; } - /// - /// 创建人ID - /// - [Description("创建人ID")] - public int CreateId { get; set; } - /// - /// 排序号 - /// - [Description("排序号")] - public int SortNo { get; set; } - /// - /// 分类名称 - /// - [Description("分类名称")] - public string TypeName { get; set; } - /// - /// 分类ID - /// - [Description("分类ID")] - public string TypeId { get; set; } - - /// - /// 负责人ID - /// - [Description("负责人ID")] - public string ChairmanId { get; set; } - - } +//------------------------------------------------------------------------------ +// +// This code was generated by a CodeSmith Template. +// +// DO NOT MODIFY contents of this file. Changes to this +// file will be lost if the code is regenerated. +// Author:Yubao Li +// +//------------------------------------------------------------------------------ +using System; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations.Schema; +using OpenAuth.Repository.Core; +using SqlSugar; + +namespace OpenAuth.Repository.Domain +{ + /// + /// 组织表 + /// + [Table("Org")] + [SugarTable("Org")] + public partial class SysOrg : TreeEntity + { + public SysOrg() + { + this.CascadeId= string.Empty; + this.Name= string.Empty; + this.HotKey= string.Empty; + this.ParentName= string.Empty; + this.IconName= string.Empty; + this.Status= 0; + this.BizCode= string.Empty; + this.CustomCode= string.Empty; + this.CreateTime= DateTime.Now; + this.CreateId= 0; + this.SortNo= 0; + this.ParentId= null; + this.TypeName= string.Empty; + this.TypeId= string.Empty; + } + + /// + /// 热键 + /// + [Description("热键")] + public string HotKey { get; set; } + + /// + /// 是否叶子节点 + /// + [Description("是否叶子节点")] + public bool IsLeaf { get; set; } + /// + /// 是否自动展开 + /// + [Description("是否自动展开")] + public bool IsAutoExpand { get; set; } + /// + /// 节点图标文件名称 + /// + [Description("节点图标文件名称")] + public string IconName { get; set; } + /// + /// 当前状态 + /// + [Description("当前状态")] + public int Status { get; set; } + /// + /// 业务对照码 + /// + [Description("业务对照码")] + public string BizCode { get; set; } + /// + /// 自定义扩展码 + /// + [Description("自定义扩展码")] + public string CustomCode { get; set; } + /// + /// 创建时间 + /// + [Description("创建时间")] + public System.DateTime CreateTime { get; set; } + /// + /// 创建人ID + /// + [Description("创建人ID")] + public int CreateId { get; set; } + /// + /// 排序号 + /// + [Description("排序号")] + public int SortNo { get; set; } + /// + /// 分类名称 + /// + [Description("分类名称")] + public string TypeName { get; set; } + /// + /// 分类ID + /// + [Description("分类ID")] + public string TypeId { get; set; } + + /// + /// 负责人ID + /// + [Description("负责人ID")] + public string ChairmanId { get; set; } + + } } \ No newline at end of file diff --git a/OpenAuth.WebApi/Controllers/CheckController.cs b/OpenAuth.WebApi/Controllers/CheckController.cs index c643213a..3ac8e2b2 100644 --- a/OpenAuth.WebApi/Controllers/CheckController.cs +++ b/OpenAuth.WebApi/Controllers/CheckController.cs @@ -146,9 +146,9 @@ namespace OpenAuth.WebApi.Controllers /// 获取登录用户的所有可访问的组织信息 /// [HttpGet] - public Response> GetOrgs() + public Response> GetOrgs() { - var result = new Response>(); + var result = new Response>(); try { result.Result = _authStrategyContext.Orgs;