/// <summary>
        /// 获取指定工作流、角色、时间段的实例集合
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userIdentity">用户身份</param>
        /// <param name="role">审批角色</param>
        /// <param name="startDate">时间段起始时间</param>
        /// <param name="endDate">时间段截止时间</param>
        /// <returns></returns>
        protected override InstanceCollection Distill(string workflowName, IUserIdentity userIdentity, ApprovalRole role, DateTime startDate, DateTime endDate)
        {
            List <StateMachineWorkflowInstance> instances = new List <StateMachineWorkflowInstance>();
            StateMachineWorkflow     workflow             = (StateMachineWorkflow)WorkflowRuntime.Current.GetService <IWorkFlowDefinePersistService>().GetWorkflowDefine(workflowName);
            Dictionary <string, int> stateIndex           = new Dictionary <string, int>();
            List <string>            allStates            = new List <string>();

            for (int i = 0; i < workflow.States.Length; i++)
            {
                ApprovalState state = workflow.States[i];
                if (state.IsApprovalState && !state.Name.Equals(workflow.InitState))
                {
                    stateIndex.Add(state.Name, i);
                    allStates.Add(state.Name);
                }
            }
            if (allStates.Count == 0)
            {
                return(new InstanceCollection());
            }

            instances.AddRange(WorkflowRuntime.Current.GetListByState(workflowName, allStates.ToArray()));
            InstanceCollection collection = new InstanceCollection();

            foreach (StateMachineWorkflowInstance one in instances)
            {
                InstanceWithRole o = new InstanceWithRole(one, role, true);
                o.TaskName = ((char)((int)'a' + stateIndex[one.CurrentState.Name])) + "." + one.CurrentState.Description;
                collection.Add(o);
            }
            return(collection);
        }
        /// <summary>
        /// 获取指定工作流、角色、时间段的实例集合
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userIdentity">用户身份</param>
        /// <param name="role">审批角色</param>
        /// <param name="startDate">时间段起始时间</param>
        /// <param name="endDate">时间段截止时间</param>
        /// <returns></returns>
        protected override InstanceCollection Distill(string workflowName, IUserIdentity userIdentity, ApprovalRole role, DateTime startDate, DateTime endDate)
        {
            InstanceCollection collection = new InstanceCollection();
            List <StateMachineWorkflowInstance> instances = new List <StateMachineWorkflowInstance>();
            List <string> states = InstanceDistillerHelper.GetMineICanCancelStates(workflowName, role);

            if (states.Count == 0)
            {
                return(collection);
            }

            string unitCode = userIdentity.GetUserUnitCode();

            unitCode = string.IsNullOrEmpty(unitCode) ? "  " : (unitCode.Trim() + "%");
            instances.AddRange(WorkflowRuntime.Current.GetUnitList(workflowName, states.ToArray(), unitCode));
            foreach (StateMachineWorkflowInstance instance in instances)
            {
                if (instance.PersistTime >= startDate &&
                    instance.PersistTime <= endDate)
                {
                    collection.Add(new InstanceWithRole(instance, role, true));
                }
            }
            return(collection);
        }
        /// <summary>
        /// 获取指定工作流、角色、时间段的实例集合
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userIdentity">用户身份</param>
        /// <param name="role">审批角色</param>
        /// <param name="startDate">时间段起始时间</param>
        /// <param name="endDate">时间段截止时间</param>
        /// <returns></returns>
        protected override InstanceCollection Distill(string workflowName, IUserIdentity userIdentity, ApprovalRole role, DateTime startDate, DateTime endDate)
        {
            List <StateMachineWorkflowInstance> instances      = new List <StateMachineWorkflowInstance>();
            List <ApprovalAssignment>           assignmentList = WorkflowRuntime.Current.GetService <IApprovalSaveService>().GetAssignmentByToUnit(workflowName, userIdentity.GetUserUnitCode());
            List <Guid> ids = new List <Guid>();

            foreach (ApprovalAssignment assignment in assignmentList)
            {
                if (!string.IsNullOrEmpty(assignment.ToUserId))
                {
                    continue;
                }
                if (!ids.Contains(assignment.WorkflowInstanceId))
                {
                    ids.Add(assignment.WorkflowInstanceId);
                }
            }
            foreach (Guid id in ids)
            {
                instances.Add((StateMachineWorkflowInstance)WorkflowRuntime.Current.GetInstance(id));
            }
            InstanceCollection collection = new InstanceCollection();

            foreach (StateMachineWorkflowInstance instance in instances)
            {
                if (InstanceDistillerHelper.IsAssignedICanDo(instance.CurrentState, role) &&
                    instance.PersistTime >= startDate &&
                    instance.PersistTime <= endDate)
                {
                    collection.Add(new InstanceWithRole(instance, role, false));
                }
            }
            return(collection);
        }
        /// <summary>
        /// 获取指定工作流、角色、时间段的实例集合
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userIdentity">用户身份</param>
        /// <param name="role">审批角色</param>
        /// <param name="startDate">时间段起始时间</param>
        /// <param name="endDate">时间段截止时间</param>
        /// <returns></returns>
        protected override InstanceCollection Distill(string workflowName, IUserIdentity userIdentity, ApprovalRole role, DateTime startDate, DateTime endDate)
        {
            InstanceCollection   instances = new InstanceCollection();
            StateMachineWorkflow workflow  = (StateMachineWorkflow)WorkflowRuntime.Current.GetService <IWorkFlowDefinePersistService>().GetWorkflowDefine(workflowName);
            //遍历工作流中的每一个状态,获取可以处理的状态对应的实例.
            List <string> canDoStates = new List <string>();

            foreach (ApprovalState oneState in workflow.States)
            {
                if (oneState.IsApprovalState && InstanceDistillerHelper.IsMineICanDo(oneState, role))
                {
                    canDoStates.Add(oneState.Name);
                }
            }

            if (canDoStates.Count == 0)
            {
                return(instances);
            }
            List <StateMachineWorkflowInstance> list = WorkflowRuntime.Current.GetListByState(workflowName, canDoStates.ToArray());

            //获取指定给本单位办理的实例
            foreach (StateMachineWorkflowInstance instance in list)
            {
                if (instance.PersistTime >= startDate &&
                    instance.PersistTime <= endDate)
                {
                    instances.Add(new InstanceWithRole(instance, role, true));
                }
            }

            return(instances);
        }
        /// <summary>
        /// 按角色名称合并集合,并按EaId和任务名称进行分组
        /// </summary>
        /// <returns></returns>
        public Dictionary <string, List <InstanceCollection> > Split()
        {
            //按角色分组
            Dictionary <string, InstanceCollection> dic = new Dictionary <string, InstanceCollection>();

            foreach (InstanceWithRole one in this)
            {
                if (dic.ContainsKey(one.Role.Name))
                {
                    dic[one.Role.Name].Add(one);
                }
                else
                {
                    InstanceCollection c = new InstanceCollection();
                    c.Add(one);
                    dic.Add(one.Role.Name, c);
                }
            }
            //对每个角色下的分组进行EaId和任务名称分组
            Dictionary <string, List <InstanceCollection> > dic2 = new Dictionary <string, List <InstanceCollection> >();

            foreach (string key in dic.Keys)
            {
                dic2.Add(key, dic[key].SplitByEaId());
            }
            return(dic2);
        }
        /// <summary>
        /// 获取指定工作流、角色、时间段的实例集合
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userIdentity">用户身份</param>
        /// <param name="role">审批角色</param>
        /// <param name="startDate">时间段起始时间</param>
        /// <param name="endDate">时间段截止时间</param>
        /// <returns></returns>
        protected override InstanceCollection Distill(string workflowName, IUserIdentity userIdentity, ApprovalRole role, DateTime startDate, DateTime endDate)
        {
            List <StateMachineWorkflowInstance> instances = new List <StateMachineWorkflowInstance>();
            StateMachineWorkflow workflow  = (StateMachineWorkflow)WorkflowRuntime.Current.GetService <IWorkFlowDefinePersistService>().GetWorkflowDefine(workflowName);
            List <string>        allStates = new List <string>();

            foreach (ApprovalState state in workflow.States)
            {
                if (state.IsApprovalState && !state.Name.Equals(workflow.InitState))
                {
                    allStates.Add(state.Name);
                }
            }
            if (allStates.Count == 0)
            {
                return(new InstanceCollection());
            }

            string unitCode = userIdentity.GetUserUnitCode();

            unitCode = string.IsNullOrEmpty(unitCode) ? "  " : (unitCode.Trim() + "%");
            instances.AddRange(WorkflowRuntime.Current.GetUnitList(workflowName, allStates.ToArray(), unitCode));

            InstanceCollection collection = new InstanceCollection();

            foreach (StateMachineWorkflowInstance one in instances)
            {
                InstanceWithRole o = new InstanceWithRole(one, role, true);
                o.TaskName = "a." + one.CurrentState.Description;
                collection.Add(o);
            }
            return(collection);
        }
