Exemple #1
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="instance">The instance.</param>
        /// <param name="userId">The user id.</param>
        /// <returns></returns>
        public virtual bool IsMyAgentInstance(WorkflowInstance instance, string userId)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }
            if (string.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException("userId");
            }
            ApprovalState        currentState    = ((StateMachineWorkflowInstance)instance).CurrentState;
            IApprovalSaveService approvalService = WorkflowRuntime.Current.GetService <IApprovalSaveService>();
            List <ApprovalAgent> agentList       = approvalService.GetValidAgentInfoByToUser(userId);

            if (agentList != null && agentList.Count > 0)
            {
                foreach (ApprovalAgent agentInfo in agentList)
                {
                    foreach (ApprovalEvent approvalEvent in currentState.Events)
                    {
                        if (IsMyTaskInstance(instance, agentInfo.SetUserId))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
 /// <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();
 }
        /// <summary>
        /// 删除某授权信息:1)如果该项代理尚已经开始生效,但是未到实效日期,那么将该项代理的失效时间设置为当前日期.
        /// 2)如果如果该项代理尚已经开始生效,且以过了实效日期,那么什么也不做.
        /// 3)如果该代理尚未生效,那么直接删除.
        /// </summary>
        /// <param name="agentInfo">The agent info.</param>
        public static void DeleteAgentInfo(ApprovalAgent agentInfo)
        {
            IApprovalSaveService service = WorkflowRuntime.Current.GetService <IApprovalSaveService>();

            if (agentInfo.BeginDate >= DateTime.Now)
            {
                service.DeleteAgentInfoById(agentInfo.Id);
            }
            else if (agentInfo.EndDate > DateTime.Now)
            {
                agentInfo.EndDate = DateTime.Now;
                service.UpdateAgentInfo(agentInfo);
            }
        }
        /// <summary>
        /// 保存用户定制意见
        /// </summary>
        /// <param name="commentInfo">定制意见内容</param>
        /// <param name="applicationName">审批应用的名称:如果要实现不同的应用下同一个审批类型可以定制不同的意见,那么需要传入非空字符串.</param>
        /// <param name="approvalType">审批操作类别</param>
        /// <param name="userId">The user id.</param>
        public static void InsertCommentInfo(string commentInfo, string applicationName, string approvalType, string userId)
        {
            IApprovalSaveService service = WorkflowRuntime.Current.GetService <IApprovalSaveService>();
            string type = string.Format("{0}{1}", applicationName, approvalType);

            if (!string.IsNullOrEmpty(commentInfo) && service.GetCommentInfo(commentInfo, userId, type).Count == 0)
            {
                //如该定制内容不存在,则添加该意见
                ApprovalComment comment = new ApprovalComment();
                comment.CommentInfo  = commentInfo;
                comment.ApprovalType = type;
                comment.OwnerUserId  = WorkflowRuntime.Current.GetService <IIdentityService>().GetUserIdentity().GetUserId();
                service.InsertCommentInfo(comment);
            }
        }
        /// <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 #7
0
		/// <summary>
		/// 获取某用户的代理办理项目列表
		/// </summary>
		/// <param name="taskName">任务名称</param>
		/// <param name="agentInfoId">待办记录的Id</param>
		/// <returns></returns>
		public virtual TaskList GetAgentProceedList(string taskName, int agentInfoId)
		{
			IApprovalSaveService service = WorkflowRuntime.Current.GetService<IApprovalSaveService>();
			ApprovalAgent agentInfo = service.GetAgentInfoById(agentInfoId);
			string agentUserId = agentInfo.ToUserId;
			string agentUserName = agentInfo.ToUserName;
			IUserIdentity setAgentUserIdentity = WorkflowRuntime.Current.GetService<IIdentityService>().GetUserIdentity(agentInfo.SetUserId);
			string setAgentUserName = setAgentUserIdentity.GetUserName();
			string agentRecordUserInfo = agentUserName + "(代" + setAgentUserName + ")";
			List<ApprovalRecord> recordList = new List<ApprovalRecord>();
			string[] workflowNames = WorkflowRuntime.Current.DefineService.GetAllWorkflowDefineName(applicationName);
			foreach (string workflowName in workflowNames)
			{
				WorkflowRuntime.Current.GetService<IApprovalSaveService>().GetRecord(workflowName, agentInfo.BeginDate, agentInfo.EndDate, agentInfo.SetUserId);
			}
			List<int> eaIds = new List<int>();
			foreach (ApprovalRecord record in recordList)
			{
				if (record.OperatorName == agentRecordUserInfo)
				{
					if (!eaIds.Contains(record.EaId))
						eaIds.Add(record.EaId);
				}
			}
			List<StateMachineWorkflowInstance> instanceList = new List<StateMachineWorkflowInstance>();
			foreach (int eaid in eaIds)
			{
				List<StateMachineWorkflowInstance> instances = WorkflowRuntime.Current.GetInstance(applicationName, eaid, false);
				foreach (StateMachineWorkflowInstance instance in instances)
				{
					if (instance.ParentId == null || instance.ParentId == Guid.Empty)
					{
						instanceList.Add(instance);
						break;
					}
				}
			}
			return new TaskList("a." + taskName, ItemProcessor.GenerateTaskTable(instanceList, true));
		}
        /// <summary>
        /// 判断某用户是否具有对指定实例进行指定动作的执行权限
        /// </summary>
        /// <param name="instance">工作流实例</param>
        /// <param name="actionName">执行动作</param>
        /// <returns></returns>
        public virtual bool CanDoAction(WorkflowInstance instance, string actionName)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }
            if (string.IsNullOrEmpty(actionName))
            {
                throw new ArgumentNullException("actionName");
            }
            IUserInRole   userInRole   = WorkflowRuntime.Current.GetService <IIdentityService>().GetUserInRole();
            IUserIdentity userIdentity = WorkflowRuntime.Current.GetService <IIdentityService>().GetUserIdentity();

            if (GetActionRole(instance, userIdentity.GetUserId(), actionName) != null)
            {
                return(true);
            }
            ApprovalEvent        approvalEvent   = ((StateMachineWorkflowInstance)instance).CurrentState.GetEventByName(actionName);
            IApprovalSaveService approvalService = WorkflowRuntime.Current.GetService <IApprovalSaveService>();
            List <ApprovalAgent> agentList       = approvalService.GetValidAgentInfoByToUser(userIdentity.GetUserId());

            if (agentList != null && agentList.Count > 0)
            {
                foreach (ApprovalAgent agentInfo in agentList)
                {
                    foreach (EventRole role in approvalEvent.Roles)
                    {
                        if (IsAuthorized(agentInfo.SetUserId, approvalEvent, instance))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        /// <summary>
        /// 删除定制意见
        /// </summary>
        /// <param name="idString">定制意见Id</param>
        public static void DeleteCommentInfo(int id)
        {
            IApprovalSaveService service = WorkflowRuntime.Current.GetService <IApprovalSaveService>();

            service.DeleteCommentInfo(id);
        }
        /// <summary>
        /// 获取用户的定制意见信息
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="applicationName">审批应用的名称:如果要实现不同的应用下同一个审批类型可以定制不同的意见,那么需要传入非空字符串.</param>
        /// <param name="approvalType">审批操作类别</param>
        /// <returns>定制意见和其Id的数组</returns>
        public static List <ApprovalComment> GetUserCommentInfo(string userId, string applicationName, string approvalType)
        {
            IApprovalSaveService service = WorkflowRuntime.Current.GetService <IApprovalSaveService>();

            return(service.GetUserCommentInfo(userId, string.Format("{0}{1}", applicationName, approvalType)));
        }