Esempio n. 1
0
        /// <summary>
        /// 解析HttpRequest中的参数,如果InstanceParams为null,则直接返回,如果流程参数在InstanceParams已经存在该参数则不添加,否则将QueryString中的参数转化为流程参数,如果转换失败,则抛出异常
        /// </summary>
        /// <param name="Request"></param>
        /// <param name="Workflow"></param>
        /// <returns></returns>
        public static void ParseRequestParams(
            System.Web.HttpRequest Request,
            OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate Workflow,
            OThinker.H3.DataModel.BizObjectSchema Schema,
            System.Collections.Generic.Dictionary <string, object> instanceParams)
        {
            if (Request == null || Workflow == null || instanceParams == null)
            {
                return;
            }

            DataModel.PropertySchema[] items = Schema.Properties;
            if (items != null)
            {
                foreach (DataModel.PropertySchema item in items)
                {
                    object v    = null;
                    string urlV = Request.QueryString[item.Name];
                    if (!string.IsNullOrEmpty(urlV) &&
                        !instanceParams.ContainsKey(item.Name) &&
                        OThinker.Data.Convertor.Convert(urlV, item.RealType, ref v))
                    {
                        instanceParams.Add(item.Name, v);
                    }
                }
            }
        }
        public List <UserCode> GetParticipants(string ActivityCode, string InstanceID)
        {
            if (!string.IsNullOrEmpty(ActivityCode) && !string.IsNullOrEmpty(InstanceID))
            {
                //流程
                OThinker.H3.Instance.InstanceContext InstanceContext = this.Engine.InstanceManager.GetInstanceContext(InstanceID);
                if (InstanceContext != null)
                {
                    //流程模板
                    OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate Template = this.Engine.WorkflowManager.GetPublishedTemplate(
                        InstanceContext.WorkflowCode,
                        InstanceContext.WorkflowVersion);
                    if (Template != null)
                    {
                        //活动信息
                        ClientActivityBase Activity = Template.GetActivityByCode(ActivityCode) as ClientActivityBase;

                        OThinker.H3.Instance.InstanceData InstanceData = new OThinker.H3.Instance.InstanceData(this.Engine, InstanceID, null);

                        string[] ParticipantIDs = Activity.ParseParticipants(InstanceData, this.Engine.Organization);
                        OThinker.Organization.Unit[] ParticipantUsers = this.Engine.Organization.GetUnits(ParticipantIDs).ToArray();

                        if (ParticipantUsers != null)
                        {
                            List <UserCode> ParticipantUserNames = new List <UserCode>();
                            foreach (OThinker.Organization.Unit u in ParticipantUsers)
                            {
                                if (u != null && u.UnitType == OThinker.Organization.UnitType.User)
                                {
                                    OThinker.Organization.User user = (OThinker.Organization.User)u;
                                    ParticipantUserNames.Add(new UserCode
                                    {
                                        Name     = user.Name,
                                        Code     = user.Code,
                                        ObjectID = user.ObjectID
                                    });
                                    //ParticipantUserNames.Add(u.Name + "[" + u.Code + "]");
                                }
                            }
                            return(ParticipantUserNames);
                        }
                    }
                }
            }

            return(null);
        }
        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);
        }
        public System.Web.Mvc.ActionResult StartWorkflow(string appId, string pwd, string userCode, string workflowCode,
            bool finishStart, string paramValues)
        {
            BPMServiceResult result = new BPMServiceResult();

            List<DataItemParam> listParams = JSSerializer.Deserialize<List<DataItemParam>>(paramValues);
            string workItemID, keyItem, errorMessage;
            workItemID = keyItem = errorMessage = string.Empty;

            try
            {
                OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate workflowTemplate = this.Engine.WorkflowManager.GetDefaultWorkflow(workflowCode);
                if (workflowTemplate == null)
                {
                    result = new BPMServiceResult(false, "流程模板不存在,模板编码:" + workflowCode + "。");
                    return Json(result);
                }
                // 查找流程发起人
                OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(userCode) as OThinker.Organization.User;
                if (user == null)
                {
                    result = new BPMServiceResult(false, "用户{" + userCode + "}不存在。");
                    return Json(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);

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


                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 (DataItemParam param in listParams)
                    {
                        OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.ItemName);
                        if (property == null) continue;
                        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 = InstanceId,
                                Activity = workflowTemplate.StartActivityCode,
                                TokenId = 1,
                                Approval = OThinker.Data.BoolMatchValue.True,
                                DataField = property.Name,
                                UserID = user.ObjectID,
                                SignatureId = comment.SignatureId,
                                Text = comment.Text
                            });
                        }
                    }
                }

                // 启动流程的消息
                OThinker.H3.Messages.StartInstanceMessage startInstanceMessage
                    = new OThinker.H3.Messages.StartInstanceMessage(
                        MessageEmergencyType.Normal,
                        InstanceId,
                        workItemID,
                        null,
                        PriorityType.Normal,
                        true,
                        null,
                        false,
                        OThinker.H3.Instance.Token.UnspecifiedID,
                        null);
                Engine.InstanceManager.SendMessage(startInstanceMessage);
                result = new BPMServiceResult(true, InstanceId, workItemID, "流程实例启动成功!", string.Empty);
            }
            catch (Exception ex)
            {
                result = new BPMServiceResult(false, ex.ToString());
            }
            return Json(result, JsonRequestBehavior.AllowGet);
        }