Example #7
0
        /// <summary>
        /// 获取指定工作流、角色、时间段的实例集合
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userIdentity">用户身份</param>
        /// <param name="role">审批角色</param>
        /// <param name="startDate">时间段起始时间</param>
        /// <param name="endDate">时间段截止时间</param>
        /// <returns></returns>
        public InstanceCollection Distill(string workflowName, IUserIdentity userIdentity, ApprovalRole role, DateTime startDate, DateTime endDate)
        {
            //提取实例集合的过程,先遍历每一个提取者对象进行实例提取,后遍历每个过滤器进行实例过滤,最后返回剩余的实例的集合
            InstanceCollection   instances = new InstanceCollection();
            StateMachineWorkflow workflow  = (StateMachineWorkflow)WorkflowRuntime.Current.GetService <IWorkFlowDefinePersistService>().GetWorkflowDefine(workflowName);

            foreach (InstanceDistiller distiller in InstanceDistillers)
            {
                instances.AddRange(distiller.InternalDistill(workflowName, userIdentity, role, startDate, endDate));
            }
            if (Filters != null)
            {
                foreach (InstanceFilter filter in Filters)
                {
                    if (filter is IInstanceCollectionFilter)
                    {
                        IInstanceCollectionFilter collFilter = (IInstanceCollectionFilter)filter;
                        collFilter.Filter(instances, role, userIdentity);
                    }
                    else
                    {
                        for (int i = instances.Count - 1; i >= 0; i--)
                        {
                            if (filter.InternalIsMatch(instances[i].Instance, role, userIdentity))
                            {
                                instances.RemoveAt(i);
                            }
                        }
                    }
                }
            }
            return(instances);
        }
        /// <summary>
        /// 获取指定工作流、角色、时间段的实例集合
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userIdentity">用户身份</param>
        /// <param name="role">审批角色</param>
        /// <param name="startDate">时间段起始时间</param>
        /// <param name="endDate">时间段截止时间</param>
        /// <returns></returns>
        protected override InstanceCollection Distill(string workflowName, IUserIdentity userIdentity, ApprovalRole role, DateTime startDate, DateTime endDate)
        {
            InstanceCollection        collection  = new InstanceCollection();
            List <ApprovalAssignment> assignments = WorkflowRuntime.Current.SaveService.GetAssignmentByToUnit(workflowName, userIdentity.GetUserUnitCode());
            List <Guid> ids = new List <Guid>();

            collection = new InstanceCollection();
            foreach (ApprovalAssignment assignment in assignments)
            {
                if (string.IsNullOrEmpty(assignment.ToUserId))
                {
                    if (!ids.Contains(assignment.WorkflowInstanceId))
                    {
                        ids.Add(assignment.WorkflowInstanceId);
                    }
                }
            }
            foreach (Guid id in ids)
            {
                StateMachineWorkflowInstance instance = (StateMachineWorkflowInstance)WorkflowRuntime.Current.GetInstance(id);
                if (instance.PersistTime > startDate && instance.PersistTime < endDate)
                {
                    collection.Add(new InstanceWithRole(instance, role, false));
                }
            }
            return(collection);
        }
 /// <summary>
 /// Gets the root instance.
 /// </summary>
 /// <param name="collection">The collection.</param>
 /// <returns></returns>
 private InstanceWithRole GetInstance(InstanceCollection collection)
 {
     foreach (InstanceWithRole one in collection)
     {
         if (one.Instance.ParentId == Guid.Empty || one.Instance.ParentId == null)
         {
             return(one);
         }
     }
     return(collection[0]);
 }
        /// <summary>
        /// 获取指定工作流、角色、时间段的实例集合
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userIdentity">用户身份</param>
        /// <param name="role">审批角色</param>
        /// <param name="startDate">时间段起始时间</param>
        /// <param name="endDate">时间段截止时间</param>
        /// <returns></returns>
        protected override InstanceCollection Distill(string workflowName, IUserIdentity userIdentity, ApprovalRole role, DateTime startDate, DateTime endDate)
        {
            StateMachineWorkflow workflow = (StateMachineWorkflow)WorkflowRuntime.Current.GetService <IWorkFlowDefinePersistService>().GetWorkflowDefine(workflowName);
            List <StateMachineWorkflowInstance> instances = WorkflowRuntime.Current.GetInstance(workflowName, startDate, endDate, new string[] { workflow.EndState }, userIdentity.GetUserUnitCode());
            InstanceCollection collection = new InstanceCollection();

            foreach (StateMachineWorkflowInstance instance in instances)
            {
                collection.Add(new InstanceWithRole(instance, role, false));
            }
            return(collection);
        }
        /// <summary>
        ///按角色查找匹配的实例结合.
        /// </summary>
        /// <param name="role">The role.</param>
        /// <returns></returns>
        public InstanceCollection GetByRole(ApprovalRole role)
        {
            InstanceCollection rtn = new InstanceCollection();

            foreach (InstanceWithRole one in this)
            {
                if (one.Role.Equals(role))
                {
                    rtn.Add(one);
                }
            }
            return(rtn);
        }
