diff --git a/Infrastructure/Const/FlowInstanceStatus.cs b/Infrastructure/Const/FlowInstanceStatus.cs new file mode 100644 index 00000000..3e3c86a3 --- /dev/null +++ b/Infrastructure/Const/FlowInstanceStatus.cs @@ -0,0 +1,30 @@ +namespace Infrastructure.Const +{ + /// + /// 流程状态 + /// + public struct FlowInstanceStatus + { + /// + /// 撤销、召回 + /// + public const int Draft = -1; + /// + /// 正在运行 + /// + public const int Running = 0; + /// + /// 完成 + /// + public const int Finished = 1; + /// + /// 不同意 + /// + public const int Disagree = 3; + /// + /// 驳回 + /// + public const int Rejected = 4; + + } +} \ No newline at end of file diff --git a/Infrastructure/Helpers/FileHelper.cs b/Infrastructure/Helpers/FileHelper.cs index 02763216..238526e5 100644 --- a/Infrastructure/Helpers/FileHelper.cs +++ b/Infrastructure/Helpers/FileHelper.cs @@ -381,6 +381,7 @@ namespace Infrastructure.Helpers /// 追加内容 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(); diff --git a/OpenAuth.App/AppManager.cs b/OpenAuth.App/AppManager/AppManager.cs similarity index 100% rename from OpenAuth.App/AppManager.cs rename to OpenAuth.App/AppManager/AppManager.cs diff --git a/OpenAuth.App/Request/QueryAppListReq.cs b/OpenAuth.App/AppManager/Request/QueryAppListReq.cs similarity index 100% rename from OpenAuth.App/Request/QueryAppListReq.cs rename to OpenAuth.App/AppManager/Request/QueryAppListReq.cs diff --git a/OpenAuth.App/Request/IdPageReq.cs b/OpenAuth.App/Base/IdPageReq.cs similarity index 94% rename from OpenAuth.App/Request/IdPageReq.cs rename to OpenAuth.App/Base/IdPageReq.cs index 127250a5..59491cbf 100644 --- a/OpenAuth.App/Request/IdPageReq.cs +++ b/OpenAuth.App/Base/IdPageReq.cs @@ -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; } + } +} diff --git a/OpenAuth.App/Request/PageReq.cs b/OpenAuth.App/Base/PageReq.cs similarity index 94% rename from OpenAuth.App/Request/PageReq.cs rename to OpenAuth.App/Base/PageReq.cs index 8dcf7ff3..73eb9695 100644 --- a/OpenAuth.App/Request/PageReq.cs +++ b/OpenAuth.App/Base/PageReq.cs @@ -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; + } + } +} diff --git a/OpenAuth.App/Response/TableData.cs b/OpenAuth.App/Base/TableData.cs similarity index 96% rename from OpenAuth.App/Response/TableData.cs rename to OpenAuth.App/Base/TableData.cs index 2ebd7f4d..63f6e171 100644 --- a/OpenAuth.App/Response/TableData.cs +++ b/OpenAuth.App/Base/TableData.cs @@ -1,56 +1,56 @@ -// *********************************************************************** -// Assembly : FundationAdmin -// Author : yubaolee -// Created : 03-09-2016 -// -// Last Modified By : yubaolee -// Last Modified On : 03-09-2016 -// *********************************************************************** -// -// 版权所有(C) Microsoft 2015 -// -// layui datatable数据返回 -// *********************************************************************** - -using System.Collections.Generic; -using Infrastructure; - -namespace OpenAuth.App.Response -{ - /// - /// table的返回数据 - /// - public class TableData - { - /// - /// 状态码 - /// - public int code { get; set; } - /// - /// 操作消息 - /// - public string msg { get; set; } - - /// - /// 总记录条数 - /// - public int count { get; set; } - - /// - /// 返回的列表头信息 - /// - public List columnHeaders; - - /// - /// 数据内容 - /// - public dynamic data { get; set; } - - public TableData() - { - code = 200; - msg = "加载成功"; - columnHeaders = new List(); - } - } +// *********************************************************************** +// Assembly : FundationAdmin +// Author : yubaolee +// Created : 03-09-2016 +// +// Last Modified By : yubaolee +// Last Modified On : 03-09-2016 +// *********************************************************************** +// +// 版权所有(C) Microsoft 2015 +// +// layui datatable数据返回 +// *********************************************************************** + +using System.Collections.Generic; +using Infrastructure; + +namespace OpenAuth.App.Response +{ + /// + /// table的返回数据 + /// + public class TableData + { + /// + /// 状态码 + /// + public int code { get; set; } + /// + /// 操作消息 + /// + public string msg { get; set; } + + /// + /// 总记录条数 + /// + public int count { get; set; } + + /// + /// 返回的列表头信息 + /// + public List columnHeaders; + + /// + /// 数据内容 + /// + public dynamic data { get; set; } + + public TableData() + { + code = 200; + msg = "加载成功"; + columnHeaders = new List(); + } + } } \ No newline at end of file diff --git a/OpenAuth.App/Response/TableResp.cs b/OpenAuth.App/Base/TableResp.cs similarity index 100% rename from OpenAuth.App/Response/TableResp.cs rename to OpenAuth.App/Base/TableResp.cs diff --git a/OpenAuth.App/BuilderTableApp.cs b/OpenAuth.App/BuilderTable/BuilderTableApp.cs similarity index 100% rename from OpenAuth.App/BuilderTableApp.cs rename to OpenAuth.App/BuilderTable/BuilderTableApp.cs diff --git a/OpenAuth.App/BuilderTableColumnApp.cs b/OpenAuth.App/BuilderTable/BuilderTableColumnApp.cs similarity index 100% rename from OpenAuth.App/BuilderTableColumnApp.cs rename to OpenAuth.App/BuilderTable/BuilderTableColumnApp.cs diff --git a/OpenAuth.App/Request/AddOrUpdateBuilderTableColumnReq.cs b/OpenAuth.App/BuilderTable/Request/AddOrUpdateBuilderTableColumnReq.cs similarity index 100% rename from OpenAuth.App/Request/AddOrUpdateBuilderTableColumnReq.cs rename to OpenAuth.App/BuilderTable/Request/AddOrUpdateBuilderTableColumnReq.cs diff --git a/OpenAuth.App/Request/AddOrUpdateBuilderTableReq.cs b/OpenAuth.App/BuilderTable/Request/AddOrUpdateBuilderTableReq.cs similarity index 100% rename from OpenAuth.App/Request/AddOrUpdateBuilderTableReq.cs rename to OpenAuth.App/BuilderTable/Request/AddOrUpdateBuilderTableReq.cs diff --git a/OpenAuth.App/Request/CreateBusiReq.cs b/OpenAuth.App/BuilderTable/Request/CreateBusiReq.cs similarity index 100% rename from OpenAuth.App/Request/CreateBusiReq.cs rename to OpenAuth.App/BuilderTable/Request/CreateBusiReq.cs diff --git a/OpenAuth.App/Request/CreateEntityReq.cs b/OpenAuth.App/BuilderTable/Request/CreateEntityReq.cs similarity index 100% rename from OpenAuth.App/Request/CreateEntityReq.cs rename to OpenAuth.App/BuilderTable/Request/CreateEntityReq.cs diff --git a/OpenAuth.App/Request/CreateVueReq.cs b/OpenAuth.App/BuilderTable/Request/CreateVueReq.cs similarity index 100% rename from OpenAuth.App/Request/CreateVueReq.cs rename to OpenAuth.App/BuilderTable/Request/CreateVueReq.cs diff --git a/OpenAuth.App/Request/QueryBuilderTableColumnListReq.cs b/OpenAuth.App/BuilderTable/Request/QueryBuilderTableColumnListReq.cs similarity index 100% rename from OpenAuth.App/Request/QueryBuilderTableColumnListReq.cs rename to OpenAuth.App/BuilderTable/Request/QueryBuilderTableColumnListReq.cs diff --git a/OpenAuth.App/Request/QueryBuilderTableListReq.cs b/OpenAuth.App/BuilderTable/Request/QueryBuilderTableListReq.cs similarity index 100% rename from OpenAuth.App/Request/QueryBuilderTableListReq.cs rename to OpenAuth.App/BuilderTable/Request/QueryBuilderTableListReq.cs diff --git a/OpenAuth.App/CategoryApp.cs b/OpenAuth.App/Category/CategoryApp.cs similarity index 97% rename from OpenAuth.App/CategoryApp.cs rename to OpenAuth.App/Category/CategoryApp.cs index 382cdbde..0a44d3e9 100644 --- a/OpenAuth.App/CategoryApp.cs +++ b/OpenAuth.App/Category/CategoryApp.cs @@ -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 - { - /// - /// 加载列表 - /// - public async Task 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(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(); - 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(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:要修改的字段赋值 - }); - - } - - /// - /// 加载一个分类类型里面的所有值,即字典的所有值 - /// - /// - /// - public List LoadByTypeId(string typeId) - { - return Repository.Find(u => u.TypeId == typeId).ToList(); - } - - public CategoryApp(IUnitWork unitWork, IRepository 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 + { + /// + /// 加载列表 + /// + public async Task 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(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(); + 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(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:要修改的字段赋值 + }); + + } + + /// + /// 加载一个分类类型里面的所有值,即字典的所有值 + /// + /// + /// + public List LoadByTypeId(string typeId) + { + return Repository.Find(u => u.TypeId == typeId).ToList(); + } + + public CategoryApp(IUnitWork unitWork, IRepository repository,IAuth auth) : base(unitWork, repository, auth) + { + } + } } \ No newline at end of file diff --git a/OpenAuth.App/CategoryTypeApp.cs b/OpenAuth.App/Category/CategoryTypeApp.cs similarity index 100% rename from OpenAuth.App/CategoryTypeApp.cs rename to OpenAuth.App/Category/CategoryTypeApp.cs diff --git a/OpenAuth.App/Request/AddOrUpdateCategoryReq.cs b/OpenAuth.App/Category/Request/AddOrUpdateCategoryReq.cs similarity index 100% rename from OpenAuth.App/Request/AddOrUpdateCategoryReq.cs rename to OpenAuth.App/Category/Request/AddOrUpdateCategoryReq.cs diff --git a/OpenAuth.App/Request/AddOrUpdateCategoryTypeReq.cs b/OpenAuth.App/Category/Request/AddOrUpdateCategoryTypeReq.cs similarity index 100% rename from OpenAuth.App/Request/AddOrUpdateCategoryTypeReq.cs rename to OpenAuth.App/Category/Request/AddOrUpdateCategoryTypeReq.cs diff --git a/OpenAuth.App/Request/QueryCategoryListReq.cs b/OpenAuth.App/Category/Request/QueryCategoryListReq.cs similarity index 100% rename from OpenAuth.App/Request/QueryCategoryListReq.cs rename to OpenAuth.App/Category/Request/QueryCategoryListReq.cs diff --git a/OpenAuth.App/Request/QueryCategoryTypeListReq.cs b/OpenAuth.App/Category/Request/QueryCategoryTypeListReq.cs similarity index 100% rename from OpenAuth.App/Request/QueryCategoryTypeListReq.cs rename to OpenAuth.App/Category/Request/QueryCategoryTypeListReq.cs diff --git a/OpenAuth.App/DataPrivilegeRuleApp.cs b/OpenAuth.App/DataPrivilege/DataPrivilegeRuleApp.cs similarity index 100% rename from OpenAuth.App/DataPrivilegeRuleApp.cs rename to OpenAuth.App/DataPrivilege/DataPrivilegeRuleApp.cs diff --git a/OpenAuth.App/Request/AddOrUpdateDataPriviReq.cs b/OpenAuth.App/DataPrivilege/Request/AddOrUpdateDataPriviReq.cs similarity index 100% rename from OpenAuth.App/Request/AddOrUpdateDataPriviReq.cs rename to OpenAuth.App/DataPrivilege/Request/AddOrUpdateDataPriviReq.cs diff --git a/OpenAuth.App/Request/QueryDataPrivilegeRuleListReq.cs b/OpenAuth.App/DataPrivilege/Request/QueryDataPrivilegeRuleListReq.cs similarity index 100% rename from OpenAuth.App/Request/QueryDataPrivilegeRuleListReq.cs rename to OpenAuth.App/DataPrivilege/Request/QueryDataPrivilegeRuleListReq.cs diff --git a/OpenAuth.App/FileApp.cs b/OpenAuth.App/Files/FileApp.cs similarity index 100% rename from OpenAuth.App/FileApp.cs rename to OpenAuth.App/Files/FileApp.cs diff --git a/OpenAuth.App/Request/QueryFileListReq.cs b/OpenAuth.App/Files/Request/QueryFileListReq.cs similarity index 100% rename from OpenAuth.App/Request/QueryFileListReq.cs rename to OpenAuth.App/Files/Request/QueryFileListReq.cs diff --git a/OpenAuth.App/Flow/FlowRuntime.cs b/OpenAuth.App/Flow/FlowRuntime.cs index ce73ad8e..d5b4b06d 100644 --- a/OpenAuth.App/Flow/FlowRuntime.cs +++ b/OpenAuth.App/Flow/FlowRuntime.cs @@ -325,6 +325,17 @@ namespace OpenAuth.App.Flow return previousId; } + /// + /// 撤销流程,清空所有节点 + /// + public void ReCall() + { + foreach (var item in Nodes) + { + item.Value.setInfo = null; + } + } + /// /// 标记节点1通过,-1不通过,0驳回 /// diff --git a/OpenAuth.App/FlowInstanceApp.cs b/OpenAuth.App/FlowInstance/FlowInstanceApp.cs similarity index 75% rename from OpenAuth.App/FlowInstanceApp.cs rename to OpenAuth.App/FlowInstance/FlowInstanceApp.cs index 182865b8..4664e90c 100644 --- a/OpenAuth.App/FlowInstanceApp.cs +++ b/OpenAuth.App/FlowInstance/FlowInstanceApp.cs @@ -1,575 +1,674 @@ -// *********************************************************************** -// Assembly : OpenAuth.App -// Author : 李玉宝 -// Created : 07-19-2018 -// -// Last Modified By : 李玉宝 -// Last Modified On : 07-19-2018 -// *********************************************************************** -// -// Copyright (c) http://www.openauth.me. All rights reserved. -// -// -// *********************************************************************** - -using Infrastructure; -using OpenAuth.App.Flow; -using OpenAuth.App.Interface; -using OpenAuth.App.Request; -using OpenAuth.App.Response; -using OpenAuth.Repository.Domain; -using OpenAuth.Repository.Interface; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Net.Http; -using System.Threading.Tasks; -using Infrastructure.Helpers; -using OpenAuth.Repository; - -namespace OpenAuth.App -{ - /// - /// 工作流实例表操作 - /// - public class FlowInstanceApp : BaseStringApp - { - private RevelanceManagerApp _revelanceApp; - private FlowSchemeApp _flowSchemeApp; - private FormApp _formApp; - private IHttpClientFactory _httpClientFactory; - private IServiceProvider _serviceProvider; - - #region 流程处理API - - /// - /// 创建一个实例 - /// - /// - public bool CreateInstance(AddFlowInstanceReq addFlowInstanceReq) - { - FlowScheme scheme = null; - if (!string.IsNullOrEmpty(addFlowInstanceReq.SchemeId)) - { - scheme = _flowSchemeApp.Get(addFlowInstanceReq.SchemeId); - } - - if ((scheme == null) && !string.IsNullOrEmpty(addFlowInstanceReq.SchemeCode)) - { - scheme = _flowSchemeApp.FindByCode(addFlowInstanceReq.SchemeCode); - } - - if (scheme == null) - { - throw new Exception("该流程模板已不存在,请重新设计流程"); - } - - addFlowInstanceReq.SchemeContent = scheme.SchemeContent; - - var form = _formApp.FindSingle(scheme.FrmId); - if (form == null) - { - throw new Exception("该流程模板对应的表单已不存在,请重新设计流程"); - } - - addFlowInstanceReq.FrmContentData = form.ContentData; - addFlowInstanceReq.FrmContentParse = form.ContentParse; - addFlowInstanceReq.FrmType = form.FrmType; - addFlowInstanceReq.FrmId = form.Id; - - var flowInstance = addFlowInstanceReq.MapTo(); - - //创建运行实例 - var wfruntime = new FlowRuntime(flowInstance); - var user = _auth.GetCurrentUser(); - - #region 根据运行实例改变当前节点状态 - - flowInstance.ActivityId = wfruntime.nextNodeId; - flowInstance.ActivityType = wfruntime.GetNextNodeType(); - flowInstance.ActivityName = wfruntime.nextNode.name; - flowInstance.PreviousId = wfruntime.currentNodeId; - flowInstance.CreateUserId = user.User.Id; - flowInstance.CreateUserName = user.User.Account; - flowInstance.MakerList = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : ""); - flowInstance.IsFinish = (wfruntime.GetNextNodeType() == 4 ? 1 : 0); - - UnitWork.Add(flowInstance); - wfruntime.flowInstanceId = flowInstance.Id; - - if (flowInstance.FrmType == 1) //如果是开发者自定义的表单 - { - var t = Type.GetType("OpenAuth.App."+ flowInstance.DbName +"App"); - ICustomerForm icf = (ICustomerForm) _serviceProvider.GetService(t); - icf.Add(flowInstance.Id, flowInstance.FrmData); - } - - #endregion 根据运行实例改变当前节点状态 - - #region 流程操作记录 - - FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory - { - InstanceId = flowInstance.Id, - CreateUserId = user.User.Id, - CreateUserName = user.User.Name, - CreateDate = DateTime.Now, - Content = "【创建】" - + user.User.Name - + "创建了一个流程进程【" - + addFlowInstanceReq.Code + "/" - + addFlowInstanceReq.CustomName + "】" - }; - UnitWork.Add(processOperationHistoryEntity); - - #endregion 流程操作记录 - - AddTransHistory(wfruntime); - UnitWork.Save(); - return true; - } - - /// - /// 节点审核 - /// - /// - /// - public bool NodeVerification(string instanceId, Tag tag) - { - FlowInstance flowInstance = Get(instanceId); - FlowInstanceOperationHistory flowInstanceOperationHistory = new FlowInstanceOperationHistory - { - InstanceId = instanceId, - CreateUserId = tag.UserId, - CreateUserName = tag.UserName, - CreateDate = DateTime.Now - };//操作记录 - FlowRuntime wfruntime = new FlowRuntime(flowInstance); - - #region 会签 - - if (flowInstance.ActivityType == 0)//当前节点是会签节点 - { - //会签时的【当前节点】一直是会签开始节点 - //TODO: 标记会签节点的状态,这个地方感觉怪怪的 - wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); - - string canCheckId = ""; //寻找当前登录用户可审核的节点Id - foreach (string fromForkStartNodeId in wfruntime.FromNodeLines[wfruntime.currentNodeId].Select(u => u.to)) - { - var fromForkStartNode = wfruntime.Nodes[fromForkStartNodeId]; //与会前开始节点直接连接的节点 - canCheckId = GetOneForkLineCanCheckNodeId(fromForkStartNode, wfruntime, tag); - if(!string.IsNullOrEmpty(canCheckId)) break; - } - - if (canCheckId == "") - { - throw (new Exception("审核异常,找不到审核节点")); - } - - flowInstanceOperationHistory.Content = "【" + wfruntime.Nodes[canCheckId].name - + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") - + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:" - + tag.Description; - - wfruntime.MakeTagNode(canCheckId, tag); //标记审核节点状态 - string res = wfruntime.NodeConfluence(canCheckId, tag); - if (res == TagState.No.ToString("D")) - { - flowInstance.IsFinish = 3; - } - else if(!string.IsNullOrEmpty(res)) - { - flowInstance.PreviousId = flowInstance.ActivityId; - flowInstance.ActivityId = wfruntime.nextNodeId; - flowInstance.ActivityType = wfruntime.nextNodeType; - flowInstance.ActivityName = wfruntime.nextNode.name; - flowInstance.IsFinish = (wfruntime.nextNodeType == 4 ? 1 : 0); - flowInstance.MakerList = - (wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime)); - - AddTransHistory(wfruntime); - } - else - { - //会签过程中,需要更新用户 - flowInstance.MakerList = GetForkNodeMakers(wfruntime, wfruntime.currentNodeId); - AddTransHistory(wfruntime); - } - - } - #endregion 会签 - - #region 一般审核 - - else - { - wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); - if (tag.Taged == (int) TagState.Ok) - { - flowInstance.PreviousId = flowInstance.ActivityId; - flowInstance.ActivityId = wfruntime.nextNodeId; - flowInstance.ActivityType = wfruntime.nextNodeType; - flowInstance.ActivityName = wfruntime.nextNode.name; - flowInstance.MakerList = wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime); - flowInstance.IsFinish = (wfruntime.nextNodeType == 4 ? 1 : 0); - AddTransHistory(wfruntime); - } - else - { - flowInstance.IsFinish = 3; //表示该节点不同意 - } - flowInstanceOperationHistory.Content = "【" + wfruntime.currentNode.name - + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") - + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:" - + tag.Description; - } - - #endregion 一般审核 - - flowInstance.SchemeContent = JsonHelper.Instance.Serialize(wfruntime.ToSchemeObj()); - - UnitWork.Update(flowInstance); - UnitWork.Add(flowInstanceOperationHistory); - UnitWork.Save(); - - wfruntime.NotifyThirdParty(_httpClientFactory.CreateClient(), tag); - return true; - } - - //会签时,获取一条会签分支上面是否有用户可审核的节点 - private string GetOneForkLineCanCheckNodeId(FlowNode fromForkStartNode, FlowRuntime wfruntime, Tag tag) - { - string canCheckId=""; - var node = fromForkStartNode; - do //沿一条分支线路执行,直到遇到会签结束节点 - { - var makerList = GetNodeMarkers(node); - - if (node.setInfo.Taged == null && !string.IsNullOrEmpty(makerList) && makerList.Split(',').Any(one => tag.UserId == one)) - { - canCheckId = node.id; - break; - } - - node = wfruntime.GetNextNode(node.id); - } while (node.type != FlowNode.JOIN); - - return canCheckId; - } - - /// - /// 驳回 - /// 如果NodeRejectStep不为空,优先使用;否则按照NodeRejectType驳回 - /// - /// - public bool NodeReject(VerificationReq reqest) - { - var user = _auth.GetCurrentUser().User; - - FlowInstance flowInstance = Get(reqest.FlowInstanceId); - - FlowRuntime wfruntime = new FlowRuntime(flowInstance); - - string rejectNode = ""; //驳回的节点 - rejectNode = string.IsNullOrEmpty(reqest.NodeRejectStep) ? wfruntime.RejectNode(reqest.NodeRejectType) : reqest.NodeRejectStep; - - var tag = new Tag - { - Description = reqest.VerificationOpinion, - Taged = (int) TagState.Reject, - UserId = user.Id, - UserName = user.Name - }; - - wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); - flowInstance.IsFinish = 4;//4表示驳回(需要申请者重新提交表单) - if (rejectNode != "") - { - flowInstance.PreviousId = flowInstance.ActivityId; - flowInstance.ActivityId = rejectNode; - flowInstance.ActivityType = wfruntime.GetNodeType(rejectNode); - flowInstance.ActivityName = wfruntime.Nodes[rejectNode].name; - flowInstance.MakerList = GetNodeMarkers(wfruntime.Nodes[rejectNode], flowInstance.CreateUserId); - - AddTransHistory(wfruntime); - } - - UnitWork.Update(flowInstance); - - UnitWork.Add(new FlowInstanceOperationHistory - { - InstanceId = reqest.FlowInstanceId - , - CreateUserId = user.Id - , - CreateUserName = user.Name - , - CreateDate = DateTime.Now - , - Content = "【" - + wfruntime.currentNode.name - + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】驳回,备注:" - + reqest.VerificationOpinion - }); - - UnitWork.Save(); - - wfruntime.NotifyThirdParty(_httpClientFactory.CreateClient(), tag); - - return true; - } - - #endregion 流程处理API - - #region 获取各种节点的流程审核者 - /// - /// 寻找下一步的执行人 - /// 一般用于本节点审核完成后,修改流程实例的当前执行人,可以做到通知等功能 - /// - /// - private string GetNextMakers(FlowRuntime wfruntime) - { - string makerList = ""; - if (wfruntime.nextNodeId == "-1") - { - throw (new Exception("无法寻找到下一个节点")); - } - if (wfruntime.nextNodeType == 0)//如果是会签节点 - { - makerList = GetForkNodeMakers(wfruntime, wfruntime.nextNodeId); - } - else - { - makerList = GetNodeMarkers(wfruntime.nextNode); - if (string.IsNullOrEmpty(makerList)) - { - throw (new Exception("无法寻找到节点的审核者,请查看流程设计是否有问题!")); - } - } - - return makerList; - } - - /// - /// 获取会签开始节点的所有可执行者 - /// - /// 会签开始节点 - /// - private string GetForkNodeMakers(FlowRuntime wfruntime, string forkNodeId) - { - string makerList=""; - foreach (string fromForkStartNodeId in wfruntime.FromNodeLines[forkNodeId].Select(u => u.to)) - { - var fromForkStartNode = wfruntime.Nodes[fromForkStartNodeId]; //与会前开始节点直接连接的节点 - if (makerList != "") - { - makerList += ","; - } - - makerList += GetOneForkLineMakers(fromForkStartNode, wfruntime); - } - - return makerList; - } - - //获取会签一条线上的审核者,该审核者应该是已审核过的节点的下一个人 - private string GetOneForkLineMakers(FlowNode fromForkStartNode, FlowRuntime wfruntime) - { - string markers=""; - var node = fromForkStartNode; - do //沿一条分支线路执行,直到遇到第一个没有审核的节点 - { - if (node.setInfo != null && node.setInfo.Taged != null) - { - if (node.type != FlowNode.FORK && node.setInfo.Taged != (int) TagState.Ok) //如果节点是不同意或驳回,则不用再找了 - { - break; - } - node = wfruntime.GetNextNode(node.id); //下一个节点 - continue; - } - var marker = GetNodeMarkers(node); - if (marker == "") - { - throw (new Exception($"节点{node.name}没有审核者,请检查!")); - } - if (marker == "1") - { - throw (new Exception($"节点{node.name}是会签节点,不能用所有人,请检查!")); - } - - if (markers != "") - { - markers += ","; - } - markers += marker; - break; - } while (node.type != FlowNode.JOIN); - - return markers; - } - - /// - /// 寻找该节点执行人 - /// - /// - /// - private string GetNodeMarkers(FlowNode node,string flowinstanceCreateUserId="") - { - string makerList = ""; - if (node.type == FlowNode.START && (!string.IsNullOrEmpty(flowinstanceCreateUserId))) //如果是开始节点,通常情况下是驳回到开始了 - { - makerList = flowinstanceCreateUserId; - } - else if (node.setInfo != null) - { - if (node.setInfo.NodeDesignate == Setinfo.ALL_USER)//所有成员 - { - makerList = "1"; - } - else if (node.setInfo.NodeDesignate == Setinfo.SPECIAL_USER)//指定成员 - { - makerList = GenericHelpers.ArrayToString(node.setInfo.NodeDesignateData.users, makerList); - } - else if (node.setInfo.NodeDesignate == Setinfo.SPECIAL_ROLE) //指定角色 - { - var users = _revelanceApp.Get(Define.USERROLE, false, node.setInfo.NodeDesignateData.roles); - makerList = GenericHelpers.ArrayToString(users, makerList); - } - } - else //如果没有设置节点信息,默认所有人都可以审核 - { - makerList = "1"; - } - return makerList; - } - #endregion - - /// - /// 审核流程 - /// 李玉宝于2017-01-20 15:44:45 - /// - public void Verification(VerificationReq request) - { - var user = _auth.GetCurrentUser().User; - var tag = new Tag - { - UserName = user.Name, - UserId = user.Id, - Description = request.VerificationOpinion, - Taged = Int32.Parse(request.VerificationFinally) - }; - bool isReject = TagState.Reject.Equals((TagState) tag.Taged); - if (isReject) //驳回 - { - NodeReject(request); - } - else - { - NodeVerification(request.FlowInstanceId, tag); - } - } - - public void Update(FlowInstance flowScheme) - { - Repository.Update(flowScheme); - } - - public async Task Load(QueryFlowInstanceListReq request) - { - var result = new TableData(); - var user = _auth.GetCurrentUser(); - - if (request.type == "wait") //待办事项 - { - Expression> waitExp = u => (u.MakerList == "1" || u.MakerList.Contains(user.User.Id)) && (u.IsFinish == 0|| u.IsFinish==4); - - // 加入搜索自定义标题 - if (!string.IsNullOrEmpty(request.key)) - { - waitExp = waitExp.And(t => t.CustomName.Contains(request.key)); - } - - result.count = UnitWork.Find(waitExp).Count(); - - result.data = UnitWork.Find(request.page, request.limit, "CreateDate descending", waitExp).ToList(); - } - else if (request.type == "disposed") //已办事项(即我参与过的流程) - { - var instances = UnitWork.Find(u => u.CreateUserId == user.User.Id) - .Select(u => u.InstanceId).Distinct(); - var query = from ti in instances - join ct in UnitWork.Find(null) on ti equals ct.Id - select ct; - - // 加入搜索自定义标题 - if (!string.IsNullOrEmpty(request.key)) - { - query = query.Where(t => t.CustomName.Contains(request.key)); - } - - result.data = query.OrderByDescending(u => u.CreateDate) - .Skip((request.page - 1) * request.limit) - .Take(request.limit).ToList(); - result.count = instances.Count(); - } - else //我的流程 - { - Expression> myFlowExp = u => u.CreateUserId == user.User.Id; - - // 加入搜索自定义标题 - if (!string.IsNullOrEmpty(request.key)) - { - myFlowExp = myFlowExp.And(t => t.CustomName.Contains(request.key)); - } - - result.count = UnitWork.Find(myFlowExp).Count(); - result.data = UnitWork.Find(request.page, request.limit, - "CreateDate descending", myFlowExp).ToList(); - } - - return result; - } - - /// - /// 添加扭转记录 - /// - private void AddTransHistory(FlowRuntime wfruntime) - { - var tag = _auth.GetCurrentUser().User; - UnitWork.Add(new FlowInstanceTransitionHistory - { - InstanceId = wfruntime.flowInstanceId, - CreateUserId = tag.Id, - CreateUserName = tag.Name, - FromNodeId = wfruntime.currentNodeId, - FromNodeName = wfruntime.currentNode.name, - FromNodeType = wfruntime.currentNodeType, - ToNodeId = wfruntime.nextNodeId, - ToNodeName = wfruntime.nextNode.name, - ToNodeType = wfruntime.nextNodeType, - IsFinish = wfruntime.nextNodeType == 4 ? 1 : 0, - TransitionSate = 0 - }); - } - - public FlowInstanceApp(IUnitWork unitWork, IRepository repository - , RevelanceManagerApp app, FlowSchemeApp flowSchemeApp, FormApp formApp, IHttpClientFactory httpClientFactory,IAuth auth, IServiceProvider serviceProvider) - : base(unitWork, repository, auth) - { - _revelanceApp = app; - _flowSchemeApp = flowSchemeApp; - _formApp = formApp; - _httpClientFactory = httpClientFactory; - _serviceProvider = serviceProvider; - } - - public List QueryHistories(QueryFlowInstanceHistoryReq request) - { - return UnitWork.Find(u => u.InstanceId == request.FlowInstanceId) - .OrderByDescending(u => u.CreateDate).ToList(); - } - } +// *********************************************************************** +// Assembly : OpenAuth.App +// Author : 李玉宝 +// Created : 07-19-2018 +// +// Last Modified By : 李玉宝 +// Last Modified On : 07-19-2018 +// *********************************************************************** +// +// Copyright (c) http://www.openauth.me. All rights reserved. +// +// +// *********************************************************************** + +using Infrastructure; +using OpenAuth.App.Flow; +using OpenAuth.App.Interface; +using OpenAuth.App.Request; +using OpenAuth.App.Response; +using OpenAuth.Repository.Domain; +using OpenAuth.Repository.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Net.Http; +using System.Threading.Tasks; +using Infrastructure.Const; +using Infrastructure.Helpers; +using OpenAuth.Repository; + +namespace OpenAuth.App +{ + /// + /// 工作流实例表操作 + /// + public class FlowInstanceApp : BaseStringApp + { + private RevelanceManagerApp _revelanceApp; + private FlowSchemeApp _flowSchemeApp; + private FormApp _formApp; + private IHttpClientFactory _httpClientFactory; + private IServiceProvider _serviceProvider; + + public FlowInstanceApp(IUnitWork unitWork, + IRepository repository + , RevelanceManagerApp app, FlowSchemeApp flowSchemeApp, FormApp formApp, + IHttpClientFactory httpClientFactory, IAuth auth, IServiceProvider serviceProvider) + : base(unitWork, repository, auth) + { + _revelanceApp = app; + _flowSchemeApp = flowSchemeApp; + _formApp = formApp; + _httpClientFactory = httpClientFactory; + _serviceProvider = serviceProvider; + } + + #region 流程处理API + + /// + /// 创建一个实例 + /// + /// + public bool CreateInstance(AddFlowInstanceReq addFlowInstanceReq) + { + FlowScheme scheme = null; + if (!string.IsNullOrEmpty(addFlowInstanceReq.SchemeId)) + { + scheme = _flowSchemeApp.Get(addFlowInstanceReq.SchemeId); + } + + if ((scheme == null) && !string.IsNullOrEmpty(addFlowInstanceReq.SchemeCode)) + { + scheme = _flowSchemeApp.FindByCode(addFlowInstanceReq.SchemeCode); + } + + if (scheme == null) + { + throw new Exception("该流程模板已不存在,请重新设计流程"); + } + + addFlowInstanceReq.SchemeContent = scheme.SchemeContent; + + var form = _formApp.FindSingle(scheme.FrmId); + if (form == null) + { + throw new Exception("该流程模板对应的表单已不存在,请重新设计流程"); + } + + addFlowInstanceReq.FrmContentData = form.ContentData; + addFlowInstanceReq.FrmContentParse = form.ContentParse; + addFlowInstanceReq.FrmType = form.FrmType; + addFlowInstanceReq.FrmId = form.Id; + + var flowInstance = addFlowInstanceReq.MapTo(); + + //创建运行实例 + var wfruntime = new FlowRuntime(flowInstance); + var user = _auth.GetCurrentUser(); + + #region 根据运行实例改变当前节点状态 + + flowInstance.ActivityId = wfruntime.nextNodeId; + flowInstance.ActivityType = wfruntime.GetNextNodeType(); + flowInstance.ActivityName = wfruntime.nextNode.name; + flowInstance.PreviousId = wfruntime.currentNodeId; + flowInstance.CreateUserId = user.User.Id; + flowInstance.CreateUserName = user.User.Account; + flowInstance.MakerList = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : ""); + flowInstance.IsFinish = (wfruntime.GetNextNodeType() == 4 + ? FlowInstanceStatus.Finished + : FlowInstanceStatus.Running); + + UnitWork.Add(flowInstance); + wfruntime.flowInstanceId = flowInstance.Id; + + if (flowInstance.FrmType == 1) //如果是开发者自定义的表单 + { + var t = Type.GetType("OpenAuth.App." + flowInstance.DbName + "App"); + ICustomerForm icf = (ICustomerForm) _serviceProvider.GetService(t); + icf.Add(flowInstance.Id, flowInstance.FrmData); + } + + #endregion 根据运行实例改变当前节点状态 + + #region 流程操作记录 + + FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory + { + InstanceId = flowInstance.Id, + CreateUserId = user.User.Id, + CreateUserName = user.User.Name, + CreateDate = DateTime.Now, + Content = "【创建】" + + user.User.Name + + "创建了一个流程进程【" + + addFlowInstanceReq.Code + "/" + + addFlowInstanceReq.CustomName + "】" + }; + UnitWork.Add(processOperationHistoryEntity); + + #endregion 流程操作记录 + + AddTransHistory(wfruntime); + UnitWork.Save(); + return true; + } + + /// + /// 节点审核 + /// + /// + /// + public bool NodeVerification(string instanceId, Tag tag) + { + FlowInstance flowInstance = Get(instanceId); + FlowInstanceOperationHistory flowInstanceOperationHistory = new FlowInstanceOperationHistory + { + InstanceId = instanceId, + CreateUserId = tag.UserId, + CreateUserName = tag.UserName, + CreateDate = DateTime.Now + }; //操作记录 + FlowRuntime wfruntime = new FlowRuntime(flowInstance); + + #region 会签 + + if (flowInstance.ActivityType == 0) //当前节点是会签节点 + { + //会签时的【当前节点】一直是会签开始节点 + //TODO: 标记会签节点的状态,这个地方感觉怪怪的 + wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); + + string canCheckId = ""; //寻找当前登录用户可审核的节点Id + foreach (string fromForkStartNodeId in wfruntime.FromNodeLines[wfruntime.currentNodeId] + .Select(u => u.to)) + { + var fromForkStartNode = wfruntime.Nodes[fromForkStartNodeId]; //与会前开始节点直接连接的节点 + canCheckId = GetOneForkLineCanCheckNodeId(fromForkStartNode, wfruntime, tag); + if (!string.IsNullOrEmpty(canCheckId)) break; + } + + if (canCheckId == "") + { + throw (new Exception("审核异常,找不到审核节点")); + } + + flowInstanceOperationHistory.Content = "【" + wfruntime.Nodes[canCheckId].name + + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:" + + tag.Description; + + wfruntime.MakeTagNode(canCheckId, tag); //标记审核节点状态 + string res = wfruntime.NodeConfluence(canCheckId, tag); + if (res == TagState.No.ToString("D")) + { + flowInstance.IsFinish = FlowInstanceStatus.Disagree; + } + else if (!string.IsNullOrEmpty(res)) + { + flowInstance.PreviousId = flowInstance.ActivityId; + flowInstance.ActivityId = wfruntime.nextNodeId; + flowInstance.ActivityType = wfruntime.nextNodeType; + flowInstance.ActivityName = wfruntime.nextNode.name; + flowInstance.IsFinish = (wfruntime.nextNodeType == 4 + ? FlowInstanceStatus.Finished + : FlowInstanceStatus.Running); + flowInstance.MakerList = + (wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime)); + + AddTransHistory(wfruntime); + } + else + { + //会签过程中,需要更新用户 + flowInstance.MakerList = GetForkNodeMakers(wfruntime, wfruntime.currentNodeId); + AddTransHistory(wfruntime); + } + } + + #endregion 会签 + + #region 一般审核 + + else + { + wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); + if (tag.Taged == (int) TagState.Ok) + { + flowInstance.PreviousId = flowInstance.ActivityId; + flowInstance.ActivityId = wfruntime.nextNodeId; + flowInstance.ActivityType = wfruntime.nextNodeType; + flowInstance.ActivityName = wfruntime.nextNode.name; + flowInstance.MakerList = wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime); + flowInstance.IsFinish = (wfruntime.nextNodeType == 4 + ? FlowInstanceStatus.Finished + : FlowInstanceStatus.Running); + AddTransHistory(wfruntime); + } + else + { + flowInstance.IsFinish = FlowInstanceStatus.Disagree; //表示该节点不同意 + } + + flowInstanceOperationHistory.Content = "【" + wfruntime.currentNode.name + + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:" + + tag.Description; + } + + #endregion 一般审核 + + flowInstance.SchemeContent = JsonHelper.Instance.Serialize(wfruntime.ToSchemeObj()); + + UnitWork.Update(flowInstance); + UnitWork.Add(flowInstanceOperationHistory); + UnitWork.Save(); + + wfruntime.NotifyThirdParty(_httpClientFactory.CreateClient(), tag); + return true; + } + + //会签时,获取一条会签分支上面是否有用户可审核的节点 + private string GetOneForkLineCanCheckNodeId(FlowNode fromForkStartNode, FlowRuntime wfruntime, Tag tag) + { + string canCheckId = ""; + var node = fromForkStartNode; + do //沿一条分支线路执行,直到遇到会签结束节点 + { + var makerList = GetNodeMarkers(node); + + if (node.setInfo.Taged == null && !string.IsNullOrEmpty(makerList) && + makerList.Split(',').Any(one => tag.UserId == one)) + { + canCheckId = node.id; + break; + } + + node = wfruntime.GetNextNode(node.id); + } while (node.type != FlowNode.JOIN); + + return canCheckId; + } + + /// + /// 驳回 + /// 如果NodeRejectStep不为空,优先使用;否则按照NodeRejectType驳回 + /// + /// + public bool NodeReject(VerificationReq reqest) + { + var user = _auth.GetCurrentUser().User; + + FlowInstance flowInstance = Get(reqest.FlowInstanceId); + + FlowRuntime wfruntime = new FlowRuntime(flowInstance); + + string rejectNode = ""; //驳回的节点 + rejectNode = string.IsNullOrEmpty(reqest.NodeRejectStep) + ? wfruntime.RejectNode(reqest.NodeRejectType) + : reqest.NodeRejectStep; + + var tag = new Tag + { + Description = reqest.VerificationOpinion, + Taged = (int) TagState.Reject, + UserId = user.Id, + UserName = user.Name + }; + + wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); + flowInstance.IsFinish = FlowInstanceStatus.Rejected; //4表示驳回(需要申请者重新提交表单) + if (rejectNode != "") + { + flowInstance.PreviousId = flowInstance.ActivityId; + flowInstance.ActivityId = rejectNode; + flowInstance.ActivityType = wfruntime.GetNodeType(rejectNode); + flowInstance.ActivityName = wfruntime.Nodes[rejectNode].name; + flowInstance.MakerList = GetNodeMarkers(wfruntime.Nodes[rejectNode], flowInstance.CreateUserId); + + AddTransHistory(wfruntime); + } + + UnitWork.Update(flowInstance); + + UnitWork.Add(new FlowInstanceOperationHistory + { + InstanceId = reqest.FlowInstanceId, + CreateUserId = user.Id, + CreateUserName = user.Name, + CreateDate = DateTime.Now, + Content = "【" + + wfruntime.currentNode.name + + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】驳回,备注:" + + reqest.VerificationOpinion + }); + + UnitWork.Save(); + + wfruntime.NotifyThirdParty(_httpClientFactory.CreateClient(), tag); + + return true; + } + + #endregion 流程处理API + + #region 获取各种节点的流程审核者 + + /// + /// 寻找下一步的执行人 + /// 一般用于本节点审核完成后,修改流程实例的当前执行人,可以做到通知等功能 + /// + /// + private string GetNextMakers(FlowRuntime wfruntime) + { + string makerList = ""; + if (wfruntime.nextNodeId == "-1") + { + throw (new Exception("无法寻找到下一个节点")); + } + + if (wfruntime.nextNodeType == 0) //如果是会签节点 + { + makerList = GetForkNodeMakers(wfruntime, wfruntime.nextNodeId); + } + else + { + makerList = GetNodeMarkers(wfruntime.nextNode); + if (string.IsNullOrEmpty(makerList)) + { + throw (new Exception("无法寻找到节点的审核者,请查看流程设计是否有问题!")); + } + } + + return makerList; + } + + /// + /// 获取会签开始节点的所有可执行者 + /// + /// 会签开始节点 + /// + private string GetForkNodeMakers(FlowRuntime wfruntime, string forkNodeId) + { + string makerList = ""; + foreach (string fromForkStartNodeId in wfruntime.FromNodeLines[forkNodeId].Select(u => u.to)) + { + var fromForkStartNode = wfruntime.Nodes[fromForkStartNodeId]; //与会前开始节点直接连接的节点 + if (makerList != "") + { + makerList += ","; + } + + makerList += GetOneForkLineMakers(fromForkStartNode, wfruntime); + } + + return makerList; + } + + //获取会签一条线上的审核者,该审核者应该是已审核过的节点的下一个人 + private string GetOneForkLineMakers(FlowNode fromForkStartNode, FlowRuntime wfruntime) + { + string markers = ""; + var node = fromForkStartNode; + do //沿一条分支线路执行,直到遇到第一个没有审核的节点 + { + if (node.setInfo != null && node.setInfo.Taged != null) + { + if (node.type != FlowNode.FORK && node.setInfo.Taged != (int) TagState.Ok) //如果节点是不同意或驳回,则不用再找了 + { + break; + } + + node = wfruntime.GetNextNode(node.id); //下一个节点 + continue; + } + + var marker = GetNodeMarkers(node); + if (marker == "") + { + throw (new Exception($"节点{node.name}没有审核者,请检查!")); + } + + if (marker == "1") + { + throw (new Exception($"节点{node.name}是会签节点,不能用所有人,请检查!")); + } + + if (markers != "") + { + markers += ","; + } + + markers += marker; + break; + } while (node.type != FlowNode.JOIN); + + return markers; + } + + /// + /// 寻找该节点执行人 + /// + /// + /// + private string GetNodeMarkers(FlowNode node, string flowinstanceCreateUserId = "") + { + string makerList = ""; + if (node.type == FlowNode.START && (!string.IsNullOrEmpty(flowinstanceCreateUserId))) //如果是开始节点,通常情况下是驳回到开始了 + { + makerList = flowinstanceCreateUserId; + } + else if (node.setInfo != null) + { + if (node.setInfo.NodeDesignate == Setinfo.ALL_USER) //所有成员 + { + makerList = "1"; + } + else if (node.setInfo.NodeDesignate == Setinfo.SPECIAL_USER) //指定成员 + { + makerList = GenericHelpers.ArrayToString(node.setInfo.NodeDesignateData.users, makerList); + } + else if (node.setInfo.NodeDesignate == Setinfo.SPECIAL_ROLE) //指定角色 + { + var users = _revelanceApp.Get(Define.USERROLE, false, node.setInfo.NodeDesignateData.roles); + makerList = GenericHelpers.ArrayToString(users, makerList); + } + } + else //如果没有设置节点信息,默认所有人都可以审核 + { + makerList = "1"; + } + + return makerList; + } + + #endregion + + /// + /// 审核流程 + /// 李玉宝于2017-01-20 15:44:45 + /// + public void Verification(VerificationReq request) + { + var user = _auth.GetCurrentUser().User; + var tag = new Tag + { + UserName = user.Name, + UserId = user.Id, + Description = request.VerificationOpinion, + Taged = Int32.Parse(request.VerificationFinally) + }; + bool isReject = TagState.Reject.Equals((TagState) tag.Taged); + if (isReject) //驳回 + { + NodeReject(request); + } + else + { + NodeVerification(request.FlowInstanceId, tag); + } + } + + public void Update(FlowInstance flowScheme) + { + Repository.Update(flowScheme); + } + + public async Task Load(QueryFlowInstanceListReq request) + { + var result = new TableData(); + var user = _auth.GetCurrentUser(); + + if (request.type == "wait") //待办事项 + { + Expression> waitExp = u => (u.MakerList == "1" + || u.MakerList.Contains(user.User.Id)) && + (u.IsFinish == FlowInstanceStatus.Running || + u.IsFinish == FlowInstanceStatus.Rejected); + + // 加入搜索自定义标题 + if (!string.IsNullOrEmpty(request.key)) + { + waitExp = waitExp.And(t => t.CustomName.Contains(request.key)); + } + + result.count = UnitWork.Find(waitExp).Count(); + + result.data = UnitWork.Find(request.page, request.limit, "CreateDate descending", waitExp).ToList(); + } + else if (request.type == "disposed") //已办事项(即我参与过的流程) + { + var instances = UnitWork.Find(u => u.CreateUserId == user.User.Id) + .Select(u => u.InstanceId).Distinct(); + var query = from ti in instances + join ct in UnitWork.Find(null) on ti equals ct.Id + select ct; + + // 加入搜索自定义标题 + if (!string.IsNullOrEmpty(request.key)) + { + query = query.Where(t => t.CustomName.Contains(request.key)); + } + + result.data = query.OrderByDescending(u => u.CreateDate) + .Skip((request.page - 1) * request.limit) + .Take(request.limit).ToList(); + result.count = instances.Count(); + } + else //我的流程 + { + Expression> myFlowExp = u => u.CreateUserId == user.User.Id; + + // 加入搜索自定义标题 + if (!string.IsNullOrEmpty(request.key)) + { + myFlowExp = myFlowExp.And(t => t.CustomName.Contains(request.key)); + } + + result.count = UnitWork.Find(myFlowExp).Count(); + result.data = UnitWork.Find(request.page, request.limit, + "CreateDate descending", myFlowExp).ToList(); + } + + return result; + } + + /// + /// 添加扭转记录 + /// + private void AddTransHistory(FlowRuntime wfruntime) + { + var tag = _auth.GetCurrentUser().User; + UnitWork.Add(new FlowInstanceTransitionHistory + { + InstanceId = wfruntime.flowInstanceId, + CreateUserId = tag.Id, + CreateUserName = tag.Name, + FromNodeId = wfruntime.currentNodeId, + FromNodeName = wfruntime.currentNode.name, + FromNodeType = wfruntime.currentNodeType, + ToNodeId = wfruntime.nextNodeId, + ToNodeName = wfruntime.nextNode.name, + ToNodeType = wfruntime.nextNodeType, + IsFinish = wfruntime.nextNodeType == 4 ? FlowInstanceStatus.Finished : FlowInstanceStatus.Running, + TransitionSate = 0 + }); + } + + public List QueryHistories(QueryFlowInstanceHistoryReq request) + { + return UnitWork.Find(u => u.InstanceId == request.FlowInstanceId) + .OrderByDescending(u => u.CreateDate).ToList(); + } + + /// + /// 召回流程 + /// + public void ReCall(RecallFlowInstanceReq request) + { + var user = _auth.GetCurrentUser().User; + FlowInstance flowInstance = Get(request.FlowInstanceId); + + FlowRuntime wfruntime = new FlowRuntime(flowInstance); + + string startNodeId = wfruntime.startNodeId; //起始节点 + + wfruntime.ReCall(); + + flowInstance.IsFinish = FlowInstanceStatus.Draft; + flowInstance.PreviousId = flowInstance.ActivityId; + flowInstance.ActivityId = startNodeId; + flowInstance.ActivityType = wfruntime.GetNodeType(startNodeId); + flowInstance.ActivityName = wfruntime.Nodes[startNodeId].name; + flowInstance.MakerList = GetNodeMarkers(wfruntime.Nodes[startNodeId], flowInstance.CreateUserId); + + AddTransHistory(wfruntime); + + UnitWork.Update(flowInstance); + + UnitWork.Add(new FlowInstanceOperationHistory + { + InstanceId = request.FlowInstanceId, + CreateUserId = user.Id, + CreateUserName = user.Name, + CreateDate = DateTime.Now, + Content = $"【撤销】由{user.Name}撤销,备注:{request.Description}" + }); + + UnitWork.Save(); + } + + /// 启动流程 + /// 通常是对状态为【草稿】的流程进行操作,进入运行状态 + public void Start(StartFlowInstanceReq request) + { + FlowInstance flowInstance = Get(request.FlowInstanceId); + var wfruntime = new FlowRuntime(flowInstance); + var user = _auth.GetCurrentUser(); + + #region 根据运行实例改变当前节点状态 + flowInstance.ActivityId = wfruntime.nextNodeId; + flowInstance.ActivityType = wfruntime.GetNextNodeType(); + flowInstance.ActivityName = wfruntime.nextNode.name; + flowInstance.PreviousId = wfruntime.currentNodeId; + flowInstance.CreateUserId = user.User.Id; + flowInstance.CreateUserName = user.User.Account; + flowInstance.MakerList = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : ""); + flowInstance.IsFinish = (wfruntime.GetNextNodeType() == 4 + ? FlowInstanceStatus.Finished + : FlowInstanceStatus.Running); + + UnitWork.Update(flowInstance); + #endregion 根据运行实例改变当前节点状态 + + #region 流程操作记录 + + FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory + { + InstanceId = flowInstance.Id, + CreateUserId = user.User.Id, + CreateUserName = user.User.Name, + CreateDate = DateTime.Now, + Content = $"【启动】由用户{user.User.Name}启动" + }; + UnitWork.Add(processOperationHistoryEntity); + + #endregion 流程操作记录 + + AddTransHistory(wfruntime); + UnitWork.Save(); + } + } } \ No newline at end of file diff --git a/OpenAuth.App/Request/AddFlowInstanceReq.cs b/OpenAuth.App/FlowInstance/Request/AddFlowInstanceReq.cs similarity index 100% rename from OpenAuth.App/Request/AddFlowInstanceReq.cs rename to OpenAuth.App/FlowInstance/Request/AddFlowInstanceReq.cs diff --git a/OpenAuth.App/Request/QueryFlowInstanceHistoryReq.cs b/OpenAuth.App/FlowInstance/Request/QueryFlowInstanceHistoryReq.cs similarity index 100% rename from OpenAuth.App/Request/QueryFlowInstanceHistoryReq.cs rename to OpenAuth.App/FlowInstance/Request/QueryFlowInstanceHistoryReq.cs diff --git a/OpenAuth.App/Request/QueryFlowInstanceListReq.cs b/OpenAuth.App/FlowInstance/Request/QueryFlowInstanceListReq.cs similarity index 95% rename from OpenAuth.App/Request/QueryFlowInstanceListReq.cs rename to OpenAuth.App/FlowInstance/Request/QueryFlowInstanceListReq.cs index 06a57187..0c8546fd 100644 --- a/OpenAuth.App/Request/QueryFlowInstanceListReq.cs +++ b/OpenAuth.App/FlowInstance/Request/QueryFlowInstanceListReq.cs @@ -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; } + } +} diff --git a/OpenAuth.App/FlowInstance/Request/RecallFlowInstanceReq.cs b/OpenAuth.App/FlowInstance/Request/RecallFlowInstanceReq.cs new file mode 100644 index 00000000..68e8d8a0 --- /dev/null +++ b/OpenAuth.App/FlowInstance/Request/RecallFlowInstanceReq.cs @@ -0,0 +1,18 @@ +namespace OpenAuth.App.Request +{ + /// + /// 召回、撤销流程 + /// + public class RecallFlowInstanceReq + { + /// + /// 召回、撤销的流程实例ID + /// + public string FlowInstanceId { get; set; } + /// + /// 撤回备注 + /// + public string Description { get; set; } + + } +} diff --git a/OpenAuth.App/FlowInstance/Request/StartFlowInstanceReq.cs b/OpenAuth.App/FlowInstance/Request/StartFlowInstanceReq.cs new file mode 100644 index 00000000..ec6a8743 --- /dev/null +++ b/OpenAuth.App/FlowInstance/Request/StartFlowInstanceReq.cs @@ -0,0 +1,14 @@ +namespace OpenAuth.App.Request +{ + /// + /// 启动流程 + /// + public class StartFlowInstanceReq + { + /// + /// 启动流程的实例Id + /// + public string FlowInstanceId { get; set; } + + } +} diff --git a/OpenAuth.App/Request/VerificationReq.cs b/OpenAuth.App/FlowInstance/Request/VerificationReq.cs similarity index 96% rename from OpenAuth.App/Request/VerificationReq.cs rename to OpenAuth.App/FlowInstance/Request/VerificationReq.cs index 5ef05f43..ae35949e 100644 --- a/OpenAuth.App/Request/VerificationReq.cs +++ b/OpenAuth.App/FlowInstance/Request/VerificationReq.cs @@ -1,26 +1,26 @@ -namespace OpenAuth.App.Request -{ - public class VerificationReq - { - public string FlowInstanceId { get; set; } - /// - /// 1:同意;2:不同意;3:驳回 - /// - public string VerificationFinally { get; set; } - - /// - /// 审核意见 - /// - public string VerificationOpinion { get; set; } - - /// - /// 驳回的步骤,即驳回到的节点ID - /// - public string NodeRejectStep { get; set; } - - /// - /// 驳回类型。null:使用节点配置的驳回类型/0:前一步/1:第一步/2:指定节点,使用NodeRejectStep - /// - public string NodeRejectType { get; set; } - } -} +namespace OpenAuth.App.Request +{ + public class VerificationReq + { + public string FlowInstanceId { get; set; } + /// + /// 1:同意;2:不同意;3:驳回 + /// + public string VerificationFinally { get; set; } + + /// + /// 审核意见 + /// + public string VerificationOpinion { get; set; } + + /// + /// 驳回的步骤,即驳回到的节点ID + /// + public string NodeRejectStep { get; set; } + + /// + /// 驳回类型。null:使用节点配置的驳回类型/0:前一步/1:第一步/2:指定节点,使用NodeRejectStep + /// + public string NodeRejectType { get; set; } + } +} diff --git a/OpenAuth.App/Response/FlowVerificationResp.cs b/OpenAuth.App/FlowInstance/Response/FlowVerificationResp.cs similarity index 95% rename from OpenAuth.App/Response/FlowVerificationResp.cs rename to OpenAuth.App/FlowInstance/Response/FlowVerificationResp.cs index c543368b..400a13ca 100644 --- a/OpenAuth.App/Response/FlowVerificationResp.cs +++ b/OpenAuth.App/FlowInstance/Response/FlowVerificationResp.cs @@ -1,16 +1,16 @@ -using OpenAuth.Repository.Domain; - -namespace OpenAuth.App.Response -{ - public class FlowVerificationResp :FlowInstance - { - /// - /// 预览表单数据 - /// - /// The FRM data HTML. - public string FrmPreviewHtml - { - get { return FormUtil.Preview(this); } - } - } -} +using OpenAuth.Repository.Domain; + +namespace OpenAuth.App.Response +{ + public class FlowVerificationResp :FlowInstance + { + /// + /// 预览表单数据 + /// + /// The FRM data HTML. + public string FrmPreviewHtml + { + get { return FormUtil.Preview(this); } + } + } +} diff --git a/OpenAuth.App/FlowSchemeApp.cs b/OpenAuth.App/FlowScheme/FlowSchemeApp.cs similarity index 97% rename from OpenAuth.App/FlowSchemeApp.cs rename to OpenAuth.App/FlowScheme/FlowSchemeApp.cs index a320e19f..b2c873d6 100644 --- a/OpenAuth.App/FlowSchemeApp.cs +++ b/OpenAuth.App/FlowScheme/FlowSchemeApp.cs @@ -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 - { - 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(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 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 unitWork, IRepository 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 + { + 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(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 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 unitWork, IRepository repository,IAuth auth) : base(unitWork, repository, auth) + { + } + } +} diff --git a/OpenAuth.App/Request/QueryFlowSchemeListReq.cs b/OpenAuth.App/FlowScheme/Request/QueryFlowSchemeListReq.cs similarity index 95% rename from OpenAuth.App/Request/QueryFlowSchemeListReq.cs rename to OpenAuth.App/FlowScheme/Request/QueryFlowSchemeListReq.cs index 6b36d215..16ac8800 100644 --- a/OpenAuth.App/Request/QueryFlowSchemeListReq.cs +++ b/OpenAuth.App/FlowScheme/Request/QueryFlowSchemeListReq.cs @@ -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; } + } +} diff --git a/OpenAuth.App/FormApp.cs b/OpenAuth.App/Form/FormApp.cs similarity index 96% rename from OpenAuth.App/FormApp.cs rename to OpenAuth.App/Form/FormApp.cs index e87ef975..76da85da 100644 --- a/OpenAuth.App/FormApp.cs +++ b/OpenAuth.App/Form/FormApp.cs @@ -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 - { - private IAuth _auth; - private IOptions _appConfiguration; - /// - /// 加载列表 - /// - public async Task 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(); - } - - public FormApp(IUnitWork unitWork, IRepository repository, - IAuth auth, IOptions 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 + { + private IAuth _auth; + private IOptions _appConfiguration; + /// + /// 加载列表 + /// + public async Task 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(); + } + + public FormApp(IUnitWork unitWork, IRepository repository, + IAuth auth, IOptions appConfiguration) : base(unitWork, repository, auth) + { + _auth = auth; + _appConfiguration = appConfiguration; + } + } } \ No newline at end of file diff --git a/OpenAuth.App/FormUtil.cs b/OpenAuth.App/Form/FormUtil.cs similarity index 97% rename from OpenAuth.App/FormUtil.cs rename to OpenAuth.App/Form/FormUtil.cs index 66ae5cc4..dd76b0d8 100644 --- a/OpenAuth.App/FormUtil.cs +++ b/OpenAuth.App/Form/FormUtil.cs @@ -1,626 +1,626 @@ -using System.Text; -using Infrastructure; -using Newtonsoft.Json.Linq; -using OpenAuth.App.Response; -using OpenAuth.Repository.Domain; - -namespace OpenAuth.App -{ - public class FormUtil { - - public static string GetHtml(string contentData, string contentParse,string frmData, string action) - { - if (string.IsNullOrEmpty(contentData)) - { - return string.Empty; - } - JObject tableData = null;//表单数据 - if (!string.IsNullOrEmpty(frmData)) - { - tableData = JsonHelper.Instance.Deserialize(frmData); - } - - string html = contentParse; - foreach (var json in contentData.ToList()) - { - string name = ""; - string leipiplugins = json.GetValue("leipiplugins").ToString(); - if ("checkboxs" == leipiplugins) - name = json.GetValue("parse_name").ToString(); - else - name = json.GetValue("name").ToString(); - - string tempHtml = ""; - switch (leipiplugins) - { - case "text": - tempHtml = GetTextBox(json, tableData, action); - break; - case "textarea": - tempHtml = GetTextArea(json, tableData, action); - break; - case "radios": - tempHtml = GetRadios(json, tableData, action); - break; - case "select": - tempHtml = GetSelect(json, tableData, action); - break; - case "checkboxs": - tempHtml = GetCheckboxs(json, tableData, action); - break; - - case "qrcode"://二维码 - tempHtml = GetQrcode(json, tableData, action); - break; - - case "progressbar"://进度条 (未做处理) - /*temp_html = GetProgressbar(json, tableData, action);*/ - break; - default: - tempHtml = json.GetValue("content").ToString(); - break; - } - - html = html.Replace("{" + name + "}", tempHtml); - } - - - return html; - } - - /// - /// 只显示编辑框 - /// - /// The form. - /// System.String. - public static string GetHtml(FormResp form){ - if (form.FrmType != 0) //只有开原版动态表单才需要转换 - { - return string.Empty; - } - - return GetHtml(form.ContentData, form.ContentParse,null, ""); - - } - - /// - /// 显示编辑框和里面的用户数据 - /// - /// The contentdata. - /// The content parse. - /// The FRM data. - /// System.String. - public static string Preview(FlowInstance flowInstance) - { - if (flowInstance.FrmType != 0) //只有开原版动态表单才需要转换 - { - return string.Empty; - } - - return GetHtml(flowInstance.FrmContentData, flowInstance.FrmContentParse, - flowInstance.FrmData, "view"); - } - - //text - private static string GetTextBox(JObject item, JObject formData,string action) - { - string temp = ""; - string name = item.GetValue("name").ToString(); - - string value =null; - JToken data; - if (formData != null && (data = formData.GetValue(name)) != null) - { - value = data.ToString(); - } - - if (value == null) - value = item.GetValue("value") == null ? "" : item.GetValue("value").ToString(); - string style =item.GetValue("style") == null ? "" : item.GetValue("style").ToString(); - string tempHtml = string.Format(temp, value, name, style); - if("view"==action) - return string.Format("",style,value); - return tempHtml; - } - - //TextArea - private static string GetTextArea(JObject item, JObject formData,string action) - { - string script = ""; - if (item.GetValue("orgrich") != null && "1"==item.GetValue("orgrich").ToString()) - script = "orgrich=\"true\" "; - string name = item.GetValue("name").ToString(); - - string value = null; - JToken data; - if (formData != null && (data = formData.GetValue(name)) != null) - { - value = data.ToString(); - } - - if (value == null) - value = item.GetValue("value")== null ? "" : item.GetValue("value").ToString(); - string style = item.GetValue("style") == null ? "" : item.GetValue("style").ToString(); - - - string temp = ""; - - string temp_html = string.Format(temp, name, name, style, script, value); - - if("view"==action) - return string.Format("", style, value); - return temp_html; - } - - //Radios - private static string GetRadios(JObject item, JObject formData,string action) - { - var radiosOptions = JArray.Parse(item.GetValue("options").ToString()); - //JArray radiosOptions = item["options"] as JArray; - string temp = "{3} "; - string temp_html = ""; - string name = item.GetValue("name").ToString(); - - string value = null; - JToken data; - if (formData != null && (data = formData.GetValue(name)) != null) - { - value = data.ToString(); - } - - foreach (var json in radiosOptions) - { - string cvalue = json["value"].ToString(); - string Ischecked = ""; - - if (value == null) - { - string check = json["checked"] != null ? json["checked"].ToString() : ""; - if ("checked" == check || "true" == check) - { - Ischecked = " checked=\"checked\" "; - value = json["value"].ToString(); - } - } - - temp_html += string.Format(temp, name, cvalue, Ischecked, cvalue); - } - - return "view"==action ? string.Format("", "", value) : temp_html; - } - - //Checkboxs - private static string GetCheckboxs(JObject item, JObject formData,string action){ - string temp_html = ""; - string temp = "{3} "; - - string view_value="";//view 查看值 - - var checkOptions = JArray.Parse(item.GetValue("options").ToString()); - foreach (var json in checkOptions) - { - string name = json["name"].ToString(); - - string value = null; - JToken data; - if (formData != null && (data = formData.GetValue(name)) != null) - { - value = data.ToString(); - } - - string cvalue = json["value"].ToString(); - string Ischecked = ""; - if (value == null) - { - string check = json["checked"] != null ? json["checked"].ToString() : ""; - if (check == "checked" || check == "true") - { - Ischecked = " checked=\"checked\" "; - view_value += cvalue + " ";//view 查看值 - } - } - else if (value != null && value == cvalue) - { - Ischecked = " checked=\"checked\" "; - view_value += cvalue + " ";//view 查看值 - } - - temp_html += string.Format(temp, name, cvalue, Ischecked, cvalue); - - } - - return "view" == action ? string.Format("", "", view_value) : temp_html; - } - - //Select(比较特殊) - private static string GetSelect(JObject item, JObject formData, string action) - { - string name = item.GetValue("name").ToString(); //控件的名称 - string value = null; - JToken data; - - if (formData != null && (data = formData.GetValue(name)) != null) - { - value = data.ToString(); - } - - string content =item.GetValue("content").ToString(); - content = content.Replace("leipiNewField", name); - if (value != null)//用户设置过值 - { - content = content.Replace("selected=\"selected\"", ""); //先去掉模板中的选中项 - var option = "value=\"" + value + "\""; //组成选项 - string selected = option + " selected=\"selected\""; //组成选中项 - content = content.Replace(option, selected); //把选项替换成选中项 - } - - return "view" == action ? string.Format("", "", value) : content; - } - - - //Qrcode 二维码 - private static string GetQrcode(JObject item, JObject formData, string action) - { - string name = item.GetValue("name").ToString(); - - string value = null; - JToken data; - if (formData != null && (data = formData.GetValue(name)) != null) - { - value = data.ToString(); - } - - string temp_html = ""; - string temp = ""; - string orgType = item.GetValue("orgtype").ToString(); - string style = item.GetValue("style").ToString(); - if ("text"==orgType) - { - orgType = "文本"; - } - else if ("url"==orgType) - { - orgType = "超链接"; - } - else if ("tel"==orgType) - { - orgType = "电话"; - } - string qrcode_value = ""; - if (item.GetValue("value")!= null) - qrcode_value = item.GetValue("value").ToString(); - //print_R($qrcode_value);exit; //array(value,qrcode_url) - if ( "edit"==action) - { - temp = orgType + "二维码 "; - temp_html = string.Format(temp, name, value); - } - else if ("view"==action) - { - //可以采用 http://qrcode.leipi.org/ - - style = ""; - if (item.GetValue("orgwidth") != null) - { - style = "width:" + item.GetValue("orgwidth") + "px;"; - } - if (item.GetValue("orgheight") != null) - { - style += "height:" + item.GetValue("orgheight") + "px;"; - } - temp = ""; - temp_html = string.Format(temp_html, name, value, style); - - - } - else if ( "preview"==action) - { - style = ""; - if (item.GetValue("orgwidth")!= null) - { - style = "width:" + item.GetValue("orgwidth") + "px;"; - } - if (item.GetValue("orgheight")!= null) - { - style += "height:" + item.GetValue("orgheight") + "px;"; - } - temp = ""; - temp_html = string.Format(temp_html, name, value, style); - } - - return temp_html; - } - - ////Listctrl - //private static string GetListctrl(JObject item, Dictionary formData, string action) - // { - // string valuetest = "{\"data_110\":[\"1\",\"2\"],\"data_111\":[\"21\",\"22\",\"22\"]}"; - - // string name = item.GetValue("name").ToString(); - // string value = formData.ContainsKey(name)?formData[name].ToString():null; - // string temp_html = ""; - // string orgSum =item.GetValue("orgsum").ToString(); - // string orgUnit =item.GetValue("orgunit").ToString(); - // string orgTitle =item.GetValue("orgtitle").ToString(); - // string title =item.GetValue("title").ToString(); - // string style =item.GetValue("style").ToString(); - // string orgcolvalue =item.GetValue("orgcolvalue").ToString(); - // string orgcoltype =item.GetValue("orgcoltype").ToString(); - // List listTitle = Arrays.asList(orgTitle.split("`")); - // List listSum = Arrays.asList(orgSum.split("`")); - // List listUnit = Arrays.asList(orgUnit.split("`")); - // List listValue =Arrays.asList(orgcolvalue.split("`")); - // List listType =Arrays.asList(orgcoltype.split("`")); - // int tdCount = listTitle.size(); - - - // string temp = "{0}{1}{2}
"; - // string btnAdd = ""; //添加按钮 - // string theader = "{1}{2}{3}";//头部模版 - - // string trTitle = "";//标题 - // for (int i = 0; i < tdCount; i++) - // { - // if (i == tdCount - 1) - // listTitle.set(i, "操作"); - // if ("view"==(action) && i == tdCount - 1) continue;//如果是查看最后一列不显示 - // trTitle += string.Format("{0}", listTitle.get(i)); - // } - // trTitle = "" + trTitle + ""; - - - // JObject dataValue=JObject.fromObject(valuetest); - - // int rowCount = dataValue != null ? dataValue.size() : 1; - - - // stringBuilder sbTr = new stringBuilder(); - // string tdSum = "";//如果有统计增加一行 - - - // TreeMap SumValueDic = new TreeMap(); - // for (int row = 0; row < rowCount; row++) - // { - - // JSONArray rowValue = (dataValue != null && dataValue.has(name + row)) ? dataValue.getJSONArray(name + row): null; - - // string tr = "";//默认一行 - // for (int i = 0; i < tdCount; i++) - // { - // string tdname = name + "[" + i + "]"; - // string sum = "1"==(listSum.get(i)) ? "sum=\"" + tdname + "\"" : "";//是否参与统计 - // string tdValue =( rowValue != null && rowValue.size() > i) ? rowValue.GetValue(i).ToString(): listValue.get(i); - // string type = listType.get(i);//类型 - - // if (sum != "")//一次循环计算该列的值 - // { - // //region 计算统计值 - // float tempTdValue = 0; - // if (SumValueDic.containsKey(i)) - // tempTdValue = SumValueDic.get(i); - // try - // { - // float resultTdTemp = 0; - // resultTdTemp=Float.parseFloat(tdValue); - // //float.TryParse(tdValue, out resultTdTemp); - // tempTdValue += resultTdTemp; - // } - // catch (Exception e) - // { - // tdValue = "0"; - // } - // if (SumValueDic.containsKey(i)) - // SumValueDic.subMap(i, (int) tempTdValue); - // else - // SumValueDic.put(i, tempTdValue); - // //endregion - - // } - - // if (i == tdCount - 1)//最后一列不显示 - // { - // if ("view"==(action)) continue; - // //tr += ""; - // else - // tr += "删除"; - // //tr += string.Format("删除", dataValue != null ? "" : "hide"); - // } - // else - // { - // if ("view"==(action)) - // { - // tr += string.Format("{0}", tdValue); - // } - // else - // { - // if ("text"==(type)) - // tr += string.Format("", tdValue, tdname, sum); - // else if ("int"==(type)) - // tr += string.Format("", tdValue, tdname, sum); - // else if ("textarea"==(type)) - // tr += string.Format("", tdname, tdValue, sum); - // else if ("calc"==(type)) - // tr += string.Format("", tdValue, tdname, sum); - // } - // } - - // if (row == 0)//统计的行只有一行 - // { - // //region - // if (sum != "") - // { - // if ("view"==(action)) - // tdSum += string.Format("合计:value{0}{1}", i, listUnit.get(i)); - // else - // tdSum += string.Format("合计:{3}", i, tdname, sum, listUnit.get(i)); - // } - // else - // { - // tdSum += ""; - // } - // //endregion - - // } - - // } - // sbTr.append(string.Format("{0}", tr) ); - - // } - // /*if(!stringUtils.isBlank(tdSum)){ - - // }*/ - - // if (!stringUtils.isBlank(tdSum)){ - // for (Integer i : SumValueDic.keySet()) { - // tdSum = tdSum.Replace("value" + i, SumValueDic.get(i).ToString()); - // tdSum = string.Format("{0}", tdSum); - // } - // } - // if ("view"==(action)) - // theader = string.Format(theader, tdCount, title, "", trTitle); - // else - // theader = string.Format(theader, tdCount, title, btnAdd, trTitle); - - // temp_html = string.Format(temp, theader, sbTr.ToString(), tdSum); - - // return temp_html; - // } - - - - - - /** - * 功能: 创建表单数据表格(基于sql server) - */ - public static string GetSql(Form form, string dbType){ - - if (dbType == Define.DBTYPE_SQLSERVER) //Sql Server - { - // 获取字段并处理 - var jsonArray = JArray.Parse(form.ContentData); - - // 数据库名称 - string tableName= form.DbName ; - // 创建数据表 - StringBuilder sql =new StringBuilder("if exists ( select * from sysobjects where name = '" - +tableName+"' and type = 'U') drop table " - + tableName +";") ; - - sql.Append("CREATE TABLE " - + tableName - + " ( [Id] varchar(50) COLLATE Chinese_PRC_CI_AS NOT NULL,"); //主键 - - string sqlDefault = ""; - - foreach (var json in jsonArray) - { - string name; - string type = json["leipiplugins"].ToString(); - - if ("checkboxs" == type) - name = json["parse_name"].ToString(); - else - name = json["name"].ToString(); - - sql.Append("[" + name + "] " + field_type_sql(type));//字段拼接 - - - if ("checkboxs" == type) - sqlDefault += field_type_sql_default(tableName, name, "0"); - else - sqlDefault += field_type_sql_default(tableName, name, "''"); - } - - sql.Append(");"); - - //设置主键 - sql.Append("ALTER TABLE "+tableName+" ADD CONSTRAINT [PK_"+form.DbName+"] PRIMARY KEY NONCLUSTERED ([Id])"); - sql.Append( - "WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) "); - sql.Append("ON [PRIMARY];"); - - //主键默认值 - sql.Append("ALTER TABLE "+tableName+" ADD DEFAULT (newid()) FOR [Id];"); - - return sql+sqlDefault; - } - else - { - // 获取字段并处理 - var jsonArray = JArray.Parse(form.ContentData); - - // 数据库名称 - string tableName= form.DbName ; - // 创建数据表 - StringBuilder sql =new StringBuilder("create table if not exists `" - + tableName - + "` ( Id varchar(50) not null primary key,") ; //主键 - - - string sqlDefault = ""; - - foreach (var json in jsonArray) - { - string name; - string type = json["leipiplugins"].ToString(); - - if ("checkboxs" == type) - name = json["parse_name"].ToString(); - else - name = json["name"].ToString(); - - sql.Append("`" + name + "` " + field_type_mysql(type));//字段拼接 - -// -// if ("checkboxs" == type) -// sqlDefault += field_type_sql_default(tableName, name, "0"); -// else -// sqlDefault += field_type_sql_default(tableName, name, "''"); - } - - sql.Append(");"); - - return sql.ToString(); - } - - } - //获取控件字段类型 的sql - private static string field_type_sql(string leipiplugins) - { - if ("textarea"==leipiplugins || "listctrl"==leipiplugins) - { - return " text NULL ,"; - } - else if ("checkboxs"==leipiplugins) - { - return " int NOT NULL ,"; - } - else - { - return " varchar(255) NULL ,"; - } - } - - private static string field_type_mysql(string leipiplugins) - { - if ("textarea"==leipiplugins || "listctrl"==leipiplugins) - { - return " varchar(255) null ,"; - } - else if ("checkboxs"==leipiplugins) - { - return " tinyint not null ,"; - } - else - { - return " varchar(255) NULL ,"; - } - } - - private static string field_type_sql_default(string tablename, string field, string defaultValue) - { - return "ALTER TABLE "+tablename+" ADD DEFAULT ("+defaultValue+") FOR ["+field+"];"; - } - } -} +using System.Text; +using Infrastructure; +using Newtonsoft.Json.Linq; +using OpenAuth.App.Response; +using OpenAuth.Repository.Domain; + +namespace OpenAuth.App +{ + public class FormUtil { + + public static string GetHtml(string contentData, string contentParse,string frmData, string action) + { + if (string.IsNullOrEmpty(contentData)) + { + return string.Empty; + } + JObject tableData = null;//表单数据 + if (!string.IsNullOrEmpty(frmData)) + { + tableData = JsonHelper.Instance.Deserialize(frmData); + } + + string html = contentParse; + foreach (var json in contentData.ToList()) + { + string name = ""; + string leipiplugins = json.GetValue("leipiplugins").ToString(); + if ("checkboxs" == leipiplugins) + name = json.GetValue("parse_name").ToString(); + else + name = json.GetValue("name").ToString(); + + string tempHtml = ""; + switch (leipiplugins) + { + case "text": + tempHtml = GetTextBox(json, tableData, action); + break; + case "textarea": + tempHtml = GetTextArea(json, tableData, action); + break; + case "radios": + tempHtml = GetRadios(json, tableData, action); + break; + case "select": + tempHtml = GetSelect(json, tableData, action); + break; + case "checkboxs": + tempHtml = GetCheckboxs(json, tableData, action); + break; + + case "qrcode"://二维码 + tempHtml = GetQrcode(json, tableData, action); + break; + + case "progressbar"://进度条 (未做处理) + /*temp_html = GetProgressbar(json, tableData, action);*/ + break; + default: + tempHtml = json.GetValue("content").ToString(); + break; + } + + html = html.Replace("{" + name + "}", tempHtml); + } + + + return html; + } + + /// + /// 只显示编辑框 + /// + /// The form. + /// System.String. + public static string GetHtml(FormResp form){ + if (form.FrmType != 0) //只有开原版动态表单才需要转换 + { + return string.Empty; + } + + return GetHtml(form.ContentData, form.ContentParse,null, ""); + + } + + /// + /// 显示编辑框和里面的用户数据 + /// + /// The contentdata. + /// The content parse. + /// The FRM data. + /// System.String. + public static string Preview(FlowInstance flowInstance) + { + if (flowInstance.FrmType != 0) //只有开原版动态表单才需要转换 + { + return string.Empty; + } + + return GetHtml(flowInstance.FrmContentData, flowInstance.FrmContentParse, + flowInstance.FrmData, "view"); + } + + //text + private static string GetTextBox(JObject item, JObject formData,string action) + { + string temp = ""; + string name = item.GetValue("name").ToString(); + + string value =null; + JToken data; + if (formData != null && (data = formData.GetValue(name)) != null) + { + value = data.ToString(); + } + + if (value == null) + value = item.GetValue("value") == null ? "" : item.GetValue("value").ToString(); + string style =item.GetValue("style") == null ? "" : item.GetValue("style").ToString(); + string tempHtml = string.Format(temp, value, name, style); + if("view"==action) + return string.Format("",style,value); + return tempHtml; + } + + //TextArea + private static string GetTextArea(JObject item, JObject formData,string action) + { + string script = ""; + if (item.GetValue("orgrich") != null && "1"==item.GetValue("orgrich").ToString()) + script = "orgrich=\"true\" "; + string name = item.GetValue("name").ToString(); + + string value = null; + JToken data; + if (formData != null && (data = formData.GetValue(name)) != null) + { + value = data.ToString(); + } + + if (value == null) + value = item.GetValue("value")== null ? "" : item.GetValue("value").ToString(); + string style = item.GetValue("style") == null ? "" : item.GetValue("style").ToString(); + + + string temp = ""; + + string temp_html = string.Format(temp, name, name, style, script, value); + + if("view"==action) + return string.Format("", style, value); + return temp_html; + } + + //Radios + private static string GetRadios(JObject item, JObject formData,string action) + { + var radiosOptions = JArray.Parse(item.GetValue("options").ToString()); + //JArray radiosOptions = item["options"] as JArray; + string temp = "{3} "; + string temp_html = ""; + string name = item.GetValue("name").ToString(); + + string value = null; + JToken data; + if (formData != null && (data = formData.GetValue(name)) != null) + { + value = data.ToString(); + } + + foreach (var json in radiosOptions) + { + string cvalue = json["value"].ToString(); + string Ischecked = ""; + + if (value == null) + { + string check = json["checked"] != null ? json["checked"].ToString() : ""; + if ("checked" == check || "true" == check) + { + Ischecked = " checked=\"checked\" "; + value = json["value"].ToString(); + } + } + + temp_html += string.Format(temp, name, cvalue, Ischecked, cvalue); + } + + return "view"==action ? string.Format("", "", value) : temp_html; + } + + //Checkboxs + private static string GetCheckboxs(JObject item, JObject formData,string action){ + string temp_html = ""; + string temp = "{3} "; + + string view_value="";//view 查看值 + + var checkOptions = JArray.Parse(item.GetValue("options").ToString()); + foreach (var json in checkOptions) + { + string name = json["name"].ToString(); + + string value = null; + JToken data; + if (formData != null && (data = formData.GetValue(name)) != null) + { + value = data.ToString(); + } + + string cvalue = json["value"].ToString(); + string Ischecked = ""; + if (value == null) + { + string check = json["checked"] != null ? json["checked"].ToString() : ""; + if (check == "checked" || check == "true") + { + Ischecked = " checked=\"checked\" "; + view_value += cvalue + " ";//view 查看值 + } + } + else if (value != null && value == cvalue) + { + Ischecked = " checked=\"checked\" "; + view_value += cvalue + " ";//view 查看值 + } + + temp_html += string.Format(temp, name, cvalue, Ischecked, cvalue); + + } + + return "view" == action ? string.Format("", "", view_value) : temp_html; + } + + //Select(比较特殊) + private static string GetSelect(JObject item, JObject formData, string action) + { + string name = item.GetValue("name").ToString(); //控件的名称 + string value = null; + JToken data; + + if (formData != null && (data = formData.GetValue(name)) != null) + { + value = data.ToString(); + } + + string content =item.GetValue("content").ToString(); + content = content.Replace("leipiNewField", name); + if (value != null)//用户设置过值 + { + content = content.Replace("selected=\"selected\"", ""); //先去掉模板中的选中项 + var option = "value=\"" + value + "\""; //组成选项 + string selected = option + " selected=\"selected\""; //组成选中项 + content = content.Replace(option, selected); //把选项替换成选中项 + } + + return "view" == action ? string.Format("", "", value) : content; + } + + + //Qrcode 二维码 + private static string GetQrcode(JObject item, JObject formData, string action) + { + string name = item.GetValue("name").ToString(); + + string value = null; + JToken data; + if (formData != null && (data = formData.GetValue(name)) != null) + { + value = data.ToString(); + } + + string temp_html = ""; + string temp = ""; + string orgType = item.GetValue("orgtype").ToString(); + string style = item.GetValue("style").ToString(); + if ("text"==orgType) + { + orgType = "文本"; + } + else if ("url"==orgType) + { + orgType = "超链接"; + } + else if ("tel"==orgType) + { + orgType = "电话"; + } + string qrcode_value = ""; + if (item.GetValue("value")!= null) + qrcode_value = item.GetValue("value").ToString(); + //print_R($qrcode_value);exit; //array(value,qrcode_url) + if ( "edit"==action) + { + temp = orgType + "二维码 "; + temp_html = string.Format(temp, name, value); + } + else if ("view"==action) + { + //可以采用 http://qrcode.leipi.org/ + + style = ""; + if (item.GetValue("orgwidth") != null) + { + style = "width:" + item.GetValue("orgwidth") + "px;"; + } + if (item.GetValue("orgheight") != null) + { + style += "height:" + item.GetValue("orgheight") + "px;"; + } + temp = ""; + temp_html = string.Format(temp_html, name, value, style); + + + } + else if ( "preview"==action) + { + style = ""; + if (item.GetValue("orgwidth")!= null) + { + style = "width:" + item.GetValue("orgwidth") + "px;"; + } + if (item.GetValue("orgheight")!= null) + { + style += "height:" + item.GetValue("orgheight") + "px;"; + } + temp = ""; + temp_html = string.Format(temp_html, name, value, style); + } + + return temp_html; + } + + ////Listctrl + //private static string GetListctrl(JObject item, Dictionary formData, string action) + // { + // string valuetest = "{\"data_110\":[\"1\",\"2\"],\"data_111\":[\"21\",\"22\",\"22\"]}"; + + // string name = item.GetValue("name").ToString(); + // string value = formData.ContainsKey(name)?formData[name].ToString():null; + // string temp_html = ""; + // string orgSum =item.GetValue("orgsum").ToString(); + // string orgUnit =item.GetValue("orgunit").ToString(); + // string orgTitle =item.GetValue("orgtitle").ToString(); + // string title =item.GetValue("title").ToString(); + // string style =item.GetValue("style").ToString(); + // string orgcolvalue =item.GetValue("orgcolvalue").ToString(); + // string orgcoltype =item.GetValue("orgcoltype").ToString(); + // List listTitle = Arrays.asList(orgTitle.split("`")); + // List listSum = Arrays.asList(orgSum.split("`")); + // List listUnit = Arrays.asList(orgUnit.split("`")); + // List listValue =Arrays.asList(orgcolvalue.split("`")); + // List listType =Arrays.asList(orgcoltype.split("`")); + // int tdCount = listTitle.size(); + + + // string temp = "{0}{1}{2}
"; + // string btnAdd = ""; //添加按钮 + // string theader = "{1}{2}{3}";//头部模版 + + // string trTitle = "";//标题 + // for (int i = 0; i < tdCount; i++) + // { + // if (i == tdCount - 1) + // listTitle.set(i, "操作"); + // if ("view"==(action) && i == tdCount - 1) continue;//如果是查看最后一列不显示 + // trTitle += string.Format("{0}", listTitle.get(i)); + // } + // trTitle = "" + trTitle + ""; + + + // JObject dataValue=JObject.fromObject(valuetest); + + // int rowCount = dataValue != null ? dataValue.size() : 1; + + + // stringBuilder sbTr = new stringBuilder(); + // string tdSum = "";//如果有统计增加一行 + + + // TreeMap SumValueDic = new TreeMap(); + // for (int row = 0; row < rowCount; row++) + // { + + // JSONArray rowValue = (dataValue != null && dataValue.has(name + row)) ? dataValue.getJSONArray(name + row): null; + + // string tr = "";//默认一行 + // for (int i = 0; i < tdCount; i++) + // { + // string tdname = name + "[" + i + "]"; + // string sum = "1"==(listSum.get(i)) ? "sum=\"" + tdname + "\"" : "";//是否参与统计 + // string tdValue =( rowValue != null && rowValue.size() > i) ? rowValue.GetValue(i).ToString(): listValue.get(i); + // string type = listType.get(i);//类型 + + // if (sum != "")//一次循环计算该列的值 + // { + // //region 计算统计值 + // float tempTdValue = 0; + // if (SumValueDic.containsKey(i)) + // tempTdValue = SumValueDic.get(i); + // try + // { + // float resultTdTemp = 0; + // resultTdTemp=Float.parseFloat(tdValue); + // //float.TryParse(tdValue, out resultTdTemp); + // tempTdValue += resultTdTemp; + // } + // catch (Exception e) + // { + // tdValue = "0"; + // } + // if (SumValueDic.containsKey(i)) + // SumValueDic.subMap(i, (int) tempTdValue); + // else + // SumValueDic.put(i, tempTdValue); + // //endregion + + // } + + // if (i == tdCount - 1)//最后一列不显示 + // { + // if ("view"==(action)) continue; + // //tr += ""; + // else + // tr += "删除"; + // //tr += string.Format("删除", dataValue != null ? "" : "hide"); + // } + // else + // { + // if ("view"==(action)) + // { + // tr += string.Format("{0}", tdValue); + // } + // else + // { + // if ("text"==(type)) + // tr += string.Format("", tdValue, tdname, sum); + // else if ("int"==(type)) + // tr += string.Format("", tdValue, tdname, sum); + // else if ("textarea"==(type)) + // tr += string.Format("", tdname, tdValue, sum); + // else if ("calc"==(type)) + // tr += string.Format("", tdValue, tdname, sum); + // } + // } + + // if (row == 0)//统计的行只有一行 + // { + // //region + // if (sum != "") + // { + // if ("view"==(action)) + // tdSum += string.Format("合计:value{0}{1}", i, listUnit.get(i)); + // else + // tdSum += string.Format("合计:{3}", i, tdname, sum, listUnit.get(i)); + // } + // else + // { + // tdSum += ""; + // } + // //endregion + + // } + + // } + // sbTr.append(string.Format("{0}", tr) ); + + // } + // /*if(!stringUtils.isBlank(tdSum)){ + + // }*/ + + // if (!stringUtils.isBlank(tdSum)){ + // for (Integer i : SumValueDic.keySet()) { + // tdSum = tdSum.Replace("value" + i, SumValueDic.get(i).ToString()); + // tdSum = string.Format("{0}", tdSum); + // } + // } + // if ("view"==(action)) + // theader = string.Format(theader, tdCount, title, "", trTitle); + // else + // theader = string.Format(theader, tdCount, title, btnAdd, trTitle); + + // temp_html = string.Format(temp, theader, sbTr.ToString(), tdSum); + + // return temp_html; + // } + + + + + + /** + * 功能: 创建表单数据表格(基于sql server) + */ + public static string GetSql(Form form, string dbType){ + + if (dbType == Define.DBTYPE_SQLSERVER) //Sql Server + { + // 获取字段并处理 + var jsonArray = JArray.Parse(form.ContentData); + + // 数据库名称 + string tableName= form.DbName ; + // 创建数据表 + StringBuilder sql =new StringBuilder("if exists ( select * from sysobjects where name = '" + +tableName+"' and type = 'U') drop table " + + tableName +";") ; + + sql.Append("CREATE TABLE " + + tableName + + " ( [Id] varchar(50) COLLATE Chinese_PRC_CI_AS NOT NULL,"); //主键 + + string sqlDefault = ""; + + foreach (var json in jsonArray) + { + string name; + string type = json["leipiplugins"].ToString(); + + if ("checkboxs" == type) + name = json["parse_name"].ToString(); + else + name = json["name"].ToString(); + + sql.Append("[" + name + "] " + field_type_sql(type));//字段拼接 + + + if ("checkboxs" == type) + sqlDefault += field_type_sql_default(tableName, name, "0"); + else + sqlDefault += field_type_sql_default(tableName, name, "''"); + } + + sql.Append(");"); + + //设置主键 + sql.Append("ALTER TABLE "+tableName+" ADD CONSTRAINT [PK_"+form.DbName+"] PRIMARY KEY NONCLUSTERED ([Id])"); + sql.Append( + "WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) "); + sql.Append("ON [PRIMARY];"); + + //主键默认值 + sql.Append("ALTER TABLE "+tableName+" ADD DEFAULT (newid()) FOR [Id];"); + + return sql+sqlDefault; + } + else + { + // 获取字段并处理 + var jsonArray = JArray.Parse(form.ContentData); + + // 数据库名称 + string tableName= form.DbName ; + // 创建数据表 + StringBuilder sql =new StringBuilder("create table if not exists `" + + tableName + + "` ( Id varchar(50) not null primary key,") ; //主键 + + + string sqlDefault = ""; + + foreach (var json in jsonArray) + { + string name; + string type = json["leipiplugins"].ToString(); + + if ("checkboxs" == type) + name = json["parse_name"].ToString(); + else + name = json["name"].ToString(); + + sql.Append("`" + name + "` " + field_type_mysql(type));//字段拼接 + +// +// if ("checkboxs" == type) +// sqlDefault += field_type_sql_default(tableName, name, "0"); +// else +// sqlDefault += field_type_sql_default(tableName, name, "''"); + } + + sql.Append(");"); + + return sql.ToString(); + } + + } + //获取控件字段类型 的sql + private static string field_type_sql(string leipiplugins) + { + if ("textarea"==leipiplugins || "listctrl"==leipiplugins) + { + return " text NULL ,"; + } + else if ("checkboxs"==leipiplugins) + { + return " int NOT NULL ,"; + } + else + { + return " varchar(255) NULL ,"; + } + } + + private static string field_type_mysql(string leipiplugins) + { + if ("textarea"==leipiplugins || "listctrl"==leipiplugins) + { + return " varchar(255) null ,"; + } + else if ("checkboxs"==leipiplugins) + { + return " tinyint not null ,"; + } + else + { + return " varchar(255) NULL ,"; + } + } + + private static string field_type_sql_default(string tablename, string field, string defaultValue) + { + return "ALTER TABLE "+tablename+" ADD DEFAULT ("+defaultValue+") FOR ["+field+"];"; + } + } +} diff --git a/OpenAuth.App/Request/QueryFormListReq.cs b/OpenAuth.App/Form/Request/QueryFormListReq.cs similarity index 95% rename from OpenAuth.App/Request/QueryFormListReq.cs rename to OpenAuth.App/Form/Request/QueryFormListReq.cs index 0a9d7732..427ac9d9 100644 --- a/OpenAuth.App/Request/QueryFormListReq.cs +++ b/OpenAuth.App/Form/Request/QueryFormListReq.cs @@ -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; } + } +} diff --git a/OpenAuth.App/Response/FormResp.cs b/OpenAuth.App/Form/Response/FormResp.cs similarity index 96% rename from OpenAuth.App/Response/FormResp.cs rename to OpenAuth.App/Form/Response/FormResp.cs index 113da963..eb29960c 100644 --- a/OpenAuth.App/Response/FormResp.cs +++ b/OpenAuth.App/Form/Response/FormResp.cs @@ -1,73 +1,73 @@ -//------------------------------------------------------------------------------ -// -// 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 -// -//------------------------------------------------------------------------------ - -namespace OpenAuth.App.Response -{ - /// - /// 表单模板表 - /// - public class FormResp - { - /// - /// 表单名称 - /// - public string Id { get; set; } - - /// - /// 表单名称 - /// - public string Name { get; set; } - /// - /// 字段个数 - /// - public int Fields { get; set; } - /// - /// 表单类型,0:默认动态表单;1:Web自定义表单 - /// - public int FrmType { get; set; } - /// - /// 系统页面标识,当表单类型为用Web自定义的表单时,需要标识加载哪个页面 - /// - public string WebId { get; set; } - /// - /// 表单中的字段数据 - /// - public string ContentData { get; set; } - /// - /// 表单替换的模板 经过处理 - /// - public string ContentParse { get; set; } - /// - /// 表单原html模板未经处理的 - /// - public string Content { get; set; } - - /// - /// 排序码 - /// - public int SortCode { get; set; } - - public string Description { get; set; } - - - /// - /// 数据库名称 - /// - public string DbName { get; set; } - /// - /// 用户显示 - /// - public string Html - { - get { return FormUtil.GetHtml(this); } - } - - } +//------------------------------------------------------------------------------ +// +// 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 +// +//------------------------------------------------------------------------------ + +namespace OpenAuth.App.Response +{ + /// + /// 表单模板表 + /// + public class FormResp + { + /// + /// 表单名称 + /// + public string Id { get; set; } + + /// + /// 表单名称 + /// + public string Name { get; set; } + /// + /// 字段个数 + /// + public int Fields { get; set; } + /// + /// 表单类型,0:默认动态表单;1:Web自定义表单 + /// + public int FrmType { get; set; } + /// + /// 系统页面标识,当表单类型为用Web自定义的表单时,需要标识加载哪个页面 + /// + public string WebId { get; set; } + /// + /// 表单中的字段数据 + /// + public string ContentData { get; set; } + /// + /// 表单替换的模板 经过处理 + /// + public string ContentParse { get; set; } + /// + /// 表单原html模板未经处理的 + /// + public string Content { get; set; } + + /// + /// 排序码 + /// + public int SortCode { get; set; } + + public string Description { get; set; } + + + /// + /// 数据库名称 + /// + public string DbName { get; set; } + /// + /// 用户显示 + /// + public string Html + { + get { return FormUtil.GetHtml(this); } + } + + } } \ No newline at end of file diff --git a/OpenAuth.App/FrmLeaveReqApp.cs b/OpenAuth.App/FrmLeave/FrmLeaveReqApp.cs similarity index 100% rename from OpenAuth.App/FrmLeaveReqApp.cs rename to OpenAuth.App/FrmLeave/FrmLeaveReqApp.cs diff --git a/OpenAuth.App/Request/QueryFrmLeaveReqListReq.cs b/OpenAuth.App/FrmLeave/Request/QueryFrmLeaveReqListReq.cs similarity index 100% rename from OpenAuth.App/Request/QueryFrmLeaveReqListReq.cs rename to OpenAuth.App/FrmLeave/Request/QueryFrmLeaveReqListReq.cs diff --git a/OpenAuth.App/OpenJobApp.cs b/OpenAuth.App/Jobs/OpenJobApp.cs similarity index 100% rename from OpenAuth.App/OpenJobApp.cs rename to OpenAuth.App/Jobs/OpenJobApp.cs diff --git a/OpenAuth.App/Request/AddOrUpdateOpenJobReq.cs b/OpenAuth.App/Jobs/Request/AddOrUpdateOpenJobReq.cs similarity index 100% rename from OpenAuth.App/Request/AddOrUpdateOpenJobReq.cs rename to OpenAuth.App/Jobs/Request/AddOrUpdateOpenJobReq.cs diff --git a/OpenAuth.App/Request/ChangeJobStatusReq.cs b/OpenAuth.App/Jobs/Request/ChangeJobStatusReq.cs similarity index 100% rename from OpenAuth.App/Request/ChangeJobStatusReq.cs rename to OpenAuth.App/Jobs/Request/ChangeJobStatusReq.cs diff --git a/OpenAuth.App/Request/QueryOpenJobListReq.cs b/OpenAuth.App/Jobs/Request/QueryOpenJobListReq.cs similarity index 100% rename from OpenAuth.App/Request/QueryOpenJobListReq.cs rename to OpenAuth.App/Jobs/Request/QueryOpenJobListReq.cs diff --git a/OpenAuth.App/ModuleManagerApp.cs b/OpenAuth.App/ModuleManager/ModuleManagerApp.cs similarity index 96% rename from OpenAuth.App/ModuleManagerApp.cs rename to OpenAuth.App/ModuleManager/ModuleManagerApp.cs index b4fa303e..70b70fc6 100644 --- a/OpenAuth.App/ModuleManagerApp.cs +++ b/OpenAuth.App/ModuleManager/ModuleManagerApp.cs @@ -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 - { - 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 用户/角色分配模块 - - /// - /// 加载特定角色的模块 - /// - /// The role unique identifier. - public IEnumerable LoadForRole(string roleId) - { - var moduleIds = UnitWork.Find(u => u.FirstId == roleId && u.Key == Define.ROLEMODULE) - .Select(u => u.SecondId); - return UnitWork.Find(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo); - } - - //获取角色可访问的模块字段 - public IEnumerable LoadPropertiesForRole(string roleId, string moduleCode) - { - return _revelanceApp.Get(Define.ROLEDATAPROPERTY, roleId, moduleCode); - } - - /// - /// 根据某角色ID获取可访问某模块的菜单项 - /// - public IEnumerable LoadMenusForRole(string moduleId, string roleId) - { - var elementIds = _revelanceApp.Get(Define.ROLEELEMENT, true, roleId); - var query = UnitWork.Find(u => elementIds.Contains(u.Id)); - if (!string.IsNullOrEmpty(moduleId)) - { - query = query.Where(u => u.ModuleId == moduleId); - } - - return query; - } - - #endregion 用户/角色分配模块 - - - #region 菜单操作 - - /// - /// 删除指定的菜单 - /// - /// - public void DelMenu(string[] ids) - { - UnitWork.Delete(u => ids.Contains(u.Id)); - UnitWork.Save(); - } - - - /// - /// 新增菜单 - /// 当前登录用户的所有角色会自动分配菜单 - /// - 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(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 unitWork, IRepository 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 + { + 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 用户/角色分配模块 + + /// + /// 加载特定角色的模块 + /// + /// The role unique identifier. + public IEnumerable LoadForRole(string roleId) + { + var moduleIds = UnitWork.Find(u => u.FirstId == roleId && u.Key == Define.ROLEMODULE) + .Select(u => u.SecondId); + return UnitWork.Find(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo); + } + + //获取角色可访问的模块字段 + public IEnumerable LoadPropertiesForRole(string roleId, string moduleCode) + { + return _revelanceApp.Get(Define.ROLEDATAPROPERTY, roleId, moduleCode); + } + + /// + /// 根据某角色ID获取可访问某模块的菜单项 + /// + public IEnumerable LoadMenusForRole(string moduleId, string roleId) + { + var elementIds = _revelanceApp.Get(Define.ROLEELEMENT, true, roleId); + var query = UnitWork.Find(u => elementIds.Contains(u.Id)); + if (!string.IsNullOrEmpty(moduleId)) + { + query = query.Where(u => u.ModuleId == moduleId); + } + + return query; + } + + #endregion 用户/角色分配模块 + + + #region 菜单操作 + + /// + /// 删除指定的菜单 + /// + /// + public void DelMenu(string[] ids) + { + UnitWork.Delete(u => ids.Contains(u.Id)); + UnitWork.Save(); + } + + + /// + /// 新增菜单 + /// 当前登录用户的所有角色会自动分配菜单 + /// + 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(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 unitWork, IRepository repository + , RevelanceManagerApp app, IAuth auth) : base(unitWork, repository, auth) + { + _revelanceApp = app; + } + } } \ No newline at end of file diff --git a/OpenAuth.App/Response/ModuleElementVM.cs b/OpenAuth.App/ModuleManager/Response/ModuleElementVM.cs similarity index 95% rename from OpenAuth.App/Response/ModuleElementVM.cs rename to OpenAuth.App/ModuleManager/Response/ModuleElementVM.cs index 60d828d1..a95b4936 100644 --- a/OpenAuth.App/Response/ModuleElementVM.cs +++ b/OpenAuth.App/ModuleManager/Response/ModuleElementVM.cs @@ -1,49 +1,49 @@ -namespace OpenAuth.App.Response -{ - /// - /// 用户ID - /// - public class ModuleElementVM - { - /// - /// 用户ID - /// - /// - public int Id { get; set; } - - /// - /// DOM ID - /// - /// - public string DomId { get; set; } - - /// - /// 组织名称 - /// - /// - public string Name { get; set; } - - //模块ID - public int ModuleId { get; set; } - - /// - /// 所属模块名称 - /// - public string ModuleName { get; set; } - - /// - /// 授权状态 - /// - 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 +{ + /// + /// 用户ID + /// + public class ModuleElementVM + { + /// + /// 用户ID + /// + /// + public int Id { get; set; } + + /// + /// DOM ID + /// + /// + public string DomId { get; set; } + + /// + /// 组织名称 + /// + /// + public string Name { get; set; } + + //模块ID + public int ModuleId { get; set; } + + /// + /// 所属模块名称 + /// + public string ModuleName { get; set; } + + /// + /// 授权状态 + /// + 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; + } + } } \ No newline at end of file diff --git a/OpenAuth.App/Response/ModuleView.cs b/OpenAuth.App/ModuleManager/Response/ModuleView.cs similarity index 95% rename from OpenAuth.App/Response/ModuleView.cs rename to OpenAuth.App/ModuleManager/Response/ModuleView.cs index a13b7f66..70118b82 100644 --- a/OpenAuth.App/Response/ModuleView.cs +++ b/OpenAuth.App/ModuleManager/Response/ModuleView.cs @@ -1,83 +1,83 @@ -using System.Collections.Generic; -using Infrastructure; -using OpenAuth.Repository.Domain; - -namespace OpenAuth.App.Response -{ - public class ModuleView - { - /// - /// ID - /// - /// - public string Id { get; set; } - - /// - /// 节点语义ID - /// - public string CascadeId { get; set; } - - /// - /// 名称 - /// - /// - public string Name { get; set; } - - /// - /// 主页面URL - /// - /// - public string Url { get; set; } - - /// - /// 父节点流水号 - /// - /// - public string ParentId { get; set; } - - /// - /// 父节点流水号 - /// - /// - public string ParentName { get; set; } - - /// - /// 节点图标文件名称 - /// - /// - public string IconName { get; set; } - - - /// - /// 当前状态,0:正常,-1:隐藏,不在导航列表中显示 - /// - public int Status { get; set; } - - - public bool Checked { get; set; } - - /// - /// 排序号 - /// - public int SortNo { get; set; } - - public string Code { get; set; } - - public bool IsSys { get; set; } - - /// - /// 模块中的元素 - /// - public List Elements { get; set; } - - public static implicit operator ModuleView(Module module) - { - return module.MapTo(); - } - - public static implicit operator Module(ModuleView view) - { - return view.MapTo(); - } - } +using System.Collections.Generic; +using Infrastructure; +using OpenAuth.Repository.Domain; + +namespace OpenAuth.App.Response +{ + public class ModuleView + { + /// + /// ID + /// + /// + public string Id { get; set; } + + /// + /// 节点语义ID + /// + public string CascadeId { get; set; } + + /// + /// 名称 + /// + /// + public string Name { get; set; } + + /// + /// 主页面URL + /// + /// + public string Url { get; set; } + + /// + /// 父节点流水号 + /// + /// + public string ParentId { get; set; } + + /// + /// 父节点流水号 + /// + /// + public string ParentName { get; set; } + + /// + /// 节点图标文件名称 + /// + /// + public string IconName { get; set; } + + + /// + /// 当前状态,0:正常,-1:隐藏,不在导航列表中显示 + /// + public int Status { get; set; } + + + public bool Checked { get; set; } + + /// + /// 排序号 + /// + public int SortNo { get; set; } + + public string Code { get; set; } + + public bool IsSys { get; set; } + + /// + /// 模块中的元素 + /// + public List Elements { get; set; } + + public static implicit operator ModuleView(Module module) + { + return module.MapTo(); + } + + public static implicit operator Module(ModuleView view) + { + return view.MapTo(); + } + } } \ No newline at end of file diff --git a/OpenAuth.App/OrgManagerApp.cs b/OpenAuth.App/OrgManager/OrgManagerApp.cs similarity index 97% rename from OpenAuth.App/OrgManagerApp.cs rename to OpenAuth.App/OrgManager/OrgManagerApp.cs index aee88341..13789dc4 100644 --- a/OpenAuth.App/OrgManagerApp.cs +++ b/OpenAuth.App/OrgManager/OrgManagerApp.cs @@ -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 - { - private RevelanceManagerApp _revelanceApp; - /// - /// 添加部门 - /// - /// The org. - /// System.Int32. - /// 未能找到该组织的父节点信息 - 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; - } - - /// - /// 删除指定ID的部门及其所有子部门 - /// - public void DelOrgCascade(string[] ids) - { - var delOrgCascadeIds = UnitWork.Find(u => ids.Contains(u.Id)).Select(u => u.CascadeId).ToArray(); - var delOrgIds = new List(); - foreach (var cascadeId in delOrgCascadeIds) - { - delOrgIds.AddRange(UnitWork.Find(u=>u.CascadeId.Contains(cascadeId)).Select(u =>u.Id).ToArray()); - } - - UnitWork.Delete(u =>u.Key == Define.USERORG && delOrgIds.Contains(u.SecondId)); - UnitWork.Delete(u => delOrgIds.Contains(u.Id)); - UnitWork.Save(); - - } - - /// - /// 加载特定用户的部门 - /// - /// The user unique identifier. - public List LoadForUser(string userId) - { - var result = from userorg in UnitWork.Find(null) - join org in UnitWork.Find(null) on userorg.SecondId equals org.Id - where userorg.FirstId == userId && userorg.Key == Define.USERORG - select org; - return result.ToList(); - } - - public OrgManagerApp(IUnitWork unitWork, IRepository 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 + { + private RevelanceManagerApp _revelanceApp; + /// + /// 添加部门 + /// + /// The org. + /// System.Int32. + /// 未能找到该组织的父节点信息 + 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; + } + + /// + /// 删除指定ID的部门及其所有子部门 + /// + public void DelOrgCascade(string[] ids) + { + var delOrgCascadeIds = UnitWork.Find(u => ids.Contains(u.Id)).Select(u => u.CascadeId).ToArray(); + var delOrgIds = new List(); + foreach (var cascadeId in delOrgCascadeIds) + { + delOrgIds.AddRange(UnitWork.Find(u=>u.CascadeId.Contains(cascadeId)).Select(u =>u.Id).ToArray()); + } + + UnitWork.Delete(u =>u.Key == Define.USERORG && delOrgIds.Contains(u.SecondId)); + UnitWork.Delete(u => delOrgIds.Contains(u.Id)); + UnitWork.Save(); + + } + + /// + /// 加载特定用户的部门 + /// + /// The user unique identifier. + public List LoadForUser(string userId) + { + var result = from userorg in UnitWork.Find(null) + join org in UnitWork.Find(null) on userorg.SecondId equals org.Id + where userorg.FirstId == userId && userorg.Key == Define.USERORG + select org; + return result.ToList(); + } + + public OrgManagerApp(IUnitWork unitWork, IRepository repository,IAuth auth, + RevelanceManagerApp revelanceApp) : base(unitWork, repository, auth) + { + _revelanceApp = revelanceApp; + } + } } \ No newline at end of file diff --git a/OpenAuth.App/Request/AssignDataReq.cs b/OpenAuth.App/Relevance/Request/AssignDataReq.cs similarity index 100% rename from OpenAuth.App/Request/AssignDataReq.cs rename to OpenAuth.App/Relevance/Request/AssignDataReq.cs diff --git a/OpenAuth.App/Request/AssignOrgUsers.cs b/OpenAuth.App/Relevance/Request/AssignOrgUsers.cs similarity index 100% rename from OpenAuth.App/Request/AssignOrgUsers.cs rename to OpenAuth.App/Relevance/Request/AssignOrgUsers.cs diff --git a/OpenAuth.App/Request/AssignReq.cs b/OpenAuth.App/Relevance/Request/AssignReq.cs similarity index 100% rename from OpenAuth.App/Request/AssignReq.cs rename to OpenAuth.App/Relevance/Request/AssignReq.cs diff --git a/OpenAuth.App/Request/AssignRoleUsers.cs b/OpenAuth.App/Relevance/Request/AssignRoleUsers.cs similarity index 100% rename from OpenAuth.App/Request/AssignRoleUsers.cs rename to OpenAuth.App/Relevance/Request/AssignRoleUsers.cs diff --git a/OpenAuth.App/RevelanceManagerApp.cs b/OpenAuth.App/Relevance/RevelanceManagerApp.cs similarity index 97% rename from OpenAuth.App/RevelanceManagerApp.cs rename to OpenAuth.App/Relevance/RevelanceManagerApp.cs index eac1bbdc..95e3f6f9 100644 --- a/OpenAuth.App/RevelanceManagerApp.cs +++ b/OpenAuth.App/Relevance/RevelanceManagerApp.cs @@ -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 - { - private readonly ILogger _logger; - public RevelanceManagerApp(IUnitWork unitWork, IRepository repository, IAuth auth, ILogger logger) : base(unitWork, - repository, auth) - { - _logger = logger; - } - - /// - /// 添加关联 - /// 比如给用户分配资源,那么firstId就是用户ID,secIds就是资源ID列表 - /// - /// 关联的类型,如Define.USERRESOURCE - public void Assign(AssignReq request) - { - Assign(request.type, request.secIds.ToLookup(u => request.firstId)); - } - - /// - /// 添加关联,需要人工删除以前的关联 - /// - /// - /// - public void Assign(string key, ILookup 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(); - } - - /// - /// 取消关联 - /// - /// 关联的类型,如Define.USERRESOURCE - /// The first identifier. - /// The sec ids. - 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)); - } - } - - /// - /// 删除关联 - /// - /// 关联标识 - /// 关联的<firstId, secondId>数组 - private void DeleteBy(string key, ILookup idMaps) - { - foreach (var sameVals in idMaps) - { - foreach (var value in sameVals) - { - _logger.LogInformation($"start=> delete {key} {sameVals.Key} {value}"); - try - { - UnitWork.Delete(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(u => firstIds.Contains(u.FirstId) && u.Key == key); - } - - - /// - /// 根据关联表的一个键获取另外键的值 - /// - /// 映射标识 - /// 返回的是否为映射表的第二列,如果不是则返回第一列 - /// 已知的ID列表 - /// List<System.String>. - public List 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(); - } - } - - /// - /// 根据key ,firstId,secondId获取thirdId - /// - /// - /// - /// - /// - public List 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(); - } - - /// - /// 分配数据字段权限 - /// - /// - public void AssignData(AssignDataReq request) - { - if (!request.Properties.Any()) - { - return; - } - - var relevances = new List(); - 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(); - } - - /// - /// 取消数据字段分配 - /// - /// - 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(u => u.Key == Define.ROLEDATAPROPERTY - && u.FirstId == request.RoleId - && u.SecondId == request.ModuleCode - && u.ThirdId == property); - } - } - } - - /// - /// 为角色分配用户,需要统一提交,会删除以前该角色的所有用户 - /// - /// - public void AssignRoleUsers(AssignRoleUsers request) - { - UnitWork.ExecuteWithTransaction(() => - { - //删除以前的所有用户 - UnitWork.Delete(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(); - }); - } - - /// - /// 为部门分配用户,需要统一提交,会删除以前该部门的所有用户 - /// - /// - public void AssignOrgUsers(AssignOrgUsers request) - { - UnitWork.ExecuteWithTransaction(() => - { - //删除以前的所有用户 - UnitWork.Delete(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 + { + private readonly ILogger _logger; + public RevelanceManagerApp(IUnitWork unitWork, IRepository repository, IAuth auth, ILogger logger) : base(unitWork, + repository, auth) + { + _logger = logger; + } + + /// + /// 添加关联 + /// 比如给用户分配资源,那么firstId就是用户ID,secIds就是资源ID列表 + /// + /// 关联的类型,如Define.USERRESOURCE + public void Assign(AssignReq request) + { + Assign(request.type, request.secIds.ToLookup(u => request.firstId)); + } + + /// + /// 添加关联,需要人工删除以前的关联 + /// + /// + /// + public void Assign(string key, ILookup 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(); + } + + /// + /// 取消关联 + /// + /// 关联的类型,如Define.USERRESOURCE + /// The first identifier. + /// The sec ids. + 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)); + } + } + + /// + /// 删除关联 + /// + /// 关联标识 + /// 关联的<firstId, secondId>数组 + private void DeleteBy(string key, ILookup idMaps) + { + foreach (var sameVals in idMaps) + { + foreach (var value in sameVals) + { + _logger.LogInformation($"start=> delete {key} {sameVals.Key} {value}"); + try + { + UnitWork.Delete(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(u => firstIds.Contains(u.FirstId) && u.Key == key); + } + + + /// + /// 根据关联表的一个键获取另外键的值 + /// + /// 映射标识 + /// 返回的是否为映射表的第二列,如果不是则返回第一列 + /// 已知的ID列表 + /// List<System.String>. + public List 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(); + } + } + + /// + /// 根据key ,firstId,secondId获取thirdId + /// + /// + /// + /// + /// + public List 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(); + } + + /// + /// 分配数据字段权限 + /// + /// + public void AssignData(AssignDataReq request) + { + if (!request.Properties.Any()) + { + return; + } + + var relevances = new List(); + 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(); + } + + /// + /// 取消数据字段分配 + /// + /// + 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(u => u.Key == Define.ROLEDATAPROPERTY + && u.FirstId == request.RoleId + && u.SecondId == request.ModuleCode + && u.ThirdId == property); + } + } + } + + /// + /// 为角色分配用户,需要统一提交,会删除以前该角色的所有用户 + /// + /// + public void AssignRoleUsers(AssignRoleUsers request) + { + UnitWork.ExecuteWithTransaction(() => + { + //删除以前的所有用户 + UnitWork.Delete(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(); + }); + } + + /// + /// 为部门分配用户,需要统一提交,会删除以前该部门的所有用户 + /// + /// + public void AssignOrgUsers(AssignOrgUsers request) + { + UnitWork.ExecuteWithTransaction(() => + { + //删除以前的所有用户 + UnitWork.Delete(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(); + }); + } + } } \ No newline at end of file diff --git a/OpenAuth.App/Request/AddOrUpdateResReq.cs b/OpenAuth.App/Resources/Request/AddOrUpdateResReq.cs similarity index 100% rename from OpenAuth.App/Request/AddOrUpdateResReq.cs rename to OpenAuth.App/Resources/Request/AddOrUpdateResReq.cs diff --git a/OpenAuth.App/Request/QueryResourcesReq.cs b/OpenAuth.App/Resources/Request/QueryResourcesReq.cs similarity index 100% rename from OpenAuth.App/Request/QueryResourcesReq.cs rename to OpenAuth.App/Resources/Request/QueryResourcesReq.cs diff --git a/OpenAuth.App/ResourceApp.cs b/OpenAuth.App/Resources/ResourceApp.cs similarity index 100% rename from OpenAuth.App/ResourceApp.cs rename to OpenAuth.App/Resources/ResourceApp.cs diff --git a/OpenAuth.App/Request/QueryRoleListReq.cs b/OpenAuth.App/RoleManager/Request/QueryRoleListReq.cs similarity index 94% rename from OpenAuth.App/Request/QueryRoleListReq.cs rename to OpenAuth.App/RoleManager/Request/QueryRoleListReq.cs index 65bd9b54..75e94fcc 100644 --- a/OpenAuth.App/Request/QueryRoleListReq.cs +++ b/OpenAuth.App/RoleManager/Request/QueryRoleListReq.cs @@ -1,6 +1,6 @@ -namespace OpenAuth.App.Request -{ - public class QueryRoleListReq : PageReq - { - } -} +namespace OpenAuth.App.Request +{ + public class QueryRoleListReq : PageReq + { + } +} diff --git a/OpenAuth.App/Response/RoleView.cs b/OpenAuth.App/RoleManager/Response/RoleView.cs similarity index 96% rename from OpenAuth.App/Response/RoleView.cs rename to OpenAuth.App/RoleManager/Response/RoleView.cs index e82e6412..07798f0a 100644 --- a/OpenAuth.App/Response/RoleView.cs +++ b/OpenAuth.App/RoleManager/Response/RoleView.cs @@ -1,60 +1,60 @@ -// *********************************************************************** -// Assembly : OpenAuth.App -// Author : yubaolee -// Created : 11-29-2015 -// -// Last Modified By : yubaolee -// Last Modified On : 11-29-2015 -// *********************************************************************** -// -// Copyright (c) www.cnblogs.com/yubaolee. All rights reserved. -// -// 角色模型视图 -// *********************************************************************** - -using Infrastructure; -using OpenAuth.Repository.Domain; - -namespace OpenAuth.App.Response -{ - public partial class RoleView - { - /// - /// 用户ID - /// - /// - public string Id { get; set; } - - /// - /// 名称 - /// - /// - public string Name { get; set; } - - /// - /// 当前状态 - /// - public int Status { get; set; } - /// - /// 角色类型 - /// - public int Type { get; set; } - - - /// - ///是否属于某用户 - /// - public bool Checked { get; set; } - - public static implicit operator RoleView(Role role) - { - return role.MapTo(); - } - - public static implicit operator Role(RoleView rolevm) - { - return rolevm.MapTo(); - } - - } -} +// *********************************************************************** +// Assembly : OpenAuth.App +// Author : yubaolee +// Created : 11-29-2015 +// +// Last Modified By : yubaolee +// Last Modified On : 11-29-2015 +// *********************************************************************** +// +// Copyright (c) www.cnblogs.com/yubaolee. All rights reserved. +// +// 角色模型视图 +// *********************************************************************** + +using Infrastructure; +using OpenAuth.Repository.Domain; + +namespace OpenAuth.App.Response +{ + public partial class RoleView + { + /// + /// 用户ID + /// + /// + public string Id { get; set; } + + /// + /// 名称 + /// + /// + public string Name { get; set; } + + /// + /// 当前状态 + /// + public int Status { get; set; } + /// + /// 角色类型 + /// + public int Type { get; set; } + + + /// + ///是否属于某用户 + /// + public bool Checked { get; set; } + + public static implicit operator RoleView(Role role) + { + return role.MapTo(); + } + + public static implicit operator Role(RoleView rolevm) + { + return rolevm.MapTo(); + } + + } +} diff --git a/OpenAuth.App/RoleApp.cs b/OpenAuth.App/RoleManager/RoleApp.cs similarity index 96% rename from OpenAuth.App/RoleApp.cs rename to OpenAuth.App/RoleManager/RoleApp.cs index ba575ca5..8522427c 100644 --- a/OpenAuth.App/RoleApp.cs +++ b/OpenAuth.App/RoleManager/RoleApp.cs @@ -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 - { - private RevelanceManagerApp _revelanceApp; - - /// - /// 加载当前登录用户可访问的全部角色 - /// - public List 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; - } - - - /// - /// 添加角色,如果当前登录用户不是System,则直接把新角色分配给当前登录用户 - /// - 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} - }); - } - }); - } - - /// - /// 更新角色属性 - /// - /// - public void Update(RoleView obj) - { - Role role = obj; - - UnitWork.Update(u => u.Id == obj.Id, u => new Role - { - Name = role.Name, - Status = role.Status - }); - - } - - - public RoleApp(IUnitWork unitWork, IRepository 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 + { + private RevelanceManagerApp _revelanceApp; + + /// + /// 加载当前登录用户可访问的全部角色 + /// + public List 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; + } + + + /// + /// 添加角色,如果当前登录用户不是System,则直接把新角色分配给当前登录用户 + /// + 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} + }); + } + }); + } + + /// + /// 更新角色属性 + /// + /// + public void Update(RoleView obj) + { + Role role = obj; + + UnitWork.Update(u => u.Id == obj.Id, u => new Role + { + Name = role.Name, + Status = role.Status + }); + + } + + + public RoleApp(IUnitWork unitWork, IRepository repository, + RevelanceManagerApp app,IAuth auth) : base(unitWork, repository, auth) + { + _revelanceApp = app; + } + } } \ No newline at end of file diff --git a/OpenAuth.App/Request/QuerySysLogListReq.cs b/OpenAuth.App/SysLogs/Request/QuerySysLogListReq.cs similarity index 100% rename from OpenAuth.App/Request/QuerySysLogListReq.cs rename to OpenAuth.App/SysLogs/Request/QuerySysLogListReq.cs diff --git a/OpenAuth.App/SysLogApp.cs b/OpenAuth.App/SysLogs/SysLogApp.cs similarity index 100% rename from OpenAuth.App/SysLogApp.cs rename to OpenAuth.App/SysLogs/SysLogApp.cs diff --git a/OpenAuth.App/Request/QuerySysMessageListReq.cs b/OpenAuth.App/SysMessage/Request/QuerySysMessageListReq.cs similarity index 100% rename from OpenAuth.App/Request/QuerySysMessageListReq.cs rename to OpenAuth.App/SysMessage/Request/QuerySysMessageListReq.cs diff --git a/OpenAuth.App/SysMessageApp.cs b/OpenAuth.App/SysMessage/SysMessageApp.cs similarity index 100% rename from OpenAuth.App/SysMessageApp.cs rename to OpenAuth.App/SysMessage/SysMessageApp.cs diff --git a/OpenAuth.App/Request/ChangePasswordReq.cs b/OpenAuth.App/UserManager/Request/ChangePasswordReq.cs similarity index 100% rename from OpenAuth.App/Request/ChangePasswordReq.cs rename to OpenAuth.App/UserManager/Request/ChangePasswordReq.cs diff --git a/OpenAuth.App/Request/ChangeProfileReq.cs b/OpenAuth.App/UserManager/Request/ChangeProfileReq.cs similarity index 100% rename from OpenAuth.App/Request/ChangeProfileReq.cs rename to OpenAuth.App/UserManager/Request/ChangeProfileReq.cs diff --git a/OpenAuth.App/Request/QueryUserListByOrgReq.cs b/OpenAuth.App/UserManager/Request/QueryUserListByOrgReq.cs similarity index 100% rename from OpenAuth.App/Request/QueryUserListByOrgReq.cs rename to OpenAuth.App/UserManager/Request/QueryUserListByOrgReq.cs diff --git a/OpenAuth.App/Request/QueryUserListByRoleReq.cs b/OpenAuth.App/UserManager/Request/QueryUserListByRoleReq.cs similarity index 100% rename from OpenAuth.App/Request/QueryUserListByRoleReq.cs rename to OpenAuth.App/UserManager/Request/QueryUserListByRoleReq.cs diff --git a/OpenAuth.App/Request/QueryUserListReq.cs b/OpenAuth.App/UserManager/Request/QueryUserListReq.cs similarity index 95% rename from OpenAuth.App/Request/QueryUserListReq.cs rename to OpenAuth.App/UserManager/Request/QueryUserListReq.cs index cd0e7ca1..161120ad 100644 --- a/OpenAuth.App/Request/QueryUserListReq.cs +++ b/OpenAuth.App/UserManager/Request/QueryUserListReq.cs @@ -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; } + } +} diff --git a/OpenAuth.App/Request/UpdateUserReq.cs b/OpenAuth.App/UserManager/Request/UpdateUserReq.cs similarity index 100% rename from OpenAuth.App/Request/UpdateUserReq.cs rename to OpenAuth.App/UserManager/Request/UpdateUserReq.cs diff --git a/OpenAuth.App/Response/UserView.cs b/OpenAuth.App/UserManager/Response/UserView.cs similarity index 95% rename from OpenAuth.App/Response/UserView.cs rename to OpenAuth.App/UserManager/Response/UserView.cs index 60830ac0..5540b8be 100644 --- a/OpenAuth.App/Response/UserView.cs +++ b/OpenAuth.App/UserManager/Response/UserView.cs @@ -1,88 +1,88 @@ -using System; -using Infrastructure; -using OpenAuth.Repository.Domain; - -namespace OpenAuth.App.Response -{ - public class UserView - { - /// - /// 用户ID - /// - /// - public string Id { get; set; } - - - /// - /// - /// - public string Account { get; set; } - - - /// - /// 组织名称 - /// - /// - public string Name { get; set; } - - - /// - /// - /// - public int Sex { get; set; } - - - /// - /// 当前状态 - /// - /// - public int Status { get; set; } - - - /// - /// 组织类型 - /// - /// - public int Type { get; set; } - - - - /// - /// 创建时间 - /// - /// - public DateTime CreateTime { get; set; } - - - /// - /// 创建人名字 - /// - /// The create user. - public string CreateUser { get; set; } - - /// - /// 所属组织名称,多个可用,分隔 - /// - /// The organizations. - public string Organizations { get; set; } - - public string OrganizationIds { get; set; } - - public static implicit operator UserView(User user) - { - return user.MapTo(); - } - - public static implicit operator User(UserView view) - { - return view.MapTo(); - } - - 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 + { + /// + /// 用户ID + /// + /// + public string Id { get; set; } + + + /// + /// + /// + public string Account { get; set; } + + + /// + /// 组织名称 + /// + /// + public string Name { get; set; } + + + /// + /// + /// + public int Sex { get; set; } + + + /// + /// 当前状态 + /// + /// + public int Status { get; set; } + + + /// + /// 组织类型 + /// + /// + public int Type { get; set; } + + + + /// + /// 创建时间 + /// + /// + public DateTime CreateTime { get; set; } + + + /// + /// 创建人名字 + /// + /// The create user. + public string CreateUser { get; set; } + + /// + /// 所属组织名称,多个可用,分隔 + /// + /// The organizations. + public string Organizations { get; set; } + + public string OrganizationIds { get; set; } + + public static implicit operator UserView(User user) + { + return user.MapTo(); + } + + public static implicit operator User(UserView view) + { + return view.MapTo(); + } + + public UserView() + { + Organizations = string.Empty; + OrganizationIds = string.Empty; + CreateUser = string.Empty; + } + } +} diff --git a/OpenAuth.App/UserManagerApp.cs b/OpenAuth.App/UserManager/UserManagerApp.cs similarity index 97% rename from OpenAuth.App/UserManagerApp.cs rename to OpenAuth.App/UserManager/UserManagerApp.cs index 881c4095..2daf510c 100644 --- a/OpenAuth.App/UserManagerApp.cs +++ b/OpenAuth.App/UserManager/UserManagerApp.cs @@ -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 - { - private RevelanceManagerApp _revelanceApp; - private OrgManagerApp _orgManagerApp; - - public UserManagerApp(IUnitWork unitWork, IRepository 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); - } - - /// - /// 加载当前登录用户可访问的一个部门及子部门全部用户 - /// 如果请求的request.OrgId为空,则可以获取到已被删除机构的用户(即:没有分配任何机构的用户) - /// - public async Task Load(QueryUserListReq request) - { - var loginUser = _auth.GetCurrentUser(); - - - IQueryable query = UnitWork.Find(null); - if (!string.IsNullOrEmpty(request.key)) - { - query = UnitWork.Find(u => u.Name.Contains(request.key) || u.Account.Contains(request.key)); - } - - var userOrgs = from user in query - join relevance in UnitWork.Find(u =>u.Key=="UserOrg") - on user.Id equals relevance.FirstId into temp - from r in temp.DefaultIfEmpty() - join org in UnitWork.Find(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(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(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(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)); - }); - - } - - /// - /// 删除用户,包含用户与组织关系、用户与角色关系 - /// - /// - public override void Delete(string[] ids) - { - UnitWork.ExecuteWithTransaction(() => - { - UnitWork.Delete(u =>(u.Key == Define.USERROLE || u.Key == Define.USERORG) - && ids.Contains(u.FirstId)); - UnitWork.Delete(u => ids.Contains(u.Id)); - UnitWork.Save(); - }); - - } - - - /// - /// 修改密码 - /// - /// - public void ChangePassword(ChangePasswordReq request) - { - Repository.Update(u => u.Account == request.Account, user => new User - { - Password = request.Password - }); - } - - /// - /// 获取指定角色包含的用户列表 - /// - /// - /// - public async Task LoadByRole(QueryUserListByRoleReq request) - { - var users = from userRole in UnitWork.Find(u => - u.SecondId == request.roleId && u.Key == Define.USERROLE) - join user in UnitWork.Find(null) on userRole.FirstId equals user.Id into temp - from c in temp.Where(u =>u.Id != null) - select c; - - return new TableData - { - count = users.Count(), - data = users.Skip((request.page - 1) * request.limit).Take(request.limit) - }; - } - - /// - /// 获取指定机构包含的用户列表 - /// - /// - /// - public async Task LoadByOrg(QueryUserListByOrgReq request) - { - var users = from userRole in UnitWork.Find(u => - u.SecondId == request.orgId && u.Key == Define.USERORG) - join user in UnitWork.Find(null) on userRole.FirstId equals user.Id into temp - from c in temp.Where(u =>u.Id != null) - select c; - - return new TableData - { - count = users.Count(), - data = users.Skip((request.page - 1) * request.limit).Take(request.limit) - }; - } - - /// - /// 修改用户资料 - /// - /// - 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 + { + private RevelanceManagerApp _revelanceApp; + private OrgManagerApp _orgManagerApp; + + public UserManagerApp(IUnitWork unitWork, IRepository 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); + } + + /// + /// 加载当前登录用户可访问的一个部门及子部门全部用户 + /// 如果请求的request.OrgId为空,则可以获取到已被删除机构的用户(即:没有分配任何机构的用户) + /// + public async Task Load(QueryUserListReq request) + { + var loginUser = _auth.GetCurrentUser(); + + + IQueryable query = UnitWork.Find(null); + if (!string.IsNullOrEmpty(request.key)) + { + query = UnitWork.Find(u => u.Name.Contains(request.key) || u.Account.Contains(request.key)); + } + + var userOrgs = from user in query + join relevance in UnitWork.Find(u =>u.Key=="UserOrg") + on user.Id equals relevance.FirstId into temp + from r in temp.DefaultIfEmpty() + join org in UnitWork.Find(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(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(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(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)); + }); + + } + + /// + /// 删除用户,包含用户与组织关系、用户与角色关系 + /// + /// + public override void Delete(string[] ids) + { + UnitWork.ExecuteWithTransaction(() => + { + UnitWork.Delete(u =>(u.Key == Define.USERROLE || u.Key == Define.USERORG) + && ids.Contains(u.FirstId)); + UnitWork.Delete(u => ids.Contains(u.Id)); + UnitWork.Save(); + }); + + } + + + /// + /// 修改密码 + /// + /// + public void ChangePassword(ChangePasswordReq request) + { + Repository.Update(u => u.Account == request.Account, user => new User + { + Password = request.Password + }); + } + + /// + /// 获取指定角色包含的用户列表 + /// + /// + /// + public async Task LoadByRole(QueryUserListByRoleReq request) + { + var users = from userRole in UnitWork.Find(u => + u.SecondId == request.roleId && u.Key == Define.USERROLE) + join user in UnitWork.Find(null) on userRole.FirstId equals user.Id into temp + from c in temp.Where(u =>u.Id != null) + select c; + + return new TableData + { + count = users.Count(), + data = users.Skip((request.page - 1) * request.limit).Take(request.limit) + }; + } + + /// + /// 获取指定机构包含的用户列表 + /// + /// + /// + public async Task LoadByOrg(QueryUserListByOrgReq request) + { + var users = from userRole in UnitWork.Find(u => + u.SecondId == request.orgId && u.Key == Define.USERORG) + join user in UnitWork.Find(null) on userRole.FirstId equals user.Id into temp + from c in temp.Where(u =>u.Id != null) + select c; + + return new TableData + { + count = users.Count(), + data = users.Skip((request.page - 1) * request.limit).Take(request.limit) + }; + } + + /// + /// 修改用户资料 + /// + /// + 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 + }); + } + } } \ No newline at end of file diff --git a/OpenAuth.App/Request/AddOrUpdateWmsInboundOrderDtblReq.cs b/OpenAuth.App/WmsInbound/Request/AddOrUpdateWmsInboundOrderDtblReq.cs similarity index 100% rename from OpenAuth.App/Request/AddOrUpdateWmsInboundOrderDtblReq.cs rename to OpenAuth.App/WmsInbound/Request/AddOrUpdateWmsInboundOrderDtblReq.cs diff --git a/OpenAuth.App/Request/AddOrUpdateWmsInboundOrderTblReq.cs b/OpenAuth.App/WmsInbound/Request/AddOrUpdateWmsInboundOrderTblReq.cs similarity index 100% rename from OpenAuth.App/Request/AddOrUpdateWmsInboundOrderTblReq.cs rename to OpenAuth.App/WmsInbound/Request/AddOrUpdateWmsInboundOrderTblReq.cs diff --git a/OpenAuth.App/Request/QueryWmsInboundOrderDtblListReq.cs b/OpenAuth.App/WmsInbound/Request/QueryWmsInboundOrderDtblListReq.cs similarity index 100% rename from OpenAuth.App/Request/QueryWmsInboundOrderDtblListReq.cs rename to OpenAuth.App/WmsInbound/Request/QueryWmsInboundOrderDtblListReq.cs diff --git a/OpenAuth.App/Request/QueryWmsInboundOrderTblListReq.cs b/OpenAuth.App/WmsInbound/Request/QueryWmsInboundOrderTblListReq.cs similarity index 100% rename from OpenAuth.App/Request/QueryWmsInboundOrderTblListReq.cs rename to OpenAuth.App/WmsInbound/Request/QueryWmsInboundOrderTblListReq.cs diff --git a/OpenAuth.App/WmsInboundOrderDtblApp.cs b/OpenAuth.App/WmsInbound/WmsInboundOrderDtblApp.cs similarity index 100% rename from OpenAuth.App/WmsInboundOrderDtblApp.cs rename to OpenAuth.App/WmsInbound/WmsInboundOrderDtblApp.cs diff --git a/OpenAuth.App/WmsInboundOrderTblApp.cs b/OpenAuth.App/WmsInbound/WmsInboundOrderTblApp.cs similarity index 100% rename from OpenAuth.App/WmsInboundOrderTblApp.cs rename to OpenAuth.App/WmsInbound/WmsInboundOrderTblApp.cs diff --git a/OpenAuth.Repository/Domain/FlowInstance.cs b/OpenAuth.Repository/Domain/FlowInstance.cs index c17281a2..a38ed63b 100644 --- a/OpenAuth.Repository/Domain/FlowInstance.cs +++ b/OpenAuth.Repository/Domain/FlowInstance.cs @@ -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; } diff --git a/OpenAuth.Repository/Domain/FlowInstanceTransitionHistory.cs b/OpenAuth.Repository/Domain/FlowInstanceTransitionHistory.cs index 8fc91ac0..ee072169 100644 --- a/OpenAuth.Repository/Domain/FlowInstanceTransitionHistory.cs +++ b/OpenAuth.Repository/Domain/FlowInstanceTransitionHistory.cs @@ -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; diff --git a/OpenAuth.WebApi/Controllers/FlowInstancesController.cs b/OpenAuth.WebApi/Controllers/FlowInstancesController.cs index e7d98253..5472e588 100644 --- a/OpenAuth.WebApi/Controllers/FlowInstancesController.cs +++ b/OpenAuth.WebApi/Controllers/FlowInstancesController.cs @@ -83,6 +83,44 @@ namespace OpenAuth.WebApi.Controllers return result; } + + /// 召回流程 + /// 召回后流程状态为【草稿】状态,可以再次发起流程。所有的流程节点状态还原,但保留审批记录 + [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; + } + + /// 启动流程 + /// 通常是对状态为【草稿】的流程进行操作,进入运行状态 + [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] diff --git a/OpenAuth.WebApi/Program.cs b/OpenAuth.WebApi/Program.cs index ba7cb1e8..b0ffc1d1 100644 --- a/OpenAuth.WebApi/Program.cs +++ b/OpenAuth.WebApi/Program.cs @@ -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(); }