Пример #1
0
        protected virtual async Task ApplyStageAsync(Expression <Func <DicRouteStage, bool> > nextStageFunc, Domain.Entities.Request.Request request)
        {
            if (nextStageFunc == null)
            {
                return;
            }

            DicRouteStage nextStage;

            try
            {
                nextStage = await _context.DicRouteStages.SingleAsync(nextStageFunc);
            }
            catch (Exception)
            {
                Log.Warning($"Workflow logic applier. The next stage query is incorrect: {nextStageFunc}!");
                return;
            }

            var workflow = new RequestWorkflow
            {
                RouteId        = nextStage.RouteId,
                OwnerId        = request.Id,
                Owner          = request,
                CurrentStageId = nextStage.Id,
                CurrentUserId  = request.CurrentWorkflow.CurrentUserId,
                FromStageId    = request.CurrentWorkflow.CurrentStageId,
                FromUserId     = request.CurrentWorkflow.CurrentUserId,
                IsComplete     = nextStage.IsLast,
                IsSystem       = nextStage.IsSystem,
                IsMain         = nextStage.IsMain
            };

            await _workflowApplier.ApplyAsync(workflow);
        }
Пример #2
0
            public async Task <MaterialWorkflowDto> Handle(Command message)
            {
                var workflowDto = message.DocumentWorkflowDto;

                workflowDto.CurrentStageCode = _context.DicRouteStages
                                               .Where(rs => rs.Id == workflowDto.CurrentStageId)
                                               .Select(rs => rs.Code).SingleOrDefault();
                var documentWorkflow = _mapper.Map <MaterialWorkflowDto, DocumentWorkflow>(workflowDto);

                await _workflowApplier.ApplyAsync(documentWorkflow);

                var document = await _context.Documents
                               .Include(d => d.Type)
                               .SingleOrDefaultAsync(d => d.Id == documentWorkflow.OwnerId);

                await _context.SaveChangesAsync();

                //await _contractWorkflowApplier.AutoApplyAsync(document);
                await _transferedDocumentApplier.ApplyAsync(documentWorkflow.OwnerId);

                await _context.SaveChangesAsync();

                var workflow = await _context.DocumentWorkflows
                               .Include(w => w.FromStage)
                               .Include(w => w.CurrentStage)
                               .Include(w => w.FromUser)
                               .Include(w => w.CurrentUser)
                               .Include(w => w.Route)
                               .Include(w => w.Owner)
                               .SingleAsync(w => w.Id == documentWorkflow.Id);

                workflowDto = _mapper.Map <DocumentWorkflow, MaterialWorkflowDto>(workflow);
                if (document != null)
                {
                    workflowDto.OutgoingNum  = document.OutgoingNumber;
                    workflowDto.DocumentDate = document.SendingDate;
                }

                return(workflowDto);
            }
Пример #3
0
        private Tuple <int, int> ResolvePortionInternal()
        {
            var tasks = _context.WorkflowTaskQueues
                        .Include(q => q.Request)
                        .ThenInclude(r => r.CurrentWorkflow)
                        .ThenInclude(cw => cw.CurrentStage)
                        .Include(q => q.Request)
                        .ThenInclude(r => r.CurrentWorkflow)
                        .ThenInclude(cw => cw.Owner)
                        .ThenInclude(cw => cw.Workflows)
                        .ThenInclude(cw => cw.CurrentStage)
                        .Include(q => q.Request)
                        .ThenInclude(r => r.CurrentWorkflow)
                        .ThenInclude(cw => cw.Owner)
                        .ThenInclude(cw => cw.Workflows)
                        .ThenInclude(cw => cw.FromStage)
                        .Include(q => q.ConditionStage)
                        .Include(q => q.ResultStage)
                        .IgnoreQueryFilters()
                        .Where(q => q.ResolveDate < DateTimeOffset.Now && q.RequestId != null)
                        .Take(Count)
                        .ToList();

            var applyedCount = 0;

            foreach (var task in tasks)
            {
                if (PosiviteConditions(task))
                {
                    _workflowApplier.ApplyAsync(GetWorkflow(task.Request.CurrentWorkflow, task)).Wait();
                    applyedCount++;
                }
            }

            _context.WorkflowTaskQueues.RemoveRange(tasks);
            _context.SaveChangesAsync().Wait();

            return(new Tuple <int, int>(tasks.Count, applyedCount));
        }
