예제 #1
0
        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.");
            }
        }
        public static string ReturnWorkItemByInstanceid(string instanceid, string userId, string commentText)
        {
            bool rtn = false;

            try
            {
                AppUtility.Engine.LogWriter.Write(DateTime.Now.ToString() + " 驳回流程节点开始,流程实例ID:" + instanceid);
                //string userId = "ac845887-3bde-4580-ae0e-fe74149465e2";//融数风控
                string workItemId = getWorkItemIDByInstanceid(instanceid);
                OThinker.H3.WorkItem.WorkItem item = AppUtility.Engine.WorkItemManager.GetWorkItem(workItemId);
                //手工节点不允许驳回
                if (item != null && item.ItemType == OThinker.H3.WorkItem.WorkItemType.Fill)
                {
                    return(rtn.ToString());
                }
                rtn = ReturnItem(userId, workItemId, commentText);
                AppUtility.Engine.LogWriter.Write(DateTime.Now.ToString() + " 驳回流程节点结束,流程实例ID:" + instanceid);
                return(rtn.ToString());
            }
            catch (Exception ex)
            {
                AppUtility.Engine.LogWriter.Write(DateTime.Now.ToString() + " 驳回流程节点异常,流程实例ID:" + instanceid + ",异常信息:" + ex.Message);
                return(rtn.ToString());
            }
        }
예제 #3
0
        public static void SubmitItem(string WorkitemId, OThinker.Data.BoolMatchValue approval, string commentText, string userId)
        {
            // 获取工作项
            OThinker.H3.WorkItem.WorkItem        item     = AppUtility.Engine.WorkItemManager.GetWorkItem(WorkitemId);
            OThinker.H3.Instance.InstanceContext instance = AppUtility.Engine.InstanceManager.GetInstanceContext(item.InstanceId);

            // 结束工作项
            AppUtility.Engine.WorkItemManager.FinishWorkItem(
                item.ObjectID,
                userId,
                OThinker.H3.WorkItem.AccessPoint.ExternalSystem,

                null,
                approval,
                commentText,
                null,
                OThinker.H3.WorkItem.ActionEventType.Forward,
                (int)OThinker.H3.Controllers.SheetButtonType.Submit);
            // 需要通知实例事件管理器结束事件
            AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage(
                MessageEmergencyType.Normal,
                item.InstanceId,
                item.ActivityCode,
                item.TokenId,
                approval,
                false,
                approval,
                true,
                null);

            AppUtility.Engine.InstanceManager.SendMessage(endMessage);
        }
예제 #4
0
        /// <summary>
        /// 提交工作项
        /// </summary>
        /// <param name="workItemId">工作项ID</param>
        /// <param name="approval">审批结果</param>
        /// <param name="commentText">审批意见</param>
        /// <param name="userId">处理人</param>
        public void SubmitItem(string workItemId, OThinker.Data.BoolMatchValue approval, string commentText, string userId)
        {
            //Console.Write("开始提交工作项");
            // 获取工作项
            OThinker.H3.WorkItem.WorkItem        item     = this.Engine.WorkItemManager.GetWorkItem(workItemId);
            OThinker.H3.Instance.InstanceContext instance = this.Engine.InstanceManager.GetInstanceContext(item.InstanceId);
            // 添加意见
            this.AppendComment(instance, item, OThinker.Data.BoolMatchValue.Unspecified, commentText);

            // 结束工作项
            this.Engine.WorkItemManager.FinishWorkItem(
                item.ObjectID,
                userId,
                OThinker.H3.WorkItem.AccessPoint.ExternalSystem,

                null,
                approval,
                commentText,
                null,
                OThinker.H3.WorkItem.ActionEventType.Forward,
                (int)OThinker.H3.Controllers.SheetButtonType.Submit);
            // 需要通知实例事件管理器结束事件
            OThinker.H3.Messages.AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage(
                OThinker.H3.Messages.MessageEmergencyType.Normal,
                item.InstanceId,
                item.ActivityCode,
                item.TokenId,
                approval,
                false,
                approval,
                true,
                null);
            this.Engine.InstanceManager.SendMessage(endMessage);
        }
        /// <summary>
        /// 通过实例ID提交工作任务
        /// </summary>
        /// <param name="workItemId"></param>
        /// <param name="commentText"></param>
        /// <returns></returns>
        public static bool SubmitWorkItemByInstanceID(string instanceid, string commentText)
        {
            string workItemId = getWorkItemIDByInstanceid(instanceid);

            if (!CommonFunction.hasData(workItemId))
            {
                //日志记录
                AppUtility.Engine.LogWriter.Write(DateTime.Now.ToString() + " 根据instanceid提交任务失败,未找到任务ID,流程实例ID:" + instanceid);
                return(false);
            }
            OThinker.H3.WorkItem.WorkItem item = AppUtility.Engine.WorkItemManager.GetWorkItem(workItemId);
            SubmitItem(workItemId, OThinker.Data.BoolMatchValue.True, commentText, AppUtility.Engine.Organization.GetUserByCode("administrator").ObjectID);
            return(true);
        }
        /// <summary>
        /// 批量通过
        /// </summary>
        /// <param name="WorkItemIDs"></param>
        /// <param name="CommentText"></param>
        /// <returns></returns>
        private string SubmitWorkItems(string[] WorkItemIDs, string CommentText)
        {
            string errors = null;

            foreach (string itemId in WorkItemIDs)
            {
                OThinker.H3.WorkItem.WorkItem item = this.Engine.WorkItemManager.GetWorkItem(itemId);
                if (item == null || !item.IsUnfinished)
                {
                    continue;
                }
                if (item.BatchProcessing == false)
                {
                    errors += item.DisplayName + ";";
                    continue;
                }

                // 添加意见
                this.AppendComment(item, OThinker.Data.BoolMatchValue.True, CommentText);

                // 结束工作项
                this.Engine.WorkItemManager.FinishWorkItem(
                    itemId,
                    this.UserValidator.UserID,
                    WorkItem.AccessPoint.Batch,
                    //null,
                    null,
                    OThinker.Data.BoolMatchValue.True,
                    CommentText,
                    null,
                    WorkItem.ActionEventType.Forward,
                    (int)SheetButtonType.Submit);
                // 需要通知实例事件管理器结束事件
                Messages.AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage(
                    Messages.MessageEmergencyType.Normal,
                    item.InstanceId,
                    item.ActivityCode,
                    item.TokenId,
                    OThinker.Data.BoolMatchValue.True,
                    false,
                    OThinker.Data.BoolMatchValue.True,
                    true,
                    null);
                this.Engine.InstanceManager.SendMessage(endMessage);
            }
            return(errors);
        }
