mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2026-06-23 00:52:07 +08:00
调整为Sqlsugar
This commit is contained in:
@@ -3,13 +3,12 @@ using System.Linq;
|
|||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using OpenAuth.App.Interface;
|
using OpenAuth.App.Interface;
|
||||||
using OpenAuth.App.Request;
|
using OpenAuth.App.Request;
|
||||||
using OpenAuth.Repository;
|
|
||||||
using OpenAuth.Repository.Domain;
|
using OpenAuth.Repository.Domain;
|
||||||
using OpenAuth.Repository.Interface;
|
using SqlSugar;
|
||||||
|
|
||||||
namespace OpenAuth.App
|
namespace OpenAuth.App
|
||||||
{
|
{
|
||||||
public class ModuleManagerApp : BaseTreeApp<Module,OpenAuthDBContext>
|
public class ModuleManagerApp : SqlSugarBaseTreeApp<Module>
|
||||||
{
|
{
|
||||||
private RevelanceManagerApp _revelanceApp;
|
private RevelanceManagerApp _revelanceApp;
|
||||||
|
|
||||||
@@ -23,7 +22,7 @@ namespace OpenAuth.App
|
|||||||
|
|
||||||
CaculateCascade(model);
|
CaculateCascade(model);
|
||||||
|
|
||||||
Repository.Add(model);
|
Repository.Insert(model);
|
||||||
|
|
||||||
AddDefaultMenus(model);
|
AddDefaultMenus(model);
|
||||||
//当前登录用户的所有角色自动分配模块
|
//当前登录用户的所有角色自动分配模块
|
||||||
@@ -52,9 +51,9 @@ namespace OpenAuth.App
|
|||||||
/// <param name="roleId">The role unique identifier.</param>
|
/// <param name="roleId">The role unique identifier.</param>
|
||||||
public IEnumerable<Module> LoadForRole(string roleId)
|
public IEnumerable<Module> LoadForRole(string roleId)
|
||||||
{
|
{
|
||||||
var moduleIds = UnitWork.Find<Relevance>(u => u.FirstId == roleId && u.RelKey == Define.ROLEMODULE)
|
var moduleIds = SugarClient.Queryable<Relevance>().Where(u => u.FirstId == roleId && u.RelKey == Define.ROLEMODULE)
|
||||||
.Select(u => u.SecondId);
|
.Select(u => u.SecondId).ToArray();
|
||||||
return UnitWork.Find<Module>(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo);
|
return SugarClient.Queryable<Module>().Where(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取角色可访问的模块字段
|
//获取角色可访问的模块字段
|
||||||
@@ -68,14 +67,14 @@ namespace OpenAuth.App
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<ModuleElement> LoadMenusForRole(string moduleId, string roleId)
|
public IEnumerable<ModuleElement> LoadMenusForRole(string moduleId, string roleId)
|
||||||
{
|
{
|
||||||
var elementIds = _revelanceApp.Get(Define.ROLEELEMENT, true, roleId);
|
var elementIds = _revelanceApp.Get(Define.ROLEELEMENT, true, roleId).ToArray();
|
||||||
var query = UnitWork.Find<ModuleElement>(u => elementIds.Contains(u.Id));
|
var query = SugarClient.Queryable<ModuleElement>().Where(u => elementIds.Contains(u.Id));
|
||||||
if (!string.IsNullOrEmpty(moduleId))
|
if (!string.IsNullOrEmpty(moduleId))
|
||||||
{
|
{
|
||||||
query = query.Where(u => u.ModuleId == moduleId);
|
query = query.Where(u => u.ModuleId == moduleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return query;
|
return query.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion 用户/角色分配模块
|
#endregion 用户/角色分配模块
|
||||||
@@ -87,9 +86,9 @@ namespace OpenAuth.App
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IEnumerable<SysPrinterPlan> LoadPrinterPlans(string moduleId)
|
public IEnumerable<SysPrinterPlan> LoadPrinterPlans(string moduleId)
|
||||||
{
|
{
|
||||||
var planids = _revelanceApp.Get(Define.MODULEPRINTERPLAN, true, moduleId);
|
var planids = _revelanceApp.Get(Define.MODULEPRINTERPLAN, true, moduleId).ToArray();
|
||||||
var query = UnitWork.Find<SysPrinterPlan>(u => planids.Contains(u.Id));
|
var query = SugarClient.Queryable<SysPrinterPlan>().Where(u => planids.Contains(u.Id));
|
||||||
return query;
|
return query.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -99,9 +98,9 @@ namespace OpenAuth.App
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IEnumerable<FlowScheme> LoadFlowSchemes(string moduleId)
|
public IEnumerable<FlowScheme> LoadFlowSchemes(string moduleId)
|
||||||
{
|
{
|
||||||
var planids = _revelanceApp.Get(Define.MODULE_FLOWSCHEME, true, moduleId);
|
var planids = _revelanceApp.Get(Define.MODULE_FLOWSCHEME, true, moduleId).ToArray();
|
||||||
var query = UnitWork.Find<FlowScheme>(u => planids.Contains(u.Id));
|
var query = SugarClient.Queryable<FlowScheme>().Where(u => planids.Contains(u.Id));
|
||||||
return query;
|
return query.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -113,8 +112,7 @@ namespace OpenAuth.App
|
|||||||
/// <param name="ids"></param>
|
/// <param name="ids"></param>
|
||||||
public void DelMenu(string[] ids)
|
public void DelMenu(string[] ids)
|
||||||
{
|
{
|
||||||
UnitWork.Delete<ModuleElement>(u => ids.Contains(u.Id));
|
SugarClient.Deleteable<ModuleElement>().Where(u => ids.Contains(u.Id)).ExecuteCommand();
|
||||||
UnitWork.Save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -130,28 +128,29 @@ namespace OpenAuth.App
|
|||||||
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
|
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnitWork.ExecuteWithTransaction(() =>
|
SugarClient.Ado.BeginTran();
|
||||||
|
if (model.KeyIsNull())
|
||||||
{
|
{
|
||||||
UnitWork.Add(model);
|
model.GenerateDefaultKeyVal();
|
||||||
|
}
|
||||||
|
SugarClient.Insertable(model).ExecuteCommand();
|
||||||
|
|
||||||
//当前登录用户的所有角色自动分配菜单
|
//当前登录用户的所有角色自动分配菜单
|
||||||
loginContext.Roles.ForEach(u =>
|
loginContext.Roles.ForEach(u =>
|
||||||
|
{
|
||||||
|
_revelanceApp.Assign(new AssignReq
|
||||||
{
|
{
|
||||||
_revelanceApp.Assign(new AssignReq
|
type = Define.ROLEELEMENT,
|
||||||
{
|
firstId = u.Id,
|
||||||
type = Define.ROLEELEMENT,
|
secIds = new[] {model.Id}
|
||||||
firstId = u.Id,
|
|
||||||
secIds = new[] {model.Id}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
UnitWork.Save();
|
|
||||||
});
|
});
|
||||||
|
SugarClient.Ado.CommitTran();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateMenu(ModuleElement model)
|
public void UpdateMenu(ModuleElement model)
|
||||||
{
|
{
|
||||||
UnitWork.Update<ModuleElement>(model);
|
SugarClient.Updateable(model).ExecuteCommand();
|
||||||
UnitWork.Save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//添加默认按钮
|
//添加默认按钮
|
||||||
@@ -197,8 +196,8 @@ namespace OpenAuth.App
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
public ModuleManagerApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Module,OpenAuthDBContext> repository
|
public ModuleManagerApp(ISqlSugarClient client
|
||||||
, RevelanceManagerApp app, IAuth auth) : base(unitWork, repository, auth)
|
, RevelanceManagerApp app, IAuth auth) : base(client, auth)
|
||||||
{
|
{
|
||||||
_revelanceApp = app;
|
_revelanceApp = app;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user