Example #12
0
        /// <summary>
        /// 对一个工作流实例集合进行过滤,将满足条件的去处
        /// </summary>
        /// <param name="instances">需要被过滤的实例集合</param>
        /// <param name="role">角色对象</param>
        /// <param name="userIdentity">身份识别标志</param>
        /// <returns>满足过滤条件的实例排除后的实例集合对象.</returns>
        public InstanceCollection Filter(InstanceCollection instances, ApprovalRole role, IUserIdentity userIdentity)
        {
            List <ApprovalAssignment> assignmentList = WorkflowRuntime.Current.GetService <IApprovalSaveService>().GetAssignment(instances.InstanceIDs);

            for (int i = instances.Count - 1; i >= 0; i--)
            {
                if (IsOthers(userIdentity, GetAssignment(instances[i], assignmentList)))
                {
                    instances.RemoveAt(i);
                }
            }
            return(instances);
        }
        /// <summary>
        /// 设置任务项目的相关属性值
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <param name="taskItem">工作项目</param>
        /// <param name="userIdentity">The user identity.</param>
        public virtual void FillItemProperty(InstanceCollection collection, ITaskItem taskItem, IUserIdentity userIdentity)
        {
            if (collection == null || collection.Count == 0)
            {
                throw new ArgumentException("实例集合不能为空", "collection");
            }
            taskItem.EaId = collection[0].Instance.EaId;
            InstanceWithRole instance = GetInstance(collection);

            taskItem.InstanceId  = instance.Instance.Id;
            taskItem.PersistTime = instance.Instance.PersistTime;
            taskItem.ExceedTime  = instance.ExceedTime;
        }
