mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-15 23:13:40 +08:00
fix issue #I80UEX 完善人员可以选择直接上级和部门负责人
This commit is contained in:
parent
c4b1f2d3c6
commit
51155a7790
@ -59,7 +59,7 @@ namespace OpenAuth.App
|
|||||||
get { return _strategy.Resources; }
|
get { return _strategy.Resources; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SysOrg> Orgs
|
public List<OrgView> Orgs
|
||||||
{
|
{
|
||||||
get { return _strategy.Orgs; }
|
get { return _strategy.Orgs; }
|
||||||
}
|
}
|
||||||
|
@ -23,13 +23,14 @@ using OpenAuth.App.Response;
|
|||||||
using OpenAuth.Repository;
|
using OpenAuth.Repository;
|
||||||
using OpenAuth.Repository.Domain;
|
using OpenAuth.Repository.Domain;
|
||||||
using OpenAuth.Repository.Interface;
|
using OpenAuth.Repository.Interface;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
namespace OpenAuth.App
|
namespace OpenAuth.App
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 普通用户授权策略
|
/// 普通用户授权策略
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class NormalAuthStrategy :BaseStringApp<User,OpenAuthDBContext>, IAuthStrategy
|
public class NormalAuthStrategy : SqlSugarBaseApp<User>, IAuthStrategy
|
||||||
{
|
{
|
||||||
|
|
||||||
protected User _user;
|
protected User _user;
|
||||||
@ -40,34 +41,12 @@ namespace OpenAuth.App
|
|||||||
public List<ModuleView> Modules
|
public List<ModuleView> Modules
|
||||||
{
|
{
|
||||||
get {
|
get {
|
||||||
var moduleIds = UnitWork.Find<Relevance>(
|
var moduleIds = SugarClient.Queryable<Relevance>().Where(
|
||||||
u =>
|
u =>
|
||||||
(u.Key == Define.ROLEMODULE && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
(u.Key == Define.ROLEMODULE && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList();
|
||||||
|
|
||||||
var modules = (from module in UnitWork.Find<Module>(u =>moduleIds.Contains(u.Id))
|
return SugarClient.Queryable<ModuleView>().Where(m =>moduleIds.Contains(m.Id)).Includes(x=>x.Elements).ToList();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,37 +54,43 @@ namespace OpenAuth.App
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var elementIds = UnitWork.Find<Relevance>(
|
var elementIds = SugarClient.Queryable<Relevance>().Where(
|
||||||
u =>
|
u =>
|
||||||
(u.Key == Define.ROLEELEMENT && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
(u.Key == Define.ROLEELEMENT && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList();
|
||||||
var usermoduleelements = UnitWork.Find<ModuleElement>(u => elementIds.Contains(u.Id));
|
var usermoduleelements = SugarClient.Queryable<ModuleElement>().Where(u => elementIds.Contains(u.Id));
|
||||||
return usermoduleelements.ToList();
|
return usermoduleelements.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Role> Roles
|
public List<Role> Roles
|
||||||
{
|
{
|
||||||
get { return UnitWork.Find<Role>(u => _userRoleIds.Contains(u.Id)).ToList(); }
|
get { return SugarClient.Queryable<Role>().Where(u => _userRoleIds.Contains(u.Id)).ToList(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Resource> Resources
|
public List<Resource> Resources
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var resourceIds = UnitWork.Find<Relevance>(
|
var resourceIds = SugarClient.Queryable<Relevance>().Where(
|
||||||
u =>
|
u =>
|
||||||
(u.Key == Define.ROLERESOURCE && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
(u.Key == Define.ROLERESOURCE && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList();
|
||||||
return UnitWork.Find<Resource>(u => resourceIds.Contains(u.Id)).ToList();
|
return SugarClient.Queryable<Resource>().Where(u => resourceIds.Contains(u.Id)).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SysOrg> Orgs
|
public List<OrgView> Orgs
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var orgids = UnitWork.Find<Relevance>(
|
var orgids = SugarClient.Queryable<Relevance>().Where(
|
||||||
u =>u.FirstId == _user.Id && u.Key == Define.USERORG).Select(u => u.SecondId);
|
u =>u.FirstId == _user.Id && u.Key == Define.USERORG).Select(u => u.SecondId).ToList();
|
||||||
return UnitWork.Find<SysOrg>(u => orgids.Contains(u.Id)).ToList();
|
return SugarClient.Queryable<SysOrg>().Where(org =>orgids.Contains(org.Id))
|
||||||
|
.LeftJoin<User>((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
|
set
|
||||||
{
|
{
|
||||||
_user = value;
|
_user = value;
|
||||||
_userRoleIds = UnitWork.Find<Relevance>(u => u.FirstId == _user.Id && u.Key == Define.USERROLE).Select(u => u.SecondId).ToList();
|
_userRoleIds = SugarClient.Queryable<Relevance>().Where(u => u.FirstId == _user.Id && u.Key == Define.USERROLE)
|
||||||
|
.Select(u => u.SecondId).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<BuilderTableColumn> GetTableColumns(string moduleCode)
|
public List<BuilderTableColumn> GetTableColumns(string moduleCode)
|
||||||
{
|
{
|
||||||
var allprops = UnitWork.Find<BuilderTableColumn>(u => u.TableName.ToLower() == moduleCode.ToLower());
|
var allprops = SugarClient.Queryable<BuilderTableColumn>()
|
||||||
|
.Where(u => u.TableName.ToLower() == moduleCode.ToLower());
|
||||||
//如果是子表,直接返回所有字段
|
//如果是子表,直接返回所有字段
|
||||||
var builderTable = UnitWork.FirstOrDefault<BuilderTable>(u => u.TableName.ToLower() == moduleCode.ToLower());
|
var builderTable = SugarClient.Queryable<BuilderTable>().First(u => u.TableName.ToLower() == moduleCode.ToLower());
|
||||||
if (builderTable == null)
|
if (builderTable == null)
|
||||||
{
|
{
|
||||||
throw new Exception($"代码生成器中找不到{moduleCode.ToLower()}的定义");
|
throw new Exception($"代码生成器中找不到{moduleCode.ToLower()}的定义");
|
||||||
@ -136,15 +123,15 @@ namespace OpenAuth.App
|
|||||||
}
|
}
|
||||||
|
|
||||||
//如果是系统模块,直接返回所有字段。防止开发者把模块配置成系统模块,还在外层调用loginContext.GetProperties("xxxx");
|
//如果是系统模块,直接返回所有字段。防止开发者把模块配置成系统模块,还在外层调用loginContext.GetProperties("xxxx");
|
||||||
bool? isSysModule = UnitWork.FirstOrDefault<Module>(u => u.Code == moduleCode)?.IsSys;
|
bool? isSysModule = SugarClient.Queryable<Module>().First(u => u.Code == moduleCode)?.IsSys;
|
||||||
if (isSysModule!= null && isSysModule.Value)
|
if (isSysModule!= null && isSysModule.Value)
|
||||||
{
|
{
|
||||||
return allprops.ToList();
|
return allprops.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
var props =UnitWork.Find<Relevance>(u =>
|
var props =SugarClient.Queryable<Relevance>().Where(u =>
|
||||||
u.Key == Define.ROLEDATAPROPERTY && _userRoleIds.Contains(u.FirstId) && u.SecondId == moduleCode)
|
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();
|
return allprops.Where(u => props.Contains(u.ColumnName)).ToList();
|
||||||
}
|
}
|
||||||
@ -154,22 +141,22 @@ namespace OpenAuth.App
|
|||||||
var allprops = _dbExtension.GetTableColumnsFromDb(moduleCode);
|
var allprops = _dbExtension.GetTableColumnsFromDb(moduleCode);
|
||||||
|
|
||||||
//如果是系统模块,直接返回所有字段。防止开发者把模块配置成系统模块,还在外层调用loginContext.GetProperties("xxxx");
|
//如果是系统模块,直接返回所有字段。防止开发者把模块配置成系统模块,还在外层调用loginContext.GetProperties("xxxx");
|
||||||
bool? isSysModule = UnitWork.FirstOrDefault<Module>(u => u.Code == moduleCode)?.IsSys;
|
bool? isSysModule = SugarClient.Queryable<Module>().First(u => u.Code == moduleCode)?.IsSys;
|
||||||
if (isSysModule!= null && isSysModule.Value)
|
if (isSysModule!= null && isSysModule.Value)
|
||||||
{
|
{
|
||||||
return allprops.ToList();
|
return allprops.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
var props =UnitWork.Find<Relevance>(u =>
|
var props =SugarClient.Queryable<Relevance>().Where(u =>
|
||||||
u.Key == Define.ROLEDATAPROPERTY && _userRoleIds.Contains(u.FirstId) && u.SecondId == moduleCode)
|
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();
|
return allprops.Where(u => props.Contains(u.ColumnName)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
//用户角色
|
//用户角色
|
||||||
|
|
||||||
public NormalAuthStrategy(IUnitWork<OpenAuthDBContext> unitWork, IRepository<User,OpenAuthDBContext> repository, DbExtension dbExtension) : base(unitWork, repository,null)
|
public NormalAuthStrategy(ISqlSugarClient client,DbExtension dbExtension) : base(client, null)
|
||||||
{
|
{
|
||||||
_dbExtension = dbExtension;
|
_dbExtension = dbExtension;
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ using OpenAuth.App.Response;
|
|||||||
using OpenAuth.Repository;
|
using OpenAuth.Repository;
|
||||||
using OpenAuth.Repository.Domain;
|
using OpenAuth.Repository.Domain;
|
||||||
using OpenAuth.Repository.Interface;
|
using OpenAuth.Repository.Interface;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
namespace OpenAuth.App
|
namespace OpenAuth.App
|
||||||
{
|
{
|
||||||
@ -30,57 +31,43 @@ namespace OpenAuth.App
|
|||||||
/// <para>超级管理员权限</para>
|
/// <para>超级管理员权限</para>
|
||||||
/// <para>超级管理员使用guid.empty为ID,可以根据需要修改</para>
|
/// <para>超级管理员使用guid.empty为ID,可以根据需要修改</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SystemAuthStrategy : BaseStringApp<User,OpenAuthDBContext>, IAuthStrategy
|
public class SystemAuthStrategy : SqlSugarBaseApp<User>, IAuthStrategy
|
||||||
{
|
{
|
||||||
protected User _user;
|
protected User _user;
|
||||||
private DbExtension _dbExtension;
|
private DbExtension _dbExtension;
|
||||||
|
|
||||||
public List<ModuleView> Modules
|
public List<ModuleView> Modules
|
||||||
{
|
{
|
||||||
get {
|
get
|
||||||
var modules = (from module in UnitWork.Find<Module>(null)
|
{
|
||||||
select new ModuleView
|
return SugarClient.Queryable<ModuleView>().Includes(x=>x.Elements).ToList();
|
||||||
{
|
|
||||||
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<ModuleElement>(u => u.ModuleId == module.Id).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
return modules;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Role> Roles
|
public List<Role> Roles
|
||||||
{
|
{
|
||||||
get { return UnitWork.Find<Role>(null).ToList(); }
|
get { return SugarClient.Queryable<Role>().ToList(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ModuleElement> ModuleElements
|
public List<ModuleElement> ModuleElements
|
||||||
{
|
{
|
||||||
get { return UnitWork.Find<ModuleElement>(null).ToList(); }
|
get { return SugarClient.Queryable<ModuleElement>().ToList(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Resource> Resources
|
public List<Resource> Resources
|
||||||
{
|
{
|
||||||
get { return UnitWork.Find<Resource>(null).ToList(); }
|
get { return SugarClient.Queryable<Resource>().ToList(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SysOrg> Orgs
|
public List<OrgView> Orgs
|
||||||
{
|
{
|
||||||
get { return UnitWork.Find<SysOrg>(null).ToList(); }
|
get { return SugarClient.Queryable<SysOrg>()
|
||||||
|
.LeftJoin<User>((org, user) => org.ChairmanId ==user.Id)
|
||||||
|
.Select((org,user)=>new OrgView
|
||||||
|
{
|
||||||
|
Id = org.Id.SelectAll(),
|
||||||
|
ChairmanName = user.Name
|
||||||
|
}).ToList(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public User User
|
public User User
|
||||||
@ -95,7 +82,7 @@ namespace OpenAuth.App
|
|||||||
|
|
||||||
public List<BuilderTableColumn> GetTableColumns(string moduleCode)
|
public List<BuilderTableColumn> GetTableColumns(string moduleCode)
|
||||||
{
|
{
|
||||||
return UnitWork.Find<BuilderTableColumn>(u => u.TableName.ToLower() == moduleCode.ToLower()).ToList();
|
return SugarClient.Queryable<BuilderTableColumn>().Where(u => u.TableName.ToLower() == moduleCode.ToLower()).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<BuilderTableColumn> GetTableColumnsFromDb(string moduleCode)
|
public List<BuilderTableColumn> GetTableColumnsFromDb(string moduleCode)
|
||||||
@ -104,7 +91,7 @@ namespace OpenAuth.App
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SystemAuthStrategy(IUnitWork<OpenAuthDBContext> unitWork, IRepository<User,OpenAuthDBContext> repository, DbExtension dbExtension) : base(unitWork, repository, null)
|
public SystemAuthStrategy(ISqlSugarClient client,DbExtension dbExtension) : base(client, null)
|
||||||
{
|
{
|
||||||
_dbExtension = dbExtension;
|
_dbExtension = dbExtension;
|
||||||
_user = new User
|
_user = new User
|
||||||
|
@ -33,7 +33,7 @@ namespace OpenAuth.App
|
|||||||
|
|
||||||
List<Resource> Resources { get; }
|
List<Resource> Resources { get; }
|
||||||
|
|
||||||
List<SysOrg> Orgs { get; }
|
List<OrgView> Orgs { get; }
|
||||||
|
|
||||||
User User
|
User User
|
||||||
{
|
{
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using OpenAuth.Repository.Domain;
|
using OpenAuth.Repository.Domain;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
namespace OpenAuth.App.Response
|
namespace OpenAuth.App.Response
|
||||||
{
|
{
|
||||||
|
[SugarTable("Module")]
|
||||||
public class ModuleView
|
public class ModuleView
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -52,10 +54,7 @@ namespace OpenAuth.App.Response
|
|||||||
/// 当前状态,0:正常,-1:隐藏,不在导航列表中显示
|
/// 当前状态,0:正常,-1:隐藏,不在导航列表中显示
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Status { get; set; }
|
public int Status { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public bool Checked { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 排序号
|
/// 排序号
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -68,6 +67,7 @@ namespace OpenAuth.App.Response
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模块中的元素
|
/// 模块中的元素
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Navigate(NavigateType.OneToMany, nameof(ModuleElement.ModuleId),nameof(Id))]
|
||||||
public List<ModuleElement> Elements { get; set; }
|
public List<ModuleElement> Elements { get; set; }
|
||||||
|
|
||||||
public static implicit operator ModuleView(Module module)
|
public static implicit operator ModuleView(Module module)
|
||||||
|
13
OpenAuth.App/OrgManager/Response/OrgView.cs
Normal file
13
OpenAuth.App/OrgManager/Response/OrgView.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using OpenAuth.Repository.Domain;
|
||||||
|
|
||||||
|
namespace OpenAuth.App.Response;
|
||||||
|
|
||||||
|
public class OrgView: SysOrg
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 负责人
|
||||||
|
/// </summary>
|
||||||
|
[Description("负责人")]
|
||||||
|
public string ChairmanName { get; set; }
|
||||||
|
}
|
@ -50,7 +50,10 @@ namespace OpenAuth.App.Response
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string ParentId { get; set; }
|
public string ParentId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 直接上级
|
||||||
|
/// </summary>
|
||||||
|
public string ParentName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建时间
|
/// 创建时间
|
||||||
|
@ -40,7 +40,10 @@ namespace OpenAuth.App
|
|||||||
{
|
{
|
||||||
query = UnitWork.Find<User>(u => u.Name.Contains(request.key) || u.Account.Contains(request.key));
|
query = UnitWork.Find<User>(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<User>(null)
|
||||||
|
on user.ParentId equals user2.Id into tempuser
|
||||||
|
from u in tempuser.DefaultIfEmpty()
|
||||||
join relevance in UnitWork.Find<Relevance>(u => u.Key == "UserOrg")
|
join relevance in UnitWork.Find<Relevance>(u => u.Key == "UserOrg")
|
||||||
on user.Id equals relevance.FirstId into temp
|
on user.Id equals relevance.FirstId into temp
|
||||||
from r in temp.DefaultIfEmpty()
|
from r in temp.DefaultIfEmpty()
|
||||||
@ -60,6 +63,7 @@ namespace OpenAuth.App
|
|||||||
user.TypeId,
|
user.TypeId,
|
||||||
user.TypeName,
|
user.TypeName,
|
||||||
user.ParentId,
|
user.ParentId,
|
||||||
|
ParentName = u.Name, //直属上级
|
||||||
r.Key,
|
r.Key,
|
||||||
r.SecondId,
|
r.SecondId,
|
||||||
OrgId = o.Id,
|
OrgId = o.Id,
|
||||||
@ -86,6 +90,7 @@ namespace OpenAuth.App
|
|||||||
Id = u.First().Id,
|
Id = u.First().Id,
|
||||||
Account = u.Key,
|
Account = u.Key,
|
||||||
Name = u.First().Name,
|
Name = u.First().Name,
|
||||||
|
ParentName = u.First().ParentName,
|
||||||
Sex = u.First().Sex,
|
Sex = u.First().Sex,
|
||||||
Status = u.First().Status,
|
Status = u.First().Status,
|
||||||
ParentId = u.First().ParentId,
|
ParentId = u.First().ParentId,
|
||||||
@ -114,6 +119,9 @@ namespace OpenAuth.App
|
|||||||
query = UnitWork.Find<User>(u => u.Name.Contains(request.key) || u.Account.Contains(request.key));
|
query = UnitWork.Find<User>(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<User>(null)
|
||||||
|
on user.ParentId equals user2.Id into tempuser
|
||||||
|
from u in tempuser.DefaultIfEmpty()
|
||||||
join relevance in UnitWork.Find<Relevance>(u => u.Key == "UserOrg")
|
join relevance in UnitWork.Find<Relevance>(u => u.Key == "UserOrg")
|
||||||
on user.Id equals relevance.FirstId into temp
|
on user.Id equals relevance.FirstId into temp
|
||||||
from r in temp.DefaultIfEmpty()
|
from r in temp.DefaultIfEmpty()
|
||||||
@ -132,6 +140,8 @@ namespace OpenAuth.App
|
|||||||
user.CreateTime,
|
user.CreateTime,
|
||||||
user.TypeId,
|
user.TypeId,
|
||||||
user.TypeName,
|
user.TypeName,
|
||||||
|
user.ParentId,
|
||||||
|
ParentName = u.Name, //直属上级
|
||||||
r.Key,
|
r.Key,
|
||||||
r.SecondId,
|
r.SecondId,
|
||||||
OrgId = o.Id,
|
OrgId = o.Id,
|
||||||
@ -151,6 +161,8 @@ namespace OpenAuth.App
|
|||||||
Status = u.First().Status,
|
Status = u.First().Status,
|
||||||
CreateTime = u.First().CreateTime,
|
CreateTime = u.First().CreateTime,
|
||||||
CreateUser = u.First().CreateId,
|
CreateUser = u.First().CreateId,
|
||||||
|
ParentName = u.First().ParentName,
|
||||||
|
ParentId = u.First().ParentId,
|
||||||
OrganizationIds = string.Join(",", u.Select(x=>x.OrgId))
|
OrganizationIds = string.Join(",", u.Select(x=>x.OrgId))
|
||||||
,Organizations = string.Join(",", u.Select(x=>x.OrgName))
|
,Organizations = string.Join(",", u.Select(x=>x.OrgName))
|
||||||
});
|
});
|
||||||
|
@ -1,196 +1,196 @@
|
|||||||
// ***********************************************************************
|
// ***********************************************************************
|
||||||
// Assembly : OpenAuth.Mvc
|
// Assembly : OpenAuth.Mvc
|
||||||
// Author : 李玉宝
|
// Author : 李玉宝
|
||||||
// Created : 06-08-2018
|
// Created : 06-08-2018
|
||||||
//
|
//
|
||||||
// Last Modified By : 李玉宝
|
// Last Modified By : 李玉宝
|
||||||
// Last Modified On : 07-04-2018
|
// Last Modified On : 07-04-2018
|
||||||
// ***********************************************************************
|
// ***********************************************************************
|
||||||
// <copyright file="UserSessionController.cs" company="OpenAuth.Mvc">
|
// <copyright file="UserSessionController.cs" company="OpenAuth.Mvc">
|
||||||
// Copyright (c) http://www.openauth.net.cn. All rights reserved.
|
// Copyright (c) http://www.openauth.net.cn. All rights reserved.
|
||||||
// </copyright>
|
// </copyright>
|
||||||
// <summary>
|
// <summary>
|
||||||
// 获取登录用户的全部信息
|
// 获取登录用户的全部信息
|
||||||
// 所有和当前登录用户相关的操作都在这里
|
// 所有和当前登录用户相关的操作都在这里
|
||||||
// </summary>
|
// </summary>
|
||||||
// ***********************************************************************
|
// ***********************************************************************
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using Infrastructure.Helpers;
|
using Infrastructure.Helpers;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||||
using OpenAuth.App;
|
using OpenAuth.App;
|
||||||
using OpenAuth.App.Interface;
|
using OpenAuth.App.Interface;
|
||||||
using OpenAuth.App.Response;
|
using OpenAuth.App.Response;
|
||||||
using OpenAuth.Repository.Domain;
|
using OpenAuth.Repository.Domain;
|
||||||
|
|
||||||
namespace OpenAuth.Mvc.Controllers
|
namespace OpenAuth.Mvc.Controllers
|
||||||
{
|
{
|
||||||
public class UserSessionController : BaseController
|
public class UserSessionController : BaseController
|
||||||
{
|
{
|
||||||
private readonly AuthStrategyContext _authStrategyContext;
|
private readonly AuthStrategyContext _authStrategyContext;
|
||||||
public UserSessionController(IAuth authUtil) : base(authUtil)
|
public UserSessionController(IAuth authUtil) : base(authUtil)
|
||||||
{
|
{
|
||||||
_authStrategyContext = _authUtil.GetCurrentUser();
|
_authStrategyContext = _authUtil.GetCurrentUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取用户资料
|
/// 获取用户资料
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetUserProfile()
|
public string GetUserProfile()
|
||||||
{
|
{
|
||||||
var resp = new Response<UserView>();
|
var resp = new Response<UserView>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
resp.Result = _authStrategyContext.User.MapTo<UserView>();
|
resp.Result = _authStrategyContext.User.MapTo<UserView>();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
resp.Code = 500;
|
resp.Code = 500;
|
||||||
resp.Message = e.Message;
|
resp.Message = e.Message;
|
||||||
}
|
}
|
||||||
return JsonHelper.Instance.Serialize(resp);
|
return JsonHelper.Instance.Serialize(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetUserName()
|
public string GetUserName()
|
||||||
{
|
{
|
||||||
return _authUtil.GetUserName();
|
return _authUtil.GetUserName();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取登录用户可访问的所有模块,及模块的操作菜单
|
/// 获取登录用户可访问的所有模块,及模块的操作菜单
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string GetModulesTree()
|
public string GetModulesTree()
|
||||||
{
|
{
|
||||||
var moduleTree = _authStrategyContext.Modules.GenerateTree(u => u.Id, u => u.ParentId);
|
var moduleTree = _authStrategyContext.Modules.GenerateTree(u => u.Id, u => u.ParentId);
|
||||||
return JsonHelper.Instance.Serialize(moduleTree);
|
return JsonHelper.Instance.Serialize(moduleTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// datatable结构的模块列表
|
/// datatable结构的模块列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pId"></param>
|
/// <param name="pId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetModulesTable(string pId)
|
public string GetModulesTable(string pId)
|
||||||
{
|
{
|
||||||
string cascadeId = ".0.";
|
string cascadeId = ".0.";
|
||||||
if (!string.IsNullOrEmpty(pId))
|
if (!string.IsNullOrEmpty(pId))
|
||||||
{
|
{
|
||||||
var obj = _authStrategyContext.Modules.SingleOrDefault(u => u.Id == pId);
|
var obj = _authStrategyContext.Modules.SingleOrDefault(u => u.Id == pId);
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
throw new Exception("未能找到指定对象信息");
|
throw new Exception("未能找到指定对象信息");
|
||||||
cascadeId = obj.CascadeId;
|
cascadeId = obj.CascadeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
var query = _authStrategyContext.Modules.Where(u => u.CascadeId.Contains(cascadeId));
|
var query = _authStrategyContext.Modules.Where(u => u.CascadeId.Contains(cascadeId));
|
||||||
|
|
||||||
return JsonHelper.Instance.Serialize(new TableData
|
return JsonHelper.Instance.Serialize(new TableData
|
||||||
{
|
{
|
||||||
data = query.ToList(),
|
data = query.ToList(),
|
||||||
count = query.Count(),
|
count = query.Count(),
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取用户可访问的模块列表
|
/// 获取用户可访问的模块列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string GetModules()
|
public string GetModules()
|
||||||
{
|
{
|
||||||
var resp = new Response<List<ModuleView>>();
|
var resp = new Response<List<ModuleView>>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
resp.Result = _authStrategyContext.Modules;
|
resp.Result = _authStrategyContext.Modules;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
resp.Code = 500;
|
resp.Code = 500;
|
||||||
resp.Message = e.Message;
|
resp.Message = e.Message;
|
||||||
}
|
}
|
||||||
return JsonHelper.Instance.Serialize(resp);
|
return JsonHelper.Instance.Serialize(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取登录用户可访问的所有部门
|
/// 获取登录用户可访问的所有部门
|
||||||
/// <para>用于树状结构</para>
|
/// <para>用于树状结构</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string GetOrgs()
|
public string GetOrgs()
|
||||||
{
|
{
|
||||||
var resp = new Response<List<SysOrg>>();
|
var resp = new Response<List<OrgView>>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
resp.Result = _authStrategyContext.Orgs;
|
resp.Result = _authStrategyContext.Orgs;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
resp.Code = 500;
|
resp.Code = 500;
|
||||||
resp.Message = e.Message;
|
resp.Message = e.Message;
|
||||||
}
|
}
|
||||||
return JsonHelper.Instance.Serialize(resp);
|
return JsonHelper.Instance.Serialize(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取当前登录用户可访问的字段
|
/// 获取当前登录用户可访问的字段
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="moduleCode">模块的Code,如Category</param>
|
/// <param name="moduleCode">模块的Code,如Category</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetProperties(string moduleCode)
|
public string GetProperties(string moduleCode)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(moduleCode))
|
if (string.IsNullOrEmpty(moduleCode))
|
||||||
{
|
{
|
||||||
throw new Exception("模块标识为空,不能分配可见字段");
|
throw new Exception("模块标识为空,不能分配可见字段");
|
||||||
}
|
}
|
||||||
var list = _authStrategyContext.GetTableColumns(moduleCode);
|
var list = _authStrategyContext.GetTableColumns(moduleCode);
|
||||||
return JsonHelper.Instance.Serialize(new TableData
|
return JsonHelper.Instance.Serialize(new TableData
|
||||||
{
|
{
|
||||||
data = list,
|
data = list,
|
||||||
count = list.Count(),
|
count = list.Count(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return JsonHelper.Instance.Serialize(new TableData
|
return JsonHelper.Instance.Serialize(new TableData
|
||||||
{
|
{
|
||||||
msg =ex.Message,
|
msg =ex.Message,
|
||||||
code = 500,
|
code = 500,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载机构的全部下级机构
|
/// 加载机构的全部下级机构
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="orgId">机构ID</param>
|
/// <param name="orgId">机构ID</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetSubOrgs(string orgId)
|
public string GetSubOrgs(string orgId)
|
||||||
{
|
{
|
||||||
string cascadeId = ".0.";
|
string cascadeId = ".0.";
|
||||||
if (!string.IsNullOrEmpty(orgId))
|
if (!string.IsNullOrEmpty(orgId))
|
||||||
{
|
{
|
||||||
var org = _authStrategyContext.Orgs.SingleOrDefault(u => u.Id == orgId);
|
var org = _authStrategyContext.Orgs.SingleOrDefault(u => u.Id == orgId);
|
||||||
if (org == null)
|
if (org == null)
|
||||||
{
|
{
|
||||||
return JsonHelper.Instance.Serialize(new TableData
|
return JsonHelper.Instance.Serialize(new TableData
|
||||||
{
|
{
|
||||||
msg ="未找到指定的节点",
|
msg ="未找到指定的节点",
|
||||||
code = 500,
|
code = 500,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
cascadeId = org.CascadeId;
|
cascadeId = org.CascadeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
var query = _authStrategyContext.Orgs.Where(u => u.CascadeId.Contains(cascadeId));
|
var query = _authStrategyContext.Orgs.Where(u => u.CascadeId.Contains(cascadeId));
|
||||||
|
|
||||||
return JsonHelper.Instance.Serialize(new TableData
|
return JsonHelper.Instance.Serialize(new TableData
|
||||||
{
|
{
|
||||||
data = query.ToList(),
|
data = query.ToList(),
|
||||||
count = query.Count(),
|
count = query.Count(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,110 +1,112 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <autogenerated>
|
// <autogenerated>
|
||||||
// This code was generated by a CodeSmith Template.
|
// This code was generated by a CodeSmith Template.
|
||||||
//
|
//
|
||||||
// DO NOT MODIFY contents of this file. Changes to this
|
// DO NOT MODIFY contents of this file. Changes to this
|
||||||
// file will be lost if the code is regenerated.
|
// file will be lost if the code is regenerated.
|
||||||
// Author:Yubao Li
|
// Author:Yubao Li
|
||||||
// </autogenerated>
|
// </autogenerated>
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using OpenAuth.Repository.Core;
|
using OpenAuth.Repository.Core;
|
||||||
|
using SqlSugar;
|
||||||
namespace OpenAuth.Repository.Domain
|
|
||||||
{
|
namespace OpenAuth.Repository.Domain
|
||||||
/// <summary>
|
{
|
||||||
/// 组织表
|
/// <summary>
|
||||||
/// </summary>
|
/// 组织表
|
||||||
[Table("Org")]
|
/// </summary>
|
||||||
public partial class SysOrg : TreeEntity
|
[Table("Org")]
|
||||||
{
|
[SugarTable("Org")]
|
||||||
public SysOrg()
|
public partial class SysOrg : TreeEntity
|
||||||
{
|
{
|
||||||
this.CascadeId= string.Empty;
|
public SysOrg()
|
||||||
this.Name= string.Empty;
|
{
|
||||||
this.HotKey= string.Empty;
|
this.CascadeId= string.Empty;
|
||||||
this.ParentName= string.Empty;
|
this.Name= string.Empty;
|
||||||
this.IconName= string.Empty;
|
this.HotKey= string.Empty;
|
||||||
this.Status= 0;
|
this.ParentName= string.Empty;
|
||||||
this.BizCode= string.Empty;
|
this.IconName= string.Empty;
|
||||||
this.CustomCode= string.Empty;
|
this.Status= 0;
|
||||||
this.CreateTime= DateTime.Now;
|
this.BizCode= string.Empty;
|
||||||
this.CreateId= 0;
|
this.CustomCode= string.Empty;
|
||||||
this.SortNo= 0;
|
this.CreateTime= DateTime.Now;
|
||||||
this.ParentId= null;
|
this.CreateId= 0;
|
||||||
this.TypeName= string.Empty;
|
this.SortNo= 0;
|
||||||
this.TypeId= string.Empty;
|
this.ParentId= null;
|
||||||
}
|
this.TypeName= string.Empty;
|
||||||
|
this.TypeId= string.Empty;
|
||||||
/// <summary>
|
}
|
||||||
/// 热键
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
[Description("热键")]
|
/// 热键
|
||||||
public string HotKey { get; set; }
|
/// </summary>
|
||||||
|
[Description("热键")]
|
||||||
/// <summary>
|
public string HotKey { get; set; }
|
||||||
/// 是否叶子节点
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
[Description("是否叶子节点")]
|
/// 是否叶子节点
|
||||||
public bool IsLeaf { get; set; }
|
/// </summary>
|
||||||
/// <summary>
|
[Description("是否叶子节点")]
|
||||||
/// 是否自动展开
|
public bool IsLeaf { get; set; }
|
||||||
/// </summary>
|
/// <summary>
|
||||||
[Description("是否自动展开")]
|
/// 是否自动展开
|
||||||
public bool IsAutoExpand { get; set; }
|
/// </summary>
|
||||||
/// <summary>
|
[Description("是否自动展开")]
|
||||||
/// 节点图标文件名称
|
public bool IsAutoExpand { get; set; }
|
||||||
/// </summary>
|
/// <summary>
|
||||||
[Description("节点图标文件名称")]
|
/// 节点图标文件名称
|
||||||
public string IconName { get; set; }
|
/// </summary>
|
||||||
/// <summary>
|
[Description("节点图标文件名称")]
|
||||||
/// 当前状态
|
public string IconName { get; set; }
|
||||||
/// </summary>
|
/// <summary>
|
||||||
[Description("当前状态")]
|
/// 当前状态
|
||||||
public int Status { get; set; }
|
/// </summary>
|
||||||
/// <summary>
|
[Description("当前状态")]
|
||||||
/// 业务对照码
|
public int Status { get; set; }
|
||||||
/// </summary>
|
/// <summary>
|
||||||
[Description("业务对照码")]
|
/// 业务对照码
|
||||||
public string BizCode { get; set; }
|
/// </summary>
|
||||||
/// <summary>
|
[Description("业务对照码")]
|
||||||
/// 自定义扩展码
|
public string BizCode { get; set; }
|
||||||
/// </summary>
|
/// <summary>
|
||||||
[Description("自定义扩展码")]
|
/// 自定义扩展码
|
||||||
public string CustomCode { get; set; }
|
/// </summary>
|
||||||
/// <summary>
|
[Description("自定义扩展码")]
|
||||||
/// 创建时间
|
public string CustomCode { get; set; }
|
||||||
/// </summary>
|
/// <summary>
|
||||||
[Description("创建时间")]
|
/// 创建时间
|
||||||
public System.DateTime CreateTime { get; set; }
|
/// </summary>
|
||||||
/// <summary>
|
[Description("创建时间")]
|
||||||
/// 创建人ID
|
public System.DateTime CreateTime { get; set; }
|
||||||
/// </summary>
|
/// <summary>
|
||||||
[Description("创建人ID")]
|
/// 创建人ID
|
||||||
public int CreateId { get; set; }
|
/// </summary>
|
||||||
/// <summary>
|
[Description("创建人ID")]
|
||||||
/// 排序号
|
public int CreateId { get; set; }
|
||||||
/// </summary>
|
/// <summary>
|
||||||
[Description("排序号")]
|
/// 排序号
|
||||||
public int SortNo { get; set; }
|
/// </summary>
|
||||||
/// <summary>
|
[Description("排序号")]
|
||||||
/// 分类名称
|
public int SortNo { get; set; }
|
||||||
/// </summary>
|
/// <summary>
|
||||||
[Description("分类名称")]
|
/// 分类名称
|
||||||
public string TypeName { get; set; }
|
/// </summary>
|
||||||
/// <summary>
|
[Description("分类名称")]
|
||||||
/// 分类ID
|
public string TypeName { get; set; }
|
||||||
/// </summary>
|
/// <summary>
|
||||||
[Description("分类ID")]
|
/// 分类ID
|
||||||
public string TypeId { get; set; }
|
/// </summary>
|
||||||
|
[Description("分类ID")]
|
||||||
/// <summary>
|
public string TypeId { get; set; }
|
||||||
/// 负责人ID
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
[Description("负责人ID")]
|
/// 负责人ID
|
||||||
public string ChairmanId { get; set; }
|
/// </summary>
|
||||||
|
[Description("负责人ID")]
|
||||||
}
|
public string ChairmanId { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@ -146,9 +146,9 @@ namespace OpenAuth.WebApi.Controllers
|
|||||||
/// 获取登录用户的所有可访问的组织信息
|
/// 获取登录用户的所有可访问的组织信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public Response<List<SysOrg>> GetOrgs()
|
public Response<List<OrgView>> GetOrgs()
|
||||||
{
|
{
|
||||||
var result = new Response<List<SysOrg>>();
|
var result = new Response<List<OrgView>>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
result.Result = _authStrategyContext.Orgs;
|
result.Result = _authStrategyContext.Orgs;
|
||||||
|
Loading…
Reference in New Issue
Block a user