예제 #7
0
        /// <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)
        {
            // 添加一个审批意见
            OThinker.H3.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 OThinker.H3.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;

                // 设置用户的默认签章
                OThinker.Organization.Signature[] signs = this.Engine.Organization.GetSignaturesByUnit(item.Participant);
                if (signs != null && signs.Length > 0)
                {
                    foreach (OThinker.Organization.Signature sign in signs)
                    {
                        if (sign.IsDefault)
                        {
                            comment.SignatureId = sign.ObjectID;
                            break;
                        }
                    }
                }
                this.Engine.BizObjectManager.AddComment(comment);
            }
        }
        public System.Web.Mvc.ActionResult SubmitWorkItem(string appId, string pwd, string userCode, string workItemId, string paramValues)
        {
            // 获取工作项
            OThinker.H3.WorkItem.WorkItem item = this.Engine.WorkItemManager.GetWorkItem(workItemId);
            if (item == null) throw new Exception("工作任务不存在");
            OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(userCode) as OThinker.Organization.User;
            if (user == null) throw new Exception("用户不存在");
            List<DataItemParam> listParamValues = JSSerializer.Deserialize<List<DataItemParam>>(paramValues);
            // 保存数据项
            SaveBizObject(item, user, OThinker.Data.BoolMatchValue.True, listParamValues);

            // 结束工作项
            this.Engine.WorkItemManager.FinishWorkItem(
                item.ObjectID,
                user.UnitID,
                OThinker.H3.WorkItem.AccessPoint.ExternalSystem,
                null,
                OThinker.Data.BoolMatchValue.True,
                string.Empty,
                null,
                OThinker.H3.WorkItem.ActionEventType.Forward,
                11);

            // 需要通知实例事件管理器结束事件
            AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage(
                    MessageEmergencyType.Normal,
                    item.InstanceId,
                    item.ActivityCode,
                    item.TokenId,
                    OThinker.Data.BoolMatchValue.True,
                    false,
                    OThinker.Data.BoolMatchValue.True,
                    true,
                    null);
            this.Engine.InstanceManager.SendMessage(endMessage);
            return Json(new
            {
                Result = true,
                Message = string.Empty
            });
        }
        /// <summary>
        /// 保存表单数据
        /// </summary>
        /// <param name="workItem"></param>
        /// <param name="user"></param>
        /// <param name="boolMatchValue"></param>
        /// <param name="paramValues"></param>
        private void SaveBizObject(OThinker.H3.WorkItem.WorkItem workItem, OThinker.Organization.User user, OThinker.Data.BoolMatchValue boolMatchValue, List<DataItemParam> paramValues)
        {
            Instance.InstanceContext InstanceContext = this.Engine.InstanceManager.GetInstanceContext(workItem.InstanceId);
            string bizObjectId = InstanceContext == null ? string.Empty : InstanceContext.BizObjectId;
            OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(InstanceContext.BizObjectSchemaCode);
            OThinker.H3.DataModel.BizObject bo = new OThinker.H3.DataModel.BizObject(this.Engine, schema, workItem.Participant);
            bo.ObjectID = bizObjectId;
            bo.Load();

            // 设置数据项的值
            foreach (DataItemParam param in paramValues)
            {
                OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.ItemName);
                if (property.LogicType == DataLogicType.Comment)
                {// 审核意见
                    CommentParam comment = JSSerializer.Deserialize<CommentParam>(param.ItemValue + string.Empty);
                    this.Engine.BizObjectManager.AddComment(new Comment()
                    {
                        BizObjectId = bo.ObjectID,
                        BizObjectSchemaCode = schema.SchemaCode,
                        InstanceId = workItem.InstanceId,
                        TokenId = workItem.TokenId,
                        Approval = boolMatchValue,
                        Activity = workItem.ActivityCode,
                        DataField = property.Name,
                        UserID = user.ObjectID,
                        SignatureId = comment.SignatureId,
                        Text = comment.Text
                    });
                }
                else
                {
                    this.SetItemValue(bo, property, param.ItemValue);
                }
            }

            bo.Update();
        }
        /// <summary>
        /// 获取当前任务表单打开模式
        /// </summary>
        public SheetMode GetSheetMode(string strMode, string WorkItemID)
        {
            SheetMode SheetMode = SheetMode.Unspecified;

            OThinker.H3.WorkItem.WorkItem CurrentWorkItem = this.GetCurrentWorkItem(WorkItemID);

            if (strMode.Trim() != string.Empty)
            {
                SheetMode = (SheetMode)Enum.Parse(typeof(SheetMode), strMode);
            }
            else if (CurrentWorkItem.State == WorkItem.WorkItemState.Finished || CurrentWorkItem.State == WorkItem.WorkItemState.Canceled)
            {
                SheetMode = SheetMode.View;
            }
            else
            {
                SheetMode = SheetMode.Work;
            }
            if (SheetMode == SheetMode.Work && (CurrentWorkItem.State == WorkItem.WorkItemState.Finished || CurrentWorkItem.State == WorkItem.WorkItemState.Canceled))
            {
                SheetMode = SheetMode.View;
            }
            return(SheetMode);
        }
