/// <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>();
            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);
        }
Exemple #3
0
        /// <summary>
        /// 撤销操作时进行的相关审批记录操作,如果要用不同的记录,必须重写该方法
        /// </summary>
        /// <param name="instance">The instance.</param>
        protected virtual void TrackUndo(WorkflowInstance instance)
        {
            ApprovalRecord       record          = new ApprovalRecord();
            IIdentityService     service         = WorkflowRuntime.Current.GetService <IIdentityService>();
            IApprovalSaveService approvalService = WorkflowRuntime.Current.GetService <IApprovalSaveService>();

            if (service == null)
            {
                throw new WorkflowExecuteExeception("身份信息提供服务为空");
            }
            IUserIdentity userInfo = service.GetUserIdentity();

            record.OperatorTime       = DateTime.Now;
            record.WorkflowInstanceId = instance.Id;
            record.OperatorId         = userInfo.GetUserId();
            record.OperatorName       = userInfo.GetUserName();
            record.OperatorUnitCode   = userInfo.GetUserUnitCode();
            record.OperatorRole       = this.UserApprovalRole;
            record.EaId = instance.EaId;

            StateMachineWorkflowInstance stateMachine = instance as StateMachineWorkflowInstance;

            record.ApprovalType = GetUndoName(instance);
            record.StateName    = stateMachine.CurrentState.Description;
            if (recordId != 0)
            {
                ApprovalRecord historyRecord = approvalService.GetRecordById(recordId);
                historyRecord.IsCanceled = true;
                approvalService.SaveRecord(historyRecord);
            }
            WorkflowRuntime.Current.GetService <IApprovalSaveService>().InsertRecord(record);
        }
        /// <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)
        {
            string               userId    = userIdentity.GetUserId();
            string               unitCode  = IgnoreUnit ? "" : userIdentity.GetUserUnitCode();
            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.PersistService.GetWorkflowInstance(workflowName, canDoStates.ToArray(), userId, unitCode);

            //获取指定给本单位办理的实例
            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="rules">审批规则</param>
 /// <param name="userIdentity">用户省份</param>
 public ApprovalProcess(string workflowName, IApprovalRules rules, IUserIdentity userIdentity)
 {
     this.approvalService        = WorkflowRuntime.Current.GetService <IApprovalSaveService>();
     this.workflowPersistService = WorkflowRuntime.Current.GetService <IWorkflowPersistService>();
     this.workflow     = (StateMachineWorkflow)WorkflowRuntime.Current.GetService <IWorkFlowDefinePersistService>().GetWorkflowDefine(workflowName);
     this.rules        = rules;
     this.userIdentity = userIdentity;
     this.unitCode     = userIdentity.GetUserUnitCode();
     this.userId       = userIdentity.GetUserId();
 }
Exemple #6
0
		/// <summary>
		/// 按最后操作时间范围获取正在审批中的所有项目任务列表
		/// </summary>
		/// <param name="mainWorkflowName">Name of the main workflow.</param>
		/// <param name="isByUnit">if set to <c>true</c> [is by unit].</param>
		/// <returns></returns>
		public virtual TaskList[] GetProcessingLists(string mainWorkflowName, bool isByUnit)
		{
			string unitCode = "";
			if (isByUnit)
				unitCode = userIdentity.GetUserUnitCode();
			List<TaskList> result = new List<TaskList>();
			Dictionary<string, string> stateNames = new Dictionary<string, string>();
			string[] workflows = WorkflowRuntime.Current.GetService<IWorkFlowDefinePersistService>().GetAllWorkflowDefineName(applicationName);
			StateMachineWorkflow stateMachine = WorkflowRuntime.Current.GetService<IWorkFlowDefinePersistService>().GetWorkflowDefine(mainWorkflowName) as StateMachineWorkflow;
			AddApprovalStates(mainWorkflowName, stateNames);
			foreach (string stateDes in stateNames.Keys)
			{
				string stateName = stateNames[stateDes];
				List<StateMachineWorkflowInstance> instanceList = new List<StateMachineWorkflowInstance>();
				instanceList.AddRange(WorkflowRuntime.Current.GetInstance(mainWorkflowName, DateTime.Now.AddYears(-5), DateTime.Now.AddDays(1), new string[] { stateName }, unitCode));
				result.Add(new TaskList("a." + stateDes, ItemProcessor.GenerateTaskTable(instanceList, true)));
			}
			return result.ToArray();
		}
Exemple #7
0
        /// <summary>
        /// 在记录操作日志前,需要判断代办情况重新设置操作记录,如果是代办那么操作用户名设置为格式***(代***),
        /// 同时需要设置当前动作的UserId为当前真正执行改该动作的用户,以允许该执行者可以撤销操作,该方法允许被重载
        /// </summary>
        /// <param name="record">The record.</param>
        protected virtual void ResetRecordAndUserId(ApprovalRecord record)
        {
            IIdentityService service       = WorkflowRuntime.Current.GetService <IIdentityService>();
            IUserIdentity    userInfo      = service.GetUserIdentity();
            string           currentUserId = userInfo.GetUserId();

            if (currentUserId != userId)
            {
                IUserIdentity userIdentity = service.GetUserIdentity(userId);
                record.OperatorName     = userInfo.GetUserName() + "(代" + userIdentity.GetUserName() + ")";
                record.OperatorUnitCode = userIdentity.GetUserUnitCode();
                userId = currentUserId;
            }
        }
        /// <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="instance">工作流实例</param>
        /// <param name="userId">用户Id</param>
        /// <returns>是返回True 不是返回False</returns>
        public virtual bool IsMyTaskInstance(WorkflowInstance instance, string userId)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }
            if (string.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException("userId");
            }
            IApprovalSaveService      service      = WorkflowRuntime.Current.GetService <IApprovalSaveService>();
            ApprovalState             currentState = ((StateMachineWorkflowInstance)instance).CurrentState;
            List <ApprovalAssignment> assignments  = service.GetAssignmentByAssignState(instance.Id, currentState.Name);

            if (assignments.Count == 0)
            {
                foreach (ApprovalEvent approvalEvent in currentState.Events)
                {
                    if (IsAuthorized(userId, approvalEvent, instance))
                    {
                        return(true);
                    }
                }
            }
            else
            {
                IUserIdentity userIdentity = WorkflowRuntime.Current.GetService <IIdentityService>().GetUserIdentity(userId);
                foreach (ApprovalAssignment assignment in assignments)
                {
                    if (assignment.ToUserId == userId)
                    {
                        return(true);
                    }
                    if (assignment.ToUserId == null && assignment.ToUnitCode.Equals(userIdentity.GetUserUnitCode(), StringComparison.OrdinalIgnoreCase))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #10
0
        /// <summary>
        /// Determines whether the specified user identity is others.
        /// </summary>
        /// <param name="userIdentity">The user identity.</param>
        /// <param name="assignmentList">The assignment list.</param>
        /// <returns>
        ///     <c>true</c> if the specified user identity is others; otherwise, <c>false</c>.
        /// </returns>
        private static bool IsOthers(IUserIdentity userIdentity, List <ApprovalAssignment> assignmentList)
        {
            //是否已指定同角色中他人专办标识
            bool assignToOther = false;

            foreach (ApprovalAssignment assignment in assignmentList)
            {
                if (assignment.ToUserId == null)
                {
                    if (assignment.ToUnitCode.Trim() == userIdentity.GetUserUnitCode().Trim())
                    {
                        return(false);
                    }
                    else
                    {
                        assignToOther = true;
                    }
                }
            }
            return(assignToOther);
        }
Exemple #11
0
        /// <summary>
        /// 执行审批操作时进行的相关审批记录操作,如果要用不同的记录,必须重写该方法
        /// </summary>
        /// <param name="instance">The instance.</param>
        protected virtual void TrackExecute(WorkflowInstance instance)
        {
            ApprovalRecord   record  = new ApprovalRecord();
            IIdentityService service = WorkflowRuntime.Current.GetService <IIdentityService>();

            if (service == null)
            {
                throw new WorkflowExecuteExeception("身份信息提供服务为空");
            }
            IUserIdentity userInfo = service.GetUserIdentity();

            record.OperatorTime       = DateTime.Now;
            record.WorkflowInstanceId = instance.Id;
            string currentUserId = userInfo.GetUserId();

            record.OperatorId       = userId;
            record.OperatorName     = userInfo.GetUserName();
            record.OperatorUnitCode = userInfo.GetUserUnitCode();

            ResetRecordAndUserId(record);

            record.OperatorRole = this.UserApprovalRole;
            record.EaId         = instance.EaId;
            StateMachineWorkflowInstance stateMachine = instance as StateMachineWorkflowInstance;

            //如果没有定义活动的名称,那么从时间的描述中取出来
            if (string.IsNullOrEmpty(this.activityName))
            {
                this.activityName = stateMachine.CurrentState.GetEventByName(eventName).Description;
            }
            record.ApprovalType = this.ActivityName;
            record.StateName    = stateMachine.CurrentState.Description;
            record.SolutionInfo = solutionInfo;
            WorkflowRuntime.Current.GetService <IApprovalSaveService>().InsertRecord(record);
            this.recordId = record.Id;
        }
        /// <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)
        {
            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>
 /// Initializes a new instance of the <see cref="TaskItemProcessor"/> class.
 /// </summary>
 /// <param name="userIdentity">The user identity.</param>
 public TaskItemProcessor(IUserIdentity userIdentity)
 {
     this.userIdentity = userIdentity;
     this.unitCode     = userIdentity.GetUserUnitCode().Trim();
 }
        /// <summary>
        /// 是否是实例的所有者
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="userId">The user id.</param>
        /// <returns>
        ///     <c>true</c> if the specified instance is owner; otherwise, <c>false</c>.
        /// </returns>
        public virtual bool IsOwner(WorkflowInstance instance, string userId)
        {
            IUserIdentity userIdentity = WorkflowRuntime.Current.GetService <IIdentityService>().GetUserIdentity(userId);

            return(userIdentity.GetUserUnitCode().Trim() == instance.Properties["UnitCode"].Trim());
        }