Example #14
0
        /// <summary>
        /// 获取某用户对某流程的角色-实例集合字典
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userId">用户Id</param>
        /// <param name="startDate">其实时间</param>
        /// <param name="endDate">终止时间</param>
        /// <returns></returns>
        private InstanceCollection DistillInstances(string workflowName, string userId, DateTime startDate, DateTime endDate)
        {
            List <ApprovalRole> roles        = WorkflowUtility.GetUserRoles(workflowName, userId);
            IUserIdentity       userIdentity = identityService.GetUserIdentity(userId);
            InstanceCollection  rtn          = new InstanceCollection();

            //对本流程中每一个角色遍历得到实例集合后合并入角色-实例集合字典
            foreach (ApprovalRole role in roles)
            {
                rtn.AddRange(DistillInstances(workflowName, userId, role.Name, startDate, endDate));
            }
            return(rtn);
        }
Example #15
0
        /// <summary>
        /// 获取某用户对某流程的任务列表
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="startDate">其实时间</param>
        /// <param name="endDate">终止时间</param>
        /// <returns></returns>
        public InstanceCollection DistillInstances(string userId, DateTime startDate, DateTime endDate)
        {
            InstanceCollection instances = new InstanceCollection();

            foreach (string workflowName in this.workflowNames)
            {
                //对每一个流程中每一个角色遍历得到实例集合后合并入角色-实例集合字典
                List <ApprovalRole> roles = WorkflowUtility.GetUserRoles(workflowName, userId);
                foreach (ApprovalRole role in roles)
                {
                    instances.AddRange(DistillInstances(workflowName, userId, role.Name, startDate, endDate));
                }
            }
            return(instances);
        }
        /// <summary>
        /// 按照Ea id和任务名称进行分类合并
        /// </summary>
        /// <returns></returns>
        public List <InstanceCollection> SplitByEaId()
        {
            //先按任务名称,EaId生成两级分组
            Dictionary <string, Dictionary <int, InstanceCollection> > dic2 = new Dictionary <string, Dictionary <int, InstanceCollection> >();

            foreach (InstanceWithRole one in this)
            {
                string taskName = one.TaskName;
                int    eaid     = one.Instance.EaId;
                //有任务名键
                if (dic2.ContainsKey(taskName))
                {
                    //有EaId的键则添加实例,否则添加键值
                    if (dic2[taskName].ContainsKey(eaid))
                    {
                        dic2[taskName][eaid].Add(one);
                    }
                    else
                    {
                        InstanceCollection o = new InstanceCollection();
                        o.Add(one);
                        dic2[taskName].Add(eaid, o);
                    }
                }
                else
                {
                    //任务名键值,则添加键值
                    InstanceCollection o = new InstanceCollection();
                    o.Add(one);
                    Dictionary <int, InstanceCollection> oDic = new Dictionary <int, InstanceCollection>();
                    oDic.Add(eaid, o);
                    dic2.Add(taskName, oDic);
                }
            }
            //返回按EaId和任务名称分组的实例集合列表
            List <InstanceCollection> splited = new List <InstanceCollection>();

            foreach (string key1 in dic2.Keys)
            {
                foreach (int key2 in dic2[key1].Keys)
                {
                    splited.Add(dic2[key1][key2]);
                }
            }
            return(splited);
        }
        /// <summary>
        /// 获取指定工作流、角色、时间段的实例集合
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userIdentity">用户身份</param>
        /// <param name="role">审批角色</param>
        /// <param name="startDate">时间段起始时间</param>
        /// <param name="endDate">时间段截止时间</param>
        /// <returns></returns>
        protected override InstanceCollection Distill(string workflowName, IUserIdentity userIdentity, ApprovalRole role, DateTime startDate, DateTime endDate)
        {
            List <StateMachineWorkflowInstance> instances = new List <StateMachineWorkflowInstance>();
            string userName   = "";
            string fromUserId = "";
            //找到代理条目给获取授权人Id和授权人姓名
            List <ApprovalAgent> agentList = WorkflowRuntime.Current.GetService <IApprovalSaveService>().GetAgentInfoByToUser(userIdentity.GetUserId());

            foreach (ApprovalAgent agent in agentList)
            {
                if (agent.BeginDate == startDate && agent.EndDate == endDate)
                {
                    userName   = string.Format("{0}(代{1})", agent.ToUserName, agent.SetUserName);
                    fromUserId = agent.SetUserId;
                }
            }
            //获取用户时间段内的审批记录,找到符合代理信息的记录,获取相应的实例
            StateMachineWorkflow  workflow = WorkflowRuntime.Current.GetService <IWorkFlowDefinePersistService>().GetWorkflowDefine(workflowName) as StateMachineWorkflow;
            List <ApprovalRecord> records  = WorkflowRuntime.Current.GetService <IApprovalSaveService>().GetRecord(workflowName, startDate, endDate, fromUserId);
            List <Guid>           ids      = new List <Guid>();

            foreach (ApprovalRecord record in records)
            {
                if (record.OperatorName == userName)
                {
                    ids.Add(record.WorkflowInstanceId);
                }
            }
            instances = new List <StateMachineWorkflowInstance>();
            foreach (Guid id in ids)
            {
                instances.Add((StateMachineWorkflowInstance)WorkflowRuntime.Current.GetInstance(id));
            }
            InstanceCollection collection = new InstanceCollection();

            foreach (StateMachineWorkflowInstance instance in instances)
            {
                if (instance.WorkflowName == workflowName)
                {
                    collection.Add(new InstanceWithRole(instance, role, false));
                }
            }
            return(collection);
        }
        /// <summary>
        /// 获取指定工作流、角色、时间段的实例集合
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userIdentity">用户身份</param>
        /// <param name="role">审批角色</param>
        /// <param name="startDate">时间段起始时间</param>
        /// <param name="endDate">时间段截止时间</param>
        /// <returns></returns>
        protected override InstanceCollection Distill(string workflowName, IUserIdentity userIdentity, ApprovalRole role, DateTime startDate, DateTime endDate)
        {
            StateMachineWorkflow workflow = WorkflowRuntime.Current.GetService <IWorkFlowDefinePersistService>().GetWorkflowDefine(workflowName) as StateMachineWorkflow;
            string userId, unitCode, roleName;

            userId = unitCode = roleName = "";
            if (isMatchUser)
            {
                userId = userIdentity.GetUserId();
            }
            if (isMatchUnit)
            {
                unitCode = userIdentity.GetUserUnitCode();
            }
            if (isMatchRole)
            {
                roleName = role.Name;
            }
            List <ApprovalRecord> records = WorkflowRuntime.Current.GetService <IApprovalSaveService>().GetRecord(workflowName, startDate, endDate, userId, unitCode, roleName);
            List <Guid>           ids     = new List <Guid>();

            foreach (ApprovalRecord record in records)
            {
                if (!ids.Contains(record.WorkflowInstanceId))
                {
                    ids.Add(record.WorkflowInstanceId);
                }
            }
            List <StateMachineWorkflowInstance> instances = new List <StateMachineWorkflowInstance>();

            foreach (Guid id in ids)
            {
                instances.Add((StateMachineWorkflowInstance)WorkflowRuntime.Current.GetInstance(id));
            }
            InstanceCollection collection = new InstanceCollection();

            foreach (StateMachineWorkflowInstance instance in instances)
            {
                collection.Add(new InstanceWithRole(instance, role, false));
            }
            return(collection);
        }
