private void ParseParams(string instanceId, string itemName, string workItemID) { // 基本参数 this.InstanceId = instanceId; this.ItemName = System.Web.HttpUtility.UrlDecode(itemName); this.WorkItemID = workItemID; // 验证参数 if (string.IsNullOrEmpty(this.InstanceId) && string.IsNullOrEmpty(this.WorkItemID)) { throw new ArgumentNullException("Param InstanceId and WorkItemID can NOT be null at the same time."); } // 获得流程或者任务对象 if (!string.IsNullOrEmpty(this.InstanceId)) { this.InstanceContext = this.Engine.InstanceManager.GetInstanceContext(this.InstanceId); if (this.InstanceContext == null) { throw new ArgumentNullException("InstanceID invalid."); } } if (!string.IsNullOrEmpty(this.WorkItemID)) { this.WorkItem = this.Engine.WorkItemManager.GetWorkItem(this.WorkItemID); this.CirculateItem = this.Engine.WorkItemManager.GetCirculateItem(this.WorkItemID); if (this.WorkItem == null && this.CirculateItem == null) { throw new ArgumentNullException("WorkItemID invalid."); } } // 获得流程模板 this.Workflow = this.Engine.WorkflowManager.GetPublishedTemplate(this.InstanceContext.WorkflowCode, this.InstanceContext.WorkflowVersion); // this.Workflow = this.Engine.WorkflowManager.GetWorkflow(this.InstanceContext.WorkflowPackage, this.InstanceContext.WorkflowName, this.InstanceContext.WorkflowVersion); if (this.Workflow == null) { throw new ArgumentNullException("Workflow Template invalid."); } // 获得数据定义 this.WorkflowDataItems = this.Engine.BizObjectManager.GetPublishedSchema(this.Workflow.BizObjectSchemaCode).Properties; //this.Workflow.GetDataItem(this.ItemName); foreach (DataModel.PropertySchema p in this.WorkflowDataItems) { if (this.ItemName == p.Name) { this.WorkflowDataItem = p; break; } } if (this.WorkflowDataItem == null) { throw new ArgumentNullException("Workflow Data Item invalid."); } }
/// <summary> /// 创建一个新的流程实例 /// </summary> /// <param name="Engine">流程引擎</param> /// <param name="BizObjectId">业务对象ID</param> /// <param name="Workflow">流程模板</param> /// <param name="Schema">数据模型结构</param> /// <param name="InstanceId">流程实例ID</param> /// <param name="Originator">发起人</param> /// <param name="OriginatedGroup">发起人选择的身份,可以为空,如果为空,则表示不以任何组成员的身份发起流程</param> /// <param name="OriginatedPost">发起人所在的岗位,可以为空,如果为空,则表示不以任何岗位的身份发起流程</param> /// <param name="InstanceName">流程实例名称</param> /// <param name="OriginatingInstance">发起流程的事件接口</param> /// <param name="ParameterTable">发起流程的参数表</param> /// <param name="Request">HttpRequest</param> /// <param name="WorkItemId">工作任务ID</param> /// <param name="ErrorMessage">错误消息</param> /// <returns>返回创建流程是否成功</returns> public static bool OriginateInstance( IEngine Engine, string BizObjectId, WorkflowTemplate.PublishedWorkflowTemplate Workflow, DataModel.BizObjectSchema Schema, ref string InstanceId, string Originator, string OriginatedJob, string InstanceName, EventHandler <OriginateInstanceEventArgs> OriginatingInstance, Dictionary <string, object> ParameterTable, System.Web.HttpRequest Request, ref string WorkItemId, ref string ErrorMessage) { return(OriginateInstance( Engine, BizObjectId, Workflow, Schema, ref InstanceId, Originator, OriginatedJob, InstanceName, Instance.PriorityType.Normal, OriginatingInstance, ParameterTable, Request, ref WorkItemId, ref ErrorMessage, false)); }
public JsonResult GetParticipants(string ActivityCode, string InstanceID) { return(ExecuteFunctionRun(() => { if (!string.IsNullOrEmpty(ActivityCode) && !string.IsNullOrEmpty(InstanceID)) { //流程 Instance.InstanceContext InstanceContext = this.Engine.InstanceManager.GetInstanceContext(InstanceID); if (InstanceContext != null) { //流程模板 WorkflowTemplate.PublishedWorkflowTemplate Template = this.Engine.WorkflowManager.GetPublishedTemplate( InstanceContext.WorkflowCode, InstanceContext.WorkflowVersion); if (Template != null) { //活动信息 ClientActivityBase Activity = Template.GetActivityByCode(ActivityCode) as ClientActivityBase; OThinker.H3.Instance.InstanceData InstanceData = new Instance.InstanceData(this.Engine, InstanceID, null); string[] ParticipantIDs = Activity.ParseParticipants(InstanceData, this.Engine.Organization); OThinker.Organization.Unit[] ParticipantUsers = this.Engine.Organization.GetUnits(ParticipantIDs).ToArray(); if (ParticipantUsers != null) { List <object> ParticipantUserNames = new List <object>(); foreach (OThinker.Organization.Unit u in ParticipantUsers) { if (u != null && u.UnitType == OThinker.Organization.UnitType.User) { OThinker.Organization.User user = (OThinker.Organization.User)u; ParticipantUserNames.Add(new { Name = user.Name, Code = user.Code, ObjectID = user.ObjectID }); //ParticipantUserNames.Add(u.Name + "[" + u.Code + "]"); } } return Json(ParticipantUserNames, JsonRequestBehavior.AllowGet); } } } } return Json(new string[] { }, JsonRequestBehavior.AllowGet); })); }
/// <summary> /// 给工作项添加审批意见 /// </summary> /// <param name="item">工作项</param> /// <param name="approval">审批结果</param> /// <param name="commentText">审批意见</param> private void AppendComment(OThinker.H3.Instance.InstanceContext Instance, OThinker.H3.WorkItem.WorkItem item, OThinker.Data.BoolMatchValue approval, string commentText) { // 添加一个审批意见 WorkflowTemplate.PublishedWorkflowTemplate workflow = this.Engine.WorkflowManager.GetPublishedTemplate( item.WorkflowCode, item.WorkflowVersion); // 审批字段 string approvalDataItem = null; if (workflow != null) { OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(item.WorkflowCode); approvalDataItem = workflow.GetDefaultCommentDataItem(schema, item.ActivityCode); } if (approvalDataItem != null) { // 创建审批 OThinker.H3.Data.Comment comment = new Data.Comment(); comment.Activity = item.ActivityCode; comment.Approval = approval; comment.CreatedTime = System.DateTime.Now; comment.DataField = approvalDataItem; comment.InstanceId = item.InstanceId; comment.BizObjectId = Instance.BizObjectId; comment.BizObjectSchemaCode = Instance.BizObjectSchemaCode; comment.OUName = this.Engine.Organization.GetName(this.Engine.Organization.GetParent(item.Participant)); comment.Text = commentText; comment.TokenId = item.TokenId; comment.UserID = item.Participant; comment.UserName = item.ParticipantName; // 设置用户的默认签章 Organization.Signature[] signs = this.Engine.Organization.GetSignaturesByUnit(item.Participant); if (signs != null && signs.Length > 0) { foreach (Organization.Signature sign in signs) { if (sign.IsDefault) { comment.SignatureId = sign.ObjectID; break; } } } this.Engine.BizObjectManager.AddComment(comment); } }
private WorkflowTemplate.PublishedWorkflowTemplate GetWorkflowTemplate(string workflowCode, int workflowVersion) { WorkflowTemplate.PublishedWorkflowTemplate workflow = null; if (!WorkflowTemplates.ContainsKey(workflowCode + "." + workflowVersion)) { // 添加一个审批意见 workflow = this.Engine.WorkflowManager.GetPublishedTemplate( workflowCode, workflowVersion); WorkflowTemplates.Add(workflowCode + "." + workflowVersion, workflow); } else { workflow = WorkflowTemplates[workflowCode + "." + workflowVersion]; } return(workflow); }
/// <summary> /// 获取发起时流程状态信息 /// </summary> /// <param name="WorkflowCode"></param> /// <param name="WorkflowVersion"></param> /// <returns></returns> public JsonResult GetWorkflowInfo(string WorkflowCode, int WorkflowVersion) { return(this.ExecuteFunctionRun(() => { WorkflowTemplate.PublishedWorkflowTemplate Workflow = this.Engine.WorkflowManager.GetPublishedTemplate( WorkflowCode, WorkflowVersion); if (Workflow == null) { var result = new { SUCCESS = false, Messages = "WorkflowInfo_WorkflowInfoNotExist" }; return Json(result, JsonRequestBehavior.AllowGet); } else { DataTable dt = OThinker.H3.WorkflowTemplate.WorkflowUtility.GetSerialTable(Workflow); //流程步骤 List <ActivitySteps> ActivitySteps = new List <H3.Controllers.ActivitySteps>(); foreach (DataRow row in dt.Rows) { ActivitySteps.Add(new ActivitySteps { SN = row[0] + string.Empty, Code = row[1] + string.Empty, Name = row[2] + string.Empty, Post = row[3] + string.Empty }); } var result = new { SUCCESS = true, ActivitySteps = ActivitySteps }; return Json(result, JsonRequestBehavior.AllowGet); } })); }
private void AppendComment(WorkItem.WorkItem Item, OThinker.Data.BoolMatchValue Approval, string Comment) { WorkflowTemplate.PublishedWorkflowTemplate workflow = GetWorkflowTemplate(Item.WorkflowCode, Item.WorkflowVersion); // 审批字段 string approvalDataItem = null; if (workflow != null) { PublishedWorkflowTemplate workflowTemplate = this.Engine.WorkflowManager.GetPublishedTemplate(Item.WorkflowCode, Item.WorkflowVersion); OThinker.H3.DataModel.BizObjectSchema schema = GetSchema(workflowTemplate.BizObjectSchemaCode); approvalDataItem = workflow.GetDefaultCommentDataItem(schema, Item.ActivityCode); } if (approvalDataItem != null) { // 创建审批 //TODO:此处待修改,Item.BizObjectId不存在,通过 OT_InstanceContext获取 Instance.InstanceContext InstanceContext = this.Engine.InstanceManager.GetInstanceContext(Item.InstanceId); string BizObjectId = InstanceContext == null ? string.Empty : InstanceContext.BizObjectId; Data.Comment comment = new Data.Comment(); comment.Activity = Item.ActivityCode; comment.Approval = Approval; comment.CreatedTime = System.DateTime.Now; comment.DataField = approvalDataItem; comment.InstanceId = Item.InstanceId; comment.OUName = this.Engine.Organization.GetName(this.Engine.Organization.GetParent(Item.Participant)); comment.Text = Comment; comment.TokenId = Item.TokenId; comment.UserID = Item.Participant; comment.UserName = Item.ParticipantName; //comment.BizObjectId = Item.BizObjectId; comment.BizObjectId = BizObjectId; comment.BizObjectSchemaCode = Item.WorkflowCode; this.Engine.BizObjectManager.AddComment(comment); } }
/// <summary> /// 创建一个新的流程实例 /// </summary> /// <param name="Engine">引擎实例对象</param> /// <param name="BizObjectId">业务对象ID</param> /// <param name="Workflow">流程模板</param> /// <param name="Schema">数据模型结构</param> /// <param name="InstanceId">流程实例ID</param> /// <param name="Originator">发起人</param> /// <param name="OriginatedJob">发起人使用的角色</param> /// <param name="InstanceName">流程实例名称</param> /// <param name="Priority">紧急程度</param> /// <param name="OriginatingInstance">发起流程的事件接口</param> /// <param name="ParameterTable">发起流程的参数表</param> /// <param name="Request">HttpRequest</param> /// <param name="WorkItemId">返回工作任务ID</param> /// <param name="ErrorMessage">错误消息</param> /// <param name="FinishStartActivity">是否结束第一个活动</param> /// <returns>返回创建流程是否成功</returns> public static bool OriginateInstance( IEngine Engine, string BizObjectId, WorkflowTemplate.PublishedWorkflowTemplate Workflow, DataModel.BizObjectSchema Schema, ref string InstanceId, string Originator, string OriginatedJob, string InstanceName, Instance.PriorityType Priority, EventHandler <OriginateInstanceEventArgs> OriginatingInstance, Dictionary <string, object> ParameterTable, System.Web.HttpRequest Request, ref string WorkItemId, ref string ErrorMessage, bool FinishStartActivity) { if (Workflow == null) { ErrorMessage = Configs.Global.ResourceManager.GetString("SheetUtility_WorkflowNotExist"); return(false); } // 创建流程实例 InstanceId = AppUtility.Engine.InstanceManager.CreateInstance( BizObjectId, Workflow.WorkflowCode, Workflow.WorkflowVersion, InstanceId, InstanceName, Originator, OriginatedJob, false, Instance.InstanceContext.UnspecifiedID, null, Instance.Token.UnspecifiedID); // 设置紧急程度为普通 OThinker.H3.Messages.MessageEmergencyType emergency = Messages.MessageEmergencyType.Normal; // 如果是发起后需要用户填写表单的模式,则紧急程度为高 if (Workflow.StartWithSheet) { emergency = OThinker.H3.Messages.MessageEmergencyType.High; } // 解析流程参数 System.Collections.Generic.Dictionary <string, object> instanceParams = ParameterTable; if (instanceParams == null) { instanceParams = new Dictionary <string, object>(); } // Http Request Parameters ParseRequestParams(Request, Workflow, Schema, instanceParams); // 调用发起事件 OriginateInstanceEventArgs originateArgs = new OriginateInstanceEventArgs(InstanceId, instanceParams); if (OriginatingInstance != null) { OriginatingInstance(OriginatingInstance, originateArgs); } WorkItemId = Guid.NewGuid().ToString().ToLower(); // 启动流程的消息 OThinker.H3.Messages.StartInstanceMessage startInstanceMessage = new OThinker.H3.Messages.StartInstanceMessage( emergency, InstanceId, WorkItemId, originateArgs == null ? null : originateArgs.InstanceParameterTable.Count == 0 ? null : originateArgs.InstanceParameterTable, Priority, false, OThinker.H3.Instance.Token.UnspecifiedID, null); Engine.InstanceManager.SendMessage(startInstanceMessage); if (!Workflow.StartWithSheet) { // 返回工作项为空 WorkItemId = H3.WorkItem.WorkItem.NullWorkItemID; return(true); } // 查找新创建的工作项 string[] jobs = null; for (int triedTimes = 0; triedTimes < 30; triedTimes++) { System.Threading.Thread.Sleep(500); if (AppUtility.Engine.WorkItemManager.GetWorkItem(WorkItemId) != null) { WorkItem.WorkItem item = AppUtility.Engine.WorkItemManager.GetWorkItem(WorkItemId); jobs = new string[] { item.WorkItemID }; break; } } if (jobs == null || jobs.Length == 0) { ErrorMessage = Configs.Global.ResourceManager.GetString("SheetUtility_OriginateFailed"); WorkItemId = OThinker.H3.WorkItem.WorkItem.NullWorkItemID; return(false); } else { // 返回新创建的工作项 WorkItemId = jobs[0]; if (FinishStartActivity) { OThinker.H3.WorkItem.WorkItem item = Engine.WorkItemManager.GetWorkItem(WorkItemId); // 结束掉第一个活动 Engine.WorkItemManager.FinishWorkItem( WorkItemId, Originator, Request.Browser.IsMobileDevice ? WorkItem.AccessPoint.Mobile : WorkItem.AccessPoint.Web, OriginatedJob, OThinker.Data.BoolMatchValue.Unspecified, null, null, WorkItem.ActionEventType.Forward, WorkItem.WorkItem.UnspecifiedActionButtonType); OThinker.H3.Messages.AsyncEndMessage endMessage = new Messages.AsyncEndMessage( Messages.MessageEmergencyType.Normal, InstanceId, item.ActivityCode, item.TokenId, OThinker.Data.BoolMatchValue.Unspecified, false, OThinker.Data.BoolMatchValue.Unspecified, true, null); Engine.InstanceManager.SendMessage(endMessage); } return(true); } }
EditSimulationViewModel ShowDataItems(string workflowCode, DataModel.BizObjectSchema Schema, InstanceSimulation simulation, Dictionary <string, object> valueTable, EditSimulationViewModel model) { if (Schema == null || Schema.Properties == null) { return(model); } //<ItemName,Values> WorkflowTemplate.PublishedWorkflowTemplate tempalte = this.Engine.WorkflowManager.GetDefaultWorkflow(workflowCode); Dictionary <string, string[]> ExistItems = new Dictionary <string, string[]>(); Dictionary <string, bool> ActivityIgnore = new Dictionary <string, bool>(); if (valueTable != null) { foreach (string key in valueTable.Keys) { string[] values = new string[1]; values[0] = valueTable[key] + string.Empty; ExistItems.Add(key, values); } } else if (simulation != null && simulation.DataItems != null && simulation.DataItems.Length > 0) { foreach (InstanceSimulationDataItem item in simulation.DataItems) { if (!ExistItems.ContainsKey(item.ItemName)) { ExistItems.Add(item.ItemName, item.ItemValues); } if (!ActivityIgnore.ContainsKey(item.ItemName)) { ActivityIgnore.Add(item.ItemName, item.Ignore); } } } //可设置的类型 Data.DataLogicType[] SetableLogicTypes = new Data.DataLogicType[] { Data.DataLogicType.Bool, //Data.DataLogicType.Comment, Data.DataLogicType.DateTime, Data.DataLogicType.Decimal, Data.DataLogicType.Double, //Data.DataLogicType.Html, Data.DataLogicType.Int, Data.DataLogicType.Long, Data.DataLogicType.MultiParticipant, Data.DataLogicType.ShortString, Data.DataLogicType.SingleParticipant, Data.DataLogicType.String, Data.DataLogicType.TimeSpan//, //Data.DataLogicType.Xml }; List <string> UserIDs = new List <string>(); foreach (DataModel.PropertySchema p in Schema.Properties) { if (!DataModel.BizObjectSchema.IsReservedProperty(p.Name) && (p.LogicType == Data.DataLogicType.SingleParticipant || p.LogicType == Data.DataLogicType.MultiParticipant) && ExistItems.ContainsKey(p.Name) && ExistItems[p.Name] != null) { foreach (string id in ExistItems[p.Name]) { UserIDs.Add(id); } } } foreach (WorkflowTemplate.Activity activity in tempalte.Activities) { if (activity.ActivityType == WorkflowTemplate.ActivityType.Start || activity.ActivityType == WorkflowTemplate.ActivityType.End) { continue; } if (activity.ActivityCode == tempalte.StartActivityCode) { continue; } if (ExistItems.ContainsKey(activity.ActivityCode)) { foreach (string id in ExistItems[activity.ActivityCode]) { UserIDs.Add(id); } } } OThinker.Organization.Unit[] Units = this.Engine.Organization.GetUnits(UserIDs.ToArray()).ToArray(); //<UserID,UserName> Dictionary <string, string> DicUnits = new Dictionary <string, string>(); if (Units != null) { foreach (OThinker.Organization.Unit u in Units) { if (!DicUnits.ContainsKey(u.ObjectID)) { DicUnits.Add(u.ObjectID, u.Name); } } } List <object> lstDataItems = new List <object>(); foreach (DataModel.PropertySchema p in Schema.Properties) { if (DataModel.BizObjectSchema.IsReservedProperty(p.Name)) { continue; } if (!SetableLogicTypes.Contains(p.LogicType)) { continue; } string DisplayValueString = string.Empty; if (ExistItems.ContainsKey(p.Name) && ExistItems[p.Name] != null && ExistItems[p.Name].Length > 0) { if (p.LogicType == Data.DataLogicType.SingleParticipant || p.LogicType == Data.DataLogicType.MultiParticipant) { foreach (string _Value in ExistItems[p.Name]) { if (DicUnits.ContainsKey(_Value)) { DisplayValueString += DicUnits[_Value] + ";"; } else { DisplayValueString += ";"; } } } else { DisplayValueString = string.Join(";", ExistItems[p.Name]); } } lstDataItems.Add(new { ItemName = p.Name, ItemValues = ExistItems.ContainsKey(p.Name) ? ExistItems[p.Name] : null, DisplayValueString = DisplayValueString, LogicType = OThinker.H3.Data.DataLogicTypeConvertor.ToLogicTypeName(p.LogicType), Editable = SetableLogicTypes.Contains(p.LogicType) }); } List <object> lstActivitys = new List <object>(); foreach (WorkflowTemplate.Activity activity in tempalte.Activities) { if (activity.ActivityType == WorkflowTemplate.ActivityType.Start || activity.ActivityType == WorkflowTemplate.ActivityType.End) { continue; } if (activity.ActivityCode == tempalte.StartActivityCode) { continue; } string DisplayValueString = string.Empty; if (ExistItems.ContainsKey(activity.ActivityCode) && ExistItems[activity.ActivityCode] != null && ExistItems[activity.ActivityCode].Length > 0) { foreach (string _Value in ExistItems[activity.ActivityCode]) { if (DicUnits.ContainsKey(_Value)) { DisplayValueString += DicUnits[_Value] + ";"; } else { DisplayValueString += ";"; } } } lstActivitys.Add(new { WorkflowTemplate = workflowCode, ActivityCode = activity.ActivityCode, ActivityName = activity.DisplayName, Participants = ExistItems.ContainsKey(activity.ActivityCode) ? ExistItems[activity.ActivityCode] : null, DisplayValueString = DisplayValueString, Ignore = ActivityIgnore.ContainsKey(activity.ActivityCode) ? ActivityIgnore[activity.ActivityCode] : false, Editable = true }); } model.DataItems = CreateLigerUIGridData(lstDataItems.ToArray()); model.Activitys = CreateLigerUIGridData(lstActivitys.ToArray()); return(model); }
public JsonResult LoadSimulation(string simulationID, string workflowCode) { return(ExecuteFunctionRun(() => { EditSimulationViewModel model = new EditSimulationViewModel(); ActionResult result = new ActionResult(true); DataModel.BizObjectSchema Schema = null; OThinker.H3.WorkflowTemplate.WorkflowClause Clause = null; InstanceSimulation Simulation = null; if (!string.IsNullOrEmpty(workflowCode)) { Clause = this.Engine.WorkflowManager.GetClause(workflowCode); } if (Clause != null) { Schema = this.Engine.BizObjectManager.GetPublishedSchema(Clause.BizSchemaCode); } if (Schema == null) { result.Success = false; result.Message = "EditBizObjectSchema.Msg0"; return Json(result, JsonRequestBehavior.AllowGet); } WorkflowTemplate.PublishedWorkflowTemplate tempalte = this.Engine.WorkflowManager.GetDefaultWorkflow(workflowCode); if (tempalte == null) { result.Success = false; result.Message = "StartInstance.StartInstance_Msg1"; return Json(result, JsonRequestBehavior.AllowGet); } if (string.IsNullOrEmpty(simulationID)) { model.WorkflowCode = workflowCode; model.WorkflowName = this.Engine.WorkflowManager.GetClauseDisplayName(workflowCode); ShowDataItems(workflowCode, Schema, null, null, model); } else { Simulation = this.Engine.SimulationManager.GetSimulation(simulationID); if (Simulation == null) { result.Success = false; result.Message = "Simulation.SimulationDetail_Mssg1"; return Json(result, JsonRequestBehavior.AllowGet); } else { if (Clause != null) { model.WorkflowName = Clause.WorkflowName + "[" + workflowCode + "]"; } model.UseCaseName = Simulation.InstanceName; model.Creator = JsonConvert.SerializeObject(Simulation.Originators); //DataItems ShowDataItems(workflowCode, Schema, Simulation, null, model); } } result.Extend = model; return Json(result, JsonRequestBehavior.AllowGet); })); }
/// <summary> /// 批量拒绝 /// </summary> /// <param name="WorkItemIDs"></param> /// <param name="CommentText"></param> /// <returns></returns> private string ReturnWorkItems(string[] WorkItemIDs, string CommentText) { string errors = null; foreach (string itemId in WorkItemIDs) { WorkItem.WorkItem item = this.Engine.WorkItemManager.GetWorkItem(itemId); if (item == null || !item.IsUnfinished) { continue; } if (item.BatchProcessing == false) { errors += item.DisplayName + ";"; continue; } WorkflowTemplate.PublishedWorkflowTemplate workflow = GetWorkflowTemplate(item.WorkflowCode, item.WorkflowVersion); // 添加意见 this.AppendComment(item, OThinker.Data.BoolMatchValue.True, CommentText); // 结束工作项 this.Engine.WorkItemManager.FinishWorkItem( item.ObjectID, this.UserValidator.UserID, H3.WorkItem.AccessPoint.ExternalSystem, //null, null, OThinker.Data.BoolMatchValue.False, CommentText, null, H3.WorkItem.ActionEventType.Backward, (int)SheetButtonType.Return); // 准备触发后面Activity的消息 OThinker.H3.Messages.ActivateActivityMessage activateMessage = new OThinker.H3.Messages.ActivateActivityMessage( OThinker.H3.Messages.MessageEmergencyType.Normal, item.InstanceId, workflow.StartActivityCode, OThinker.H3.Instance.Token.UnspecifiedID, null, new int[] { item.TokenId }, false, H3.WorkItem.ActionEventType.Backward); // 通知该Activity已经完成 OThinker.H3.Messages.AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage( OThinker.H3.Messages.MessageEmergencyType.Normal, item.InstanceId, item.ActivityCode, item.TokenId, OThinker.Data.BoolMatchValue.False, true, OThinker.Data.BoolMatchValue.False, false, activateMessage); this.Engine.InstanceManager.SendMessage(endMessage); } return(errors); }
/// <summary> /// 打开流程表单 /// </summary> /// <param name="paramString"></param> /// <returns></returns> public JsonResult InstanceSheets(string paramString) { return(ExecuteFunctionRun(() => { ActionResult result = new ActionResult(false, ""); Dictionary <string, string> dicParams = JsonConvert.DeserializeObject <Dictionary <string, string> >(paramString); bool isMobile = false; foreach (string key in dicParams.Keys) { if (key == Param_InstanceId) { InstanceID = dicParams[key]; continue; } if (key == Param_IsMobile) { bool.TryParse(dicParams[key], out isMobile); IsMobile = isMobile; continue; } } if (InstanceContext == null) { result.Message = "InstanceSheets_InstanceNotExist"; return Json(result, JsonRequestBehavior.AllowGet); } // 获取流程模板信息 WorkflowTemplate.PublishedWorkflowTemplate workflow = this.Engine.WorkflowManager.GetPublishedTemplate(InstanceContext.WorkflowCode, InstanceContext.WorkflowVersion); if (workflow == null) { result.Message = "InstanceSheets_WorkflowNotExist"; return Json(result, JsonRequestBehavior.AllowGet); } //WorkflowVersion,InstanceID,UserID DataTable dtWorkItem = this.GetItemTable(InstanceID); string activity, sheetCode; Dictionary <string, string> sheetWorkItemIds = new Dictionary <string, string>(); //当前用户参与过流程时,则打开参与过的流程表单,否则打开系统流程表单 if (dtWorkItem != null && dtWorkItem.Rows.Count > 0) { foreach (DataRow row in dtWorkItem.Rows) { activity = row[WorkItem.WorkItem.PropertyName_ActivityCode] + string.Empty; sheetCode = this.GetSheetCodeByActivity(((WorkflowTemplate.ClientActivity)workflow.GetActivityByCode(activity))); if (!sheetWorkItemIds.ContainsKey(sheetCode)) { sheetWorkItemIds.Add(sheetCode, row[WorkItem.WorkItem.PropertyName_ObjectID].ToString()); } } } else { // 管理员,未参与过流程 foreach (WorkflowTemplate.Activity act in workflow.Activities) { if (act is WorkflowTemplate.ClientActivity) { sheetCode = this.GetSheetCodeByActivity(((WorkflowTemplate.ClientActivity)act)); if (!string.IsNullOrEmpty(sheetCode) && !sheetWorkItemIds.ContainsKey(sheetCode)) { sheetWorkItemIds.Add(sheetCode, string.Empty); } } } } if (sheetWorkItemIds.Count == 0) { Instance.InstanceContext instanceContext = InstanceContext; if (instanceContext != null) { // 未参与过流程,并且未设置默认表单,那么再获取默认表单 Sheet.BizSheet[] sheets = this.Engine.BizSheetManager.GetBizSheetBySchemaCode(instanceContext.BizObjectSchemaCode); if (sheets != null && sheets.Length > 0) { foreach (Sheet.BizSheet sheet in sheets) { if (!string.IsNullOrEmpty(sheet.SheetCode) && !sheetWorkItemIds.ContainsKey(sheet.SheetCode)) { sheetWorkItemIds.Add(sheet.SheetCode, string.Empty); } } } } } WorkItem.WorkItem workItem = null; WorkItem.CirculateItem circulateItem = null; string url, workItemId; List <ListUrl> ListUrl = new List <ListUrl>(); foreach (string key in sheetWorkItemIds.Keys) { Sheet.BizSheet sheet = this.Engine.BizSheetManager.GetBizSheetByCode(key); workItemId = sheetWorkItemIds[key]; if (workItemId == string.Empty) { url = this.GetViewSheetUrl( sheet, InstanceID, SheetMode.View, IsMobile); } else { workItem = this.Engine.WorkItemManager.GetWorkItem(workItemId); if (workItem != null) { url = this.GetViewSheetUrl( workItem, sheet, SheetMode.View, this.IsMobile); } else { circulateItem = this.Engine.WorkItemManager.GetCirculateItem(workItemId); if (circulateItem == null) { continue; } url = this.GetViewSheetUrl( circulateItem, sheet, SheetMode.View, this.IsMobile); } } // 处理缓存 DateTime t = DateTime.Now; url += "&T=" + t.ToString("HHmmss"); //只有一个表单直接跳转打开 if (sheetWorkItemIds.Count == 1) { result.Success = true; result.Message = url; result.Extend = "Redirect"; return Json(result, JsonRequestBehavior.AllowGet); } else //多个表单在界面上呈现连接选择打开 { ListUrl.Add(new ListUrl { Title = "InstanceSheets_Sheet", Text = string.Format("{0}[{1}]", sheet.DisplayName, key), Url = url }); } } result.Success = true; result.Message = "MultiSheets"; result.Extend = ListUrl; return Json(result, JsonRequestBehavior.AllowGet); })); }