/// <summary> /// 获取审批意见 /// </summary> /// <param name="eaid">被审批对象的Id</param> /// <returns></returns> public List <ApprovalSolution> GetApprovalSolutions(int eaid) { DrillApprovalSolution drill = new DrillApprovalSolution(); string userId = WorkflowRuntime.Current.GetService <IIdentityService>().GetUserIdentity().GetUserId(); string rootName = WorkflowRuntime.Current.DefineService.GetRoot(this.applicationName); List <ApprovalRole> roles = WorkflowUtility.GetUserRoles(rootName, userId); if (roles == null || roles.Count == 0) { //没有角色用户,不能看任何记录 return(new List <ApprovalSolution>()); } if (this.solutionFilters != null && this.solutionFilters.Count >= 0) { ApprovalRole role = roles[0]; foreach (IApprovalSolutionFilter one in this.solutionFilters) { one.SetValues(rootName, role, userId); drill.Filters.Add(one); } } return(drill.GetInfo(this.applicationName, eaid)); }
internal static List <string> GetMineICanCancelStates(string workflowName, ApprovalRole role) { StateMachineWorkflow workflow = WorkflowRuntime.Current.GetService <IWorkFlowDefinePersistService>().GetWorkflowDefine(workflowName) as StateMachineWorkflow; List <string> states = new List <string>(); //得到审批角色所有可撤销状态列表 foreach (ApprovalState state in workflow.States) { foreach (ApprovalEvent oneEvent in state.Events) { foreach (EventRole one in oneEvent.Roles) { if (one.Name.Equals(role.Name, StringComparison.OrdinalIgnoreCase) && (oneEvent.Authorization == Authorization.OwnerOnly.ToString() || oneEvent.Authorization == Authorization.All.ToString())) { foreach (string nextStateName in oneEvent.NextStateNames) { if (workflow.GetStateByName(nextStateName).AllowedCancel) { if (!states.Contains(nextStateName)) { states.Add(nextStateName); } } } } } } } return(states); }
/// <summary> /// Determines whether the specified <see cref="System.Object"/> is equal to this instance. /// </summary> /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param> /// <returns> /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>. /// </returns> /// <exception cref="T:System.NullReferenceException"> /// The <paramref name="obj"/> parameter is null. /// </exception> public override bool Equals(object obj) { if (obj is ApprovalRole) { ApprovalRole role = obj as ApprovalRole; return(role.Name == this.name && role.Group == this.group && role.Grade == this.grade); } return(false); }
/// <summary> ///设置环境参数 /// </summary> /// <param name="workflowName">Name of the workflow.</param> /// <param name="role">用户的审批角色</param> /// <param name="userId">以用户的Id</param> public void SetValues(string workflowName, ApprovalRole role, string userId) { if (role == null) { throw new ArgumentNullException("role"); } this.userRole = role; this.workflowName = workflowName; this.userId = userId; }
/// <summary> /// 判断指定实例是否需要满足过滤条件,满足则返回True,否则返回False /// </summary> /// <param name="instance">工作流实例</param> /// <param name="role">用户的审批角色</param> /// <param name="userIdentity">用户的身份</param> /// <returns>满足则返回True,否则返回False</returns> protected override bool IsMatch(StateMachineWorkflowInstance instance, ApprovalRole role, IUserIdentity userIdentity) { List <ApprovalAssignment> assignmentList = WorkflowRuntime.Current.GetService <IApprovalSaveService>().GetAssignment(instance.Id); if (assignmentList.Count == 0) { return(false); } return(IsOthers(userIdentity, assignmentList)); }
/// <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); }
/// <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> /// 判断指定实例是否需要满足过滤条件,满足则返回True,否则返回False /// </summary> /// <param name="instance">工作流实例</param> /// <param name="role">用户的审批角色</param> /// <param name="userIdentity">用户的身份</param> /// <returns>满足则返回True,否则返回False</returns> protected override bool IsMatch(StateMachineWorkflowInstance instance, ApprovalRole role, IUserIdentity userIdentity) { List <ApprovalRecord> records = WorkflowRuntime.Current.SaveService.GetRecord(instance.WorkflowName, instance.EaId); foreach (ApprovalRecord record in records) { if (record.OperatorId == userIdentity.GetUserId() && record.OperatorRole == role.Name) { return(false); } } return(true); }
internal static bool IsMineICanDo(ApprovalState state, ApprovalRole role) { foreach (ApprovalEvent oneEvent in state.Events) { foreach (EventRole one in oneEvent.Roles) { if (one.Name.Equals(role.Name, StringComparison.OrdinalIgnoreCase) && (oneEvent.Authorization == Authorization.OwnerOnly.ToString() || oneEvent.Authorization == Authorization.All.ToString())) { return(true); } } } return(false); }
/// <summary> /// 判断指定实例是否需要满足过滤条件,满足则返回True,否则返回False /// </summary> /// <param name="instance">工作流实例</param> /// <param name="role">用户的审批角色</param> /// <param name="userIdentity">用户的身份</param> /// <returns> /// 满足则返回True,否则返回False /// </returns> internal bool InternalIsMatch(StateMachineWorkflowInstance instance, ApprovalRole role, IUserIdentity userIdentity) { if (instance == null) { throw new ArgumentNullException("instance"); } if (role == null) { throw new ArgumentNullException("role"); } if (userIdentity == null) { throw new ArgumentNullException("userIdentity"); } return(IsMatch(instance, role, userIdentity)); }
/// <summary> /// 判断指定实例是否需要满足过滤条件,满足则返回True,否则返回False /// </summary> /// <param name="instance">工作流实例</param> /// <param name="role">用户的审批角色</param> /// <param name="userIdentity">用户的身份</param> /// <returns>满足则返回True,否则返回False</returns> protected override bool IsMatch(StateMachineWorkflowInstance instance, ApprovalRole role, IUserIdentity userIdentity) { if (string.IsNullOrEmpty(this.StateNames)) { throw new ApplicationException("请配置需要过滤的状态名"); } string[] stateList = this.StateNames.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string one in stateList) { if (instance.CurrentState.Name.Equals(one.Trim(), StringComparison.OrdinalIgnoreCase)) { return(true); } } return(false); }
/// <summary> /// Gets the batch process list. /// </summary> /// <param name="workflowName">Name of the workflow.</param> /// <param name="batchProcessType">Type of the batch process.</param> /// <returns></returns> public virtual TaskList GetBatchProcessList(string workflowName, BatchProcessType batchProcessType) { StateMachineWorkflow workflow = (StateMachineWorkflow)WorkflowRuntime.Current.GetService<IWorkFlowDefinePersistService>().GetWorkflowDefine(workflowName); string stateName = string.Empty; ApprovalRole role = null; if (batchProcessType == BatchProcessType.Receive) { //获取操作为“接收”所在的状态名称 foreach (ApprovalState state in workflow.States) { foreach (ApprovalEvent approvalEvent in state.Events) { if (approvalEvent.Name == "接收") { role = WorkflowUtility.GetUserRoleByName(workflowName, approvalEvent.Roles[0].Name); stateName = state.Name; } } } } else if (batchProcessType == BatchProcessType.Approve) { //遍历工作流状态,找到下一状态为工作流终止状态的状态名 foreach (ApprovalState state in workflow.States) { foreach (ApprovalEvent approvalEvent in state.Events) { if (approvalEvent.NextStateNames != null && approvalEvent.NextStateNames.Length > 0 && approvalEvent.NextStateNames[0] == workflow.EndState) { role = WorkflowUtility.GetUserRoleByName(workflowName, approvalEvent.Roles[0].Name); stateName = state.Name; } } } } else throw new ArgumentException("batchProcessType"); ApprovalProcess process = CreateProcess(workflowName, role); //获取所有在该状态下的工作流实例 List<StateMachineWorkflowInstance> instanceList = process.GetList(new string[] { stateName }); return new TaskList("a." + batchProcessType.ToString(), new List<ITaskItem>(ItemProcessor.GenerateTaskTable(instanceList))); }
/// <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> /// 判断指定实例是否需要满足过滤条件,满足则返回True,否则返回False /// </summary> /// <param name="instance">工作流实例</param> /// <param name="role">用户的审批角色</param> /// <param name="userIdentity">用户的身份</param> /// <returns>满足则返回True,否则返回False</returns> protected override bool IsMatch(StateMachineWorkflowInstance instance, ApprovalRole role, IUserIdentity userIdentity) { //最后一个Activity的执行者是否为当前用户如果是返回false if (instance == null) { throw new ArgumentNullException("instance"); } StateMachineWorkflowInstance stateMachine = (StateMachineWorkflowInstance)WorkflowRuntime.Current.GetInstance(instance.Id); //最后一个activity为空 返回true if (stateMachine.LastActivity == null) { return(true); } //最后一个activity执行者与用户身份和角色匹配,返回false if (string.Equals(stateMachine.LastActivity.UserId.Trim(), userIdentity.GetUserId().Trim(), StringComparison.OrdinalIgnoreCase) && string.Equals(stateMachine.LastActivity.UserApprovalRole, role.Name)) { return(false); } return(true); }
/// <summary> /// Executes the specified instance. /// </summary> /// <param name="instance">The instance.</param> /// <param name="activity">The activity.</param> public void Execute(WorkflowInstance instance, ActivityBase activity) { if (instance == null) { throw new ArgumentNullException("instance"); } if (activity == null) { throw new ArgumentNullException("activity"); } if (string.IsNullOrEmpty(activity.UserId)) { activity.UserId = GetService <IIdentityService>().GetUserIdentity().GetUserId(); } IWorkflowSecurityService service = GetService <IWorkflowSecurityService>(); ApprovalRole role = service.GetActionRole(instance, activity.UserId, activity.EventName); activity.UserApprovalRole = role.Name; if (service.CanDoAction(instance, activity.EventName)) { ITransactionService transactionService = GetService <ITransactionService>(); transactionService.BeginTransaction(); try { instance.InternalExecute(activity); transactionService.CommitTransaction(); } catch (Exception ep) { transactionService.RollbackTransaction(); throw ep; } } else { throw new WorkflowExecuteExeception(string.Format("不能执行本次操作:流程当前状态\"{0}\"不能进行\"{1}\"操作,或您不具备执行该操作的权限.", ((StateMachineWorkflowInstance)instance).CurrentState.Description)); } }
/// <summary> ///记录是否被过滤掉:如果记录需要被过滤掉(去除),那么返回true,否则返回false /// </summary> /// <param name="record">The record.</param> /// <returns> /// <c>true</c> if the specified record is filtered; otherwise, <c>false</c>. /// </returns> public bool IsFiltered(T record) { //没有定义审批角色的不显示 if (string.IsNullOrEmpty(record.OperatorRole)) { return(true); } //该角色名称对应的角色不正确的不显示 ApprovalRole role = GetApprovalRoleByName(record.OperatorRole); if (role == null) { return(true); } //有角色,如果级别不在一个级别,那么不显示,或者显示隐藏信息 if (role.Group != userRole.Group) { return(true); } return(false); }
/// <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); }
/// <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> /// 获取指定工作流、角色、时间段的实例集合 /// </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) { 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="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> /// 获取指定工作流、角色、时间段的实例集合 /// </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); }
/// <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) { 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); }
/// <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); }
/// <summary> /// 获取指定工作流、角色、时间段的实例集合 /// </summary> /// <param name="workflowName">流程名称</param> /// <param name="userIdentity">用户身份</param> /// <param name="role">审批角色</param> /// <param name="startDate">时间段起始时间</param> /// <param name="endDate">时间段截止时间</param> /// <returns></returns> internal InstanceCollection InternalDistill(string workflowName, IUserIdentity userIdentity, ApprovalRole role, DateTime startDate, DateTime endDate) { if (workflowName == null) { throw new ArgumentNullException("workflowName"); } if (userIdentity == null) { throw new ArgumentNullException("userIdentity"); } if (role == null) { throw new ArgumentNullException("role"); } return(Distill(workflowName, userIdentity, role, startDate, endDate)); }
/// <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 abstract InstanceCollection Distill(string workflowName, IUserIdentity userIdentity, ApprovalRole role, DateTime startDate, DateTime endDate);
/// <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) { List <StateMachineWorkflowInstance> instances = new List <StateMachineWorkflowInstance>(); List <string> states = InstanceDistillerHelper.GetAssignedICanCancelStates(workflowName, role); if (states.Count == 0) { return(new InstanceCollection()); } 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 (states.Contains(instance.CurrentState.Name) && instance.PersistTime >= startDate && instance.PersistTime <= endDate) { collection.Add(new InstanceWithRole(instance, role, false)); } } return(collection); }
/// <summary> ///设置环境参数 /// </summary> /// <param name="workflowName">Name of the workflow.</param> /// <param name="role">用户的审批角色</param> /// <param name="userId">以用户的Id</param> public void SetValues(string workflowName, ApprovalRole role, string userId) { this.approvalRole = role; }