Example #19
0
        /// <summary>
        /// 获取角色和对应实例集合的键-值对
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userId">用户Id</param>
        /// <param name="roleName">角色名称</param>
        /// <param name="startDate">时间段起始时间</param>
        /// <param name="endDate">时间段截止时间</param>
        /// <returns></returns>
        private InstanceCollection DistillInstances(string workflowName, string userId, string roleName, DateTime startDate, DateTime endDate)
        {
            IUserIdentity userIdentity = identityService.GetUserIdentity(userId);
            //获取流程对应的审批角色对象,并从角色-提取者字典中获取角色对应的提取者
            InstanceCollection instances = new InstanceCollection();
            ApprovalRole       role      = WorkflowUtility.GetUserRoleByName(workflowName, roleName);

            if (role != null)
            {
                //用户不在该角色
                if (!userInRole.IsUserInRole(userIdentity.GetUserId(), role.Name))
                {
                    throw new ApplicationException(string.Format("{0} is not in role {1}", userIdentity.GetUserId(), role.Name));
                }
                //取得角色的任务提取器
                TaskDistiller distiller = GetRoleDistiller(roleName);
                instances.AddRange(distiller.Distill(workflowName, userIdentity, role, startDate, endDate));
            }
            return(instances);
        }
        /// <summary>
        /// 获取指定工作流、角色、时间段的实例集合
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userIdentity">用户身份</param>
        /// <param name="role">审批角色</param>
        /// <param name="startDate">时间段起始时间</param>
        /// <param name="endDate">时间段截止时间</param>
        /// <returns></returns>
        protected override InstanceCollection Distill(string workflowName, IUserIdentity userIdentity, ApprovalRole role, DateTime startDate, DateTime endDate)
        {
            InstanceCollection instances = new InstanceCollection();

            if (this.states != null)
            {
                List <StateMachineWorkflowInstance> list = WorkflowRuntime.Current.GetListByState(workflowName, this.states);
                //获取指定给本单位办理的实例
                foreach (StateMachineWorkflowInstance instance in list)
                {
                    if (instance.PersistTime >= startDate &&
                        instance.PersistTime <= endDate)
                    {
                        instances.Add(new InstanceWithRole(instance, role, true));
                    }
                }
            }

            return(instances);
        }