예제 #11
0
        /// <summary>
        /// 提交工作项
        /// </summary>
        /// <param name="workflowCode"></param>
        /// <param name="instanceId"></param>
        /// <param name="workItemId"></param>
        /// <param name="approval"></param>
        /// <param name="commentText"></param>
        /// <param name="userId"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        private BPMServiceResult SubmitItem(string workflowCode, string instanceId, string workItemId, OThinker.Data.BoolMatchValue approval, string commentText, string userId, List <DataItemParam> values)
        {
            BPMServiceResult result = new BPMServiceResult();

            try
            {
                string user = GetUserIDByCode(userId);
                if (user == null)
                {
                    return(new BPMServiceResult(false, "流程启动失败,用户{" + userId + "}不存在。"));
                }
                OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate workflowTemplate = Engine.WorkflowManager.GetDefaultWorkflow(workflowCode);
                InstanceContext ic = Engine.InstanceManager.GetInstanceContext(instanceId);
                if (ic == null)
                {
                    return(new BPMServiceResult(false, "InstanceID错误,此ID在H3系统中不存在,请检查"));
                }
                OThinker.H3.DataModel.BizObjectSchema schema = Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode);
                OThinker.H3.DataModel.BizObject       bo     = new OThinker.H3.DataModel.BizObject(Engine.Organization, Engine.MetadataRepository, Engine.BizObjectManager, null, schema, user);
                bo.ObjectID = ic.BizObjectId;
                bo.Load();
                foreach (DataItemParam value in values)
                {
                    OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(value.ItemName);
                    if (property.LogicType == OThinker.H3.Data.DataLogicType.BizObjectArray)
                    {
                        var t = new List <OThinker.H3.DataModel.BizObject>();
                        foreach (List <DataItemParam> list in (IEnumerable)value.ItemValue)
                        {
                            var m = new OThinker.H3.DataModel.BizObject(Engine.Organization, Engine.MetadataRepository, Engine.BizObjectManager, null, property.ChildSchema, bo.OwnerId);
                            foreach (DataItemParam dataItem in list)
                            {
                                if (m.Schema.ContainsField(dataItem.ItemName))
                                {
                                    m.SetValue(dataItem.ItemName, dataItem.ItemValue);
                                }
                            }
                            t.Add(m);
                        }
                        bo[value.ItemName] = t.ToArray();
                    }
                    else if (bo.Schema.ContainsField(value.ItemName))
                    {
                        bo[value.ItemName] = value.ItemValue;
                    }
                }
                bo.Update();
                // 获取工作项
                OThinker.H3.WorkItem.WorkItem        item     = Engine.WorkItemManager.GetWorkItem(workItemId);
                OThinker.H3.Instance.InstanceContext instance = Engine.InstanceManager.GetInstanceContext(item.InstanceId);
                // 结束工作项
                Engine.WorkItemManager.FinishWorkItem(item.ObjectID, userId, OThinker.H3.WorkItem.AccessPoint.ExternalSystem, null, approval,
                                                      commentText, null, OThinker.H3.WorkItem.ActionEventType.Forward, (int)OThinker.H3.Controllers.SheetButtonType.Submit);
                // 需要通知实例事件管理器结束事件
                OThinker.H3.Messages.AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage(OThinker.H3.Messages.MessageEmergencyType.Normal,
                                                                                                           item.InstanceId, item.ActivityCode, item.TokenId, approval, false, approval, true, null);
                Engine.InstanceManager.SendMessage(endMessage);
                result = new BPMServiceResult(true, "", null, "流程实例启动成功!", "");
            }
            catch (Exception ex)
            {
                result = new BPMServiceResult(false, "流程实例启动失败!错误:" + ex.Message);
            }
            return(result);
        }
