public void Remove(FlowNodeData model) { if (model == null) { return; } DB.FlowNodeDatas.Remove(model); DB.SaveChanges(); }
public void Submit(FlowNodeData model) { var entity = DB.FlowNodeDatas.FirstOrDefault(e => e.ID == model.ID); entity.Content = model.Content; entity.UpdateTime = DateTime.Now; entity.Result = model.Result; DB.SaveChanges(); }
public bool CanSubmit(FlowData flowData, FlowNodeData flowNodeData) { if (flowData.Completed) { return(false); } if (flowData.Nodes == null || flowData.Nodes.Count == 0) { return(true); } return(flowNodeData != null && Core.FlowNodeDataManager.CanSubmit(flowNodeData)); }
public bool CanCancel(FlowData flowData, FlowNodeData flowNodeData) { if (flowNodeData == null || !flowNodeData.Submited) { return(false); } //var childNodeData = flowData.Nodes.OrderBy(e => e.ID).FirstOrDefault(e => e.ParentId == flowNodeData.ID); //if (childNodeData != null) //{ // return false; //} var nextNodeData = flowData.GetNextNodeData(flowNodeData.ID); //否则判断当前步骤的下一步是否已经提交,如果提交,则不能撤回 return(nextNodeData == null || (!nextNodeData.HasChanged() && !flowData.Nodes.Any(e => e.ParentId == nextNodeData.ID))); }
public FlowNodeData CreateBackNodeData(FlowNodeData backNodeData) { var user = Core.UserManager.GetModel(backNodeData.UserId); var model = new FlowNodeData { CreateTime = DateTime.Now, FlowDataId = backNodeData.FlowDataId, Signature = user.RealName, UserId = user.ID, FlowNodeId = backNodeData.FlowNodeId, FlowNodeName = backNodeData.FlowNodeName, }; Core.FlowNodeDataManager.Save(model); return(model); }
public void Save(FlowNodeData model) { if (model.ID > 0) { var entity = DB.FlowNodeDatas.FirstOrDefault(e => e.ID == model.ID); entity.Result = model.Result; entity.UpdateTime = model.Result.HasValue ? DateTime.Now : default(DateTime?); entity.Content = model.Content; model = entity; } else { DB.FlowNodeDatas.Add(model); } DB.SaveChanges(); }
public FlowNodeData CreateNodeData(int flowDataId, FlowNode flowNode, int toUserId, int extendId = 0) { if (flowNode == null) { throw new Exception("流程配置不正确,请停止提交并联系管理员"); } var toUser = Core.UserManager.GetModel(toUserId) ?? new User(); var model = new FlowNodeData { FlowNodeId = flowNode.ID, FlowNodeName = flowNode.Name, Signature = toUser.RealName, UserId = toUser.ID, FlowDataId = flowDataId, ExtendId = extendId }; Core.FlowNodeDataManager.Save(model); return(model); }
public FlowNodeData CreateChildNodeData(FlowNodeData parent, int toUserId, int extendId = 0) { if (toUserId == 0) { throw new Exception("没有选择发送人"); } var user = Core.UserManager.GetModel(toUserId); var model = new FlowNodeData { FlowNodeId = parent.FlowNodeId, FlowNodeName = parent.FlowNodeName, Signature = user.RealName, UserId = user.ID, FlowDataId = parent.FlowDataId, ParentId = parent.ID, ExtendId = extendId }; Core.FlowNodeDataManager.Save(model); return(model); }
public bool CanSubmit(FlowNodeData model) { var result = !model.Result.HasValue; if (!result && model.FreeFlowData != null) { result = model.FreeFlowData.Completed; } if (!result) { var children = DB.FlowNodeDatas.Where(e => e.ParentId == model.ID); foreach (var child in children) { result = CanSubmit(child); if (!result) { break; } } } return(result); }
//public void Submit(int infoId, int userId, int toUserId, bool result, string content) //{ // var info = Core.FormInfoManager.GetModel(infoId); // if (info == null) // { // throw new ArgumentException("参数错误,找不到FormInfo"); // } // if (info.FlowDataId == 0) // { // var form = Core.FormManager.GetModel(info.FormId); // //创建流程 // info.FlowData = Create(form.FLowId, info); // info.FlowDataId = info.FlowData.ID; // } // var currentNodeData = info.FlowData.GetLastNodeData(userId); // if (currentNodeData.Result.HasValue) // { // throw new Exception("无法提交"); // } // currentNodeData.Content = content; // currentNodeData.Result = result; // Core.FlowNodeDataManager.Save(currentNodeData); // //更新userforminfo的状态 // Core.UserFormInfoManager.Save(new UserFormInfo // { // FormId = info.FormId, // InfoId = info.ID, // Status = FlowStatus.Done, // UserId = userId, // FlowNodeDataId = currentNodeData.ID // }); // //创建下一步节点 // var flow = Core.FlowManager.Get(info.Form.FLowId); // if (currentNodeData.Result == true) // { // //判断是否流程结束 // if (!info.FlowData.CanComplete(currentNodeData)) // { // var toUser = Core.UserManager.GetModel(toUserId); // var nextNodedata = Core.FlowNodeDataManager.CreateNextNodeData(info, toUser, currentNodeData.FlowNodeId); // info.FlowStep = nextNodedata.FlowNodeName; // Core.UserFormInfoManager.Save(new UserFormInfo // { // FormId = info.FormId, // InfoId = info.ID, // Status = FlowStatus.Doing, // UserId = nextNodedata.UserId, // FlowNodeDataId = nextNodedata.ID, // }); // Core.FeedManager.Save(new Feed // { // InfoId = info.ID, // Action = UserAction.Submit, // FromUserId = currentNodeData.UserId, // ToUserId = nextNodedata.UserId, // Type = FeedType.Flow, // Title = info.Title, // Description = currentNodeData.Content // }); // } // else // { // Core.FlowDataManager.Complete(info); // var userIds = Core.UserFormInfoManager.GetUserIds(infoId); // foreach (var uid in userIds) // { // Core.FeedManager.Save(new Feed // { // InfoId = info.ID, // Action = UserAction.Submit, // FromUserId = currentNodeData.UserId, // ToUserId = uid, // Type = FeedType.Flow, // Title = info.Title, // Description = currentNodeData.Content // }); // } // } // } // else if (flow.CanBack) // { // var firstNodeData = info.FlowData.GetFirstNodeData(); // var nextNodeData = Core.FlowNodeDataManager.CreateBackNodeData(info, firstNodeData); // info.FlowStep = nextNodeData.FlowNodeName; // Core.UserFormInfoManager.Save(new UserFormInfo // { // InfoId = info.ID, // FormId = info.FormId, // UserId = nextNodeData.UserId, // Status = FlowStatus.Back, // FlowNodeDataId = nextNodeData.ID, // }); // } // else // { // //如果不可以退回,则直接结束流程 // info.FlowData.Completed = true; // Core.FlowDataManager.Save(info.FlowData); // } //} public void Cancel(FlowData flowData, FlowNodeData nodeData) { var nextNodeData = flowData.GetNextNodeData(nodeData.ID); if (nextNodeData != null) { DB.FlowNodeDatas.Remove(nextNodeData); } else { flowData.Completed = false; } nodeData.UpdateTime = null; nodeData.Result = null; DB.SaveChanges(); var infoId = flowData.InfoId; var toUserId = nextNodeData.UserId; var fromUserId = nodeData.UserId; if (nextNodeData != null) { Core.UserFormInfoManager.Remove(infoId, toUserId); Core.FeedManager.Delete(new Feed { InfoId = infoId, FromUserId = fromUserId, ToUserId = toUserId }); } Core.UserFormInfoManager.Save(new UserFormInfo { InfoId = infoId, UserId = fromUserId, FlowStatus = FlowStatus.Doing }); }
public FlowNodeData SubmitToBack(FlowData flowData, FlowNodeData currentNodeData) { var prevNodeData = flowData.GetPrevNodeData(currentNodeData); return(Core.FlowNodeDataManager.CreateBackNodeData(prevNodeData)); }
public bool CanComplete(Flow flow, FlowNodeData data) { var lastNode = flow.GetLastNode(); return(lastNode.ID == data.FlowNodeId || lastNode.CanSkip); }
public IHttpActionResult Submit([FromBody] FlowNodeData data, int infoId, int nextFlowNodeId = 0, int toUserId = 0) { var info = Core.FormInfoManager.GetModel(infoId); if (info == null) { return(BadRequest("参数错误,找不到FormInfo")); } if (info.FlowDataId == 0) { throw new Exception("该信息还是草稿状态,无法提交"); } var currentNodeData = Core.FlowNodeDataManager.GetModel(data.ID); if (currentNodeData == null || currentNodeData.UserId != Identity.ID) { return(BadRequest("参数错误,找不到当前流程")); } if (currentNodeData.Result.HasValue) { return(BadRequest("无法提交")); } currentNodeData.Content = data.Content; currentNodeData.Result = data.Result; Core.FlowNodeDataManager.Save(currentNodeData); //更新userforminfo的状态 Core.UserFormInfoManager.Save(new UserFormInfo { InfoId = info.ID, FlowStatus = FlowStatus.Done, UserId = Identity.ID, }); if (currentNodeData.Result == true) { //判断是否流程结束 if (!Core.FlowDataManager.CanComplete(info.FlowData.Flow, currentNodeData)) { var nextNodedata = Core.FlowDataManager.SubmitToUser(info.FlowData, toUserId, nextFlowNodeId); info.FlowStep = nextNodedata.FlowNodeName; Core.UserFormInfoManager.Save(new UserFormInfo { InfoId = info.ID, FlowStatus = FlowStatus.Doing, UserId = nextNodedata.UserId, }); var feed = new Feed { InfoId = info.ID, Action = UserAction.Submit, FromUserId = currentNodeData.UserId, ToUserId = nextNodedata.UserId, Type = FeedType.Flow, Title = info.Title, Description = currentNodeData.Content }; Core.FeedManager.Save(feed); Core.MessageManager.Add(feed); } else { Core.FlowDataManager.Complete(info); var userIds = Core.UserFormInfoManager.GetUserIds(infoId); foreach (var uid in userIds) { var feed = new Feed { InfoId = info.ID, Action = UserAction.Submit, FromUserId = currentNodeData.UserId, ToUserId = uid, Type = FeedType.Flow, Title = info.Title, Description = currentNodeData.Content }; Core.FeedManager.Save(feed); } Core.MessageManager.Add(new Message { Content = info.Title, InfoId = info.ID, CreatorId = currentNodeData.UserId }, userIds); } } else { var flow = Core.FlowManager.Get(info.Form.FLowId); if (flow.CanBack) { var backNodeData = Core.FlowDataManager.SubmitToBack(info.FlowData, currentNodeData); info.FlowStep = backNodeData.FlowNodeName; Core.UserFormInfoManager.Save(new UserFormInfo { InfoId = info.ID, UserId = backNodeData.UserId, FlowStatus = FlowStatus.Back, }); var feed = new Feed { Action = UserAction.Submit, Type = FeedType.Flow, InfoId = info.ID, FromUserId = Identity.ID, ToUserId = backNodeData.UserId, Title = "[退回流程]" + info.Title, }; Core.FeedManager.Save(feed); Core.MessageManager.Add(feed); } else { //如果不可以退回,则直接结束流程 info.FlowData.Completed = true; Core.FlowDataManager.Save(info.FlowData); } } return(Ok(data)); }
public FlowNodeData CreateNextNodeData(FlowNodeData currentNodeData, int toUserId, int extendId = 0) { var flowNode = Core.FlowNodeManager.GetNextNode(currentNodeData.FlowNodeId); return(CreateNodeData(currentNodeData.FlowDataId, flowNode, toUserId, extendId)); }
public object Model(int id) { var model = Core.FormInfoManager.GetModel(id); if (model == null) { return(BadRequest("参数错误")); } var canView = Core.FormInfoManager.CanView(model, CurrentUser); if (!canView) { return(BadRequest("您没有权限查看该文档")); } var canSubmitFlow = true; var canEdit = true; var canCancel = false; var canSubmitFreeFlow = false; var canCompleteFreeFlow = false; var canComplete = false; var canBack = false; FlowNodeData lastNodeData = null; FreeFlowNodeData freeFlowNodeData = null; if (model.FlowDataId > 0) { var flowData = model.FlowData ?? Core.FlowDataManager.Get(model.FlowDataId); var currentFlowNodeData = flowData.GetUserLastNodeData(Identity.ID); canSubmitFlow = Core.FlowDataManager.CanSubmit(model.FlowData, currentFlowNodeData); canEdit = canSubmitFlow; canCancel = Core.FlowDataManager.CanCancel(flowData, currentFlowNodeData); lastNodeData = model.FlowData.GetLastNodeData(); canComplete = Core.FlowDataManager.CanComplete(flowData.Flow, lastNodeData); canEdit = lastNodeData.UserId == Identity.ID && !lastNodeData.Result.HasValue; //当前步骤如果是流程的第一步,则不能退 canBack = Core.FlowDataManager.CanBack(flowData); //如果该步骤开启了自由流程 freeFlowNodeData = lastNodeData.GetLastFreeNodeData(Identity.ID); canSubmitFreeFlow = Core.FreeFlowDataManager.CanSubmit(flowData, Identity.ID); var user = Core.UserManager.GetModel(Identity.ID); canCompleteFreeFlow = Core.FreeFlowDataManager.CanComplete(flowData, user); } var userformInfo = Core.UserFormInfoManager.GetModel(model.ID, Identity.ID); return(new { model, canView, canEdit, canSubmit = canSubmitFlow || canSubmitFreeFlow, canSubmitFlow, canSubmitFreeFlow, canCompleteFreeFlow, canCancel, canComplete, canBack, status = userformInfo == null ? FlowStatus.Done : userformInfo.FlowStatus, flowNodeData = lastNodeData, freeFlowNodeData }); }