Exemplo n.º 1
0
        /// <summary>
        /// 获取所有活动名称
        /// </summary>
        private void LoadActivityList()
        {
            string workflowCode;

            workflowCode = Request["WorkflowCode"];
            //string workflowPackage, workflowName;
            // workflowPackage = Request["PackageName"];
            //workflowName = Request["WorkflowName"];
            //Data.ClauseDataItem[] items = this.Engine.ClauseDataManager.GetColumns(workflowPackage, workflowName);

            // 获得模板

            OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate template = AppUtility.Engine.WorkflowManager.GetDefaultWorkflow(workflowCode);
            StringBuilder builder = new StringBuilder();

            builder.Append("({Items:[");
            int index = 0;

            //foreach (OThinker.H3.WorkflowTemplate.ActivityTemplate tmp in template.)
            foreach (OThinker.H3.WorkflowTemplate.Activity tmp in template.Activities)
            {
                // if (tmp.DisplayName == this.PortalResource.GetString("AjaxServices_End")) continue;
                if (index > 0)
                {
                    builder.Append(",");
                }
                builder.Append("{\"Name\":\"" + tmp.DisplayName + "\"}");
                index++;
            }
            builder.Append("]})");
            Response.Clear();
            Response.Write(builder.ToString());
            Response.Buffer = true;
        }
        /// <summary>
        /// 结束流程
        /// </summary>
        /// <param name="instanceId"></param>
        /// <returns></returns>
        public static bool FinishedInstance(string instanceId)
        {
            try
            {
                AppUtility.Engine.LogWriter.Write(DateTime.Now.ToString() + " 根据instanceid强制结束流程开始,流程实例ID:" + instanceId);
                OThinker.H3.Instance.InstanceContext context = AppUtility.Engine.InstanceManager.GetInstanceContext(instanceId);
                if (context == null)
                {
                    return(false);
                }

                OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate workflow = AppUtility.Engine.WorkflowManager.GetDefaultWorkflow(context.WorkflowCode);

                OThinker.H3.Messages.ActivateActivityMessage activateMessage = new OThinker.H3.Messages.ActivateActivityMessage(
                    OThinker.H3.Messages.MessageEmergencyType.High,
                    instanceId,
                    workflow.EndActivityCode,
                    OThinker.H3.Instance.Token.UnspecifiedID,
                    null,
                    null,
                    false,
                    OThinker.H3.WorkItem.ActionEventType.Adjust
                    );
                AppUtility.Engine.InstanceManager.SendMessage(activateMessage);
                AppUtility.Engine.LogWriter.Write(DateTime.Now.ToString() + " 根据instanceid强制结束流程成功,流程实例ID:" + instanceId);
                return(true);
            }
            catch
            {
                AppUtility.Engine.LogWriter.Write(DateTime.Now.ToString() + " 根据instanceid强制结束流程失败,流程实例ID:" + instanceId);
                return(false);
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
        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);
        }