예제 #12
0
        /// <summary>
        /// 驳回工作任务
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="workItemId"></param>
        /// <param name="commentText"></param>
        /// <returns></returns>
        public bool ReturnItem(string userId, string workItemId, string commentText)
        {
            //Console.Write("不回");
            OThinker.Organization.User user = this.Engine.Organization.GetUnit(userId) as OThinker.Organization.User;
            if (user == null)
            {
                return(false);
            }
            // 获取工作项
            OThinker.H3.WorkItem.WorkItem        item    = this.Engine.WorkItemManager.GetWorkItem(workItemId);
            OThinker.H3.Instance.InstanceContext context = this.Engine.InstanceManager.GetInstanceContext(item.InstanceId);
            // ToKen
            OThinker.H3.Instance.IToken Token = context.GetToken(item.TokenId);
            if (Token.PreTokens == null)
            {
                return(false);
            }
            int PreToken = int.Parse(Token.PreTokens[0].ToString());

            OThinker.H3.Instance.IToken PreToken1 = context.GetToken(PreToken);
            string activityName = PreToken1.Activity;

            // 添加意见
            this.AppendComment(context, item, OThinker.Data.BoolMatchValue.False, commentText);
            // 结束工作项
            this.Engine.WorkItemManager.FinishWorkItem(
                item.ObjectID,
                user.ObjectID,
                OThinker.H3.WorkItem.AccessPoint.ExternalSystem,

                null,
                OThinker.Data.BoolMatchValue.False,
                commentText,
                null,
                OThinker.H3.WorkItem.ActionEventType.Backward,
                (int)OThinker.H3.Controllers.SheetButtonType.Return);
            // 准备触发后面Activity的消息
            OThinker.H3.Messages.ActivateActivityMessage activateMessage
                = new OThinker.H3.Messages.ActivateActivityMessage(
                      OThinker.H3.Messages.MessageEmergencyType.Normal,
                      item.InstanceId,
                      activityName,
                      OThinker.H3.Instance.Token.UnspecifiedID,
                      null,
                      new int[] { item.TokenId },
                      false,
                      OThinker.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(true);
        }
        private object LoadInstances(string SimulationID, string InstanceId)
        {
            if (string.IsNullOrEmpty(SimulationID))
            {
                return(null);
            }
            InstanceSimulation Simulation = this.Engine.SimulationManager.GetSimulation(SimulationID);

            if (Simulation == null || Simulation.NextBatchNo <= InstanceSimulationLog.InitialBatchNo)
            {
                return(null);
            }
            InstanceContext context = this.Engine.InstanceManager.GetInstanceContext(InstanceId);

            if (context == null)
            {
                return(null);
            }

            var InstanceName = Simulation.InstanceName;
            var Originator   = this.Engine.Organization.GetName(Simulation.Originators[0]);
            var State        = "InstanceState.InstanceState_" + Enum.Parse(typeof(InstanceState), (int)context.State + string.Empty).ToString();

            Dictionary <string, bool>     ActivityIgnore = new Dictionary <string, bool>();
            Dictionary <string, string[]> ExistItems     = new Dictionary <string, string[]>();
            Dictionary <string, string>   DicUnits       = new Dictionary <string, string>();

            if (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);
                    }
                }
            }

            OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate tempalte = this.Engine.WorkflowManager.GetDefaultWorkflow(Simulation.WorkflowCode);
            foreach (OThinker.H3.WorkflowTemplate.Activity activity in tempalte.Activities)
            {
                if (ExistItems.ContainsKey(activity.ActivityCode))
                {
                    OThinker.Organization.Unit[] Units = this.Engine.Organization.GetUnits(ExistItems[activity.ActivityCode]).ToArray();
                    if (Units != null)
                    {
                        foreach (OThinker.Organization.Unit u in Units)
                        {
                            if (!DicUnits.ContainsKey(u.ObjectID))
                            {
                                DicUnits.Add(u.ObjectID, u.Name);
                            }
                        }
                    }
                }
            }

            int failedCount = 0;
            int IgnoreCount = 0;

            //输出到前台的表格数据
            List <object> InstanceObjs = new List <object>();

            string[] workitemIds           = this.Engine.Query.QueryWorkItems(InstanceId, -1, OThinker.H3.WorkItem.WorkItemType.Unspecified, OThinker.H3.WorkItem.WorkItemState.Finished, OThinker.Data.BoolMatchValue.Unspecified);
            string[] workitemIdsUnfinished = this.Engine.Query.QueryWorkItems(InstanceId, -1, OThinker.H3.WorkItem.WorkItemType.Unspecified, OThinker.H3.WorkItem.WorkItemState.Unfinished, OThinker.Data.BoolMatchValue.Unspecified);
            workitemIds = OThinker.Data.ArrayConvertor <string> .Add(workitemIds, workitemIdsUnfinished);

            if (workitemIds != null || workitemIds.Length > 0)
            {
                foreach (string workitemId in workitemIds)
                {
                    OThinker.H3.WorkItem.WorkItem workItem = this.Engine.WorkItemManager.GetWorkItem(workitemId);
                    if (ActivityIgnore.ContainsKey(workItem.ActivityCode))
                    {
                        if (!ActivityIgnore[workItem.ActivityCode])
                        {
                            if (ExistItems.ContainsKey(workItem.ActivityCode))
                            {
                                if (ExistItems[workItem.ActivityCode] == null || ExistItems[workItem.ActivityCode].Length == 0)
                                {
                                    IgnoreCount++;
                                }
                                else if (!ExistItems[workItem.ActivityCode].Contains(workItem.Participant))
                                {
                                    failedCount++;
                                }
                            }
                        }
                        else
                        {
                            IgnoreCount++;
                        }
                        string UnitNames = string.Empty;
                        foreach (string id in ExistItems[workItem.ActivityCode])
                        {
                            if (DicUnits.ContainsKey(id))
                            {
                                UnitNames += DicUnits[id] + ";";
                            }
                        }

                        bool result = true;
                        if (!ActivityIgnore[workItem.ActivityCode] && ExistItems[workItem.ActivityCode].Length > 0 && !ExistItems[workItem.ActivityCode].Contains(workItem.Participant))
                        {
                            result = false;
                        }

                        InstanceObjs.Add(new
                        {
                            WorkItemName = workItem.DisplayName,
                            Participant  = this.Engine.Organization.GetName(workItem.Participant),
                            ExisItem     = UnitNames.TrimEnd(';'),
                            Ignore       = ActivityIgnore[workItem.ActivityCode] ? "Simulation.SheetPrint_Yes" : "Simulation.SheetPrint_No",
                            Result       = result
                        });
                    }
                }
            }

            var WorkItemCount = workitemIds.Length + string.Empty;
            var SuccessCount  = (workitemIds.Length - IgnoreCount - failedCount) + string.Empty;
            var FailedCount   = failedCount + string.Empty;

            double Percent = 0;

            if (workitemIds.Length > 0)
            {
                Percent = (workitemIds.Length - IgnoreCount - failedCount) * 100 / (workitemIds.Length - IgnoreCount);
            }
            var PercentString = Percent + "%";

            var gridData = CreateLigerUIGridData(InstanceObjs.ToArray());

            var obj = new
            {
                InstanceName  = InstanceName,
                Originator    = Originator,
                State         = State,
                WorkItemCount = WorkItemCount,
                SuccessCount  = SuccessCount,
                FailedCount   = FailedCount,
                IgnoreCount   = IgnoreCount.ToString(),
                Percent       = PercentString,
                Instances     = gridData
            };

            return(obj);
            //ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "Instances", "var Instances=" + CreateLigerUIGridData(InstanceObjs.ToArray()) + ";", true);
        }
