/// <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="taskName">任务名称</param> /// <param name="agentId">授权代理记录的Id</param> /// <returns></returns> public string GetAgentProceedTask(string taskName, int agentId) { ApprovalAgent agentInfo = WorkflowRuntime.Current.SaveService.GetAgentInfoById(agentId); if (agentInfo == null) { return(string.Empty); } StringBuilder builders = new StringBuilder(); foreach (ApprovalService service in this) { builders.Append(service.AgentService.Distill(agentInfo.ToUserId, agentInfo.BeginDate, agentInfo.EndDate)); } return(builders.ToString()); }
/// <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)); }