private void CreateWorkflowAutomaticStageTask() { var request = Executor.GetQuery <GetRequestByIdQuery>().Process(r => r.Execute(WorkflowRequest.CurrentWorkflowObject.Id)); var nextStageOrders = Executor.GetQuery <GetNextDicRouteStageOrdersByCodeQuery>() .Process(r => r.Execute(request.CurrentWorkflow.CurrentStage.Code)); var automaticStages = nextStageOrders.Where(r => r.IsAutomatic == true); foreach (var autoStageOrder in automaticStages) { var workflowTaskQueueResolveDate = Executor.GetHandler <CalculateWorkflowTaskQueueResolveDateHandler>() .Process(r => r.Execute(request.Id, Owner.Type.Request, autoStageOrder.NextStage.Code)); var workflowTaskQueue = new WorkflowTaskQueue { RequestId = request.Id, ResolveDate = workflowTaskQueueResolveDate, ResultStageId = autoStageOrder.NextStageId, ConditionStageId = autoStageOrder.CurrentStage.Id, }; Executor.GetCommand <CreateWorkflowTaskQueueCommand>() .Process(r => r.Execute(workflowTaskQueue)); } }
public void Execute(WorkflowTaskQueue workflowTaskQueue) { var workflowTaskQueueRepository = Uow.GetRepository <WorkflowTaskQueue>(); workflowTaskQueueRepository.Create(workflowTaskQueue); Uow.SaveChanges(); }
/// <summary> /// Запускает рабочий процесс связанный, с охранным документом(ОД), с пометкой "автоматический". /// </summary> /// <param name="workflowTaskEvent">Запланированная задача.</param> private static void ProcessProtectionDocumentWorkflowEvent(WorkflowTaskQueue workflowTaskEvent) { var protectionDocumentWorkFlowRequest = new ProtectionDocumentWorkFlowRequest { ProtectionDocId = workflowTaskEvent.ProtectionDocId ?? default(int), IsAuto = true }; NiisWorkflowAmbientContext.Current.ProtectionDocumentWorkflowService.Process(protectionDocumentWorkFlowRequest); }
/// <summary> /// Запускает рабочий процесс, связанный с договором, с пометкой "автоматический". /// </summary> /// <param name="workflowTaskEvent"></param> private static void ProcessContractWorkflowEvent(WorkflowTaskQueue workflowTaskEvent) { var сontractWorkFlowRequest = new ContractWorkFlowRequest { ContractId = workflowTaskEvent.ContractId ?? default(int), IsAuto = true }; NiisWorkflowAmbientContext.Current.ContractWorkflowService.Process(сontractWorkFlowRequest); }
private RequestWorkflow GetWorkflow(RequestWorkflow currentWorkflow, WorkflowTaskQueue task) { var taskResultStage = task.ResultStage ?? GetCalculatedResultStage(currentWorkflow); return(new RequestWorkflow { OwnerId = currentWorkflow.OwnerId, FromUserId = currentWorkflow.CurrentUserId, FromStageId = currentWorkflow.CurrentStageId, CurrentUserId = currentWorkflow.CurrentUserId, CurrentStageId = taskResultStage.Id, RouteId = taskResultStage.RouteId, IsComplete = taskResultStage.IsLast, IsSystem = taskResultStage.IsSystem, IsMain = taskResultStage.IsMain }); }
private void ResolveSpecificLogicTask(WorkflowTaskQueue task) { if (task.ConditionStage.Code == "DK02.4.0") { var contract = task.Contract; if (contract == null) { return; } ContractDocument newContractDocument = GenerateDocument(contract); if (contract.CurrentWorkflow.CurrentUserId != null) { _documentWorkflowApplier.ApplyInitialAsync(newContractDocument.Document, contract.CurrentWorkflow.CurrentUserId.Value); } contract.Documents.Add(newContractDocument); contract.IsRead = false; _context.SaveChangesAsync().Wait(); } }
protected Action SendContractToNextStage(string stageCode) { return(() => { var nextWorkFlow = CreateRequestWorkFlow(stageCode); Executor.GetCommand <CreateContractWorkflowCommand>().Process(r => r.Execute(nextWorkFlow)); var contract = Executor.GetQuery <GetContractByIdQuery>().Process(r => r.Execute(WorkflowRequest.CurrentWorkflowObject.Id)); contract.CurrentWorkflow = nextWorkFlow; contract.CurrentWorkflowId = nextWorkFlow.Id; Executor.GetCommand <UpdateContractCommand>().Process(r => r.Execute(contract)); contract = Executor.GetQuery <GetContractByIdQuery>().Process(r => r.Execute(contract.Id)); Executor.GetCommand <UpdateMarkAsExecutedWorkflowTaskEvenstByRequestIdCommand>().Process(r => r.Execute(contract.Id)); #region Планирование автоэтапов var nextStageOrders = Executor.GetQuery <GetNextDicRouteStageOrdersByCodeQuery>().Process(r => r.Execute(contract.CurrentWorkflow.CurrentStage.Code)); var automaticStages = nextStageOrders.Where(r => r.IsAutomatic == true); foreach (var autoStageOrder in automaticStages) { var now = NiisAmbientContext.Current.DateTimeProvider.Now; var workflowTaskQueue = new WorkflowTaskQueue { ContractId = contract.Id, ResolveDate = now.AddMinutes(5), //TODO: специальное вычисление даты уведомления ResultStageId = autoStageOrder.NextStageId, ConditionStageId = autoStageOrder.CurrentStage.Id, }; Executor.GetCommand <CreateWorkflowTaskQueueCommand>().Process(r => r.Execute(workflowTaskQueue)); } #endregion }); }
/// <summary> /// Создает выполняемую задачу из запланированной задачи из бд. /// </summary> /// <param name="workflowTaskEvent">Запланированная задача из бл.</param> /// <returns>Выполняемая задача.</returns> public static WorkflowAutoExecutionEventObject ConstructFrom(WorkflowTaskQueue workflowTaskEvent) { var workflowEventObject = new WorkflowAutoExecutionEventObject { EventName = workflowTaskEvent.WorkflowEventKey, WorkflowTaskEvent = workflowTaskEvent }; if (workflowTaskEvent.IsRequestEvent) { workflowEventObject.EventAction = ProcessRequestWorkflowEvent; } else if (workflowTaskEvent.IsContractEvent) { workflowEventObject.EventAction = ProcessContractWorkflowEvent; } else if (workflowTaskEvent.IsProtectionDocEvent) { workflowEventObject.EventAction = ProcessProtectionDocumentWorkflowEvent; } return(workflowEventObject); }
public async Task RegisterAsync(int contractId) { var contract = await _context.Contracts .Include(c => c.CurrentWorkflow).ThenInclude(w => w.CurrentStage) .Include(c => c.Documents).ThenInclude(d => d.Document).ThenInclude(d => d.Type) .SingleOrDefaultAsync(c => c.Id == contractId); var resultStage = GetResultStage(contract.CurrentWorkflow.CurrentStage.Code); var resolveDate = GetResolveDate(contract); if (resolveDate != null) { var workflowTask = new WorkflowTaskQueue { Contract = contract, ResolveDate = resolveDate.Value, ResultStage = resultStage == contract.CurrentWorkflow.CurrentStage ? null : resultStage, ConditionStage = contract.CurrentWorkflow.CurrentStage }; await _context.WorkflowTaskQueues.AddAsync(workflowTask); await _context.SaveChangesAsync(); } }
protected Action SendProtectionDocumentToNextStage(string stageCode) { return(() => { List <DicRouteStage> nextStages = new List <DicRouteStage>(); var protectionDoc = Executor.GetQuery <GetProtectionDocByIdQuery>().Process(r => r.Execute(WorkflowRequest.CurrentWorkflowObject.Id)); List <ProtectionDocWorkflow> nextWorkFlows = new List <ProtectionDocWorkflow>(); if (stageCode == RouteStageCodes.ODParallel) { WorkflowRequest.SpecificNextStageUserIds[RouteStageCodes.ODParallel] = WorkflowRequest .CurrentWorkflowObject .CurrentWorkflow .CurrentUserId .HasValue ? WorkflowRequest.CurrentWorkflowObject.CurrentWorkflow.CurrentUserId.Value : WorkflowRequest.SpecificNextStageUserIds.Last().Value; List <string> stages; if (WorkflowRequest.SpecificNextStageUserIds.Any(x => x.Key == RouteStageCodes.OD01_6)) { stages = new List <string> { RouteStageCodes.OD01_3, RouteStageCodes.OD01_2_2, RouteStageCodes.OD01_6 } } ; else { stages = new List <string> { RouteStageCodes.OD01_3, RouteStageCodes.OD01_2_2, RouteStageCodes.OD03_1 } }; foreach (var stage_code in stages) { if (!protectionDoc.Workflows.Any(x => x.CurrentStage.Code == stage_code || (x.FromStage != null && x.FromStage.Code == stage_code))) { nextStages.Add(Executor.GetQuery <GetDicRouteStageByCodeQuery>().Process(q => q.Execute(stage_code))); nextWorkFlows.Add(CreateProtectionDocWorkFlow(stage_code)); } } ; nextWorkFlows.Add(CreateProtectionDocWorkFlow(RouteStageCodes.ODParallel)); } else { nextStages.Add(Executor.GetQuery <GetDicRouteStageByCodeQuery>().Process(q => q.Execute(stageCode))); nextWorkFlows.Add(CreateProtectionDocWorkFlow(stageCode)); } nextWorkFlows.ForEach(x => Executor.GetCommand <CreateProtectionDocWorkflowCommand>().Process(r => r.Execute(x))); for (int i = 0; i < nextWorkFlows.Count - 1; i++) { Executor.GetCommand <CreateProtectionDocParallelWorkflowCommand>().Process(r => r.Execute(nextWorkFlows[i])); } protectionDoc.CurrentWorkflow = nextWorkFlows.Last(); protectionDoc.CurrentWorkflowId = nextWorkFlows.Last().Id; protectionDoc.StatusId = nextStages.Last()?.ProtectionDocStatusId ?? protectionDoc.StatusId; Executor.GetCommand <UpdateProtectionDocCommand>().Process(r => r.Execute(protectionDoc)); protectionDoc = Executor.GetQuery <GetProtectionDocByIdQuery>().Process(r => r.Execute(protectionDoc.Id)); Executor.GetCommand <UpdateMarkAsExecutedWorkflowTaskEvenstByRequestIdCommand>().Process(r => r.Execute(protectionDoc.Id)); #region Запланируем автоэтап. var nextStageOrders = Executor.GetQuery <GetNextDicRouteStageOrdersByCodeQuery>().Process(r => r.Execute(protectionDoc.CurrentWorkflow.CurrentStage.Code)); var automaticStages = nextStageOrders.Where(r => r.IsAutomatic == true); foreach (var autoStageOrder in automaticStages) { var workflowTaskQueueResolveDate = Executor.GetHandler <CalculateWorkflowTaskQueueResolveDateHandler>().Process(r => r.Execute(protectionDoc.Id, Owner.Type.ProtectionDoc, autoStageOrder.NextStage.Code)); var workflowTaskQueue = new WorkflowTaskQueue { ProtectionDocId = protectionDoc.Id, ResolveDate = workflowTaskQueueResolveDate, ResultStageId = autoStageOrder.NextStageId, ConditionStageId = autoStageOrder.CurrentStage.Id, }; Executor.GetCommand <CreateWorkflowTaskQueueCommand>().Process(r => r.Execute(workflowTaskQueue)); } #endregion #region Создание патента/сертификата if (stageCode == RouteStageCodes.OD04_5) { CreatePatentOrCertificate(WorkflowRequest.CurrentWorkflowObject.Id); } #endregion #region Внесение ОД в реестр на отправку в МЮ if (stageCode == RouteStageCodes.OD01_3) { CreateProtectionDocRegister(WorkflowRequest.CurrentWorkflowObject.Id); } #endregion #region Создание удостоверений авторов //if (stageCode == RouteStageCodes.OD01_2_1) //{ // CreateAuthorsCertificate(WorkflowRequest.CurrentWorkflowObject.Id); //} #endregion #region Создание тарифов на поддержку ОД //if (stageCode == RouteStageCodes.OD01_5) //{ // CreateProtectionDocSupportTariffs(WorkflowRequest.CurrentWorkflowObject.Id); //} #endregion }); }
private static bool PosiviteConditions(WorkflowTaskQueue task) { return(!task.Request.IsDeleted && task.Request.CurrentWorkflow.CurrentStage.Id == task.ConditionStage.Id); }