mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2026-02-15 04:48:19 +08:00
增加撤销与启动,详见:#I3ILBG
调整工程结构,采用模块化机制
This commit is contained in:
30
Infrastructure/Const/FlowInstanceStatus.cs
Normal file
30
Infrastructure/Const/FlowInstanceStatus.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
namespace Infrastructure.Const
|
||||
{
|
||||
/// <summary>
|
||||
/// 流程状态
|
||||
/// </summary>
|
||||
public struct FlowInstanceStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// 撤销、召回
|
||||
/// </summary>
|
||||
public const int Draft = -1;
|
||||
/// <summary>
|
||||
/// 正在运行
|
||||
/// </summary>
|
||||
public const int Running = 0;
|
||||
/// <summary>
|
||||
/// 完成
|
||||
/// </summary>
|
||||
public const int Finished = 1;
|
||||
/// <summary>
|
||||
/// 不同意
|
||||
/// </summary>
|
||||
public const int Disagree = 3;
|
||||
/// <summary>
|
||||
/// 驳回
|
||||
/// </summary>
|
||||
public const int Rejected = 4;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -381,6 +381,7 @@ namespace Infrastructure.Helpers
|
||||
/// <param name="addStr">追加内容</param>
|
||||
public static void RegxAddContentByParenthesis(string path, string addStr)
|
||||
{
|
||||
path = StringExtension.ReplacePath(path);
|
||||
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
StreamReader sr = new StreamReader(fs);
|
||||
string originStr = sr.ReadToEnd();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class IdPageReq :PageReq
|
||||
{
|
||||
public string id { get; set; }
|
||||
}
|
||||
}
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class IdPageReq :PageReq
|
||||
{
|
||||
public string id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class PageReq
|
||||
{
|
||||
public int page { get; set; }
|
||||
public int limit { get; set; }
|
||||
|
||||
public string key { get; set; }
|
||||
|
||||
public PageReq()
|
||||
{
|
||||
page = 1;
|
||||
limit = 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class PageReq
|
||||
{
|
||||
public int page { get; set; }
|
||||
public int limit { get; set; }
|
||||
|
||||
public string key { get; set; }
|
||||
|
||||
public PageReq()
|
||||
{
|
||||
page = 1;
|
||||
limit = 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +1,56 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : FundationAdmin
|
||||
// Author : yubaolee
|
||||
// Created : 03-09-2016
|
||||
//
|
||||
// Last Modified By : yubaolee
|
||||
// Last Modified On : 03-09-2016
|
||||
// ***********************************************************************
|
||||
// <copyright file="TableData.cs" company="Microsoft">
|
||||
// 版权所有(C) Microsoft 2015
|
||||
// </copyright>
|
||||
// <summary>layui datatable数据返回</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Infrastructure;
|
||||
|
||||
namespace OpenAuth.App.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// table的返回数据
|
||||
/// </summary>
|
||||
public class TableData
|
||||
{
|
||||
/// <summary>
|
||||
/// 状态码
|
||||
/// </summary>
|
||||
public int code { get; set; }
|
||||
/// <summary>
|
||||
/// 操作消息
|
||||
/// </summary>
|
||||
public string msg { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总记录条数
|
||||
/// </summary>
|
||||
public int count { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回的列表头信息
|
||||
/// </summary>
|
||||
public List<KeyDescription> columnHeaders;
|
||||
|
||||
/// <summary>
|
||||
/// 数据内容
|
||||
/// </summary>
|
||||
public dynamic data { get; set; }
|
||||
|
||||
public TableData()
|
||||
{
|
||||
code = 200;
|
||||
msg = "加载成功";
|
||||
columnHeaders = new List<KeyDescription>();
|
||||
}
|
||||
}
|
||||
// ***********************************************************************
|
||||
// Assembly : FundationAdmin
|
||||
// Author : yubaolee
|
||||
// Created : 03-09-2016
|
||||
//
|
||||
// Last Modified By : yubaolee
|
||||
// Last Modified On : 03-09-2016
|
||||
// ***********************************************************************
|
||||
// <copyright file="TableData.cs" company="Microsoft">
|
||||
// 版权所有(C) Microsoft 2015
|
||||
// </copyright>
|
||||
// <summary>layui datatable数据返回</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Infrastructure;
|
||||
|
||||
namespace OpenAuth.App.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// table的返回数据
|
||||
/// </summary>
|
||||
public class TableData
|
||||
{
|
||||
/// <summary>
|
||||
/// 状态码
|
||||
/// </summary>
|
||||
public int code { get; set; }
|
||||
/// <summary>
|
||||
/// 操作消息
|
||||
/// </summary>
|
||||
public string msg { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总记录条数
|
||||
/// </summary>
|
||||
public int count { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回的列表头信息
|
||||
/// </summary>
|
||||
public List<KeyDescription> columnHeaders;
|
||||
|
||||
/// <summary>
|
||||
/// 数据内容
|
||||
/// </summary>
|
||||
public dynamic data { get; set; }
|
||||
|
||||
public TableData()
|
||||
{
|
||||
code = 200;
|
||||
msg = "加载成功";
|
||||
columnHeaders = new List<KeyDescription>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,98 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class CategoryApp : BaseStringApp<Category,OpenAuthDBContext>
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载列表
|
||||
/// </summary>
|
||||
public async Task<TableData> Load(QueryCategoryListReq request)
|
||||
{
|
||||
var loginContext = _auth.GetCurrentUser();
|
||||
if (loginContext == null)
|
||||
{
|
||||
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
|
||||
}
|
||||
|
||||
var properties = loginContext.GetProperties("Category");
|
||||
|
||||
if (properties == null || properties.Count == 0)
|
||||
{
|
||||
throw new Exception("当前登录用户没有访问该模块字段的权限,请联系管理员配置");
|
||||
}
|
||||
|
||||
var result = new TableData();
|
||||
var objs = UnitWork.Find<Category>(null);
|
||||
if (!string.IsNullOrEmpty(request.TypeId))
|
||||
{
|
||||
objs = objs.Where(u => u.TypeId == request.TypeId);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
objs = objs.Where(u => u.Id.Contains(request.key) || u.Name.Contains(request.key));
|
||||
}
|
||||
|
||||
var propertyStr = string.Join(',', properties.Select(u =>u.Key));
|
||||
result.columnHeaders = properties;
|
||||
result.data = objs.OrderBy(u => u.DtCode)
|
||||
.Skip((request.page - 1) * request.limit)
|
||||
.Take(request.limit).Select($"new ({propertyStr})");
|
||||
result.count = objs.Count();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Add(AddOrUpdateCategoryReq req)
|
||||
{
|
||||
var obj = req.MapTo<Category>();
|
||||
obj.CreateTime = DateTime.Now;
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
obj.CreateUserId = user.Id;
|
||||
obj.CreateUserName = user.Name;
|
||||
Repository.Add(obj);
|
||||
}
|
||||
|
||||
public void Update(AddOrUpdateCategoryReq obj)
|
||||
{
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
UnitWork.Update<Category>(u => u.Id == obj.Id, u => new Category
|
||||
{
|
||||
Enable = obj.Enable,
|
||||
DtValue = obj.DtValue,
|
||||
DtCode = obj.DtCode,
|
||||
TypeId = obj.TypeId,
|
||||
UpdateTime = DateTime.Now,
|
||||
UpdateUserId = user.Id,
|
||||
UpdateUserName = user.Name
|
||||
//todo:要修改的字段赋值
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载一个分类类型里面的所有值,即字典的所有值
|
||||
/// </summary>
|
||||
/// <param name="typeId"></param>
|
||||
/// <returns></returns>
|
||||
public List<Category> LoadByTypeId(string typeId)
|
||||
{
|
||||
return Repository.Find(u => u.TypeId == typeId).ToList();
|
||||
}
|
||||
|
||||
public CategoryApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Category,OpenAuthDBContext> repository,IAuth auth) : base(unitWork, repository, auth)
|
||||
{
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class CategoryApp : BaseStringApp<Category,OpenAuthDBContext>
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载列表
|
||||
/// </summary>
|
||||
public async Task<TableData> Load(QueryCategoryListReq request)
|
||||
{
|
||||
var loginContext = _auth.GetCurrentUser();
|
||||
if (loginContext == null)
|
||||
{
|
||||
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
|
||||
}
|
||||
|
||||
var properties = loginContext.GetProperties("Category");
|
||||
|
||||
if (properties == null || properties.Count == 0)
|
||||
{
|
||||
throw new Exception("当前登录用户没有访问该模块字段的权限,请联系管理员配置");
|
||||
}
|
||||
|
||||
var result = new TableData();
|
||||
var objs = UnitWork.Find<Category>(null);
|
||||
if (!string.IsNullOrEmpty(request.TypeId))
|
||||
{
|
||||
objs = objs.Where(u => u.TypeId == request.TypeId);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
objs = objs.Where(u => u.Id.Contains(request.key) || u.Name.Contains(request.key));
|
||||
}
|
||||
|
||||
var propertyStr = string.Join(',', properties.Select(u =>u.Key));
|
||||
result.columnHeaders = properties;
|
||||
result.data = objs.OrderBy(u => u.DtCode)
|
||||
.Skip((request.page - 1) * request.limit)
|
||||
.Take(request.limit).Select($"new ({propertyStr})");
|
||||
result.count = objs.Count();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Add(AddOrUpdateCategoryReq req)
|
||||
{
|
||||
var obj = req.MapTo<Category>();
|
||||
obj.CreateTime = DateTime.Now;
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
obj.CreateUserId = user.Id;
|
||||
obj.CreateUserName = user.Name;
|
||||
Repository.Add(obj);
|
||||
}
|
||||
|
||||
public void Update(AddOrUpdateCategoryReq obj)
|
||||
{
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
UnitWork.Update<Category>(u => u.Id == obj.Id, u => new Category
|
||||
{
|
||||
Enable = obj.Enable,
|
||||
DtValue = obj.DtValue,
|
||||
DtCode = obj.DtCode,
|
||||
TypeId = obj.TypeId,
|
||||
UpdateTime = DateTime.Now,
|
||||
UpdateUserId = user.Id,
|
||||
UpdateUserName = user.Name
|
||||
//todo:要修改的字段赋值
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载一个分类类型里面的所有值,即字典的所有值
|
||||
/// </summary>
|
||||
/// <param name="typeId"></param>
|
||||
/// <returns></returns>
|
||||
public List<Category> LoadByTypeId(string typeId)
|
||||
{
|
||||
return Repository.Find(u => u.TypeId == typeId).ToList();
|
||||
}
|
||||
|
||||
public CategoryApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Category,OpenAuthDBContext> repository,IAuth auth) : base(unitWork, repository, auth)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,6 +325,17 @@ namespace OpenAuth.App.Flow
|
||||
return previousId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 撤销流程,清空所有节点
|
||||
/// </summary>
|
||||
public void ReCall()
|
||||
{
|
||||
foreach (var item in Nodes)
|
||||
{
|
||||
item.Value.setInfo = null;
|
||||
}
|
||||
}
|
||||
|
||||
///<summary>
|
||||
/// 标记节点1通过,-1不通过,0驳回
|
||||
/// </summary>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class QueryFlowInstanceListReq : PageReq
|
||||
{
|
||||
public string type { get; set; }
|
||||
}
|
||||
}
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class QueryFlowInstanceListReq : PageReq
|
||||
{
|
||||
public string type { get; set; }
|
||||
}
|
||||
}
|
||||
18
OpenAuth.App/FlowInstance/Request/RecallFlowInstanceReq.cs
Normal file
18
OpenAuth.App/FlowInstance/Request/RecallFlowInstanceReq.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// 召回、撤销流程
|
||||
/// </summary>
|
||||
public class RecallFlowInstanceReq
|
||||
{
|
||||
/// <summary>
|
||||
/// 召回、撤销的流程实例ID
|
||||
/// </summary>
|
||||
public string FlowInstanceId { get; set; }
|
||||
/// <summary>
|
||||
/// 撤回备注
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
14
OpenAuth.App/FlowInstance/Request/StartFlowInstanceReq.cs
Normal file
14
OpenAuth.App/FlowInstance/Request/StartFlowInstanceReq.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// 启动流程
|
||||
/// </summary>
|
||||
public class StartFlowInstanceReq
|
||||
{
|
||||
/// <summary>
|
||||
/// 启动流程的实例Id
|
||||
/// </summary>
|
||||
public string FlowInstanceId { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,26 @@
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class VerificationReq
|
||||
{
|
||||
public string FlowInstanceId { get; set; }
|
||||
/// <summary>
|
||||
/// 1:同意;2:不同意;3:驳回
|
||||
/// </summary>
|
||||
public string VerificationFinally { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 审核意见
|
||||
/// </summary>
|
||||
public string VerificationOpinion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 驳回的步骤,即驳回到的节点ID
|
||||
/// </summary>
|
||||
public string NodeRejectStep { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 驳回类型。null:使用节点配置的驳回类型/0:前一步/1:第一步/2:指定节点,使用NodeRejectStep
|
||||
/// </summary>
|
||||
public string NodeRejectType { get; set; }
|
||||
}
|
||||
}
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class VerificationReq
|
||||
{
|
||||
public string FlowInstanceId { get; set; }
|
||||
/// <summary>
|
||||
/// 1:同意;2:不同意;3:驳回
|
||||
/// </summary>
|
||||
public string VerificationFinally { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 审核意见
|
||||
/// </summary>
|
||||
public string VerificationOpinion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 驳回的步骤,即驳回到的节点ID
|
||||
/// </summary>
|
||||
public string NodeRejectStep { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 驳回类型。null:使用节点配置的驳回类型/0:前一步/1:第一步/2:指定节点,使用NodeRejectStep
|
||||
/// </summary>
|
||||
public string NodeRejectType { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
using OpenAuth.Repository.Domain;
|
||||
|
||||
namespace OpenAuth.App.Response
|
||||
{
|
||||
public class FlowVerificationResp :FlowInstance
|
||||
{
|
||||
/// <summary>
|
||||
/// 预览表单数据
|
||||
/// </summary>
|
||||
/// <value>The FRM data HTML.</value>
|
||||
public string FrmPreviewHtml
|
||||
{
|
||||
get { return FormUtil.Preview(this); }
|
||||
}
|
||||
}
|
||||
}
|
||||
using OpenAuth.Repository.Domain;
|
||||
|
||||
namespace OpenAuth.App.Response
|
||||
{
|
||||
public class FlowVerificationResp :FlowInstance
|
||||
{
|
||||
/// <summary>
|
||||
/// 预览表单数据
|
||||
/// </summary>
|
||||
/// <value>The FRM data HTML.</value>
|
||||
public string FrmPreviewHtml
|
||||
{
|
||||
get { return FormUtil.Preview(this); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,73 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class FlowSchemeApp :BaseStringApp<FlowScheme,OpenAuthDBContext>
|
||||
{
|
||||
public void Add(FlowScheme flowScheme)
|
||||
{
|
||||
if (Repository.Any(u => u.SchemeName == flowScheme.SchemeName))
|
||||
{
|
||||
throw new Exception("流程名称已经存在");
|
||||
}
|
||||
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
flowScheme.CreateUserId = user.Id;
|
||||
flowScheme.CreateUserName = user.Name;
|
||||
Repository.Add(flowScheme);
|
||||
}
|
||||
|
||||
public FlowScheme FindByCode(string code)
|
||||
{
|
||||
return Repository.FirstOrDefault(u => u.SchemeCode == code);
|
||||
}
|
||||
|
||||
public void Update(FlowScheme flowScheme)
|
||||
{
|
||||
if (Repository.Any(u => u.SchemeName == flowScheme.SchemeName && u.Id != flowScheme.Id))
|
||||
{
|
||||
throw new Exception("流程名称已经存在");
|
||||
}
|
||||
|
||||
UnitWork.Update<FlowScheme>(u => u.Id == flowScheme.Id, u => new FlowScheme
|
||||
{
|
||||
SchemeContent = flowScheme.SchemeContent,
|
||||
SchemeName = flowScheme.SchemeName,
|
||||
ModifyDate = DateTime.Now,
|
||||
FrmId = flowScheme.FrmId,
|
||||
FrmType = flowScheme.FrmType,
|
||||
Disabled = flowScheme.Disabled,
|
||||
Description = flowScheme.Description,
|
||||
OrgId = flowScheme.OrgId
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<TableData> Load(QueryFlowSchemeListReq request)
|
||||
{
|
||||
var result = new TableData();
|
||||
var objs = GetDataPrivilege("u");
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
objs = objs.Where(u => u.SchemeName.Contains(request.key) || u.Id.Contains(request.key));
|
||||
}
|
||||
|
||||
result.data = objs.OrderByDescending(u => u.CreateDate)
|
||||
.Skip((request.page - 1) * request.limit)
|
||||
.Take(request.limit).ToList();
|
||||
result.count = objs.Count();
|
||||
return result;
|
||||
}
|
||||
|
||||
public FlowSchemeApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<FlowScheme,OpenAuthDBContext> repository,IAuth auth) : base(unitWork, repository, auth)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class FlowSchemeApp :BaseStringApp<FlowScheme,OpenAuthDBContext>
|
||||
{
|
||||
public void Add(FlowScheme flowScheme)
|
||||
{
|
||||
if (Repository.Any(u => u.SchemeName == flowScheme.SchemeName))
|
||||
{
|
||||
throw new Exception("流程名称已经存在");
|
||||
}
|
||||
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
flowScheme.CreateUserId = user.Id;
|
||||
flowScheme.CreateUserName = user.Name;
|
||||
Repository.Add(flowScheme);
|
||||
}
|
||||
|
||||
public FlowScheme FindByCode(string code)
|
||||
{
|
||||
return Repository.FirstOrDefault(u => u.SchemeCode == code);
|
||||
}
|
||||
|
||||
public void Update(FlowScheme flowScheme)
|
||||
{
|
||||
if (Repository.Any(u => u.SchemeName == flowScheme.SchemeName && u.Id != flowScheme.Id))
|
||||
{
|
||||
throw new Exception("流程名称已经存在");
|
||||
}
|
||||
|
||||
UnitWork.Update<FlowScheme>(u => u.Id == flowScheme.Id, u => new FlowScheme
|
||||
{
|
||||
SchemeContent = flowScheme.SchemeContent,
|
||||
SchemeName = flowScheme.SchemeName,
|
||||
ModifyDate = DateTime.Now,
|
||||
FrmId = flowScheme.FrmId,
|
||||
FrmType = flowScheme.FrmType,
|
||||
Disabled = flowScheme.Disabled,
|
||||
Description = flowScheme.Description,
|
||||
OrgId = flowScheme.OrgId
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<TableData> Load(QueryFlowSchemeListReq request)
|
||||
{
|
||||
var result = new TableData();
|
||||
var objs = GetDataPrivilege("u");
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
objs = objs.Where(u => u.SchemeName.Contains(request.key) || u.Id.Contains(request.key));
|
||||
}
|
||||
|
||||
result.data = objs.OrderByDescending(u => u.CreateDate)
|
||||
.Skip((request.page - 1) * request.limit)
|
||||
.Take(request.limit).ToList();
|
||||
result.count = objs.Count();
|
||||
return result;
|
||||
}
|
||||
|
||||
public FlowSchemeApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<FlowScheme,OpenAuthDBContext> repository,IAuth auth) : base(unitWork, repository, auth)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class QueryFlowSchemeListReq : PageReq
|
||||
{
|
||||
public string orgId { get; set; }
|
||||
}
|
||||
}
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class QueryFlowSchemeListReq : PageReq
|
||||
{
|
||||
public string orgId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,87 +1,87 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Infrastructure;
|
||||
using Microsoft.Extensions.Options;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class FormApp : BaseStringApp<Form,OpenAuthDBContext>
|
||||
{
|
||||
private IAuth _auth;
|
||||
private IOptions<AppSetting> _appConfiguration;
|
||||
/// <summary>
|
||||
/// 加载列表
|
||||
/// </summary>
|
||||
public async Task<TableData> Load(QueryFormListReq request)
|
||||
{
|
||||
var result = new TableData();
|
||||
var forms = GetDataPrivilege("u");
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
forms = forms.Where(u => u.Name.Contains(request.key) || u.Id.Contains(request.key));
|
||||
}
|
||||
|
||||
result.data = forms.OrderByDescending(u => u.CreateDate)
|
||||
.Skip((request.page - 1) * request.limit)
|
||||
.Take(request.limit).ToList();
|
||||
result.count = forms.Count();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Add(Form obj)
|
||||
{
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
obj.CreateUserId = user.Id;
|
||||
obj.CreateUserName = user.Name;
|
||||
UnitWork.Add(obj);
|
||||
if (!string.IsNullOrEmpty(obj.DbName))
|
||||
{
|
||||
UnitWork.ExecuteSql(FormUtil.GetSql(obj, _appConfiguration.Value.DbType));
|
||||
}
|
||||
UnitWork.Save();
|
||||
}
|
||||
|
||||
public void Update(Form obj)
|
||||
{
|
||||
Repository.Update(u => u.Id == obj.Id, u => new Form
|
||||
{
|
||||
ContentData = obj.ContentData,
|
||||
Content = obj.Content,
|
||||
ContentParse = obj.ContentParse,
|
||||
Name = obj.Name,
|
||||
Disabled = obj.Disabled,
|
||||
DbName = obj.DbName,
|
||||
SortCode = obj.SortCode,
|
||||
Description = obj.Description,
|
||||
OrgId = obj.OrgId,
|
||||
ModifyDate = DateTime.Now
|
||||
});
|
||||
|
||||
if (!string.IsNullOrEmpty(obj.DbName))
|
||||
{
|
||||
UnitWork.ExecuteSql(FormUtil.GetSql(obj, _appConfiguration.Value.DbType));
|
||||
}
|
||||
}
|
||||
|
||||
public FormResp FindSingle(string id)
|
||||
{
|
||||
var form = Get(id);
|
||||
return form.MapTo<FormResp>();
|
||||
}
|
||||
|
||||
public FormApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Form,OpenAuthDBContext> repository,
|
||||
IAuth auth, IOptions<AppSetting> appConfiguration) : base(unitWork, repository, auth)
|
||||
{
|
||||
_auth = auth;
|
||||
_appConfiguration = appConfiguration;
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Infrastructure;
|
||||
using Microsoft.Extensions.Options;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class FormApp : BaseStringApp<Form,OpenAuthDBContext>
|
||||
{
|
||||
private IAuth _auth;
|
||||
private IOptions<AppSetting> _appConfiguration;
|
||||
/// <summary>
|
||||
/// 加载列表
|
||||
/// </summary>
|
||||
public async Task<TableData> Load(QueryFormListReq request)
|
||||
{
|
||||
var result = new TableData();
|
||||
var forms = GetDataPrivilege("u");
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
forms = forms.Where(u => u.Name.Contains(request.key) || u.Id.Contains(request.key));
|
||||
}
|
||||
|
||||
result.data = forms.OrderByDescending(u => u.CreateDate)
|
||||
.Skip((request.page - 1) * request.limit)
|
||||
.Take(request.limit).ToList();
|
||||
result.count = forms.Count();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Add(Form obj)
|
||||
{
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
obj.CreateUserId = user.Id;
|
||||
obj.CreateUserName = user.Name;
|
||||
UnitWork.Add(obj);
|
||||
if (!string.IsNullOrEmpty(obj.DbName))
|
||||
{
|
||||
UnitWork.ExecuteSql(FormUtil.GetSql(obj, _appConfiguration.Value.DbType));
|
||||
}
|
||||
UnitWork.Save();
|
||||
}
|
||||
|
||||
public void Update(Form obj)
|
||||
{
|
||||
Repository.Update(u => u.Id == obj.Id, u => new Form
|
||||
{
|
||||
ContentData = obj.ContentData,
|
||||
Content = obj.Content,
|
||||
ContentParse = obj.ContentParse,
|
||||
Name = obj.Name,
|
||||
Disabled = obj.Disabled,
|
||||
DbName = obj.DbName,
|
||||
SortCode = obj.SortCode,
|
||||
Description = obj.Description,
|
||||
OrgId = obj.OrgId,
|
||||
ModifyDate = DateTime.Now
|
||||
});
|
||||
|
||||
if (!string.IsNullOrEmpty(obj.DbName))
|
||||
{
|
||||
UnitWork.ExecuteSql(FormUtil.GetSql(obj, _appConfiguration.Value.DbType));
|
||||
}
|
||||
}
|
||||
|
||||
public FormResp FindSingle(string id)
|
||||
{
|
||||
var form = Get(id);
|
||||
return form.MapTo<FormResp>();
|
||||
}
|
||||
|
||||
public FormApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Form,OpenAuthDBContext> repository,
|
||||
IAuth auth, IOptions<AppSetting> appConfiguration) : base(unitWork, repository, auth)
|
||||
{
|
||||
_auth = auth;
|
||||
_appConfiguration = appConfiguration;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class QueryFormListReq : PageReq
|
||||
{
|
||||
public string orgId { get; set; }
|
||||
}
|
||||
}
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class QueryFormListReq : PageReq
|
||||
{
|
||||
public string orgId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,73 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <autogenerated>
|
||||
// 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
|
||||
// </autogenerated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace OpenAuth.App.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// 表单模板表
|
||||
/// </summary>
|
||||
public class FormResp
|
||||
{
|
||||
/// <summary>
|
||||
/// 表单名称
|
||||
/// </summary>
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 表单名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// 字段个数
|
||||
/// </summary>
|
||||
public int Fields { get; set; }
|
||||
/// <summary>
|
||||
/// 表单类型,0:默认动态表单;1:Web自定义表单
|
||||
/// </summary>
|
||||
public int FrmType { get; set; }
|
||||
/// <summary>
|
||||
/// 系统页面标识,当表单类型为用Web自定义的表单时,需要标识加载哪个页面
|
||||
/// </summary>
|
||||
public string WebId { get; set; }
|
||||
/// <summary>
|
||||
/// 表单中的字段数据
|
||||
/// </summary>
|
||||
public string ContentData { get; set; }
|
||||
/// <summary>
|
||||
/// 表单替换的模板 经过处理
|
||||
/// </summary>
|
||||
public string ContentParse { get; set; }
|
||||
/// <summary>
|
||||
/// 表单原html模板未经处理的
|
||||
/// </summary>
|
||||
public string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序码
|
||||
/// </summary>
|
||||
public int SortCode { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 数据库名称
|
||||
/// </summary>
|
||||
public string DbName { get; set; }
|
||||
/// <summary>
|
||||
/// 用户显示
|
||||
/// </summary>
|
||||
public string Html
|
||||
{
|
||||
get { return FormUtil.GetHtml(this); }
|
||||
}
|
||||
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
// <autogenerated>
|
||||
// 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
|
||||
// </autogenerated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace OpenAuth.App.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// 表单模板表
|
||||
/// </summary>
|
||||
public class FormResp
|
||||
{
|
||||
/// <summary>
|
||||
/// 表单名称
|
||||
/// </summary>
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 表单名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// 字段个数
|
||||
/// </summary>
|
||||
public int Fields { get; set; }
|
||||
/// <summary>
|
||||
/// 表单类型,0:默认动态表单;1:Web自定义表单
|
||||
/// </summary>
|
||||
public int FrmType { get; set; }
|
||||
/// <summary>
|
||||
/// 系统页面标识,当表单类型为用Web自定义的表单时,需要标识加载哪个页面
|
||||
/// </summary>
|
||||
public string WebId { get; set; }
|
||||
/// <summary>
|
||||
/// 表单中的字段数据
|
||||
/// </summary>
|
||||
public string ContentData { get; set; }
|
||||
/// <summary>
|
||||
/// 表单替换的模板 经过处理
|
||||
/// </summary>
|
||||
public string ContentParse { get; set; }
|
||||
/// <summary>
|
||||
/// 表单原html模板未经处理的
|
||||
/// </summary>
|
||||
public string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序码
|
||||
/// </summary>
|
||||
public int SortCode { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 数据库名称
|
||||
/// </summary>
|
||||
public string DbName { get; set; }
|
||||
/// <summary>
|
||||
/// 用户显示
|
||||
/// </summary>
|
||||
public string Html
|
||||
{
|
||||
get { return FormUtil.GetHtml(this); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,182 +1,182 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class ModuleManagerApp : BaseTreeApp<Module,OpenAuthDBContext>
|
||||
{
|
||||
private RevelanceManagerApp _revelanceApp;
|
||||
|
||||
public void Add(Module model)
|
||||
{
|
||||
var loginContext = _auth.GetCurrentUser();
|
||||
if (loginContext == null)
|
||||
{
|
||||
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
|
||||
}
|
||||
|
||||
CaculateCascade(model);
|
||||
|
||||
Repository.Add(model);
|
||||
|
||||
AddDefaultMenus(model);
|
||||
//当前登录用户的所有角色自动分配模块
|
||||
loginContext.Roles.ForEach(u =>
|
||||
{
|
||||
_revelanceApp.Assign(new AssignReq
|
||||
{
|
||||
type = Define.ROLEMODULE,
|
||||
firstId = u.Id,
|
||||
secIds = new[] {model.Id}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void Update(Module obj)
|
||||
{
|
||||
UpdateTreeObj(obj);
|
||||
}
|
||||
|
||||
|
||||
#region 用户/角色分配模块
|
||||
|
||||
/// <summary>
|
||||
/// 加载特定角色的模块
|
||||
/// </summary>
|
||||
/// <param name="roleId">The role unique identifier.</param>
|
||||
public IEnumerable<Module> LoadForRole(string roleId)
|
||||
{
|
||||
var moduleIds = UnitWork.Find<Relevance>(u => u.FirstId == roleId && u.Key == Define.ROLEMODULE)
|
||||
.Select(u => u.SecondId);
|
||||
return UnitWork.Find<Module>(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo);
|
||||
}
|
||||
|
||||
//获取角色可访问的模块字段
|
||||
public IEnumerable<string> LoadPropertiesForRole(string roleId, string moduleCode)
|
||||
{
|
||||
return _revelanceApp.Get(Define.ROLEDATAPROPERTY, roleId, moduleCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据某角色ID获取可访问某模块的菜单项
|
||||
/// </summary>
|
||||
public IEnumerable<ModuleElement> LoadMenusForRole(string moduleId, string roleId)
|
||||
{
|
||||
var elementIds = _revelanceApp.Get(Define.ROLEELEMENT, true, roleId);
|
||||
var query = UnitWork.Find<ModuleElement>(u => elementIds.Contains(u.Id));
|
||||
if (!string.IsNullOrEmpty(moduleId))
|
||||
{
|
||||
query = query.Where(u => u.ModuleId == moduleId);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
#endregion 用户/角色分配模块
|
||||
|
||||
|
||||
#region 菜单操作
|
||||
|
||||
/// <summary>
|
||||
/// 删除指定的菜单
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
public void DelMenu(string[] ids)
|
||||
{
|
||||
UnitWork.Delete<ModuleElement>(u => ids.Contains(u.Id));
|
||||
UnitWork.Save();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 新增菜单
|
||||
/// <para>当前登录用户的所有角色会自动分配菜单</para>
|
||||
/// </summary>
|
||||
public void AddMenu(ModuleElement model)
|
||||
{
|
||||
var loginContext = _auth.GetCurrentUser();
|
||||
if (loginContext == null)
|
||||
{
|
||||
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
|
||||
}
|
||||
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
UnitWork.Add(model);
|
||||
|
||||
//当前登录用户的所有角色自动分配菜单
|
||||
loginContext.Roles.ForEach(u =>
|
||||
{
|
||||
_revelanceApp.Assign(new AssignReq
|
||||
{
|
||||
type = Define.ROLEELEMENT,
|
||||
firstId = u.Id,
|
||||
secIds = new[] {model.Id}
|
||||
});
|
||||
});
|
||||
UnitWork.Save();
|
||||
});
|
||||
}
|
||||
|
||||
public void UpdateMenu(ModuleElement model)
|
||||
{
|
||||
UnitWork.Update<ModuleElement>(model);
|
||||
UnitWork.Save();
|
||||
}
|
||||
|
||||
//添加默认按钮
|
||||
private void AddDefaultMenus(Module module)
|
||||
{
|
||||
AddMenu(new ModuleElement
|
||||
{
|
||||
ModuleId = module.Id,
|
||||
DomId = "btnAdd",
|
||||
Script = "add()",
|
||||
Name = "添加",
|
||||
Sort = 1,
|
||||
Icon = "xinzeng",
|
||||
Class = "success",
|
||||
Remark = "新增" + module.Name
|
||||
});
|
||||
AddMenu(new ModuleElement
|
||||
{
|
||||
ModuleId = module.Id,
|
||||
DomId = "btnEdit",
|
||||
Script = "edit()",
|
||||
Name = "编辑",
|
||||
Sort = 2,
|
||||
Icon = "bianji-copy",
|
||||
Class = "primary",
|
||||
Remark = "修改" + module.Name
|
||||
});
|
||||
AddMenu(new ModuleElement
|
||||
{
|
||||
ModuleId = module.Id,
|
||||
DomId = "btnDel",
|
||||
Script = "del()",
|
||||
Name = "删除",
|
||||
Sort = 3,
|
||||
Icon = "shanchu",
|
||||
Class = "danger",
|
||||
Remark = "删除" + module.Name
|
||||
});
|
||||
|
||||
//todo:可以自己添加更多默认按钮
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public ModuleManagerApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Module,OpenAuthDBContext> repository
|
||||
, RevelanceManagerApp app, IAuth auth) : base(unitWork, repository, auth)
|
||||
{
|
||||
_revelanceApp = app;
|
||||
}
|
||||
}
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class ModuleManagerApp : BaseTreeApp<Module,OpenAuthDBContext>
|
||||
{
|
||||
private RevelanceManagerApp _revelanceApp;
|
||||
|
||||
public void Add(Module model)
|
||||
{
|
||||
var loginContext = _auth.GetCurrentUser();
|
||||
if (loginContext == null)
|
||||
{
|
||||
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
|
||||
}
|
||||
|
||||
CaculateCascade(model);
|
||||
|
||||
Repository.Add(model);
|
||||
|
||||
AddDefaultMenus(model);
|
||||
//当前登录用户的所有角色自动分配模块
|
||||
loginContext.Roles.ForEach(u =>
|
||||
{
|
||||
_revelanceApp.Assign(new AssignReq
|
||||
{
|
||||
type = Define.ROLEMODULE,
|
||||
firstId = u.Id,
|
||||
secIds = new[] {model.Id}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void Update(Module obj)
|
||||
{
|
||||
UpdateTreeObj(obj);
|
||||
}
|
||||
|
||||
|
||||
#region 用户/角色分配模块
|
||||
|
||||
/// <summary>
|
||||
/// 加载特定角色的模块
|
||||
/// </summary>
|
||||
/// <param name="roleId">The role unique identifier.</param>
|
||||
public IEnumerable<Module> LoadForRole(string roleId)
|
||||
{
|
||||
var moduleIds = UnitWork.Find<Relevance>(u => u.FirstId == roleId && u.Key == Define.ROLEMODULE)
|
||||
.Select(u => u.SecondId);
|
||||
return UnitWork.Find<Module>(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo);
|
||||
}
|
||||
|
||||
//获取角色可访问的模块字段
|
||||
public IEnumerable<string> LoadPropertiesForRole(string roleId, string moduleCode)
|
||||
{
|
||||
return _revelanceApp.Get(Define.ROLEDATAPROPERTY, roleId, moduleCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据某角色ID获取可访问某模块的菜单项
|
||||
/// </summary>
|
||||
public IEnumerable<ModuleElement> LoadMenusForRole(string moduleId, string roleId)
|
||||
{
|
||||
var elementIds = _revelanceApp.Get(Define.ROLEELEMENT, true, roleId);
|
||||
var query = UnitWork.Find<ModuleElement>(u => elementIds.Contains(u.Id));
|
||||
if (!string.IsNullOrEmpty(moduleId))
|
||||
{
|
||||
query = query.Where(u => u.ModuleId == moduleId);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
#endregion 用户/角色分配模块
|
||||
|
||||
|
||||
#region 菜单操作
|
||||
|
||||
/// <summary>
|
||||
/// 删除指定的菜单
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
public void DelMenu(string[] ids)
|
||||
{
|
||||
UnitWork.Delete<ModuleElement>(u => ids.Contains(u.Id));
|
||||
UnitWork.Save();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 新增菜单
|
||||
/// <para>当前登录用户的所有角色会自动分配菜单</para>
|
||||
/// </summary>
|
||||
public void AddMenu(ModuleElement model)
|
||||
{
|
||||
var loginContext = _auth.GetCurrentUser();
|
||||
if (loginContext == null)
|
||||
{
|
||||
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
|
||||
}
|
||||
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
UnitWork.Add(model);
|
||||
|
||||
//当前登录用户的所有角色自动分配菜单
|
||||
loginContext.Roles.ForEach(u =>
|
||||
{
|
||||
_revelanceApp.Assign(new AssignReq
|
||||
{
|
||||
type = Define.ROLEELEMENT,
|
||||
firstId = u.Id,
|
||||
secIds = new[] {model.Id}
|
||||
});
|
||||
});
|
||||
UnitWork.Save();
|
||||
});
|
||||
}
|
||||
|
||||
public void UpdateMenu(ModuleElement model)
|
||||
{
|
||||
UnitWork.Update<ModuleElement>(model);
|
||||
UnitWork.Save();
|
||||
}
|
||||
|
||||
//添加默认按钮
|
||||
private void AddDefaultMenus(Module module)
|
||||
{
|
||||
AddMenu(new ModuleElement
|
||||
{
|
||||
ModuleId = module.Id,
|
||||
DomId = "btnAdd",
|
||||
Script = "add()",
|
||||
Name = "添加",
|
||||
Sort = 1,
|
||||
Icon = "xinzeng",
|
||||
Class = "success",
|
||||
Remark = "新增" + module.Name
|
||||
});
|
||||
AddMenu(new ModuleElement
|
||||
{
|
||||
ModuleId = module.Id,
|
||||
DomId = "btnEdit",
|
||||
Script = "edit()",
|
||||
Name = "编辑",
|
||||
Sort = 2,
|
||||
Icon = "bianji-copy",
|
||||
Class = "primary",
|
||||
Remark = "修改" + module.Name
|
||||
});
|
||||
AddMenu(new ModuleElement
|
||||
{
|
||||
ModuleId = module.Id,
|
||||
DomId = "btnDel",
|
||||
Script = "del()",
|
||||
Name = "删除",
|
||||
Sort = 3,
|
||||
Icon = "shanchu",
|
||||
Class = "danger",
|
||||
Remark = "删除" + module.Name
|
||||
});
|
||||
|
||||
//todo:可以自己添加更多默认按钮
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public ModuleManagerApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Module,OpenAuthDBContext> repository
|
||||
, RevelanceManagerApp app, IAuth auth) : base(unitWork, repository, auth)
|
||||
{
|
||||
_revelanceApp = app;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +1,49 @@
|
||||
namespace OpenAuth.App.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
public class ModuleElementVM
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// DOM ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string DomId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 组织名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Name { get; set; }
|
||||
|
||||
//模块ID
|
||||
public int ModuleId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属模块名称
|
||||
/// </summary>
|
||||
public string ModuleName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 授权状态
|
||||
/// </summary>
|
||||
public bool Accessed { get; set; }
|
||||
|
||||
public ModuleElementVM()
|
||||
{
|
||||
this.Id = 0;
|
||||
this.DomId = string.Empty;
|
||||
this.Name = string.Empty;
|
||||
this.ModuleId = 0;
|
||||
this.ModuleName = string.Empty;
|
||||
this.Accessed = false;
|
||||
}
|
||||
}
|
||||
namespace OpenAuth.App.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
public class ModuleElementVM
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// DOM ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string DomId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 组织名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Name { get; set; }
|
||||
|
||||
//模块ID
|
||||
public int ModuleId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属模块名称
|
||||
/// </summary>
|
||||
public string ModuleName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 授权状态
|
||||
/// </summary>
|
||||
public bool Accessed { get; set; }
|
||||
|
||||
public ModuleElementVM()
|
||||
{
|
||||
this.Id = 0;
|
||||
this.DomId = string.Empty;
|
||||
this.Name = string.Empty;
|
||||
this.ModuleId = 0;
|
||||
this.ModuleName = string.Empty;
|
||||
this.Accessed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,83 +1,83 @@
|
||||
using System.Collections.Generic;
|
||||
using Infrastructure;
|
||||
using OpenAuth.Repository.Domain;
|
||||
|
||||
namespace OpenAuth.App.Response
|
||||
{
|
||||
public class ModuleView
|
||||
{
|
||||
/// <summary>
|
||||
/// ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 节点语义ID
|
||||
/// </summary>
|
||||
public string CascadeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主页面URL
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 父节点流水号
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string ParentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 父节点流水号
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string ParentName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 节点图标文件名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string IconName { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当前状态,0:正常,-1:隐藏,不在导航列表中显示
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
|
||||
|
||||
public bool Checked { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序号
|
||||
/// </summary>
|
||||
public int SortNo { get; set; }
|
||||
|
||||
public string Code { get; set; }
|
||||
|
||||
public bool IsSys { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模块中的元素
|
||||
/// </summary>
|
||||
public List<ModuleElement> Elements { get; set; }
|
||||
|
||||
public static implicit operator ModuleView(Module module)
|
||||
{
|
||||
return module.MapTo<ModuleView>();
|
||||
}
|
||||
|
||||
public static implicit operator Module(ModuleView view)
|
||||
{
|
||||
return view.MapTo<Module>();
|
||||
}
|
||||
}
|
||||
using System.Collections.Generic;
|
||||
using Infrastructure;
|
||||
using OpenAuth.Repository.Domain;
|
||||
|
||||
namespace OpenAuth.App.Response
|
||||
{
|
||||
public class ModuleView
|
||||
{
|
||||
/// <summary>
|
||||
/// ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 节点语义ID
|
||||
/// </summary>
|
||||
public string CascadeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主页面URL
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 父节点流水号
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string ParentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 父节点流水号
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string ParentName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 节点图标文件名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string IconName { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当前状态,0:正常,-1:隐藏,不在导航列表中显示
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
|
||||
|
||||
public bool Checked { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序号
|
||||
/// </summary>
|
||||
public int SortNo { get; set; }
|
||||
|
||||
public string Code { get; set; }
|
||||
|
||||
public bool IsSys { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模块中的元素
|
||||
/// </summary>
|
||||
public List<ModuleElement> Elements { get; set; }
|
||||
|
||||
public static implicit operator ModuleView(Module module)
|
||||
{
|
||||
return module.MapTo<ModuleView>();
|
||||
}
|
||||
|
||||
public static implicit operator Module(ModuleView view)
|
||||
{
|
||||
return view.MapTo<Module>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,94 +1,94 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class OrgManagerApp : BaseTreeApp<Org,OpenAuthDBContext>
|
||||
{
|
||||
private RevelanceManagerApp _revelanceApp;
|
||||
/// <summary>
|
||||
/// 添加部门
|
||||
/// </summary>
|
||||
/// <param name="org">The org.</param>
|
||||
/// <returns>System.Int32.</returns>
|
||||
/// <exception cref="System.Exception">未能找到该组织的父节点信息</exception>
|
||||
public string Add(Org org)
|
||||
{
|
||||
var loginContext = _auth.GetCurrentUser();
|
||||
if (loginContext == null)
|
||||
{
|
||||
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
|
||||
}
|
||||
CaculateCascade(org);
|
||||
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
UnitWork.Add(org);
|
||||
UnitWork.Save();
|
||||
|
||||
//如果当前账号不是SYSTEM,则直接分配
|
||||
if (loginContext.User.Account != Define.SYSTEM_USERNAME)
|
||||
{
|
||||
_revelanceApp.Assign(new AssignReq
|
||||
{
|
||||
type = Define.USERORG,
|
||||
firstId = loginContext.User.Id,
|
||||
secIds = new[] { org.Id }
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return org.Id;
|
||||
}
|
||||
|
||||
public string Update(Org org)
|
||||
{
|
||||
UpdateTreeObj(org);
|
||||
|
||||
return org.Id;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除指定ID的部门及其所有子部门
|
||||
/// </summary>
|
||||
public void DelOrgCascade(string[] ids)
|
||||
{
|
||||
var delOrgCascadeIds = UnitWork.Find<Org>(u => ids.Contains(u.Id)).Select(u => u.CascadeId).ToArray();
|
||||
var delOrgIds = new List<string>();
|
||||
foreach (var cascadeId in delOrgCascadeIds)
|
||||
{
|
||||
delOrgIds.AddRange(UnitWork.Find<Org>(u=>u.CascadeId.Contains(cascadeId)).Select(u =>u.Id).ToArray());
|
||||
}
|
||||
|
||||
UnitWork.Delete<Relevance>(u =>u.Key == Define.USERORG && delOrgIds.Contains(u.SecondId));
|
||||
UnitWork.Delete<Org>(u => delOrgIds.Contains(u.Id));
|
||||
UnitWork.Save();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载特定用户的部门
|
||||
/// </summary>
|
||||
/// <param name="userId">The user unique identifier.</param>
|
||||
public List<Org> LoadForUser(string userId)
|
||||
{
|
||||
var result = from userorg in UnitWork.Find<Relevance>(null)
|
||||
join org in UnitWork.Find<Org>(null) on userorg.SecondId equals org.Id
|
||||
where userorg.FirstId == userId && userorg.Key == Define.USERORG
|
||||
select org;
|
||||
return result.ToList();
|
||||
}
|
||||
|
||||
public OrgManagerApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Org,OpenAuthDBContext> repository,IAuth auth,
|
||||
RevelanceManagerApp revelanceApp) : base(unitWork, repository, auth)
|
||||
{
|
||||
_revelanceApp = revelanceApp;
|
||||
}
|
||||
}
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class OrgManagerApp : BaseTreeApp<Org,OpenAuthDBContext>
|
||||
{
|
||||
private RevelanceManagerApp _revelanceApp;
|
||||
/// <summary>
|
||||
/// 添加部门
|
||||
/// </summary>
|
||||
/// <param name="org">The org.</param>
|
||||
/// <returns>System.Int32.</returns>
|
||||
/// <exception cref="System.Exception">未能找到该组织的父节点信息</exception>
|
||||
public string Add(Org org)
|
||||
{
|
||||
var loginContext = _auth.GetCurrentUser();
|
||||
if (loginContext == null)
|
||||
{
|
||||
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
|
||||
}
|
||||
CaculateCascade(org);
|
||||
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
UnitWork.Add(org);
|
||||
UnitWork.Save();
|
||||
|
||||
//如果当前账号不是SYSTEM,则直接分配
|
||||
if (loginContext.User.Account != Define.SYSTEM_USERNAME)
|
||||
{
|
||||
_revelanceApp.Assign(new AssignReq
|
||||
{
|
||||
type = Define.USERORG,
|
||||
firstId = loginContext.User.Id,
|
||||
secIds = new[] { org.Id }
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return org.Id;
|
||||
}
|
||||
|
||||
public string Update(Org org)
|
||||
{
|
||||
UpdateTreeObj(org);
|
||||
|
||||
return org.Id;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除指定ID的部门及其所有子部门
|
||||
/// </summary>
|
||||
public void DelOrgCascade(string[] ids)
|
||||
{
|
||||
var delOrgCascadeIds = UnitWork.Find<Org>(u => ids.Contains(u.Id)).Select(u => u.CascadeId).ToArray();
|
||||
var delOrgIds = new List<string>();
|
||||
foreach (var cascadeId in delOrgCascadeIds)
|
||||
{
|
||||
delOrgIds.AddRange(UnitWork.Find<Org>(u=>u.CascadeId.Contains(cascadeId)).Select(u =>u.Id).ToArray());
|
||||
}
|
||||
|
||||
UnitWork.Delete<Relevance>(u =>u.Key == Define.USERORG && delOrgIds.Contains(u.SecondId));
|
||||
UnitWork.Delete<Org>(u => delOrgIds.Contains(u.Id));
|
||||
UnitWork.Save();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载特定用户的部门
|
||||
/// </summary>
|
||||
/// <param name="userId">The user unique identifier.</param>
|
||||
public List<Org> LoadForUser(string userId)
|
||||
{
|
||||
var result = from userorg in UnitWork.Find<Relevance>(null)
|
||||
join org in UnitWork.Find<Org>(null) on userorg.SecondId equals org.Id
|
||||
where userorg.FirstId == userId && userorg.Key == Define.USERORG
|
||||
select org;
|
||||
return result.ToList();
|
||||
}
|
||||
|
||||
public OrgManagerApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Org,OpenAuthDBContext> repository,IAuth auth,
|
||||
RevelanceManagerApp revelanceApp) : base(unitWork, repository, auth)
|
||||
{
|
||||
_revelanceApp = revelanceApp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,238 +1,238 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Infrastructure;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class RevelanceManagerApp : BaseStringApp<Relevance,OpenAuthDBContext>
|
||||
{
|
||||
private readonly ILogger<RevelanceManagerApp> _logger;
|
||||
public RevelanceManagerApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Relevance,OpenAuthDBContext> repository, IAuth auth, ILogger<RevelanceManagerApp> logger) : base(unitWork,
|
||||
repository, auth)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加关联
|
||||
/// <para>比如给用户分配资源,那么firstId就是用户ID,secIds就是资源ID列表</para>
|
||||
/// </summary>
|
||||
/// <param name="type">关联的类型,如Define.USERRESOURCE</param>
|
||||
public void Assign(AssignReq request)
|
||||
{
|
||||
Assign(request.type, request.secIds.ToLookup(u => request.firstId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加关联,需要人工删除以前的关联
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="idMaps"></param>
|
||||
public void Assign(string key, ILookup<string, string> idMaps)
|
||||
{
|
||||
UnitWork.BatchAdd((from sameVals in idMaps
|
||||
from value in sameVals
|
||||
select new Relevance
|
||||
{
|
||||
Key = key,
|
||||
FirstId = sameVals.Key,
|
||||
SecondId = value,
|
||||
OperateTime = DateTime.Now
|
||||
}).ToArray());
|
||||
UnitWork.Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消关联
|
||||
/// </summary>
|
||||
/// <param name="type">关联的类型,如Define.USERRESOURCE</param>
|
||||
/// <param name="firstId">The first identifier.</param>
|
||||
/// <param name="secIds">The sec ids.</param>
|
||||
public void UnAssign(AssignReq req)
|
||||
{
|
||||
if (req.secIds == null || req.secIds.Length == 0)
|
||||
{
|
||||
DeleteBy(req.type, req.firstId);
|
||||
}
|
||||
else
|
||||
{
|
||||
DeleteBy(req.type, req.secIds.ToLookup(u => req.firstId));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除关联
|
||||
/// </summary>
|
||||
/// <param name="key">关联标识</param>
|
||||
/// <param name="idMaps">关联的<firstId, secondId>数组</param>
|
||||
private void DeleteBy(string key, ILookup<string, string> idMaps)
|
||||
{
|
||||
foreach (var sameVals in idMaps)
|
||||
{
|
||||
foreach (var value in sameVals)
|
||||
{
|
||||
_logger.LogInformation($"start=> delete {key} {sameVals.Key} {value}");
|
||||
try
|
||||
{
|
||||
UnitWork.Delete<Relevance>(u => u.Key == key && u.FirstId == sameVals.Key && u.SecondId == value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e,e.Message);
|
||||
}
|
||||
_logger.LogInformation($"end=> {key} {sameVals.Key} {value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteBy(string key, params string[] firstIds)
|
||||
{
|
||||
UnitWork.Delete<Relevance>(u => firstIds.Contains(u.FirstId) && u.Key == key);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据关联表的一个键获取另外键的值
|
||||
/// </summary>
|
||||
/// <param name="key">映射标识</param>
|
||||
/// <param name="returnSecondIds">返回的是否为映射表的第二列,如果不是则返回第一列</param>
|
||||
/// <param name="ids">已知的ID列表</param>
|
||||
/// <returns>List<System.String>.</returns>
|
||||
public List<string> Get(string key, bool returnSecondIds, params string[] ids)
|
||||
{
|
||||
if (returnSecondIds)
|
||||
{
|
||||
return Repository.Find(u => u.Key == key
|
||||
&& ids.Contains(u.FirstId)).Select(u => u.SecondId).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Repository.Find(u => u.Key == key
|
||||
&& ids.Contains(u.SecondId)).Select(u => u.FirstId).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据key ,firstId,secondId获取thirdId
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="firstId"></param>
|
||||
/// <param name="secondId"></param>
|
||||
/// <returns></returns>
|
||||
public List<string> Get(string key, string firstId, string secondId)
|
||||
{
|
||||
return Repository.Find(u => u.Key == key && u.FirstId == firstId && u.SecondId == secondId)
|
||||
.Select(u => u.ThirdId).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分配数据字段权限
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
public void AssignData(AssignDataReq request)
|
||||
{
|
||||
if (!request.Properties.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var relevances = new List<Relevance>();
|
||||
foreach (var requestProperty in request.Properties)
|
||||
{
|
||||
relevances.Add(new Relevance
|
||||
{
|
||||
Key = Define.ROLEDATAPROPERTY,
|
||||
FirstId = request.RoleId,
|
||||
SecondId = request.ModuleCode,
|
||||
ThirdId = requestProperty,
|
||||
OperateTime = DateTime.Now
|
||||
});
|
||||
}
|
||||
|
||||
UnitWork.BatchAdd(relevances.ToArray());
|
||||
UnitWork.Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消数据字段分配
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
public void UnAssignData(AssignDataReq request)
|
||||
{
|
||||
if (request.Properties == null || request.Properties.Length == 0)
|
||||
{
|
||||
if (string.IsNullOrEmpty(request.ModuleCode)) //模块为空,直接把角色的所有授权删除
|
||||
{
|
||||
DeleteBy(Define.ROLEDATAPROPERTY, request.RoleId);
|
||||
}
|
||||
else //把角色的某一个模块权限全部删除
|
||||
{
|
||||
DeleteBy(Define.ROLEDATAPROPERTY, new[] {request.ModuleCode}.ToLookup(u => request.RoleId));
|
||||
}
|
||||
}
|
||||
else //按具体的id删除
|
||||
{
|
||||
foreach (var property in request.Properties)
|
||||
{
|
||||
UnitWork.Delete<Relevance>(u => u.Key == Define.ROLEDATAPROPERTY
|
||||
&& u.FirstId == request.RoleId
|
||||
&& u.SecondId == request.ModuleCode
|
||||
&& u.ThirdId == property);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为角色分配用户,需要统一提交,会删除以前该角色的所有用户
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
public void AssignRoleUsers(AssignRoleUsers request)
|
||||
{
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
//删除以前的所有用户
|
||||
UnitWork.Delete<Relevance>(u => u.SecondId == request.RoleId && u.Key == Define.USERROLE);
|
||||
//批量分配用户角色
|
||||
UnitWork.BatchAdd((from firstId in request.UserIds
|
||||
select new Relevance
|
||||
{
|
||||
Key = Define.USERROLE,
|
||||
FirstId = firstId,
|
||||
SecondId = request.RoleId,
|
||||
OperateTime = DateTime.Now
|
||||
}).ToArray());
|
||||
UnitWork.Save();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为部门分配用户,需要统一提交,会删除以前该部门的所有用户
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
public void AssignOrgUsers(AssignOrgUsers request)
|
||||
{
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
//删除以前的所有用户
|
||||
UnitWork.Delete<Relevance>(u => u.SecondId == request.OrgId && u.Key == Define.USERORG);
|
||||
//批量分配用户角色
|
||||
UnitWork.BatchAdd((from firstId in request.UserIds
|
||||
select new Relevance
|
||||
{
|
||||
Key = Define.USERORG,
|
||||
FirstId = firstId,
|
||||
SecondId = request.OrgId,
|
||||
OperateTime = DateTime.Now
|
||||
}).ToArray());
|
||||
UnitWork.Save();
|
||||
});
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Infrastructure;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class RevelanceManagerApp : BaseStringApp<Relevance,OpenAuthDBContext>
|
||||
{
|
||||
private readonly ILogger<RevelanceManagerApp> _logger;
|
||||
public RevelanceManagerApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Relevance,OpenAuthDBContext> repository, IAuth auth, ILogger<RevelanceManagerApp> logger) : base(unitWork,
|
||||
repository, auth)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加关联
|
||||
/// <para>比如给用户分配资源,那么firstId就是用户ID,secIds就是资源ID列表</para>
|
||||
/// </summary>
|
||||
/// <param name="type">关联的类型,如Define.USERRESOURCE</param>
|
||||
public void Assign(AssignReq request)
|
||||
{
|
||||
Assign(request.type, request.secIds.ToLookup(u => request.firstId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加关联,需要人工删除以前的关联
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="idMaps"></param>
|
||||
public void Assign(string key, ILookup<string, string> idMaps)
|
||||
{
|
||||
UnitWork.BatchAdd((from sameVals in idMaps
|
||||
from value in sameVals
|
||||
select new Relevance
|
||||
{
|
||||
Key = key,
|
||||
FirstId = sameVals.Key,
|
||||
SecondId = value,
|
||||
OperateTime = DateTime.Now
|
||||
}).ToArray());
|
||||
UnitWork.Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消关联
|
||||
/// </summary>
|
||||
/// <param name="type">关联的类型,如Define.USERRESOURCE</param>
|
||||
/// <param name="firstId">The first identifier.</param>
|
||||
/// <param name="secIds">The sec ids.</param>
|
||||
public void UnAssign(AssignReq req)
|
||||
{
|
||||
if (req.secIds == null || req.secIds.Length == 0)
|
||||
{
|
||||
DeleteBy(req.type, req.firstId);
|
||||
}
|
||||
else
|
||||
{
|
||||
DeleteBy(req.type, req.secIds.ToLookup(u => req.firstId));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除关联
|
||||
/// </summary>
|
||||
/// <param name="key">关联标识</param>
|
||||
/// <param name="idMaps">关联的<firstId, secondId>数组</param>
|
||||
private void DeleteBy(string key, ILookup<string, string> idMaps)
|
||||
{
|
||||
foreach (var sameVals in idMaps)
|
||||
{
|
||||
foreach (var value in sameVals)
|
||||
{
|
||||
_logger.LogInformation($"start=> delete {key} {sameVals.Key} {value}");
|
||||
try
|
||||
{
|
||||
UnitWork.Delete<Relevance>(u => u.Key == key && u.FirstId == sameVals.Key && u.SecondId == value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e,e.Message);
|
||||
}
|
||||
_logger.LogInformation($"end=> {key} {sameVals.Key} {value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteBy(string key, params string[] firstIds)
|
||||
{
|
||||
UnitWork.Delete<Relevance>(u => firstIds.Contains(u.FirstId) && u.Key == key);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据关联表的一个键获取另外键的值
|
||||
/// </summary>
|
||||
/// <param name="key">映射标识</param>
|
||||
/// <param name="returnSecondIds">返回的是否为映射表的第二列,如果不是则返回第一列</param>
|
||||
/// <param name="ids">已知的ID列表</param>
|
||||
/// <returns>List<System.String>.</returns>
|
||||
public List<string> Get(string key, bool returnSecondIds, params string[] ids)
|
||||
{
|
||||
if (returnSecondIds)
|
||||
{
|
||||
return Repository.Find(u => u.Key == key
|
||||
&& ids.Contains(u.FirstId)).Select(u => u.SecondId).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Repository.Find(u => u.Key == key
|
||||
&& ids.Contains(u.SecondId)).Select(u => u.FirstId).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据key ,firstId,secondId获取thirdId
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="firstId"></param>
|
||||
/// <param name="secondId"></param>
|
||||
/// <returns></returns>
|
||||
public List<string> Get(string key, string firstId, string secondId)
|
||||
{
|
||||
return Repository.Find(u => u.Key == key && u.FirstId == firstId && u.SecondId == secondId)
|
||||
.Select(u => u.ThirdId).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分配数据字段权限
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
public void AssignData(AssignDataReq request)
|
||||
{
|
||||
if (!request.Properties.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var relevances = new List<Relevance>();
|
||||
foreach (var requestProperty in request.Properties)
|
||||
{
|
||||
relevances.Add(new Relevance
|
||||
{
|
||||
Key = Define.ROLEDATAPROPERTY,
|
||||
FirstId = request.RoleId,
|
||||
SecondId = request.ModuleCode,
|
||||
ThirdId = requestProperty,
|
||||
OperateTime = DateTime.Now
|
||||
});
|
||||
}
|
||||
|
||||
UnitWork.BatchAdd(relevances.ToArray());
|
||||
UnitWork.Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消数据字段分配
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
public void UnAssignData(AssignDataReq request)
|
||||
{
|
||||
if (request.Properties == null || request.Properties.Length == 0)
|
||||
{
|
||||
if (string.IsNullOrEmpty(request.ModuleCode)) //模块为空,直接把角色的所有授权删除
|
||||
{
|
||||
DeleteBy(Define.ROLEDATAPROPERTY, request.RoleId);
|
||||
}
|
||||
else //把角色的某一个模块权限全部删除
|
||||
{
|
||||
DeleteBy(Define.ROLEDATAPROPERTY, new[] {request.ModuleCode}.ToLookup(u => request.RoleId));
|
||||
}
|
||||
}
|
||||
else //按具体的id删除
|
||||
{
|
||||
foreach (var property in request.Properties)
|
||||
{
|
||||
UnitWork.Delete<Relevance>(u => u.Key == Define.ROLEDATAPROPERTY
|
||||
&& u.FirstId == request.RoleId
|
||||
&& u.SecondId == request.ModuleCode
|
||||
&& u.ThirdId == property);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为角色分配用户,需要统一提交,会删除以前该角色的所有用户
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
public void AssignRoleUsers(AssignRoleUsers request)
|
||||
{
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
//删除以前的所有用户
|
||||
UnitWork.Delete<Relevance>(u => u.SecondId == request.RoleId && u.Key == Define.USERROLE);
|
||||
//批量分配用户角色
|
||||
UnitWork.BatchAdd((from firstId in request.UserIds
|
||||
select new Relevance
|
||||
{
|
||||
Key = Define.USERROLE,
|
||||
FirstId = firstId,
|
||||
SecondId = request.RoleId,
|
||||
OperateTime = DateTime.Now
|
||||
}).ToArray());
|
||||
UnitWork.Save();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为部门分配用户,需要统一提交,会删除以前该部门的所有用户
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
public void AssignOrgUsers(AssignOrgUsers request)
|
||||
{
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
//删除以前的所有用户
|
||||
UnitWork.Delete<Relevance>(u => u.SecondId == request.OrgId && u.Key == Define.USERORG);
|
||||
//批量分配用户角色
|
||||
UnitWork.BatchAdd((from firstId in request.UserIds
|
||||
select new Relevance
|
||||
{
|
||||
Key = Define.USERORG,
|
||||
FirstId = firstId,
|
||||
SecondId = request.OrgId,
|
||||
OperateTime = DateTime.Now
|
||||
}).ToArray());
|
||||
UnitWork.Save();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class QueryRoleListReq : PageReq
|
||||
{
|
||||
}
|
||||
}
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class QueryRoleListReq : PageReq
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,60 +1,60 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : OpenAuth.App
|
||||
// Author : yubaolee
|
||||
// Created : 11-29-2015
|
||||
//
|
||||
// Last Modified By : yubaolee
|
||||
// Last Modified On : 11-29-2015
|
||||
// ***********************************************************************
|
||||
// <copyright file="RoleVM.cs" company="www.cnblogs.com/yubaolee">
|
||||
// Copyright (c) www.cnblogs.com/yubaolee. All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>角色模型视图</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using Infrastructure;
|
||||
using OpenAuth.Repository.Domain;
|
||||
|
||||
namespace OpenAuth.App.Response
|
||||
{
|
||||
public partial class RoleView
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前状态
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
/// <summary>
|
||||
/// 角色类型
|
||||
/// </summary>
|
||||
public int Type { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
///是否属于某用户
|
||||
/// </summary>
|
||||
public bool Checked { get; set; }
|
||||
|
||||
public static implicit operator RoleView(Role role)
|
||||
{
|
||||
return role.MapTo<RoleView>();
|
||||
}
|
||||
|
||||
public static implicit operator Role(RoleView rolevm)
|
||||
{
|
||||
return rolevm.MapTo<Role>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// ***********************************************************************
|
||||
// Assembly : OpenAuth.App
|
||||
// Author : yubaolee
|
||||
// Created : 11-29-2015
|
||||
//
|
||||
// Last Modified By : yubaolee
|
||||
// Last Modified On : 11-29-2015
|
||||
// ***********************************************************************
|
||||
// <copyright file="RoleVM.cs" company="www.cnblogs.com/yubaolee">
|
||||
// Copyright (c) www.cnblogs.com/yubaolee. All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>角色模型视图</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using Infrastructure;
|
||||
using OpenAuth.Repository.Domain;
|
||||
|
||||
namespace OpenAuth.App.Response
|
||||
{
|
||||
public partial class RoleView
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前状态
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
/// <summary>
|
||||
/// 角色类型
|
||||
/// </summary>
|
||||
public int Type { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
///是否属于某用户
|
||||
/// </summary>
|
||||
public bool Checked { get; set; }
|
||||
|
||||
public static implicit operator RoleView(Role role)
|
||||
{
|
||||
return role.MapTo<RoleView>();
|
||||
}
|
||||
|
||||
public static implicit operator Role(RoleView rolevm)
|
||||
{
|
||||
return rolevm.MapTo<Role>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,84 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
using System.Linq;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.Repository;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class RoleApp : BaseStringApp<Role,OpenAuthDBContext>
|
||||
{
|
||||
private RevelanceManagerApp _revelanceApp;
|
||||
|
||||
/// <summary>
|
||||
/// 加载当前登录用户可访问的全部角色
|
||||
/// </summary>
|
||||
public List<Role> Load(QueryRoleListReq request)
|
||||
{
|
||||
var loginUser = _auth.GetCurrentUser();
|
||||
var roles = loginUser.Roles;
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
roles = roles.Where(u => u.Name.Contains(request.key)).ToList();
|
||||
}
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加角色,如果当前登录用户不是System,则直接把新角色分配给当前登录用户
|
||||
/// </summary>
|
||||
public void Add(RoleView obj)
|
||||
{
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
Role role = obj;
|
||||
role.CreateTime = DateTime.Now;
|
||||
UnitWork.Add(role);
|
||||
UnitWork.Save();
|
||||
obj.Id = role.Id; //要把保存后的ID存入view
|
||||
|
||||
//如果当前账号不是SYSTEM,则直接分配
|
||||
var loginUser = _auth.GetCurrentUser();
|
||||
if (loginUser.User.Account != Define.SYSTEM_USERNAME)
|
||||
{
|
||||
_revelanceApp.Assign(new AssignReq
|
||||
{
|
||||
type = Define.USERROLE,
|
||||
firstId = loginUser.User.Id,
|
||||
secIds = new[] {role.Id}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新角色属性
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
public void Update(RoleView obj)
|
||||
{
|
||||
Role role = obj;
|
||||
|
||||
UnitWork.Update<Role>(u => u.Id == obj.Id, u => new Role
|
||||
{
|
||||
Name = role.Name,
|
||||
Status = role.Status
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
public RoleApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Role,OpenAuthDBContext> repository,
|
||||
RevelanceManagerApp app,IAuth auth) : base(unitWork, repository, auth)
|
||||
{
|
||||
_revelanceApp = app;
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
using System.Linq;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.Repository;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class RoleApp : BaseStringApp<Role,OpenAuthDBContext>
|
||||
{
|
||||
private RevelanceManagerApp _revelanceApp;
|
||||
|
||||
/// <summary>
|
||||
/// 加载当前登录用户可访问的全部角色
|
||||
/// </summary>
|
||||
public List<Role> Load(QueryRoleListReq request)
|
||||
{
|
||||
var loginUser = _auth.GetCurrentUser();
|
||||
var roles = loginUser.Roles;
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
roles = roles.Where(u => u.Name.Contains(request.key)).ToList();
|
||||
}
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加角色,如果当前登录用户不是System,则直接把新角色分配给当前登录用户
|
||||
/// </summary>
|
||||
public void Add(RoleView obj)
|
||||
{
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
Role role = obj;
|
||||
role.CreateTime = DateTime.Now;
|
||||
UnitWork.Add(role);
|
||||
UnitWork.Save();
|
||||
obj.Id = role.Id; //要把保存后的ID存入view
|
||||
|
||||
//如果当前账号不是SYSTEM,则直接分配
|
||||
var loginUser = _auth.GetCurrentUser();
|
||||
if (loginUser.User.Account != Define.SYSTEM_USERNAME)
|
||||
{
|
||||
_revelanceApp.Assign(new AssignReq
|
||||
{
|
||||
type = Define.USERROLE,
|
||||
firstId = loginUser.User.Id,
|
||||
secIds = new[] {role.Id}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新角色属性
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
public void Update(RoleView obj)
|
||||
{
|
||||
Role role = obj;
|
||||
|
||||
UnitWork.Update<Role>(u => u.Id == obj.Id, u => new Role
|
||||
{
|
||||
Name = role.Name,
|
||||
Status = role.Status
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
public RoleApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Role,OpenAuthDBContext> repository,
|
||||
RevelanceManagerApp app,IAuth auth) : base(unitWork, repository, auth)
|
||||
{
|
||||
_revelanceApp = app;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class QueryUserListReq : PageReq
|
||||
{
|
||||
public string orgId { get; set; }
|
||||
}
|
||||
}
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class QueryUserListReq : PageReq
|
||||
{
|
||||
public string orgId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,88 +1,88 @@
|
||||
using System;
|
||||
using Infrastructure;
|
||||
using OpenAuth.Repository.Domain;
|
||||
|
||||
namespace OpenAuth.App.Response
|
||||
{
|
||||
public class UserView
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Id { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Account { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 组织名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Name { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Sex { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当前状态
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Status { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 组织类型
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Type { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DateTime CreateTime { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建人名字
|
||||
/// </summary>
|
||||
/// <value>The create user.</value>
|
||||
public string CreateUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属组织名称,多个可用,分隔
|
||||
/// </summary>
|
||||
/// <value>The organizations.</value>
|
||||
public string Organizations { get; set; }
|
||||
|
||||
public string OrganizationIds { get; set; }
|
||||
|
||||
public static implicit operator UserView(User user)
|
||||
{
|
||||
return user.MapTo<UserView>();
|
||||
}
|
||||
|
||||
public static implicit operator User(UserView view)
|
||||
{
|
||||
return view.MapTo<User>();
|
||||
}
|
||||
|
||||
public UserView()
|
||||
{
|
||||
Organizations = string.Empty;
|
||||
OrganizationIds = string.Empty;
|
||||
CreateUser = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using Infrastructure;
|
||||
using OpenAuth.Repository.Domain;
|
||||
|
||||
namespace OpenAuth.App.Response
|
||||
{
|
||||
public class UserView
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Id { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Account { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 组织名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Name { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Sex { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当前状态
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Status { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 组织类型
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Type { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DateTime CreateTime { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建人名字
|
||||
/// </summary>
|
||||
/// <value>The create user.</value>
|
||||
public string CreateUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属组织名称,多个可用,分隔
|
||||
/// </summary>
|
||||
/// <value>The organizations.</value>
|
||||
public string Organizations { get; set; }
|
||||
|
||||
public string OrganizationIds { get; set; }
|
||||
|
||||
public static implicit operator UserView(User user)
|
||||
{
|
||||
return user.MapTo<UserView>();
|
||||
}
|
||||
|
||||
public static implicit operator User(UserView view)
|
||||
{
|
||||
return view.MapTo<User>();
|
||||
}
|
||||
|
||||
public UserView()
|
||||
{
|
||||
Organizations = string.Empty;
|
||||
OrganizationIds = string.Empty;
|
||||
CreateUser = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,262 +1,262 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Castle.Core.Internal;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Extensions;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class UserManagerApp : BaseStringApp<User,OpenAuthDBContext>
|
||||
{
|
||||
private RevelanceManagerApp _revelanceApp;
|
||||
private OrgManagerApp _orgManagerApp;
|
||||
|
||||
public UserManagerApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<User,OpenAuthDBContext> repository,
|
||||
RevelanceManagerApp app,IAuth auth, OrgManagerApp orgManagerApp) : base(unitWork, repository, auth)
|
||||
{
|
||||
_revelanceApp = app;
|
||||
_orgManagerApp = orgManagerApp;
|
||||
}
|
||||
|
||||
public User GetByAccount(string account)
|
||||
{
|
||||
return Repository.FirstOrDefault(u => u.Account == account);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载当前登录用户可访问的一个部门及子部门全部用户
|
||||
/// 如果请求的request.OrgId为空,则可以获取到已被删除机构的用户(即:没有分配任何机构的用户)
|
||||
/// </summary>
|
||||
public async Task<TableData> Load(QueryUserListReq request)
|
||||
{
|
||||
var loginUser = _auth.GetCurrentUser();
|
||||
|
||||
|
||||
IQueryable<User> query = UnitWork.Find<User>(null);
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
query = UnitWork.Find<User>(u => u.Name.Contains(request.key) || u.Account.Contains(request.key));
|
||||
}
|
||||
|
||||
var userOrgs = from user in query
|
||||
join relevance in UnitWork.Find<Relevance>(u =>u.Key=="UserOrg")
|
||||
on user.Id equals relevance.FirstId into temp
|
||||
from r in temp.DefaultIfEmpty()
|
||||
join org in UnitWork.Find<Org>(null)
|
||||
on r.SecondId equals org.Id into orgtmp
|
||||
from o in orgtmp.DefaultIfEmpty()
|
||||
select new
|
||||
{
|
||||
user.Account,
|
||||
user.Name,
|
||||
user.Id,
|
||||
user.Sex,
|
||||
user.Status,
|
||||
user.BizCode,
|
||||
user.CreateId,
|
||||
user.CreateTime,
|
||||
user.TypeId,
|
||||
user.TypeName,
|
||||
r.Key,
|
||||
r.SecondId,
|
||||
OrgId = o.Id,
|
||||
OrgName= o.Name
|
||||
};
|
||||
|
||||
//如果请求的orgId不为空
|
||||
if (!string.IsNullOrEmpty(request.orgId))
|
||||
{
|
||||
var org = loginUser.Orgs.SingleOrDefault(u => u.Id == request.orgId);
|
||||
var cascadeId = org.CascadeId;
|
||||
|
||||
var orgIds = loginUser.Orgs.Where(u => u.CascadeId.Contains(cascadeId)).Select(u => u.Id).ToArray();
|
||||
|
||||
//只获取机构里面的用户
|
||||
userOrgs = userOrgs.Where(u => u.Key == Define.USERORG && orgIds.Contains(u.OrgId));
|
||||
}
|
||||
else //todo:如果请求的orgId为空,即为跟节点,这时可以额外获取到机构已经被删除的用户,从而进行机构分配。可以根据自己需求进行调整
|
||||
{
|
||||
var orgIds = loginUser.Orgs.Select(u => u.Id).ToArray();
|
||||
|
||||
//获取用户可以访问的机构的用户和没有任何机构关联的用户(机构被删除后,没有删除这里面的关联关系)
|
||||
userOrgs = userOrgs.Where(u => (u.Key == Define.USERORG && orgIds.Contains(u.OrgId)) || (u.OrgId == null));
|
||||
}
|
||||
|
||||
|
||||
|
||||
var userViews = userOrgs.ToList().GroupBy(b => b.Account).Select(u =>new UserView
|
||||
{
|
||||
Id = u.First().Id,
|
||||
Account = u.Key,
|
||||
Name = u.First().Name,
|
||||
Sex = u.First().Sex,
|
||||
Status = u.First().Status,
|
||||
CreateTime = u.First().CreateTime,
|
||||
CreateUser = u.First().CreateId,
|
||||
OrganizationIds = string.Join(",", u.Select(x=>x.OrgId))
|
||||
,Organizations = string.Join(",", u.Select(x=>x.OrgName))
|
||||
|
||||
});
|
||||
|
||||
return new TableData
|
||||
{
|
||||
count = userViews.Count(),
|
||||
data = userViews.OrderBy(u => u.Name)
|
||||
.Skip((request.page - 1) * request.limit)
|
||||
.Take(request.limit),
|
||||
};
|
||||
}
|
||||
|
||||
public void AddOrUpdate(UpdateUserReq request)
|
||||
{
|
||||
request.ValidationEntity(u => new {u.Account,u.Name, u.OrganizationIds});
|
||||
|
||||
if (string.IsNullOrEmpty(request.OrganizationIds))
|
||||
throw new Exception("请为用户分配机构");
|
||||
User requser = request;
|
||||
requser.CreateId = _auth.GetCurrentUser().User.Id;
|
||||
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(request.Id))
|
||||
{
|
||||
if (UnitWork.Any<User>(u => u.Account == request.Account))
|
||||
{
|
||||
throw new Exception("用户账号已存在");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(requser.Password))
|
||||
{
|
||||
requser.Password = requser.Account; //如果客户端没提供密码,默认密码同账号
|
||||
}
|
||||
|
||||
requser.CreateTime = DateTime.Now;
|
||||
|
||||
UnitWork.Add(requser);
|
||||
request.Id = requser.Id; //要把保存后的ID存入view
|
||||
}
|
||||
else
|
||||
{
|
||||
UnitWork.Update<User>(u => u.Id == request.Id, u => new User
|
||||
{
|
||||
Account = requser.Account,
|
||||
BizCode = requser.BizCode,
|
||||
Name = requser.Name,
|
||||
Sex = requser.Sex,
|
||||
Status = requser.Status
|
||||
});
|
||||
if (!string.IsNullOrEmpty(requser.Password)) //密码为空的时候,不做修改
|
||||
{
|
||||
UnitWork.Update<User>(u => u.Id == request.Id, u => new User
|
||||
{
|
||||
Password = requser.Password
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
UnitWork.Save();
|
||||
string[] orgIds = request.OrganizationIds.Split(',').ToArray();
|
||||
|
||||
_revelanceApp.DeleteBy(Define.USERORG, requser.Id);
|
||||
_revelanceApp.Assign(Define.USERORG, orgIds.ToLookup(u => requser.Id));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户,包含用户与组织关系、用户与角色关系
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
public override void Delete(string[] ids)
|
||||
{
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
UnitWork.Delete<Relevance>(u =>(u.Key == Define.USERROLE || u.Key == Define.USERORG)
|
||||
&& ids.Contains(u.FirstId));
|
||||
UnitWork.Delete<User>(u => ids.Contains(u.Id));
|
||||
UnitWork.Save();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 修改密码
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
public void ChangePassword(ChangePasswordReq request)
|
||||
{
|
||||
Repository.Update(u => u.Account == request.Account, user => new User
|
||||
{
|
||||
Password = request.Password
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定角色包含的用户列表
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<TableData> LoadByRole(QueryUserListByRoleReq request)
|
||||
{
|
||||
var users = from userRole in UnitWork.Find<Relevance>(u =>
|
||||
u.SecondId == request.roleId && u.Key == Define.USERROLE)
|
||||
join user in UnitWork.Find<User>(null) on userRole.FirstId equals user.Id into temp
|
||||
from c in temp.Where(u =>u.Id != null)
|
||||
select c;
|
||||
|
||||
return new TableData
|
||||
{
|
||||
count = users.Count(),
|
||||
data = users.Skip((request.page - 1) * request.limit).Take(request.limit)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定机构包含的用户列表
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<TableData> LoadByOrg(QueryUserListByOrgReq request)
|
||||
{
|
||||
var users = from userRole in UnitWork.Find<Relevance>(u =>
|
||||
u.SecondId == request.orgId && u.Key == Define.USERORG)
|
||||
join user in UnitWork.Find<User>(null) on userRole.FirstId equals user.Id into temp
|
||||
from c in temp.Where(u =>u.Id != null)
|
||||
select c;
|
||||
|
||||
return new TableData
|
||||
{
|
||||
count = users.Count(),
|
||||
data = users.Skip((request.page - 1) * request.limit).Take(request.limit)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户资料
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
public void ChangeProfile(ChangeProfileReq request)
|
||||
{
|
||||
if (request.Account == Define.SYSTEM_USERNAME)
|
||||
{
|
||||
throw new Exception("不能修改超级管理员信息");
|
||||
}
|
||||
|
||||
Repository.Update(u => u.Account == request.Account, user => new User
|
||||
{
|
||||
Name = request.Name,
|
||||
Sex = request.Sex
|
||||
});
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Castle.Core.Internal;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Extensions;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class UserManagerApp : BaseStringApp<User,OpenAuthDBContext>
|
||||
{
|
||||
private RevelanceManagerApp _revelanceApp;
|
||||
private OrgManagerApp _orgManagerApp;
|
||||
|
||||
public UserManagerApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<User,OpenAuthDBContext> repository,
|
||||
RevelanceManagerApp app,IAuth auth, OrgManagerApp orgManagerApp) : base(unitWork, repository, auth)
|
||||
{
|
||||
_revelanceApp = app;
|
||||
_orgManagerApp = orgManagerApp;
|
||||
}
|
||||
|
||||
public User GetByAccount(string account)
|
||||
{
|
||||
return Repository.FirstOrDefault(u => u.Account == account);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载当前登录用户可访问的一个部门及子部门全部用户
|
||||
/// 如果请求的request.OrgId为空,则可以获取到已被删除机构的用户(即:没有分配任何机构的用户)
|
||||
/// </summary>
|
||||
public async Task<TableData> Load(QueryUserListReq request)
|
||||
{
|
||||
var loginUser = _auth.GetCurrentUser();
|
||||
|
||||
|
||||
IQueryable<User> query = UnitWork.Find<User>(null);
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
query = UnitWork.Find<User>(u => u.Name.Contains(request.key) || u.Account.Contains(request.key));
|
||||
}
|
||||
|
||||
var userOrgs = from user in query
|
||||
join relevance in UnitWork.Find<Relevance>(u =>u.Key=="UserOrg")
|
||||
on user.Id equals relevance.FirstId into temp
|
||||
from r in temp.DefaultIfEmpty()
|
||||
join org in UnitWork.Find<Org>(null)
|
||||
on r.SecondId equals org.Id into orgtmp
|
||||
from o in orgtmp.DefaultIfEmpty()
|
||||
select new
|
||||
{
|
||||
user.Account,
|
||||
user.Name,
|
||||
user.Id,
|
||||
user.Sex,
|
||||
user.Status,
|
||||
user.BizCode,
|
||||
user.CreateId,
|
||||
user.CreateTime,
|
||||
user.TypeId,
|
||||
user.TypeName,
|
||||
r.Key,
|
||||
r.SecondId,
|
||||
OrgId = o.Id,
|
||||
OrgName= o.Name
|
||||
};
|
||||
|
||||
//如果请求的orgId不为空
|
||||
if (!string.IsNullOrEmpty(request.orgId))
|
||||
{
|
||||
var org = loginUser.Orgs.SingleOrDefault(u => u.Id == request.orgId);
|
||||
var cascadeId = org.CascadeId;
|
||||
|
||||
var orgIds = loginUser.Orgs.Where(u => u.CascadeId.Contains(cascadeId)).Select(u => u.Id).ToArray();
|
||||
|
||||
//只获取机构里面的用户
|
||||
userOrgs = userOrgs.Where(u => u.Key == Define.USERORG && orgIds.Contains(u.OrgId));
|
||||
}
|
||||
else //todo:如果请求的orgId为空,即为跟节点,这时可以额外获取到机构已经被删除的用户,从而进行机构分配。可以根据自己需求进行调整
|
||||
{
|
||||
var orgIds = loginUser.Orgs.Select(u => u.Id).ToArray();
|
||||
|
||||
//获取用户可以访问的机构的用户和没有任何机构关联的用户(机构被删除后,没有删除这里面的关联关系)
|
||||
userOrgs = userOrgs.Where(u => (u.Key == Define.USERORG && orgIds.Contains(u.OrgId)) || (u.OrgId == null));
|
||||
}
|
||||
|
||||
|
||||
|
||||
var userViews = userOrgs.ToList().GroupBy(b => b.Account).Select(u =>new UserView
|
||||
{
|
||||
Id = u.First().Id,
|
||||
Account = u.Key,
|
||||
Name = u.First().Name,
|
||||
Sex = u.First().Sex,
|
||||
Status = u.First().Status,
|
||||
CreateTime = u.First().CreateTime,
|
||||
CreateUser = u.First().CreateId,
|
||||
OrganizationIds = string.Join(",", u.Select(x=>x.OrgId))
|
||||
,Organizations = string.Join(",", u.Select(x=>x.OrgName))
|
||||
|
||||
});
|
||||
|
||||
return new TableData
|
||||
{
|
||||
count = userViews.Count(),
|
||||
data = userViews.OrderBy(u => u.Name)
|
||||
.Skip((request.page - 1) * request.limit)
|
||||
.Take(request.limit),
|
||||
};
|
||||
}
|
||||
|
||||
public void AddOrUpdate(UpdateUserReq request)
|
||||
{
|
||||
request.ValidationEntity(u => new {u.Account,u.Name, u.OrganizationIds});
|
||||
|
||||
if (string.IsNullOrEmpty(request.OrganizationIds))
|
||||
throw new Exception("请为用户分配机构");
|
||||
User requser = request;
|
||||
requser.CreateId = _auth.GetCurrentUser().User.Id;
|
||||
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(request.Id))
|
||||
{
|
||||
if (UnitWork.Any<User>(u => u.Account == request.Account))
|
||||
{
|
||||
throw new Exception("用户账号已存在");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(requser.Password))
|
||||
{
|
||||
requser.Password = requser.Account; //如果客户端没提供密码,默认密码同账号
|
||||
}
|
||||
|
||||
requser.CreateTime = DateTime.Now;
|
||||
|
||||
UnitWork.Add(requser);
|
||||
request.Id = requser.Id; //要把保存后的ID存入view
|
||||
}
|
||||
else
|
||||
{
|
||||
UnitWork.Update<User>(u => u.Id == request.Id, u => new User
|
||||
{
|
||||
Account = requser.Account,
|
||||
BizCode = requser.BizCode,
|
||||
Name = requser.Name,
|
||||
Sex = requser.Sex,
|
||||
Status = requser.Status
|
||||
});
|
||||
if (!string.IsNullOrEmpty(requser.Password)) //密码为空的时候,不做修改
|
||||
{
|
||||
UnitWork.Update<User>(u => u.Id == request.Id, u => new User
|
||||
{
|
||||
Password = requser.Password
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
UnitWork.Save();
|
||||
string[] orgIds = request.OrganizationIds.Split(',').ToArray();
|
||||
|
||||
_revelanceApp.DeleteBy(Define.USERORG, requser.Id);
|
||||
_revelanceApp.Assign(Define.USERORG, orgIds.ToLookup(u => requser.Id));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户,包含用户与组织关系、用户与角色关系
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
public override void Delete(string[] ids)
|
||||
{
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
UnitWork.Delete<Relevance>(u =>(u.Key == Define.USERROLE || u.Key == Define.USERORG)
|
||||
&& ids.Contains(u.FirstId));
|
||||
UnitWork.Delete<User>(u => ids.Contains(u.Id));
|
||||
UnitWork.Save();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 修改密码
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
public void ChangePassword(ChangePasswordReq request)
|
||||
{
|
||||
Repository.Update(u => u.Account == request.Account, user => new User
|
||||
{
|
||||
Password = request.Password
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定角色包含的用户列表
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<TableData> LoadByRole(QueryUserListByRoleReq request)
|
||||
{
|
||||
var users = from userRole in UnitWork.Find<Relevance>(u =>
|
||||
u.SecondId == request.roleId && u.Key == Define.USERROLE)
|
||||
join user in UnitWork.Find<User>(null) on userRole.FirstId equals user.Id into temp
|
||||
from c in temp.Where(u =>u.Id != null)
|
||||
select c;
|
||||
|
||||
return new TableData
|
||||
{
|
||||
count = users.Count(),
|
||||
data = users.Skip((request.page - 1) * request.limit).Take(request.limit)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定机构包含的用户列表
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<TableData> LoadByOrg(QueryUserListByOrgReq request)
|
||||
{
|
||||
var users = from userRole in UnitWork.Find<Relevance>(u =>
|
||||
u.SecondId == request.orgId && u.Key == Define.USERORG)
|
||||
join user in UnitWork.Find<User>(null) on userRole.FirstId equals user.Id into temp
|
||||
from c in temp.Where(u =>u.Id != null)
|
||||
select c;
|
||||
|
||||
return new TableData
|
||||
{
|
||||
count = users.Count(),
|
||||
data = users.Skip((request.page - 1) * request.limit).Take(request.limit)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户资料
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
public void ChangeProfile(ChangeProfileReq request)
|
||||
{
|
||||
if (request.Account == Define.SYSTEM_USERNAME)
|
||||
{
|
||||
throw new Exception("不能修改超级管理员信息");
|
||||
}
|
||||
|
||||
Repository.Update(u => u.Account == request.Account, user => new User
|
||||
{
|
||||
Name = request.Name,
|
||||
Sex = request.Sex
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Infrastructure.Const;
|
||||
using OpenAuth.Repository.Core;
|
||||
|
||||
namespace OpenAuth.Repository.Domain
|
||||
@@ -44,7 +45,7 @@ namespace OpenAuth.Repository.Domain
|
||||
this.CreateUserName= string.Empty;
|
||||
this.FlowLevel= 0;
|
||||
this.Description= string.Empty;
|
||||
this.IsFinish= 0;
|
||||
this.IsFinish= FlowInstanceStatus.Running;
|
||||
this.MakerList= string.Empty;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Infrastructure.Const;
|
||||
using OpenAuth.Repository.Core;
|
||||
|
||||
namespace OpenAuth.Repository.Domain
|
||||
@@ -28,7 +29,7 @@ namespace OpenAuth.Repository.Domain
|
||||
this.ToNodeId= string.Empty;
|
||||
this.ToNodeName= string.Empty;
|
||||
this.TransitionSate= 0;
|
||||
this.IsFinish= 0;
|
||||
this.IsFinish= FlowInstanceStatus.Running;
|
||||
this.CreateDate= DateTime.Now;
|
||||
this.CreateUserId= string.Empty;
|
||||
this.CreateUserName= string.Empty;
|
||||
|
||||
@@ -83,6 +83,44 @@ namespace OpenAuth.WebApi.Controllers
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>召回流程</summary>
|
||||
/// <remarks> 召回后流程状态为【草稿】状态,可以再次发起流程。所有的流程节点状态还原,但保留审批记录 </remarks>
|
||||
[HttpPost]
|
||||
public Response ReCall(RecallFlowInstanceReq obj)
|
||||
{
|
||||
var result = new Response();
|
||||
try
|
||||
{
|
||||
_app.ReCall(obj);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Code = 500;
|
||||
result.Message = ex.InnerException?.Message ?? ex.Message;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>启动流程</summary>
|
||||
/// <remarks> 通常是对状态为【草稿】的流程进行操作,进入运行状态 </remarks>
|
||||
[HttpPost]
|
||||
public Response Start(StartFlowInstanceReq obj)
|
||||
{
|
||||
var result = new Response();
|
||||
try
|
||||
{
|
||||
_app.Start(obj);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Code = 500;
|
||||
result.Message = ex.InnerException?.Message ?? ex.Message;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//添加或修改
|
||||
[HttpPost]
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace OpenAuth.WebApi
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(@"
|
||||
Console.WriteLine($@"
|
||||
____ _ _ _ _ _
|
||||
/ __ \ /\ | | | | | \ | | | |
|
||||
| | | |_ __ ___ _ __ / \ _ _| |_| |__ | \| | ___| |_
|
||||
@@ -24,7 +24,7 @@ namespace OpenAuth.WebApi
|
||||
.Net 5 Repository: https://gitee.com/dotnetchina/OpenAuth.Net
|
||||
.Net core 3.1 : https://gitee.com/yubaolee/OpenAuth.Core
|
||||
-------------------------------------------------------------------
|
||||
");
|
||||
Start Time:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user