Example #21
0
        /// <summary>
        /// 将角色-实例集合转化为用户的任务列表
        /// </summary>
        /// <param name="userId">用户Id.</param>
        /// <param name="instances">角色-实例集合.</param>
        /// <returns></returns>
        private Dictionary <string, TaskListCollection> ConvertToTasklists(string userId, InstanceCollection instances)
        {
            Dictionary <string, TaskListCollection> taskLists = new Dictionary <string, TaskListCollection>();
            IUserIdentity       userIdentity = identityService.GetUserIdentity(userId);
            List <ApprovalRole> allRoles     = instances.GetAllRoles();

            //按角色分别呈现角色对应的任务列表
            foreach (ApprovalRole role in allRoles)
            {
                InstanceCollection c = instances.GetByRole(role);

                TaskListCollection lists = new TaskListCollection();
                //获取该角色对应的提取器对象
                TaskDistiller distiller = GetRoleDistiller(role.Name);
                distiller.ForRole = role;
                if (distiller.ItemDistiller is IInitializableDistiller)
                {
                    ((IInitializableDistiller)(distiller.ItemDistiller)).Initialize(role, c);
                }

                List <InstanceCollection> collection = c.SplitByEaId();
                foreach (InstanceCollection one in collection)
                {
                    List <ITaskItem> items = new List <ITaskItem>();

                    ITaskItem taskItem = distiller.ItemDistiller.Distill(one, userIdentity);
                    items.Add(taskItem);
                    TaskList list = new TaskList(one.TaskName, items);
                    //给任务列表名称赋值
                    if (!string.IsNullOrEmpty(this.taskName))
                    {
                        list.Cagegory = this.taskName;
                    }
                    lists.Merge(list);
                }
                taskLists.Add(role.Name, lists);
            }
            return(taskLists);
        }
        /// <summary>
        /// 获取指定工作流、角色、时间段的实例集合
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userIdentity">用户身份</param>
        /// <param name="role">审批角色</param>
        /// <param name="startDate">时间段起始时间</param>
        /// <param name="endDate">时间段截止时间</param>
        /// <returns></returns>
        protected override InstanceCollection Distill(string workflowName, IUserIdentity userIdentity, ApprovalRole role, DateTime startDate, DateTime endDate)
        {
            InstanceCollection collection = new InstanceCollection();
            List <StateMachineWorkflowInstance> instances = new List <StateMachineWorkflowInstance>();
            List <string> states = InstanceDistillerHelper.GetMineICanCancelStates(workflowName, role);

            if (states.Count == 0)
            {
                return(collection);
            }
            List <StateMachineWorkflowInstance> list = WorkflowRuntime.Current.GetListByState(workflowName, states.ToArray());

            instances.AddRange(list);

            foreach (StateMachineWorkflowInstance instance in instances)
            {
                if (instance.PersistTime >= startDate &&
                    instance.PersistTime <= endDate)
                {
                    collection.Add(new InstanceWithRole(instance, role, true));
                }
            }
            return(collection);
        }
Example #23
0
 /// <summary>
 /// 将任务列表呈现为HTML.
 /// </summary>
 /// <param name="userId">The user id.</param>
 /// <param name="instances">The instances.</param>
 /// <param name="mergeRoles">if set to <c>true</c> [merge roles].</param>
 /// <returns></returns>
 public string Render(string userId, InstanceCollection instances, bool mergeRoles)
 {
     return(Render(ConvertToTasklists(userId, instances), mergeRoles));
 }
Example #24
0
        /// <summary>
        /// 获取某用户对某流程的任务列表
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userId">用户Id</param>
        /// <param name="roleName">角色名称</param>
        /// <param name="startDate">起始时间</param>
        /// <param name="endDate">终止时间</param>
        /// <returns></returns>
        public string Distill(string workflowName, string userId, string roleName, DateTime startDate, DateTime endDate)
        {
            InstanceCollection instances = DistillInstances(workflowName, userId, roleName, startDate, endDate);

            return(Render(ConvertToTasklists(userId, instances)));
        }