Пример #4
0
        public void Resolve()
        {
            var tasks = _context.WorkflowTaskQueues
                        .Include(t => t.Contract).ThenInclude(c => c.CurrentWorkflow)
                        .Include(t => t.Contract).ThenInclude(c => c.Documents)
                        .Include(t => t.Contract).ThenInclude(c => c.ContractCustomers).ThenInclude(c => c.CustomerRole)
                        .Include(t => t.ResultStage)
                        .Include(t => t.ConditionStage)
                        .Where(t => t.ResolveDate < DateTimeOffset.Now);

            foreach (var task in tasks)
            {
                if (task.ResultStage != null)
                {
                    _contractWorkflowApplier.ApplyAsync(GenerateWorkflow(task.Contract.CurrentWorkflow, task.ResultStage)).Wait();
                }
                else
                {
                    ResolveSpecificLogicTask(task);
                }
            }
            _context.WorkflowTaskQueues.RemoveRange(tasks);
        }
Пример #5
0
 public async Task <object> Handle(Command message)
 {
     foreach (var id in message.Ids)
     {
         var protectionDoc = _context.ProtectionDocs
                             .Include(pd => pd.CurrentWorkflow)
                             .Single(pd => pd.Id == id);
         var nextStage    = _context.DicRouteStages.Single(rs => rs.Code.Equals("OD01.3"));
         var nextWorkflow = new ProtectionDocWorkflow
         {
             OwnerId        = protectionDoc.Id,
             FromUserId     = protectionDoc.CurrentWorkflow.CurrentUserId,
             FromStageId    = protectionDoc.CurrentWorkflow.CurrentStageId,
             CurrentUserId  = message.UserId,
             CurrentStageId = nextStage.Id,
             RouteId        = nextStage.RouteId,
             IsComplete     = nextStage.IsLast,
             IsSystem       = nextStage.IsSystem,
             IsMain         = nextStage.IsMain
         };
         await _workflowApplier.ApplyAsync(nextWorkflow);
     }
     return(null);
 }
Пример #6
0
            public async Task <WorkflowDto> Handle(Create.Command message)
            {
                var workflowDto = message.WorkflowDto;

                try
                {
                    switch (message.OwnerType)
                    {
                    case Owner.Type.Request:
                    {
                        var requestWorkflow = _mapper.Map <WorkflowDto, RequestWorkflow>(workflowDto);

                        await _workflowApplier.ApplyAsync(requestWorkflow);

                        await _context.SaveChangesAsync();

                        var workflow = await _context.RequestWorkflows
                                       .Include(r => r.FromStage)
                                       .Include(r => r.CurrentStage)
                                       .Include(r => r.FromUser)
                                       .Include(r => r.CurrentUser)
                                       .Include(r => r.Route)
                                       .Include(r => r.Owner)
                                       .SingleAsync(w => w.Id == requestWorkflow.Id);

                        return(_mapper.Map <RequestWorkflow, WorkflowDto>(workflow));
                    }

                    case Owner.Type.ProtectionDoc:
                        var protectionDocWorkflow = _mapper.Map <WorkflowDto, ProtectionDocWorkflow>(workflowDto);

                        await _protectionDocWorkflowApplier.ApplyAsync(protectionDocWorkflow);

                        await _context.SaveChangesAsync();

                        var newProtectionDocWorkflow = await _context.ProtectionDocWorkflows
                                                       .Include(r => r.FromStage)
                                                       .Include(r => r.CurrentStage)
                                                       .Include(r => r.FromUser)
                                                       .Include(r => r.CurrentUser)
                                                       .Include(r => r.Route)
                                                       .Include(r => r.Owner)
                                                       .SingleAsync(w => w.Id == protectionDocWorkflow.Id);

                        return(_mapper.Map <ProtectionDocWorkflow, WorkflowDto>(newProtectionDocWorkflow));

                    case Owner.Type.Contract:
                    {
                        var contractWorkflow = _mapper.Map <WorkflowDto, ContractWorkflow>(workflowDto);

                        await _contractworkflowApplier.ApplyAsync(contractWorkflow);

                        await _context.SaveChangesAsync();

                        var workflow = await _context.ContractWorkflows
                                       .Include(r => r.FromStage)
                                       .Include(r => r.CurrentStage)
                                       .Include(r => r.FromUser)
                                       .Include(r => r.CurrentUser)
                                       .Include(r => r.Route)
                                       .Include(r => r.Owner)
                                       .SingleAsync(w => w.Id == contractWorkflow.Id);

                        return(_mapper.Map <ContractWorkflow, WorkflowDto>(workflow));
                    }

                    case Owner.Type.Material:
                        throw new NotImplementedException();

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                catch (Exception e)
                {
                    throw new DatabaseException(e.InnerException?.Message ?? e.Message);
                }
            }