public virtual IQueryable <Sungero.Workflow.IAssignmentBase> OnApprovalDataQuery(IQueryable <Sungero.Workflow.IAssignmentBase> query) { // Фильтр по типу. var typeFilterEnabled = _filter != null && (_filter.RuleBased || _filter.Free); var showRuleBasedApproval = !typeFilterEnabled || _filter.RuleBased; var showFreeApproval = !typeFilterEnabled || _filter.Free; var result = query .Where(a => showRuleBasedApproval && (ApprovalAssignments.Is(a) || ApprovalManagerAssignments.Is(a)) || showFreeApproval && FreeApprovalAssignments.Is(a)); // Запрос непрочитанных без фильтра. if (_filter == null) { return(RecordManagement.PublicFunctions.Module.ApplyCommonSubfolderFilters(result)); } // Фильтры по статусу, замещению и периоду. result = RecordManagement.PublicFunctions.Module.ApplyCommonSubfolderFilters(result, _filter.InProcess, _filter.Last30Days, _filter.Last90Days, _filter.Last180Days, false); return(result); }
public virtual void Script5Execute() { // Если родительское задание прекращено, то срок не продлять. if (_obj.ParentAssignment.Status != Workflow.AssignmentBase.Status.InProcess) { return; } var desiredDeadline = _obj.NewDeadline; if (RecordManagement.ActionItemExecutionAssignments.As(_obj.ParentAssignment) != null) { // Обновить срок у задания. var actionItemAssignment = RecordManagement.ActionItemExecutionAssignments.Get(_obj.ParentAssignment.Id); actionItemAssignment.Deadline = desiredDeadline; actionItemAssignment.ScheduledDate = desiredDeadline; // Обновить срок у задачи. var actionItemExecution = RecordManagement.ActionItemExecutionTasks.Get(actionItemAssignment.Task.Id); actionItemExecution.Deadline = desiredDeadline; actionItemExecution.MaxDeadline = desiredDeadline; // Обновить срок у составной задачи. if (actionItemExecution.ActionItemType == RecordManagement.ActionItemExecutionTask.ActionItemType.Component) { var component = RecordManagement.ActionItemExecutionTasks.Get(actionItemExecution.ParentTask.Id); var actionItem = component.ActionItemParts.FirstOrDefault(j => Equals(j.Assignee, actionItemExecution.Assignee) && (Equals(j.ActionItemPart, actionItemExecution.ActionItem) || string.IsNullOrEmpty(j.ActionItemPart)) && (j.Deadline == _obj.CurrentDeadline || j.Deadline == null)); if (actionItem != null) { actionItem.Deadline = desiredDeadline; } } // Продлить сроки соисполнителей. foreach (var performer in actionItemExecution.CoAssignees) { var subTasks = RecordManagement.ActionItemExecutionTasks.GetAll(t => Equals(t.MainTask, actionItemExecution) && t.Status == Sungero.Workflow.Task.Status.InProcess && Equals(t.Assignee, performer.Assignee)); foreach (var subTask in subTasks) { subTask.Deadline = desiredDeadline; subTask.MaxDeadline = desiredDeadline; // Продлить срок у активного задания соисполнителя. var assignment = RecordManagement.ActionItemExecutionAssignments.GetAll() .FirstOrDefault(a => Equals(a.Task, subTask) && a.Status == Sungero.Workflow.AssignmentBase.Status.InProcess); if (assignment != null) { assignment.Deadline = desiredDeadline; assignment.ScheduledDate = desiredDeadline; } } } } else if (RecordManagement.ReportRequestAssignments.Is(_obj.ParentAssignment)) { // Обновить срок у задания. _obj.ParentAssignment.Deadline = desiredDeadline; // Обновить срок у задачи. var reportRequestTask = RecordManagement.StatusReportRequestTasks.Get(_obj.ParentAssignment.Task.Id); reportRequestTask.MaxDeadline = desiredDeadline; } else if (FreeApprovalAssignments.Is(_obj.ParentAssignment)) { // Обновить срок у задания. var freeApprovalAssignment = FreeApprovalAssignments.Get(_obj.ParentAssignment.Id); freeApprovalAssignment.Deadline = desiredDeadline; // Обновить срок у задачи. var freeApprovalTask = FreeApprovalTasks.Get(_obj.ParentAssignment.Task.Id); if (Functions.Module.CheckDeadline(desiredDeadline, freeApprovalTask.MaxDeadline)) { freeApprovalTask.MaxDeadline = desiredDeadline; } } else if (ApprovalCheckReturnAssignments.Is(_obj.ParentAssignment)) { // Обновить срок у задания. var checkReturnAssignment = ApprovalCheckReturnAssignments.As(_obj.ParentAssignment); checkReturnAssignment.Deadline = desiredDeadline; // Обновить срок на вкладке "Выдача" документа. if (checkReturnAssignment.DocumentGroup.OfficialDocuments.Any()) { var document = checkReturnAssignment.DocumentGroup.OfficialDocuments.FirstOrDefault(); ((Domain.Shared.IExtendedEntity)document).Params[Docflow.Constants.Module.DeadlineExtentsionTaskCallContext] = true; var tracks = document.Tracking.Where(t => Equals(t.ReturnTask, checkReturnAssignment.Task) && t.ReturnResult == null && t.ReturnDeadline != null); foreach (var track in tracks) { track.ReturnDeadline = desiredDeadline; } } } else if (CheckReturnAssignments.Is(_obj.ParentAssignment)) { // Обновить срок у задания. var checkReturnAssignment = CheckReturnAssignments.As(_obj.ParentAssignment); checkReturnAssignment.Deadline = desiredDeadline; if (CheckReturnTasks.Is(checkReturnAssignment.Task)) { var checkReturnTask = CheckReturnTasks.As(checkReturnAssignment.Task); checkReturnTask.MaxDeadline = desiredDeadline; } // Обновить срок на вкладке "Выдача" документа. if (checkReturnAssignment.DocumentGroup.OfficialDocuments.Any()) { var document = checkReturnAssignment.DocumentGroup.OfficialDocuments.FirstOrDefault(); ((Domain.Shared.IExtendedEntity)document).Params[Docflow.Constants.Module.DeadlineExtentsionTaskCallContext] = true; var tracks = document.Tracking.Where(t => Equals(t.ReturnTask, checkReturnAssignment.Task) && t.ReturnResult == null && t.ReturnDeadline != null); foreach (var track in tracks) { track.ReturnDeadline = desiredDeadline; } } } else { // Обновить срок у задания. _obj.ParentAssignment.Deadline = desiredDeadline; } // Обновить срок у задач. var parentAssignment = _obj.ParentAssignment; if (ApprovalTasks.Is(parentAssignment.MainTask)) { var approvalTask = ApprovalTasks.As(parentAssignment.MainTask); approvalTask.MaxDeadline = Functions.ApprovalTask.GetExpectedDate(approvalTask); } else if (RecordManagement.AcquaintanceTasks.Is(parentAssignment.MainTask)) { var acquaintanceTask = RecordManagement.AcquaintanceTasks.As(parentAssignment.MainTask); if (Functions.Module.CheckDeadline(desiredDeadline, acquaintanceTask.Deadline)) { acquaintanceTask.Deadline = desiredDeadline; } } }
/// <summary> /// Получить заголовок. /// </summary> /// <param name="assignment">Задание.</param> /// <returns>Информация о задании: исполнитель, срок, результат - отформатированная для предметного отображения.</returns> public Structures.FreeApprovalTask.AssignmentInfo GetPerformerAndDeadlineAndStatus(IAssignment assignment) { var performerName = PublicFunctions.OfficialDocument.GetAuthor(assignment.Performer, assignment.CompletedBy); var actionLabel = string.Empty; var emptyResult = Structures.FreeApprovalTask.AssignmentInfo.Create(string.Empty, string.Empty, string.Empty); // Задание завершено. if (assignment.Status == Workflow.AssignmentBase.Status.Completed) { // Согласование. if (FreeApprovalAssignments.Is(assignment)) { if (assignment.Result == Docflow.FreeApprovalAssignment.Result.Approved) { actionLabel = ApprovalTasks.Resources.StateViewEndorsed; } else if (assignment.Result == Docflow.FreeApprovalAssignment.Result.ForRework) { actionLabel = ApprovalTasks.Resources.StateViewNotApproved; } else if (assignment.Result == Docflow.FreeApprovalAssignment.Result.Forward) { actionLabel = ApprovalTasks.Resources.StateViewForwarded; } else { return(emptyResult); } } // Задание на завершение согласования. if (FreeApprovalFinishAssignments.Is(assignment)) { if (assignment.Result == Docflow.FreeApprovalFinishAssignment.Result.Complete) { actionLabel = ApprovalTasks.Resources.StateViewDone; } else { return(emptyResult); } } // Прекращение на доработке. if (FreeApprovalReworkAssignments.Is(assignment) && assignment.Status == Workflow.AssignmentBase.Status.Aborted) { actionLabel = ApprovalTasks.Resources.StateViewAborted; } var completed = Functions.Module.ToShortDateShortTime(assignment.Completed.Value.ToUserTime()); if (!string.IsNullOrWhiteSpace(actionLabel)) { return(Structures.FreeApprovalTask.AssignmentInfo.Create(string.Format("{0} ", performerName), string.Format("{0}: {1}", OfficialDocuments.Resources.StateViewDate, completed), actionLabel)); } } // Задание в работе или прекращено. if (assignment.Status == Workflow.AssignmentBase.Status.InProcess || assignment.Status == Workflow.AssignmentBase.Status.Aborted || assignment.Status == Workflow.AssignmentBase.Status.Suspended) { var status = ApprovalTasks.Resources.StateViewAborted.ToString(); if (assignment.Status == Workflow.AssignmentBase.Status.InProcess) { status = assignment.IsRead == true ? ApprovalTasks.Resources.StateViewInProcess : ApprovalTasks.Resources.StateViewUnRead; } var deadline = assignment.Deadline.HasValue ? Functions.Module.ToShortDateShortTime(assignment.Deadline.Value.ToUserTime()) : OfficialDocuments.Resources.StateViewWithoutTerm; return(Structures.FreeApprovalTask.AssignmentInfo.Create(string.Format("{0} ", performerName), string.Format("{0}: {1}", OfficialDocuments.Resources.StateViewDeadline, deadline), status)); } return(emptyResult); }
public Sungero.Core.StateView GetStateView() { // Добавить заголовок. var stateView = StateView.Create(); var taskBeginText = _obj.Texts.OrderBy(t => t.Created).FirstOrDefault(); var comment = taskBeginText != null ? taskBeginText.Body : string.Empty; comment = comment != FreeApprovalTasks.Resources.ApprovalText ? comment : string.Empty; if (_obj.Started.HasValue) { Docflow.PublicFunctions.OfficialDocument .AddUserActionBlock(stateView, _obj.Author, ApprovalTasks.Resources.StateViewDocumentSentForApproval, _obj.Started.Value, _obj, comment, _obj.StartedBy); } else { Docflow.PublicFunctions.OfficialDocument .AddUserActionBlock(stateView, _obj.Author, ApprovalTasks.Resources.StateViewTaskDrawCreated, _obj.Created.Value, _obj, comment, _obj.Author); } // Добавить основной блок для задачи. var taskBlock = this.AddTaskBlock(stateView); // Получить все задания по задаче. var taskAssignments = Assignments.GetAll().Where(a => Equals(a.Task, _obj)).ToList(); // Определить итерации. var iterations = Functions.Module.GetIterationDates(_obj); // Обработать каждую итерацию. foreach (var iteration in iterations) { var date = iteration.Date; var hasReworkBefore = iteration.IsRework; var hasRestartBefore = iteration.IsRestart; var nextIteration = iterations.Where(d => d.Date > date).FirstOrDefault(); var nextDate = Calendar.Now; if (nextIteration != null) { nextDate = nextIteration.Date; } // Получить задания в рамках круга согласования. var assignments = taskAssignments .Where(a => a.Created >= date && a.Created < nextDate) .OrderBy(a => a.Created) .ToList(); // Если нет заданий, то перейти к следующей итерации. if (!assignments.Any()) { continue; } // Добавить блок отправки. this.AddSendForApprovalBlock(taskBlock, assignments.First(), hasReworkBefore, hasRestartBefore); StateBlock parentBlock = null; // Выделить этап согласования. var approvalAssignments = assignments.Where(a => FreeApprovalAssignments.Is(a)); if (approvalAssignments.Any()) { // Вставить блок для группировки этапа согласования. var iterationBlock = taskBlock.AddChildBlock(); iterationBlock.NeedGroupChildren = true; iterationBlock.IsExpanded = approvalAssignments.Any(a => a.Status == Workflow.AssignmentBase.Status.InProcess); // Заголовок блока итерации. iterationBlock.AddLabel(ApprovalTasks.Resources.StateViewApprovalStage, Docflow.PublicFunctions.Module.CreateHeaderStyle()); iterationBlock.AddLineBreak(); // Добавить информацию по исполнителям группы согласования. var performersLabel = string.Join(", ", approvalAssignments .Select(a => a.Performer) .Distinct() .Select(a => (Sungero.Company.Employees.Is(a) ? Company.PublicFunctions.Employee.GetShortName(Sungero.Company.Employees.As(a), false) : a.Name))); iterationBlock.AddLabel(performersLabel, Docflow.PublicFunctions.Module.CreatePerformerDeadlineStyle()); parentBlock = iterationBlock; } // Добавить задания. assignments = assignments.OrderByDescending(a => a.Result.HasValue).ThenBy(a => a.Completed).ToList(); this.AddAssignmentsBlocks(parentBlock, taskBlock, assignments); // Установить иконку и статус для группировки этапа согласования. var endStatus = string.Empty; if (parentBlock != null) { // Иконка по умолчанию. parentBlock.AssignIcon(FreeApprovalTasks.Resources.FreeApproveStage, StateBlockIconSize.Large); if (approvalAssignments.Any(a => a.Result == Docflow.FreeApprovalAssignment.Result.ForRework)) { parentBlock.AssignIcon(ApprovalTasks.Resources.Notapprove, StateBlockIconSize.Large); endStatus = ApprovalTasks.Resources.StateViewNotApproved; } else if (!approvalAssignments.Any(a => a.Result != Docflow.FreeApprovalAssignment.Result.Approved)) { parentBlock.AssignIcon(ApprovalTasks.Resources.Approve, StateBlockIconSize.Large); endStatus = ApprovalTasks.Resources.StateViewEndorsed; } if (assignments.Any(a => a.Status == Workflow.AssignmentBase.Status.Aborted)) { parentBlock.AssignIcon(StateBlockIconType.Abort, StateBlockIconSize.Large); endStatus = ApprovalTasks.Resources.StateViewAborted; } Functions.Module.AddInfoToRightContent(parentBlock, parentBlock.IsExpanded ? ApprovalTasks.Resources.StateViewInProcess : endStatus); } } return(stateView); }
/// <summary> /// Установить иконку задания. /// </summary> /// <param name="block">Блок задания.</param> /// <param name="assignment">Задание.</param> public void SetIcon(Sungero.Core.StateBlock block, IAssignment assignment) { // Размер иконок: большой, если не задание согласования. var iconSize = StateBlockIconSize.Large; if (FreeApprovalAssignments.Is(assignment)) { iconSize = StateBlockIconSize.Small; } block.AssignIcon(StateBlockIconType.OfEntity, iconSize); if (assignment.Result != null) { // Согласовано. if (assignment.Result == Docflow.FreeApprovalAssignment.Result.Approved) { iconSize = StateBlockIconSize.Small; block.AssignIcon(ApprovalTasks.Resources.Approve, iconSize); } // На доработку. if (assignment.Result == Docflow.FreeApprovalAssignment.Result.ForRework) { iconSize = StateBlockIconSize.Small; block.AssignIcon(ApprovalTasks.Resources.Notapprove, iconSize); } // На повторное согласование. if (assignment.Result == Docflow.FreeApprovalReworkAssignment.Result.Reworked) { block.AssignIcon(StateBlockIconType.User, iconSize); block.ShowBorder = false; block.DockType = DockType.Bottom; } // Выполнено. if (assignment.Result == Docflow.FreeApprovalFinishAssignment.Result.Complete) { block.AssignIcon(ApprovalTasks.Resources.Completed, iconSize); } // Переадресовано. if (assignment.Result == Docflow.FreeApprovalAssignment.Result.Forward) { block.AssignIcon(FreeApprovalTasks.Resources.Forward, iconSize); } // Прекращено if (assignment.Status == Workflow.AssignmentBase.Status.Aborted) { block.AssignIcon(StateBlockIconType.Abort, iconSize); } } // Прекращено, остановлено по ошибке. if (assignment.Status == Workflow.AssignmentBase.Status.Aborted || assignment.Status == Workflow.AssignmentBase.Status.Suspended) { block.AssignIcon(StateBlockIconType.Abort, iconSize); } }
/// <summary> /// Добавить задания свободного согласования. /// </summary> /// <param name="parentBlock">Блок группировки.</param> /// <param name="taskBlock">Блок задачи.</param> /// <param name="assignments">Список заданий в рамках этапа согласования.</param> public void AddAssignmentsBlocks(Sungero.Core.StateBlock parentBlock, Sungero.Core.StateBlock taskBlock, List <IAssignment> assignments) { foreach (var assignment in assignments) { var noteStyle = Functions.Module.CreateNoteStyle(); var separatorStyle = Docflow.PublicFunctions.Module.CreateSeparatorStyle(); var performerDeadlineStyle = Docflow.PublicFunctions.Module.CreatePerformerDeadlineStyle(); var performerAndDeadlineAndStatus = this.GetPerformerAndDeadlineAndStatus(assignment); var performer = performerAndDeadlineAndStatus.Performer; var deadline = performerAndDeadlineAndStatus.Deadline; var status = performerAndDeadlineAndStatus.Status; if (string.IsNullOrWhiteSpace(performer)) { continue; } StateBlock block; if (parentBlock != null && FreeApprovalAssignments.Is(assignment)) { block = parentBlock.AddChildBlock(); } else { block = taskBlock.AddChildBlock(); } this.SetIcon(block, assignment); block.Entity = assignment; // Заголовок блока с заданием о завершении или доработке. if (!FreeApprovalAssignments.Is(assignment)) { var blockLabel = string.Empty; if (FreeApprovalFinishAssignments.Is(assignment)) { blockLabel = FreeApprovalTasks.Resources.StateViewCompleteApprovalAssignment; } else if (FreeApprovalReworkAssignments.Is(assignment)) { blockLabel = FreeApprovalTasks.Resources.StateViewReworkByRemarks; } block.AddLabel(blockLabel, Docflow.PublicFunctions.Module.CreateHeaderStyle()); block.AddLineBreak(); } // Заполнить участников. var performerLabel = string.Format("{0}{1}", performer, deadline); block.AddLabel(performerLabel, performerDeadlineStyle); var comment = Docflow.Functions.Module.GetAssignmentUserComment(assignment); if (!string.IsNullOrWhiteSpace(comment)) { block.AddLineBreak(); block.AddLabel(Constants.Module.SeparatorText, separatorStyle); block.AddLineBreak(); block.AddEmptyLine(Constants.Module.EmptyLineMargin); block.AddLabel(comment, noteStyle); } // Заполнить статус задания и просрочку. Functions.Module.AddInfoToRightContent(block, status); if (assignment.Status == Workflow.AssignmentBase.Status.InProcess && assignment.Deadline.HasValue) { Functions.OfficialDocument.AddDeadlineHeaderToRight(block, assignment.Deadline.Value, assignment.Performer); } } }