public JsonResult SaveWorkflowPackage(WorkflowPackageViewModel model) { return(ExecuteFunctionRun(() => { ActionResult result = new ActionResult(false); if (this.WorkflowLimit != 0) { int workflowCount = this.Engine.Query.Count(OThinker.H3.WorkflowTemplate.WorkflowClause.TableName, new string[] { OThinker.H3.WorkflowTemplate.WorkflowClause.PropertyName_State + "=" + (int)OThinker.H3.WorkflowTemplate.WorkflowState.Active }); if (workflowCount >= this.WorkflowLimit) { result.Success = false; result.Message = "WorkflowPackage.OverLimit"; return Json(result, JsonRequestBehavior.AllowGet); } } FunctionNodeType nodeType = string.IsNullOrWhiteSpace(model.ObjectType) ? FunctionNodeType.BizWorkflowPackage : (FunctionNodeType)Enum.Parse(typeof(FunctionNodeType), model.ObjectType); if (!Validator(nodeType, model, out result)) { return Json(result, JsonRequestBehavior.AllowGet); } if (nodeType == FunctionNodeType.BizWorkflowPackage) //流程包 { result = SavePackage(model); return Json(result, JsonRequestBehavior.AllowGet); } else //流程 { string code = model.Code.Trim(); if (this.Engine.WorkflowManager.GetDraftTemplate(code) != null) { result.Success = false; result.Message = "WorkflowPackage.Msg8"; return Json(result, JsonRequestBehavior.AllowGet); } int sortKey; Int32.TryParse(model.SortKey, out sortKey); OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetDraftSchema(model.Folder); WorkflowTemplate.WorkflowClause wClause = new WorkflowTemplate.WorkflowClause(model.Folder, code, model.DisplayName, sortKey); wClause.IsShared = schema.IsShared; if (schema.IsQuotePacket) { //使用共享包的,用共享包的模型创建 wClause = new WorkflowTemplate.WorkflowClause(schema.BindPacket, code, model.DisplayName, sortKey); //加自己的标识 wClause.OwnSchemaCode = schema.SchemaCode; } result.Success = this.Engine.WorkflowManager.AddClause(wClause); result.Extend = model.ParentId; } return Json(result, JsonRequestBehavior.AllowGet); })); }
public JsonResult GetWorkflowPackage(string id, string objectType, string parentId, string parentCode) { return(ExecuteFunctionRun(() => { ActionResult result = new ActionResult(); string bizTreeCode = string.Empty; if (!string.IsNullOrEmpty(id)) { var bizTreeNode = this.Engine.FunctionAclManager.GetFunctionNode(id); bizTreeCode = bizTreeNode.Code; BizObjectSchema schema = this.Engine.BizObjectManager.GetDraftSchema(bizTreeNode.Code); if (schema == null) { schema = this.Engine.BizObjectManager.GetPublishedSchema(bizTreeNode.Code); } WorkflowPackageViewModel model = new WorkflowPackageViewModel() { ObjectID = bizTreeNode.ObjectID, Code = bizTreeNode.Code, DisplayName = bizTreeNode.DisplayName, Folder = string.IsNullOrWhiteSpace(parentCode) ? this.Engine.FunctionAclManager.GetFunctionNode(parentId).Code : parentCode, SortKey = bizTreeNode.SortKey.ToString(), StorageType = ((int)schema.StorageType).ToString(), CheckedUser = bizTreeNode.IsLocked ? this.Engine.Organization.GetName(bizTreeNode.LockedBy) : "WorkflowPackage.UnLocked", ParentId = parentId, ObjectType = objectType, IsShared = schema.IsShared, IsQuotePacket = schema.IsQuotePacket, BindPacket = schema.BindPacket }; result.Extend = new { WorkflowPackage = model, Folders = GetFloders(objectType, parentId), CurrentUser = this.UserValidator.UserName }; } else { result.Extend = new { WorkflowPackage = new WorkflowPackageViewModel() { Folder = string.IsNullOrWhiteSpace(parentCode) ? this.Engine.FunctionAclManager.GetFunctionNode(parentId).Code : parentCode, SortKey = "1", StorageType = "0", ParentId = parentId, ObjectType = objectType }, Folders = GetFloders(objectType, parentId) }; } return Json(result.Extend, JsonRequestBehavior.AllowGet); })); }
/// <summary> /// 表单信息验证 /// </summary> /// <param name="NodeType">节点类型</param> /// <param name="model">工作流程信息</param> /// <param name="result">out:验证结果</param> /// <returns>验证是否通过</returns> private bool Validator(FunctionNodeType NodeType, WorkflowPackageViewModel model, out ActionResult result) { result = new ActionResult(); if (string.IsNullOrWhiteSpace(model.Code.Trim()) || string.IsNullOrWhiteSpace(model.DisplayName.Trim())) { result.Success = false; result.Message = "WorkflowPackage.Msg2"; return(false); } if (model.Code.Trim().Replace(" ", string.Empty).Length != model.Code.Trim().Length) { result.Success = false; result.Message = "WorkflowPackage.Msg3"; return(false); } int MaxColeLength = NodeType == FunctionNodeType.BizWorkflowPackage ? BizObjectSchema.MaxCodeLength : FunctionNode.MaxCodeLength; if (model.Code.Trim().Length > MaxColeLength) { result.Success = false; result.Message = "WorkflowPackage.Msg4"; result.Extend = MaxColeLength; } //校验编码规范 System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(BizObjectSchema.CodeRegex); if (!regex.Match(model.Code.Trim()).Success) { result.Success = false; result.Message = "WorkflowPackage.SchemaMsg"; return(false); } if (model.DisplayName.Trim().Length > FunctionNode.MaxNameLength) { result.Success = false; result.Message = "WorkflowPackage.Msg4"; result.Extend = FunctionNode.MaxNameLength; return(false); } return(true); }
/// <summary> /// 保存工作流程信息 /// </summary> /// <param name="model">工作流程信息</param> /// <returns>是否成功</returns> private ActionResult SavePackage(WorkflowPackageViewModel model) { ActionResult result = new ActionResult(); FunctionNode functionNode = new FunctionNode(); if (string.IsNullOrEmpty(model.ObjectID)) { if (!ValidateExist(model.Code, out result)) { return(result); } functionNode.ParentCode = model.Folder; functionNode.Code = model.Code.Trim(); functionNode.NodeType = FunctionNodeType.BizWorkflowPackage; int sortKey; if (Int32.TryParse(model.SortKey, out sortKey)) { functionNode.SortKey = sortKey; } functionNode.DisplayName = model.DisplayName.Trim(); result.Extend = model.Folder; //添加流程包里的数据 result.Success = this.Engine.AppPackageManager.AddAppPackage(functionNode, (StorageType)int.Parse(model.StorageType), model.IsShared, model.IsQuotePacket, model.BindPacket); //使用了共享包,复制共享包的流程模型 if (model.IsQuotePacket) { //复制流程包的流程模板 OThinker.H3.WorkflowTemplate.WorkflowClause[] WorkflowClauses = this.Engine.WorkflowManager.GetClausesBySchemaCode(model.BindPacket); if (null != WorkflowClauses && WorkflowClauses.Length != 0) { //复制所有的父流程模板 WorkflowClauses = WorkflowClauses.Where(s => s.IsShared).ToArray(); for (int i = 0; i < WorkflowClauses.Length; i++) { string workflowClauseCode = i == 0 ? model.Code : model.Code + i; //使用共享包的,用共享包的模型创建 WorkflowTemplate.DraftWorkflowTemplate template = this.Engine.WorkflowManager.GetDraftTemplate(WorkflowClauses[i].WorkflowCode); if (template == null) { continue; } template.WorkflowCode = workflowClauseCode; this.Engine.WorkflowManager.SaveDraftTemplate(this.UserValidator.UserID, template); //添加流程包时已经默认增加了一个流程模板 if (i > 0) { WorkflowTemplate.WorkflowClause wClause = new WorkflowTemplate.WorkflowClause(model.BindPacket, workflowClauseCode, model.DisplayName, WorkflowClauses[i].SortKey); wClause.OwnSchemaCode = model.Code; this.Engine.WorkflowManager.AddClause(wClause); } } } } } else { functionNode = this.Engine.FunctionAclManager.GetFunctionNode(model.ObjectID); int sortKey; if (Int32.TryParse(model.SortKey, out sortKey)) { functionNode.SortKey = sortKey; } functionNode.DisplayName = model.DisplayName.Trim(); string nodeParentId = this.Engine.FunctionAclManager.GetFunctionNodeByCode(functionNode.ParentCode).ObjectID; functionNode.ParentCode = model.Folder; result.Success = this.Engine.FunctionAclManager.UpdateFunctionNode(functionNode) == ErrorCode.SUCCESS; result.Extend = nodeParentId; } return(result); }