예제 #14
0
        public RestfulResult StartWorkflow_Base(string USER_CODE, string WORKFLOW_CODE, bool FINISH_START, string INSTANCE_ID, string PARAM_VALUES)
        {
            Engine.LogWriter.Write("Restful 服务,方法:StartWorkflow,参数:USER_CODE-->" + USER_CODE + ",WORKFLOW_CODE-->" + WORKFLOW_CODE + ",FINISH_START-->" + FINISH_START + ",INSTANCE_ID-->" + INSTANCE_ID + ",PARAM_VALUES-->" + JsonConvert.SerializeObject(PARAM_VALUES));
            RestfulResult result = new RestfulResult();
            Dictionary <string, object> listParams = JsonConvert.DeserializeObject <Dictionary <string, object> >(PARAM_VALUES);
            string workItemID, keyItem, errorMessage;

            workItemID = keyItem = errorMessage = string.Empty;
            try
            {
                #region 参数校验
                OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate workflowTemplate = this.Engine.WorkflowManager.GetDefaultWorkflow(WORKFLOW_CODE);
                if (workflowTemplate == null)
                {
                    result.INSTANCE_ID   = "";
                    result.MESSAGE       = "流程模板不存在,模板编码:" + WORKFLOW_CODE + "。";
                    result.STATUS        = "0";
                    result.WORKFLOW_CODE = WORKFLOW_CODE;
                    result.USER_CODE     = USER_CODE;
                    return(result);
                }
                // 查找流程发起人
                OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(USER_CODE);
                if (user == null)
                {
                    result.INSTANCE_ID   = "";
                    result.MESSAGE       = "用户{" + USER_CODE + "}不存在。";
                    result.STATUS        = "0";
                    result.WORKFLOW_CODE = WORKFLOW_CODE;
                    result.USER_CODE     = USER_CODE;
                    return(result);
                }
                #endregion

                #region 流程实例ID为空:发起新流程
                if (string.IsNullOrEmpty(INSTANCE_ID))
                {
                    OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode);
                    OThinker.H3.DataModel.BizObject       bo     = new OThinker.H3.DataModel.BizObject(
                        this.Engine.Organization,
                        this.Engine.MetadataRepository,
                        this.Engine.BizObjectManager,
                        null,
                        schema,
                        user.ObjectID,
                        user.ParentID);

                    if (listParams != null)
                    {
                        // 这里可以在创建流程的时候赋值
                        foreach (KeyValuePair <string, object> param in listParams)
                        {
                            OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.Key);
                            if (property == null)
                            {
                                continue;
                            }
                            SetItemValue(bo, property, param.Value);
                        }
                    }

                    bo.Create();

                    // 创建流程实例
                    string InstanceId = this.Engine.InstanceManager.CreateInstance(
                        bo.ObjectID,
                        workflowTemplate.WorkflowCode,
                        workflowTemplate.WorkflowVersion,
                        null,
                        null,
                        user.UnitID,
                        null,
                        false,
                        InstanceContext.UnspecifiedID,
                        null,
                        Token.UnspecifiedID);

                    if (listParams != null)
                    {
                        // 这里可以在创建流程的时候赋值
                        foreach (KeyValuePair <string, object> param in listParams)
                        {
                            OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.Key);
                            if (property == null)
                            {
                                continue;
                            }
                            if (property.LogicType == DataLogicType.Comment)
                            {// 审核意见
                                CommentParam comment = JsonConvert.DeserializeObject <CommentParam>(JsonConvert.SerializeObject(param.Value));
                                this.Engine.BizObjectManager.AddComment(new Comment()
                                {
                                    BizObjectId         = bo.ObjectID,
                                    BizObjectSchemaCode = schema.SchemaCode,
                                    InstanceId          = InstanceId,
                                    Activity            = workflowTemplate.StartActivityCode,
                                    TokenId             = 1,
                                    Approval            = OThinker.Data.BoolMatchValue.True,
                                    DataField           = property.Name,
                                    UserID      = user.ObjectID,
                                    UserName    = user.Name,
                                    SignatureId = comment.SignatureId,
                                    Text        = comment.Text
                                });
                            }
                        }
                    }

                    // 启动流程的消息
                    OThinker.H3.Messages.StartInstanceMessage startInstanceMessage
                        = new OThinker.H3.Messages.StartInstanceMessage(
                              MessageEmergencyType.Normal,
                              InstanceId,
                              workItemID,
                              null,
                              PriorityType.Normal,
                              FINISH_START,
                              null,
                              false,
                              OThinker.H3.Instance.Token.UnspecifiedID,
                              null);
                    Engine.InstanceManager.SendMessage(startInstanceMessage);

                    result.INSTANCE_ID   = InstanceId;
                    result.MESSAGE       = "流程实例启动成功!";
                    result.BIZOBJECTID   = bo.ObjectID;
                    result.STATUS        = "2";
                    result.WORKFLOW_CODE = WORKFLOW_CODE;
                    result.USER_CODE     = USER_CODE;
                }
                #endregion

                #region 流程实例ID不为空:更新流程数据;
                else
                {
                    InstanceContext ic = this.Engine.InstanceManager.GetInstanceContext(INSTANCE_ID);
                    if (ic == null)
                    {
                        result.INSTANCE_ID   = INSTANCE_ID;
                        result.MESSAGE       = "InstanceID错误,此ID在H3系统中不存在,请检查";
                        result.STATUS        = "0";
                        result.WORKFLOW_CODE = WORKFLOW_CODE;
                        result.USER_CODE     = USER_CODE;
                        return(result);
                    }

                    OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode);
                    OThinker.H3.DataModel.BizObject       bo     = new OThinker.H3.DataModel.BizObject(
                        this.Engine.Organization,
                        this.Engine.MetadataRepository,
                        this.Engine.BizObjectManager,
                        null,
                        schema,
                        user.ObjectID,
                        user.ParentID);

                    bo.ObjectID = ic.BizObjectId;
                    bo.Load();//装载流程数据;

                    if (listParams != null)
                    {
                        // 这里可以在创建流程的时候赋值
                        foreach (KeyValuePair <string, object> param in listParams)
                        {
                            OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.Key);
                            if (property == null)
                            {
                                continue;
                            }
                            SetItemValue(bo, property, param.Value);
                        }
                    }

                    bo.Update();
                    #region 提交当前任务,往下流转
                    if (FINISH_START)
                    {
                        string sql = "SELECT ObjectID FROM OT_WorkItem WHERE InstanceId='{0}' ORDER BY TokenId desc";
                        sql = string.Format(sql, INSTANCE_ID);
                        string workItemId = this.Engine.EngineConfig.CommandFactory.CreateCommand().ExecuteScalar(sql) + string.Empty;
                        if (workItemId != "")
                        {
                            // 获取工作项
                            OThinker.H3.WorkItem.WorkItem item = this.Engine.WorkItemManager.GetWorkItem(workItemId);

                            // 结束工作项
                            this.Engine.WorkItemManager.FinishWorkItem(
                                item.ObjectID,
                                user.UnitID,
                                OThinker.H3.WorkItem.AccessPoint.ExternalSystem,
                                null,
                                OThinker.Data.BoolMatchValue.True,
                                string.Empty,
                                null,
                                OThinker.H3.WorkItem.ActionEventType.Forward,
                                11);

                            // 需要通知实例事件管理器结束事件
                            AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage(
                                MessageEmergencyType.Normal,
                                item.InstanceId,
                                item.ActivityCode,
                                item.TokenId,
                                OThinker.Data.BoolMatchValue.True,
                                false,
                                OThinker.Data.BoolMatchValue.True,
                                true,
                                null);
                            this.Engine.InstanceManager.SendMessage(endMessage);
                        }
                    }
                    #endregion

                    result.INSTANCE_ID   = INSTANCE_ID;
                    result.MESSAGE       = "流程实例启动成功!(更新数据项的值)";
                    result.BIZOBJECTID   = ic.BizObjectId;
                    result.STATUS        = "2";
                    result.WORKFLOW_CODE = WORKFLOW_CODE;
                    result.USER_CODE     = USER_CODE;
                }
                #endregion
            }
            catch (Exception ex)
            {
                result               = new RestfulResult();
                result.INSTANCE_ID   = "";
                result.BIZOBJECTID   = "";
                result.MESSAGE       = "接口异常:" + ex.ToString();
                result.STATUS        = "0";
                result.WORKFLOW_CODE = WORKFLOW_CODE;
                result.USER_CODE     = USER_CODE;
            }
            return(result);
        }
        object LoadInstances(string SimulationListID)
        {
            ActionResult results = new ActionResult(false, "");

            if (string.IsNullOrEmpty(SimulationListID))
            {
                return(null);
            }
            InstanceSimulationList SimulationLists = this.Engine.SimulationManager.GetSimulationList(SimulationListID);

            if (SimulationLists == null || SimulationLists.Simulations == null)
            {
                return(null);
            }

            Dictionary <string, string[]> ExistItems     = new Dictionary <string, string[]>();
            Dictionary <string, bool>     ActivityIgnore = new Dictionary <string, bool>();
            List <object> InstanceObjs = new List <object>();

            InstanceSimulation[]        simulations    = this.Engine.SimulationManager.GetSimulations(SimulationLists.Simulations);
            Dictionary <string, string> DicUnits       = new Dictionary <string, string>();
            Dictionary <string, string> lstInstanceIds = new Dictionary <string, string>();
            Dictionary <string, string> lstState       = new Dictionary <string, string>();
            List <string>            lstUserIDs        = new List <string>();
            Dictionary <string, int> result            = new Dictionary <string, int>();

            if (simulations != null || simulations.Length > 0)
            {
                foreach (InstanceSimulation Simulation in simulations)
                {
                    if (Simulation.NextBatchNo < 2)
                    {
                        results.Message = "Simulation.SimulationReport_Mssg";
                        return(results);
                    }

                    if (Simulation.DataItems != null && Simulation.DataItems.Length > 0)
                    {
                        foreach (InstanceSimulationDataItem item in Simulation.DataItems)
                        {
                            if (!ExistItems.ContainsKey(Simulation.ObjectID + item.ItemName))
                            {
                                ExistItems.Add(Simulation.ObjectID + item.ItemName, item.ItemValues);
                            }
                            if (!ActivityIgnore.ContainsKey(Simulation.ObjectID + item.ItemName))
                            {
                                ActivityIgnore.Add(Simulation.ObjectID + item.ItemName, item.Ignore);
                            }
                        }
                    }

                    int SimulationTokenID = 0;
                    if (SimulationTokenID <= InstanceSimulationLog.InitialBatchNo || SimulationTokenID >= Simulation.NextBatchNo)
                    {
                        SimulationTokenID = Simulation.NextBatchNo - 1;
                    }

                    DataTable InstanceTable = this.Engine.EngineConfig.CommandFactory.CreateCommand().ExecuteDataTable(
                        " SELECT "
                        + "B." + InstanceContext.C_ObjectID
                        + ",B." + InstanceContext.PropertyName_Originator
                        + ",B." + InstanceContext.PropertyName_InstanceName
                        + ",B." + InstanceContext.PropertyName_State
                        + " FROM " + InstanceSimulationLog.TableName + " A JOIN " + InstanceContext.TableName + " B "
                        + " ON A." + InstanceSimulationLog.PropertyName_InstanceId + "=B." + InstanceContext.C_ObjectID
                        + " WHERE A." + InstanceSimulationLog.PropertyName_SimulationID + "='" + Simulation.ObjectID + "'"
                        + " AND A." + InstanceSimulationLog.PropertyName_BatchNo + "=" + SimulationTokenID + " ");

                    if (InstanceTable != null && InstanceTable.Rows.Count > 0)
                    {
                        //一次获取所有用户
                        foreach (DataRow row in InstanceTable.Rows)
                        {
                            lstUserIDs.Add(row[InstanceContext.PropertyName_Originator] + string.Empty);
                            if (!lstInstanceIds.ContainsKey(Simulation.ObjectID))
                            {
                                lstInstanceIds.Add(Simulation.ObjectID, row[InstanceContext.C_ObjectID] + string.Empty);
                            }
                            if (!lstState.ContainsKey(Simulation.ObjectID))
                            {
                                lstState.Add(Simulation.ObjectID, row[InstanceContext.PropertyName_State] + string.Empty);
                            }
                        }
                        OThinker.Organization.Unit[] Units = this.Engine.Organization.GetUnits(lstUserIDs.ToArray()).ToArray();
                        if (Units != null)
                        {
                            foreach (OThinker.Organization.Unit u in Units)
                            {
                                if (!DicUnits.ContainsKey(u.ObjectID))
                                {
                                    DicUnits.Add(u.ObjectID, u.Name);
                                }
                            }
                        }
                    }
                }
                foreach (InstanceSimulation Simulation in simulations)
                {
                    List <string> message = new List <string>();

                    int  workItemCount = 0;
                    int  failedCount   = 0;
                    int  IgnoreCount   = 0;
                    bool exception     = false;
                    if (lstInstanceIds != null && lstInstanceIds.Count > 0)
                    {
                        string          InstanceId = lstInstanceIds[Simulation.ObjectID];
                        InstanceContext context    = this.Engine.InstanceManager.GetInstanceContext(InstanceId);
                        if (!context.Exceptional)
                        {
                            string[] workitemIds = this.Engine.Query.QueryWorkItems(InstanceId, -1, OThinker.H3.WorkItem.WorkItemType.Unspecified, OThinker.H3.WorkItem.WorkItemState.Finished, OThinker.Data.BoolMatchValue.Unspecified);
                            if (workitemIds != null || workitemIds.Length > 0)
                            {
                                foreach (string workitemId in workitemIds)
                                {
                                    OThinker.H3.WorkItem.WorkItem workItem = this.Engine.WorkItemManager.GetWorkItem(workitemId);
                                    if (ActivityIgnore.ContainsKey(Simulation.ObjectID + workItem.ActivityCode))
                                    {
                                        if (!ActivityIgnore[Simulation.ObjectID + workItem.ActivityCode])
                                        {
                                            if (ExistItems.ContainsKey(Simulation.ObjectID + workItem.ActivityCode))
                                            {
                                                if (ExistItems[Simulation.ObjectID + workItem.ActivityCode] == null || ExistItems[Simulation.ObjectID + workItem.ActivityCode].Length == 0)
                                                {
                                                    IgnoreCount++;
                                                }
                                                else if (!ExistItems[Simulation.ObjectID + workItem.ActivityCode].Contains(workItem.Participant))
                                                {
                                                    failedCount++;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            IgnoreCount++;
                                        }
                                    }
                                }
                                workItemCount = workitemIds.Length - IgnoreCount;
                            }
                        }
                        else
                        {
                            exception = true;
                            if (!result.ContainsKey(Simulation.ObjectID))
                            {
                                result.Add(Simulation.ObjectID, 1);
                            }
                        }
                        if (failedCount > 0 && !result.ContainsKey(Simulation.ObjectID))
                        {
                            result.Add(Simulation.ObjectID, 1);
                        }

                        double Percent = 0;
                        if (workItemCount > 0)
                        {
                            Percent = (workItemCount - failedCount) * 100 / workItemCount;
                        }
                        InstanceObjs.Add(new
                        {
                            ObjectID      = InstanceId,
                            Originator    = DicUnits.ContainsKey(Simulation.Originators[0]) ? DicUnits[Simulation.Originators[0]] : "",
                            InstanceName  = Simulation.InstanceName,
                            State         = (exception ? "Simulation.InstanceGrid_Exceptional" : "InstanceState.InstanceState_" + Enum.Parse(typeof(InstanceState), lstState[Simulation.ObjectID] + string.Empty).ToString()),
                            Url           = this.GetInstanceUrl(InstanceId, "", DateTime.Now.ToString("yyyyMMddHHmmss")),
                            workItemCount = workItemCount + IgnoreCount,
                            SuccessCount  = workItemCount - failedCount,
                            failedCount   = failedCount,
                            IgnoreCount   = IgnoreCount,
                            Percent       = Percent + "%",
                            SimulationID  = Simulation.ObjectID
                        });
                    }
                }
            }

            List <object> lstSimulationObjs = new List <object>();

            int failed = 0;

            foreach (string simulationId in SimulationLists.Simulations)
            {
                if (result.ContainsKey(simulationId))
                {
                    failed += result[simulationId];
                }
            }

            int    total      = SimulationLists.Simulations.Length;
            int    SuccessNum = SimulationLists.Simulations.Length - failed;
            double percent    = SuccessNum * 100 / total;

            var SimulationListCode = SimulationLists.SimulationListCode;
            var RunTime            = DateTime.MinValue.ToLongDateString();

            if (SimulationLists.LastRunTime > DateTime.Parse("1753-1-1") && SimulationLists.LastRunTime < DateTime.MaxValue)
            {
                RunTime = SimulationLists.LastRunTime.ToLongDateString();
            }
            var SimulationNum = total + string.Empty;

            var FailedNum     = failed + string.Empty;
            var PercentString = percent + "%";

            var gridData = CreateLigerUIGridData(InstanceObjs.ToArray());

            results.Success = true;
            results.Extend  = new{
                GridData           = gridData,
                SimulationListCode = SimulationListCode,
                RunTime            = RunTime,
                SimulationNum      = SimulationNum,
                FailedNum          = FailedNum,
                SuccessNum         = SuccessNum.ToString(),
                Percent            = PercentString
            };

            return(results);
        }
        public System.Web.Mvc.ActionResult RejectWorkItem(string appId, string pwd, string userCode, string workItemId, string rejectToActivity, string paramValues)
        {
            // 获取工作项
            OThinker.H3.WorkItem.WorkItem item = this.Engine.WorkItemManager.GetWorkItem(workItemId);
            if (item == null) throw new Exception("工作任务不存在");
            OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(userCode) as OThinker.Organization.User;
            if (user == null) throw new Exception("用户不存在");
            List<DataItemParam> listParamValues = JSSerializer.Deserialize<List<DataItemParam>>(paramValues);
            // 保存数据项
            SaveBizObject(item, user, OThinker.Data.BoolMatchValue.True, listParamValues);

            // 获取驳回节点
            if (string.IsNullOrEmpty(rejectToActivity))
            {// 目标节点为空,则判断当前节点允许驳回的环节 
                PublishedWorkflowTemplate template = this.Engine.WorkflowManager.GetPublishedTemplate(item.WorkflowCode, item.WorkflowVersion);
                ParticipativeActivity activity = template.GetActivityByCode(item.ActivityCode) as ParticipativeActivity;
                if (activity == null) throw new Exception("当前环节不允许驳回");
                if (activity.PermittedActions.RejectToStart) rejectToActivity = template.StartActivityCode; // 驳回到开始
                else if (activity.PermittedActions.RejectToFixed || activity.PermittedActions.RejectToAny)
                {
                    if (activity.PermittedActions.RejectToActivityCodes != null && activity.PermittedActions.RejectToActivityCodes.Length > 0)
                    {
                        rejectToActivity = activity.PermittedActions.RejectToActivityCodes[0];
                    }
                }
                else if (activity.PermittedActions.Reject)
                {// 驳回上一步 
                    InstanceContext context = this.Engine.InstanceManager.GetInstanceContext(item.InstanceId);
                    int[] tokens = context.GetToken(item.TokenId).PreTokens;
                    if (tokens != null && tokens.Length > 0)
                    {
                        rejectToActivity = context.GetToken(tokens[0]).Activity;
                    }
                }

                if (string.IsNullOrEmpty(rejectToActivity))
                {
                    rejectToActivity = template.StartActivityCode;
                }
            }

            // 结束工作项
            this.Engine.WorkItemManager.FinishWorkItem(
                  item.ObjectID,
                  user.ObjectID,
                  H3.WorkItem.AccessPoint.ExternalSystem,
                  null,
                  OThinker.Data.BoolMatchValue.False,
                  string.Empty,
                  null,
                  H3.WorkItem.ActionEventType.Backward,
                  10);
            // 准备触发后面Activity的消息
            OThinker.H3.Messages.ActivateActivityMessage activateMessage
                = new OThinker.H3.Messages.ActivateActivityMessage(
                OThinker.H3.Messages.MessageEmergencyType.Normal,
                item.InstanceId,
                rejectToActivity,
                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 Json(new
            {
                Result = true,
                Message = string.Empty
            });
        }
예제 #17
0
        /// <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);
            }
        }
        public System.Web.Mvc.ActionResult GetInstanceInfo(string appId, string pwd, string userCode, string workItemId)
        {
            OThinker.H3.WorkItem.WorkItem workItem = this.Engine.WorkItemManager.GetWorkItem(workItemId);
            if (workItem == null) throw new Exception("工作任务不存在");
            OThinker.H3.Instance.InstanceContext instance = this.Engine.InstanceManager.GetInstanceContext(workItem.InstanceId);

            OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate template = this.Engine.WorkflowManager.GetPublishedTemplate(instance.WorkflowCode, instance.WorkflowVersion);
            OThinker.H3.WorkflowTemplate.Activity activity = template.GetActivityByCode(workItem.ActivityCode);

            InstanceInfo result = new InstanceInfo()
            {
                ActivityCode = activity.ActivityCode,
                ActivityName = activity.DisplayName,
                DataPermissions = (activity is OThinker.H3.WorkflowTemplate.ParticipativeActivity) ? ((OThinker.H3.WorkflowTemplate.ParticipativeActivity)activity).DataPermissions : null,
                InstanceId = instance.InstanceId,
                InstanceState = instance.State,
                Originator = instance.Originator,
                TokenId = workItem.TokenId,
                WorkflowCode = template.WorkflowCode,
                WorkflowName = template.WorkflowFullName,
                SequenceNo = instance.SequenceNo,
                WorkItemState = workItem.State
            };

            OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(userCode) as OThinker.Organization.User;
            if (user != null)
            {
                OThinker.Organization.Signature[] signatures = this.Engine.Organization.GetSignaturesByUnit(user.ObjectID);
                result.MySignatures = new List<SignatureParam>();
                if (signatures != null)
                {
                    foreach (OThinker.Organization.Signature signature in signatures)
                    {
                        result.MySignatures.Add(new SignatureParam()
                        {
                            IsDefault = signature.IsDefault,
                            SignatureName = signature.Name,
                            SignautreId = signature.ObjectID,
                            SortKey = signature.SortKey
                        });
                    }
                }

                result.FrequentlyComment = this.Engine.Organization.GetFrequentlyUsedCommentTextsByUser(user.ObjectID);

                if (activity is OThinker.H3.WorkflowTemplate.ParticipativeActivity)
                {
                    // PermittedActions actions = new PermittedActions();
                    OThinker.H3.WorkflowTemplate.ParticipativeActivity participative = activity as OThinker.H3.WorkflowTemplate.ParticipativeActivity;
                    //actions.AdjustParticipant = participative.PermittedActions.AdjustParticipant;
                    //actions.Assist = participative.PermittedActions.Assist;
                    //actions.CancelIfUnfinished = participative.PermittedActions.CancelIfUnfinished;
                    //actions.Choose = participative.PermittedActions.Choose;
                    //actions.Circulate = participative.PermittedActions.Circulate;
                    //actions.Consult = participative.PermittedActions.Consult;
                    //actions.Forward = participative.PermittedActions.Forward;
                    //actions.Reject = participative.PermittedActions.Reject || participative.PermittedActions.RejectToAny || participative.PermittedActions.RejectToFixed;

                    if (participative.PermittedActions.RejectToAny)
                    {// 获取允许驳回的节点
                        List<ActivityParam> rejectActivies = new List<ActivityParam>();
                        foreach (OThinker.H3.Instance.Token token in instance.Tokens)
                        {
                            if (token.Activity == activity.ActivityCode) continue;
                            ParticipativeActivity act = template.GetActivityByCode(token.Activity) as ParticipativeActivity;
                            if (act == null) continue;
                            rejectActivies.Add(new ActivityParam()
                            {
                                ActivityCode = act.ActivityCode,
                                DisplayName = act.DisplayName
                            });
                        }
                        result.RejectActivies = rejectActivies;
                    }

                    result.PermittedActions = participative.PermittedActions;
                }
            }

            return Json(result);
        }
 /// <summary>
 /// 获取当前工作任务
 /// </summary>
 public OThinker.H3.WorkItem.WorkItem GetCurrentWorkItem(string WorkItemID)
 {
     OThinker.H3.WorkItem.WorkItem CurrentWorkItem = null;
     CurrentWorkItem = this.Engine.WorkItemManager.GetWorkItem(WorkItemID);
     return(CurrentWorkItem);
 }