예제 #1
0
        /// <summary>
        ///  用途:撤回流程活动
        ///  范围:大管理员|流程模型管理员|当前流程实例活动的操作者|当前流程实例活动的代理操作者
        /// </summary>
        /// <param name="workitemInstanceGuid"></param>
        /// <returns></returns>
        public ResultMessage RecallWorkitemInstance(string workitemInstanceGuid)
        {
            WorkitemInstance wii = this.GetWorkitemInstance(workitemInstanceGuid);

            ///加入权限控制大管理员|流程模型管理员|当前流程实例活动的操作者|当前流程实例活动的代理操作者
            if (!(this.Context.CurUser.IsAdministrator() ||
                  wii.GetWorkflowInstance().GetWorkflow().Administrators.Contains(this.Context.CurUser, _uc) ||
                  wii.User.Guid.Equals(this.Context.CurUser.Guid) ||
                  (wii.IsProxy && wii.ProxyUser.Guid.Equals(this.Context.CurUser.Guid))
                  ))
            {
                return new ResultMessage()
                       {
                           State = false, Message = "不在许可操作范围内!"
                       }
            }
            ;
            ///不允许回收尚不在运行的流程实例
            if (!wii.GetWorkflowInstance().WorkflowState.Equals(eWorkflowState.Running))
            {
                return new ResultMessage()
                       {
                           State = false, Message = "该流程实例已经结束或者中止,请先回收流程实例再回收具体步骤!"
                       }
            }
            ;
            ///对尚在运行的流程实例无需回收
            if (wii.WorkitemInstanceState.Equals(eWorkitemState.Running)
                ||
                wii.WorkitemInstanceState.Equals(eWorkitemState.ExclusionCompleted)
                ||
                wii.WorkitemInstanceState.Equals(eWorkitemState.Ready))
            {
                return new ResultMessage()
                       {
                           State = false, Message = "该流程活动无需回收!"
                       }
            }
            ;
            var nwiis = wii.GetNextWorkitemInstances();
            ///判断后继流程活动有无被处理,未处理的可以回收
            bool b = true;

            foreach (var t in nwiis)
            {
                if (t.WorkitemInstanceState.Equals(eWorkitemState.Abort)
                    ||
                    t.WorkitemInstanceState.Equals(eWorkitemState.Completed)
                    ||
                    t.WorkitemInstanceState.Equals(eWorkitemState.ExclusionCompleted)
                    )
                {
                    b = false;
                    break;
                }
            }
            if (!b)
            {
                return new ResultMessage()
                       {
                           State = false, Message = "后继流程节点已经被处理,不能回收!"
                       }
            }
            ;
            ///进行回收
            for (int i = 0, cnt = nwiis.Count; i < cnt; i++)
            {
                this.SetWorkitemInstance(nwiis[i], eStoreType.Remove);
            }
            wii.Restart();
            wii.NextActivities = new List <NextActivity>();
            b = this.SetWorkitemInstance(wii, eStoreType.Update);
            if (b)
            {
                return new ResultMessage()
                       {
                           State = true, Message = "回收流程活动成功!"
                       }
            }
            ;
            else
            {
                return new ResultMessage()
                       {
                           State = false, Message = "回收流程活动失败!"
                       }
            };
        }
    }
}