예제 #1
0
        /// <summary>
        /// 用途:得到流程活动实例
        /// </summary>
        /// <param name="workitemInstanceGuid">流程活动实例guid</param>
        /// <returns>流程活动实例</returns>
        public WorkitemInstance GetWorkitemInstance(string workitemInstanceGuid)
        {
            WorkitemInstance wii = this.Context.Store.GetWorkitemInstance(workitemInstanceGuid);

            wii.SetContext(this.Context);
            return(wii);
        }
        /// <summary>
        /// 流程活动处理
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ResultMessage SubmitWorkitemInstance(RequestBySubmitWorkitem request)
        {
            ResultMessage rm = new ResultMessage()
            {
                State = true, Message = ""
            };

            WorkitemInstance wii = this.GetWorkitemInstance(request.WorkitemInstanceGuid);

            ///不在许可范围之内的,直接返回失败
            if (!this.IsEffective(wii))
            {
                return new ResultMessage()
                       {
                           State = false, Message = "不在许可操作范围内!"
                       }
            }
            ;

            wii.AduitContent = request.AduitContent;
            wii.AduitSign    = request.AduitSign;

            wii.SelectVoteItem       = request.SelectVoteItem;
            wii.OtherVoteItemContent = request.OtherVoteItemContent;
            wii.IsProxy = request.IsProxyUser;
            if (wii.IsProxy)
            {
                wii.ProxyUser = this.Context.CurUser;
            }
            else
            {
                wii.User = this.Context.CurUser;
            }
            //wii.SetDataEntity(request.DataEntity);

            switch (request.State)
            {
                #region Running 挂起流程操作
            case eWorkitemState.Running:
            {
                wii.Hung();
                wii.Save();
            }
            break;
                #endregion

                #region Abort 退出流程处理,中止流程
            case eWorkitemState.Abort:
            {
                #region 条件判断
                bool b = false;
                ///是否大管理员
                if (this.Context.CurUser.IsAdministrator())
                {
                    b = true;
                }
                ///是否流程模型管理员
                if (wii.GetWorkflowInstance().GetWorkflow().Administrators.Contains(this.Context.CurUser, _uc))
                {
                    b = true;
                }
                ///是否是流程发起人
                if (_uc.Equals(this.Context.CurUser, wii.GetWorkflowInstance().Author))
                {
                    b = true;
                }
                if (!b)
                {
                    rm.State   = false;
                    rm.Message = "你不具体中止流程的权限。只有管理员和发起人才可以中止流程!";
                    break;
                }
                #endregion

                wii.Abort();
                wii.Save();
                wii.GetWorkflowInstance().Save();
                break;
            }
                #endregion

                #region Completed 正常完成流程处理
            case eWorkitemState.Completed:
            {
                wii.GetWorkflowInstance().SetDataEntity(request.DataEntity);

                #region 创建后继流程活动工作项
                IList <NextActivity> tmp = new List <NextActivity>();
                foreach (var na in request.NextActivities)
                {
                    foreach (var o in na.Operaters)
                    {
                        var x = new NextActivity()
                        {
                            WorkitemInstanceGuid = System.Guid.NewGuid().ToString(),
                            ActivityGuid         = na.Activity,
                            ActivityByname       = na.ActivityName,
                            User = this.GetUser(o),
                        };

                        #region 创建后继流程活动工作项
                        WorkitemInstance xwii = new WorkitemInstance(wii.GetWorkflowInstance().Guid,
                                                                     wii.GetWorkflow().GetActivity(na.Activity, eDaoItem.Guid))
                        {
                            ActivityGuid   = x.ActivityGuid,
                            AduitContent   = "",
                            ReadTime       = null,
                            NextActivities = null,
                            EndTime        = null,
                            User           = x.User,
                            ProxyUser      = null,
                            //WorkitemInstanceState = eWorkitemState.Ready,
                            IsProxy = false,
                            FromWorkitemInstanceGuid = wii.Guid,
                            AttachmentTrainsitions   = null,
                        };
                        xwii.SetContext(this.Context);
                        ///取流程实例数据到流程实例活动
                        xwii.Start();
                        //xwii.BeforeTrigger();
                        xwii.Save();
                        #endregion
                        tmp.Add(x);
                    }
                }
                wii.NextActivities = tmp;
                #endregion

                ///完成流程实例活动
                wii.AfterTrigger();
                wii.Save();
                wii.GetWorkflowInstance().Save();
                break;
            }
                #endregion

                #region Other
            case eWorkitemState.Ready:
            case eWorkitemState.ExclusionCompleted:
            default:
            {
                break;
            }
                #endregion
            }
            ///解锁
            this.DecodeLock(wii);
            if (!rm.State)
            {
                return(rm);
            }

            return(rm);
        }
    }
        /// <summary>
        /// 用途:创建流程实例并返回首个流程活动工作项
        /// 约定:
        /// 1、一个流程有且仅有一个根活动
        /// 2、代理人不能发起委托人的新流程,只能处理委托日期后正在流转的流程数据
        /// 3、有发起流程模型权限方可以操作
        /// </summary>
        /// <param name="workflowGuid">流程模型guid</param>
        /// <returns>首个流程活动工作项</returns>
        public ResponseByWorkitem CreateWorkflowInstance(string workflowGuid, string name = null)
        {
            ///创建流程实例
            WorkflowInstance wfi = new WorkflowInstance(workflowGuid, name);

            //wfi.Guid ...
            //wfi.Name ...
            //wfi.WorkflowGuid ...
            wfi.Author = this.Context.CurUser;
            //wfi.WorkflowState ...
            //wfi.Participator ...
            //wfi.Locker ...
            //wfi.BeginTime ...;
            //wfi.EndTime ...;
            //wfi.DataEntity ...

            wfi.SetContext(this.Context);

            ///加入权限控制
            if (!(this.Context.CurUser.IsAdministrator() ||//是否大管理员
                  wfi.GetWorkflow().IsAdministrators(this.Context.CurUser) ||//是否流程模型管理员
                  wfi.GetWorkflow().IsLegalAuthor(this.Context.CurUser)   //流程的合法发起用户
                  ))
            {
                return(new ResponseByWorkitem()
                {
                    CallBackMessage = new ResultMessage()
                    {
                        State = false, Message = "不能发起流程!"
                    }
                });
            }

            ///开启流程实例服务
            wfi.Start();
            wfi.Save();

            //创建活动实例
            WorkitemInstance wii = new WorkitemInstance(wfi.Guid, wfi.GetWorkflow().GetStartNode());

            //wii.Guid ...
            //wii.Name ...
            //wii.ActivityGuid ...
            //wii.WorkflowInstanceGuid ...
            //wii.AduitContent = "";
            //wii.AduitSign = "";
            //wii.ReadTime = null;
            //wii.NextActivities = null;
            wii.User = this.Context.CurUser;
            //wii.ProxyUser = null;
            //wii.IsProxy = false;
            //wii.WorkitemInstanceState ...
            //wii.FromWorkitemInstanceGuid = "";
            //wii.AttachmentTrainsitions = null;
            //wii.SelectVoteItem = "";
            //wii.OtherVoteItemContent = "";
            //wii.BeginTime ...;
            //wii.EndTime ...;
            //wii.DataEntity ...

            wii.SetContext(this.Context);
            ///开启活动实例
            wii.Start();
            wii.Save();
            ///活动前事件处理
            var rm = wii.BeforeTrigger();

            ResponseByWorkitem response;

            ///如果不满足
            if (!rm.State)
            {
                response = new ResponseByWorkitem()
                {
                    ActivityInstance = wii,
                    //NextMaybeActivities=null,
                    UIRight         = this.Context.Config.RightByReadOnly,
                    CallBackMessage = rm,
                };
            }
            else
            {
                response = new ResponseByWorkitem()
                {
                    ActivityInstance    = wii,
                    NextMaybeActivities = wii.GetNextEffectiveActivities(),
                    UIRight             = wii.GetActivity().UIRight,
                    CallBackMessage     = new ResultMessage()
                    {
                        State = true, Message = ""
                    },
                };
            }
            return(response);
        }