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;
                    OThinker.Reporting.ReportPage schema = this.Engine.ReportManager.GetReportPage(bizTreeNode.Code);
                    if (schema == null)
                    {
                        schema = this.Engine.ReportManager.GetReportPage(bizTreeNode.Code);
                    }
                    ReportPagePackageViewModel report = new ReportPagePackageViewModel()
                    {
                        ObjectID = bizTreeNode.ObjectID,
                        Code = bizTreeNode.Code,
                        DisplayName = bizTreeNode.DisplayName,
                        Folder = bizTreeNode.ParentCode,
                        SortKey = bizTreeNode.SortKey.ToString(),

                        CheckedUser = bizTreeNode.IsLocked ? this.Engine.Organization.GetName(bizTreeNode.LockedBy) : "Reporting.UnLocked",
                        ParentId = parentId,
                        ObjectType = objectType
                    };

                    result.Extend = new
                    {
                        WorkflowPackage = report,
                        Folders = GetFloders(objectType, parentId)
                    };
                }
                else
                {
                    result.Extend = new
                    {
                        WorkflowPackage = new ReportPagePackageViewModel()
                        {
                            Folder = string.IsNullOrWhiteSpace(parentCode) ? this.Engine.FunctionAclManager.GetFunctionNode(parentId).Code : parentCode,
                            SortKey = "1",
                            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, ReportPagePackageViewModel model, out ActionResult result)
        {
            result = new ActionResult();
            if (string.IsNullOrWhiteSpace(model.Code.Trim()) ||
                string.IsNullOrWhiteSpace(model.DisplayName.Trim()))
            {
                result.Success = false;
                result.Message = "Reporting.Msg2";
                return(false);
            }
            if (model.Code.Trim().Replace(" ", string.Empty).Length != model.Code.Trim().Length)
            {
                result.Success = false;
                result.Message = "Reporting.Msg3";
                return(false);
            }

            int MaxColeLength = NodeType == FunctionNodeType.BizWorkflowPackage ? BizObjectSchema.MaxCodeLength : FunctionNode.MaxCodeLength;

            if (model.Code.Trim().Length > MaxColeLength)
            {
                result.Success = false;
                result.Message = "Reporting.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 = "Reporting.SchemaMsg";
                return(false);
            }

            if (model.DisplayName.Trim().Length > FunctionNode.MaxNameLength)
            {
                result.Success = false;
                result.Message = "Reporting.Msg4";
                result.Extend  = FunctionNode.MaxNameLength;
                return(false);
            }
            return(true);
        }
        public JsonResult SaveWorkflowPackage(ReportPagePackageViewModel model)
        {
            return(ExecuteFunctionRun(() =>
            {
                ActionResult result = new ActionResult();

                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.ReportFolder) //报表页
                {
                    result = SavePackage(model);
                    return Json(result, JsonRequestBehavior.AllowGet);
                }
                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }
        /// <summary>
        /// 保存报表数据到function
        /// </summary>
        /// <param name="model">工作流程信息</param>
        /// <returns>是否成功</returns>
        private ActionResult SavePackage(ReportPagePackageViewModel 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.ReportFolderPage;
                functionNode.IconCss    = "fa icon-charubiaoge";
                int sortKey;
                if (Int32.TryParse(model.SortKey, out sortKey))
                {
                    functionNode.SortKey = sortKey;
                }
                functionNode.DisplayName = model.DisplayName.Trim();
                functionNode.Url         = "Reporting/IndexInfo.html&RportCode=" + model.Code.Trim();
                if (model.Folder == "ReportModel")
                {
                    FunctionNode fun = this.Engine.FunctionAclManager.GetFunctionNodeByCode(model.Folder);
                    if (fun != null)
                    {
                        result.Extend = fun.ObjectID;
                    }
                }
                else
                {
                    result.Extend = model.ParentId;
                }

                //添加功能节点
                result.Success = this.Engine.FunctionAclManager.AddFunctionNode(functionNode) == ErrorCode.SUCCESS;
                string code = model.Code.Trim();
                //新增报表页
                OThinker.Reporting.ReportPage report = new OThinker.Reporting.ReportPage();
                report.ObjectID           = Guid.NewGuid().ToString();
                report.Code               = code;
                report.Creator            = this.UserValidator.UserID;
                report.DisplayName        = model.DisplayName;
                report.CreatedTime        = DateTime.Now;
                report.ParentObjectID     = model.ParentId;
                report.ParentPropertyName = "";
                if (result.Success == true)
                {
                    result.Success = this.Engine.ReportManager.AddReportPage(report);
                }
            }
            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);
        }