public virtual object Process(HttpContext context) { YZRequest request = new YZRequest(context); int stepid = request.GetInt32("StepID"); string uid = request.GetString("uid", YZAuthHelper.LoginUserAccount); //共享任务uid为空,会导致重定向到登录页面,产生异常 using (BPMConnection cn = new BPMConnection()) { string orguid = YZAuthHelper.LoginUserAccount; YZAuthHelper.SetAuthCookie(uid); try { cn.WebOpen(); } finally { YZAuthHelper.SetAuthCookie(orguid); } ProcessInfo processInfo = BPMProcess.GetProcessInfo(cn, stepid); if (processInfo.Links.Count == 0) { throw new BPMException(BPMExceptionType.MissOutLink, processInfo.NodeName); } string postXml = @"{0} <XForm> <Header> <Method>Process</Method> <PID>{1}</PID> <Action>{2}</Action> <Comment></Comment> </Header> <FormData> </FormData> </XForm>"; postXml = String.Format(postXml, "<?xml version=\"1.0\"?>", stepid, YZUtility.EncodeXMLInnerText(processInfo.Links[0].DisplayString)); using (MemoryStream postStream = new MemoryStream(Encoding.UTF8.GetBytes(postXml))) { PostResult postResult = BPMProcess.Post(cn, postStream); return(new { success = true, result = (postResult.PostResultType == PostResultType.TaskFinishedApproved || postResult.PostResultType == PostResultType.TaskFinishedRejected) ? "finished" : "running" }); } } }
public virtual JObject GetProcessInfo(HttpContext context) { YZRequest request = new YZRequest(context); int stepid = request.GetInt32("pid"); string permisions = request.GetString("Permisions", null); using (BPMConnection cn = new BPMConnection()) { cn.WebOpen(); BPMProcStep step = BPMProcStep.Load(cn, stepid); BPMTask task = BPMTask.Load(cn, step.TaskID); ProcessInfo processInfo = BPMProcess.GetProcessInfo(cn, stepid); //检查处理权 if (!step.Share || !String.IsNullOrEmpty(step.OwnerAccount)) //常规任务及已获取的共享任务 { if (!NameCompare.EquName(step.OwnerAccount, cn.UID) && !NameCompare.EquName(step.AgentAccount, cn.UID)) { throw new BPMException(BPMExceptionType.ProcessErrPermDenied); } } //获得ProcessSubModel ProcessSubModel subModel; if (step.Share && String.IsNullOrEmpty(step.OwnerAccount)) { subModel = ProcessSubModel.Share; } else { if (processInfo.StepProcessPermision == StepProcessPermision.Inform) { subModel = ProcessSubModel.Inform; } else if (processInfo.StepProcessPermision == StepProcessPermision.Indicate) { subModel = ProcessSubModel.Indicate; } else { subModel = ProcessSubModel.Process; } } //ProcessSubModel.Process - 则获得任务操作权限 JObject perm = null; if (subModel == ProcessSubModel.Process || subModel == ProcessSubModel.Inform || subModel == ProcessSubModel.Indicate) { perm = this.CheckPermision(cn, step.TaskID, stepid, permisions); } else { perm = new JObject(); } if (String.IsNullOrEmpty(processInfo.FormFile)) { throw new Exception(String.Format(Resources.YZStrings.Aspx_Process_MissForm, step.NodeName)); } JObject rv = new JObject(); rv[YZJsonProperty.success] = true; rv["uid"] = cn.UID; rv["subModel"] = subModel.ToString(); rv["sn"] = task.SerialNum; rv["taskid"] = task.TaskID; rv["urlParams"] = task.UrlParams; rv["url"] = YZUtility.GetFormRedirectUrl(processInfo.FormFile).ToString(); rv["NodePermisions"] = this.Serialize(processInfo.NodePermision); rv["Comments"] = step.Comments; rv["perm"] = perm; if (subModel == ProcessSubModel.Process) { rv["shareTask"] = step.Share; rv["IsConsign"] = step.IsConsignStep; JArray links = new JArray(); rv["links"] = links; foreach (Link link in processInfo.Links) { links.Add(this.Serialize(link, "normal")); } rv["directsend"] = this.GetDirectSendInfo(cn, step, processInfo.SystemLinks); //自由流 if (!step.IsConsignStep) //加签不显示自由流 { rv["ParticipantDeclares"] = JArray.FromObject(processInfo.ParticipantDeclares); rv["Routing"] = processInfo.Routing; } } return(rv); } }
private JObject GetFormInfo(BPMConnection cn, string UserAccount, int TaskID, int StepID) { FlowDataSet formData = null; BPMTask task = null; string FormXml = ""; //获取表单名称 JObject rv = new JObject(); //最终组合的 JArray TaskCommList = new JArray(); rv["TaskCommList"] = TaskCommList; JArray FormInfo = new JArray(); rv["FormInfo"] = FormInfo; JArray ButtonList = new JArray(); rv["ButtonList"] = ButtonList; if (StepID < 0) { BPMStepCollection Steps = BPM.Client.BPMTask.GetAllSteps(cn, TaskID); foreach (BPM.Client.BPMProcStep item in Steps) { if (item.NodeName.Equals("开始")) { StepID = item.StepID; break; } } } //按钮开始 BPM.Client.ProcessInfo processInfo = BPM.Client.BPMProcess.GetProcessInfo(cn, StepID); BPMTask bt = BPMTask.Load(cn, TaskID); JObject TaskComm = new JObject(); TaskCommList.Add(TaskComm); TaskComm["TaskID"] = bt.TaskID; TaskComm["ParentStepID"] = bt.ParentStepID; TaskComm["SerialNum"] = bt.SerialNum; TaskComm["ProcessName"] = bt.ProcessName; TaskComm["ApplicantAccount"] = bt.ApplicantAccount; TaskComm["AgentAccount"] = bt.AgentAccount; TaskComm["AgentDisplayName"] = bt.AgentDisplayName; TaskComm["AgentDisplayName"] = bt.AgentDisplayName; TaskComm["OwnerAccount"] = bt.OwnerAccount; TaskComm["OwnerDisplayName"] = bt.OwnerDisplayName; TaskComm["OwnerFullName"] = bt.OwnerFullName; TaskComm["CreateAt"] = bt.CreateAt; TaskComm["FinishAt"] = bt.FinishAt; TaskComm["OptAt"] = bt.OptAt; TaskComm["OptUser"] = bt.OptUser; TaskComm["OptMemo"] = bt.OptMemo; //TaskComm["Description"] = bt.Description; // TaskComm["ReturnToParent"] = bt.ReturnToParent; TaskComm["TaskState"] = bt.TaskState.ToString(); TaskComm["State"] = bt.State.ToString(); if (IsCurrentStep(cn, UserAccount, StepID, TaskID) && bt.TaskState.ToString().Equals("Running", StringComparison.OrdinalIgnoreCase)) { BPM.Client.LinkCollection links = processInfo.Links;//提交按钮 foreach (Link link in links) { JObject button = new JObject(); ButtonList.Add(button); string s = link.DisplayString; button["Text"] = s; button["Action"] = s; button["Type"] = "Post"; } bool canReject = (processInfo.NodePermision & NodePermision.Reject) == NodePermision.Reject;//拒绝按钮 if (canReject) { JObject button = new JObject(); ButtonList.Add(button); button["Text"] = "拒绝"; button["Action"] = "Reject"; button["Type"] = "Reject"; } bool canTransfer = (processInfo.NodePermision & NodePermision.Transfer) == NodePermision.Transfer;//委托按钮 if (canTransfer) { JObject button = new JObject(); ButtonList.Add(button); button["Text"] = "委托"; button["Action"] = "Transfer"; button["Type"] = "Transfer"; } bool canConsign = (processInfo.NodePermision & NodePermision.Consign) == NodePermision.Consign;//加签按钮 if (canConsign) { string s = links[0].DisplayString; JObject button = new JObject(); ButtonList.Add(button); button["Text"] = "加签"; button["Action"] = s; button["Type"] = "Consign"; } bool canRecedeBack = (processInfo.NodePermision & NodePermision.RecedeBack) == NodePermision.RecedeBack;//退回重填按钮 if (canRecedeBack) { JObject button = new JObject(); ButtonList.Add(button); button["Text"] = "退回某步"; button["Action"] = "RecedeBack"; button["Type"] = "RecedeBack"; } bool recedeRestart = (processInfo.NodePermision & NodePermision.RecedeRestart) == NodePermision.RecedeRestart;//退回重填 BPMProcStep stepLoad = BPMProcStep.Load(cn, StepID); int idx = processInfo.SystemLinks.Find(SystemLinkType.DirectSend); if (stepLoad.RecedeFromStep != -1 && idx != -1 && processInfo.SystemLinks[idx].Enabled) { BPMStepCollection directSendToSteps = BPMProcStep.LoadPrevSteps(cn, StepID); BPMObjectNameCollection stepNames = new BPMObjectNameCollection(); foreach (BPMProcStep step in directSendToSteps) { if (step.IsHumanStep) { stepNames.Add(step.NodeName + ":" + YZStringHelper.GetUserFriendlyName(step.RecipientAccount, step.RecipientFullName)); string buttonText = "直送->" + stepNames.ToStringList(';'); JObject button = new JObject(); ButtonList.Add(button); button["Text"] = buttonText; button["Action"] = "DirectSend"; button["Type"] = "DirectSend"; } } } } //按钮结束 FormXml = processInfo.FormFile; //获取表单数据 formData = BPMProcess.GetFormData(cn, StepID); if (formData.Tables.Count == 0) { throw new Exception("获取表单数据失败"); } //初始化布局文件 task = BPMTask.Load(cn, TaskID); if (task == null) { throw new Exception("通过TaskID获取任务失败"); } //int startIndex=FormXml.LastIndexOf(@"\"); //int endIndex=FormXml.LastIndexOf(".aspx"); // FormXml = FormXml.Substring(startIndex+1, endIndex - startIndex-1); FormXml = FormXml.Replace(".aspx", ""); FormXml = FormXml.Replace("\\", "("); //throw new Exception(FormXml); XmlDocument layoutDoc = new XmlDocument(); string layoutFilePath = HttpContext.Current.Server.MapPath(String.Format("~/FormLayout/{0}.xml", FormXml)); string debugger = ""; if (System.IO.File.Exists(layoutFilePath)) { layoutDoc.Load(layoutFilePath); XmlNodeList layoutTables = layoutDoc.SelectNodes("Layout/Table"); foreach (XmlNode layoutTable in layoutTables) { string TableID = TryGetNodeAttribute(layoutTable, "ID"); //测试报文中Table是否与流程中的Table匹配 debugger += "[TableID]" + TableID; foreach (FlowDataTable item in formData.Tables) { debugger += "[TableName]" + item.TableName; } // FlowDataTable formDataTable = formData.Tables[TableID]; try { if (formDataTable != null) { JObject bwTable = new JObject(); FormInfo.Add(bwTable); bwTable["TableName"] = TableID; bwTable["DisplayName"] = TryGetNodeAttribute(layoutTable, "Name"); bwTable["IsRepeatable"] = formDataTable.IsRepeatableTable; JArray bwRows = new JArray(); bwTable["Rows"] = bwRows; foreach (FlowDataRow formDataRow in formDataTable.Rows) { JObject bwRow = new JObject(); bwRows.Add(bwRow); XmlNodeList layoutColumns = layoutTable.ChildNodes; int i = 0; foreach (XmlNode layoutColumn in layoutColumns) { //debugger += "**" + TryGetNodeAttribute(layoutColumn, "Type") + "**"; if (!string.IsNullOrEmpty(TryGetNodeAttribute(layoutColumn, "Type")) && TryGetNodeAttribute(layoutColumn, "Type").Equals("Attachment", StringComparison.OrdinalIgnoreCase)) { JObject bwColumn = new JObject(); bwRow["Attachments_" + layoutColumn.Name] = bwColumn; bwColumn["Name"] = TryGetNodeAttribute(layoutColumn, "Name"); string FileID = Convert.ToString(formDataRow[layoutColumn.Name]); //调用方法获取附件名称,附件路径 JObject Attachments = GetAttachments(FileID); JArray bwAttachments = new JArray(); bwColumn["Items"] = bwAttachments; foreach (JObject item in JTokenToJArray(Attachments["files"])) { JObject attachment1 = new JObject(); bwAttachments.Add(attachment1); attachment1["FileName"] = item["name"]; attachment1["DownloadUrl"] = item["DownloadUrl"]; } i++; } else { JObject bwColumn = new JObject(); bwRow[layoutColumn.Name] = bwColumn; bwColumn["DataType"] = TryGetNodeAttribute(layoutColumn, "DataType"); bwColumn["DataFormat"] = TryGetNodeAttribute(layoutColumn, "DataFormat"); bwColumn["Order"] = TryGetNodeAttribute(layoutColumn, "Order"); bwColumn["Name"] = TryGetNodeAttribute(layoutColumn, "Name"); bwColumn["Value"] = Convert.ToString(formDataRow[layoutColumn.Name]); } } } } } catch (Exception e) { throw new Exception(debugger + "---------" + e.Message); } } } else { //throw new Exception(String.Format("流程[{0}]没有布局文件[{1}]", task.ProcessName, layoutFilePath)); } return(rv); }