Exemplo n.º 1
0
        protected virtual async Task ApplyStageAsync(Expression <Func <DicRouteStage, bool> > nextStageFunc,
                                                     Domain.Entities.Document.Document document, Domain.Entities.Contract.Contract contract)
        {
            if (nextStageFunc == null)
            {
                return;
            }

            DicRouteStage nextStage;

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

            var workflow = new ContractWorkflow
            {
                RouteId        = nextStage.RouteId,
                OwnerId        = contract.Id,
                Owner          = contract,
                CurrentStageId = nextStage.Id,
                CurrentUserId  = document.CurrentWorkflow.CurrentUserId,
                FromStageId    = contract.CurrentWorkflow.CurrentStageId,
                FromUserId     = contract.CurrentWorkflow.CurrentUserId,
                IsComplete     = nextStage.IsLast,
                IsSystem       = nextStage.IsSystem
            };

            await _workflowApplier.ApplyAsync(workflow);
        }
        public void ExecuteAsync(ContractWorkflow contractWorkflow)
        {
            var contractWorkflowRepository = Uow.GetRepository <ContractWorkflow>();

            contractWorkflowRepository.Update(contractWorkflow);
            Uow.SaveChanges();
        }
Exemplo n.º 3
0
        private ContractWorkflow CreateWorkflow(WtPtWorkoffice oldWorkoffice, int newContractId)
        {
            try
            {
                var wf = new ContractWorkflow
                {
                    ControlDate    = GetNullableDate(oldWorkoffice.ControlDate),
                    CurrentStageId = GetObjectId <DicRouteStage>(oldWorkoffice.ToStageId),
                    CurrentUserId  = GetUserId(oldWorkoffice.ToUserId),
                    DateCreate     = new DateTimeOffset(oldWorkoffice.DateCreate.GetValueOrDefault(DateTime.Now)),
                    DateUpdate     = new DateTimeOffset(oldWorkoffice.Stamp.GetValueOrDefault(DateTime.Now)),
                    Description    = oldWorkoffice.Description,
                    ExternalId     = oldWorkoffice.Id,
                    FromStageId    = GetObjectId <DicRouteStage>(oldWorkoffice.FromStageId),
                    FromUserId     = GetUserId(oldWorkoffice.FromUserId),
                    IsComplete     = GenerateHelper.StringToNullableBool(oldWorkoffice.IsComplete),
                    IsMain         = false,
                    IsSystem       = GenerateHelper.StringToNullableBool(oldWorkoffice.IsSystem),
                    OwnerId        = newContractId,
                    RouteId        = GetObjectId <DicRoute>(oldWorkoffice.TypeId),
                    Timestamp      = BitConverter.GetBytes(DateTime.Now.Ticks),
                };

                return(wf);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public async Task <ContractWorkflow> ExecuteAsync(Contract contract, int userId)
        {
            var dicProtectionDocTypesRepository = Uow.GetRepository <DicProtectionDocType>();
            var protectionDocType = await dicProtectionDocTypesRepository.AsQueryable().FirstOrDefaultAsync(t => t.Id == contract.ProtectionDocTypeId);

            var dicRouteStagesRepository = Uow.GetRepository <DicRouteStage>();
            var initialStage             = await dicRouteStagesRepository.AsQueryable().FirstOrDefaultAsync(s => s.IsFirst && s.RouteId == protectionDocType.RouteId);

            if (initialStage == null)
            {
                return(null);
            }

            var contractWorkflow = new ContractWorkflow
            {
                CurrentUserId  = userId,
                OwnerId        = contract.Id,
                CurrentStageId = initialStage.Id,
                RouteId        = initialStage.RouteId,
                IsComplete     = initialStage.IsLast,
                IsSystem       = initialStage.IsSystem,
            };

            return(contractWorkflow);
        }
Exemplo n.º 5
0
        public async Task Handle(ContractWorkflow contractWorkflow, int userId)
        {
            var contract = await Executor.GetQuery <GetContractByIdQuery>().Process(q => q.ExecuteAsync(contractWorkflow.OwnerId));

            //todo перенес из апплаера как есть. понятния не имею зачем это тут надо, скорее всго удалим
            if (contract == null)
            {
                throw new ApplicationException($"Workflow has incorrect contract id: {contractWorkflow.OwnerId}");
            }

            var routeStage = contractWorkflow.CurrentStageId.HasValue
                ? Executor.GetQuery <GetDicRouteStageByIdQuery>().Process(q => q.Execute(contractWorkflow.CurrentStageId.Value))
                : null;
            await Executor.GetCommand <CreateContractWorkflowCommand>().Process(c => c.ExecuteAsync(contractWorkflow));

            contract.CurrentWorkflow = contractWorkflow;
            contract.StatusId        = routeStage?.ContractStatusId ?? contract.StatusId;
            contract.MarkAsUnRead();
            contract.GosDate = routeStage != null && routeStage.Code.Equals(RouteStageCodes.DK02_9_2)
                ? _calendarProvider.GetPublicationDate(contract.RegDate ?? contract.DateCreate)
                : contract.GosDate;
            Executor.GetCommand <UpdateContractCommand>().Process(c => c.Execute(contract));

            //TODO: Рабочий процесс await _taskRegister.RegisterAsync(contract.Id);
            // _notificationSender.ProcessContract(contract.Id);
        }
        public void Execute(ContractWorkflow contract)
        {
            var requestWorkflowRepository = Uow.GetRepository <ContractWorkflow>();

            requestWorkflowRepository.Create(contract);

            Uow.SaveChanges();
        }
        public async Task <int> ExecuteAsync(ContractWorkflow contractWorkflow)
        {
            var contractWorkflowRepository = Uow.GetRepository <ContractWorkflow>();

            contractWorkflowRepository.Create(contractWorkflow);
            await Uow.SaveChangesAsync();

            return(contractWorkflow.Id);
        }
Exemplo n.º 8
0
 private ContractWorkflow GenerateWorkflow(ContractWorkflow currentWorkflow, DicRouteStage taskResultStage)
 {
     return(new ContractWorkflow
     {
         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
     });
 }
Exemplo n.º 9
0
        /// <summary>
        /// Добавление договора
        /// </summary>
        /// <param name="request">Входные параметры</param>
        /// <param name="response">Данные для ответа</param>
        /// <returns></returns>
        public ContractResponse AddContract(ContractRequest request, ContractResponse response)
        {
            var         typeId = _dictionaryHelper.GetDictionaryIdByExternalId(nameof(DicDocumentType), request.DocumentType.Id);
            DicCustomer customer;

            customer = Mapper.Map <DicCustomer>(
                request,
                el => el.Items[nameof(customer.TypeId)] = _dictionaryHelper.GetDictionaryEntityByExternalId(nameof(DicCustomerType), request.Addressee.CustomerType.Id).Id);

            customer.CountryId = _dictionaryHelper.GetDictionaryIdByExternalId(nameof(DicCountry), request.Addressee.CountryInfo.Id);

            var addressee = _integrationDictionaryHelper.GetCustomerIdOrCreateNew(customer);


            var correspondence      = request.CorrespondenceAddress;
            var protectionDocTypeId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicProtectionDocType),
                                                                              DicProtectionDocTypeCodes.ProtectionDocTypeContractCode);

            #region Добавление договора
            var contract = new Contract
            {
                ProtectionDocTypeId = protectionDocTypeId,
                Description         = request.DocumentDescriptionRu,
                ReceiveTypeId       = int.Parse(DicReceiveTypeCodes.ElectronicFeed),
                DivisionId          = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicDivision), DicDivisionCodes.RGP_NIIS),
                AddresseeId         = addressee.Id,
                AddresseeAddress    = addressee.Address,
                StatusId            = 1
            };

            CreateContract(Mapper.Map(request, contract));
            #endregion

            #region Добавление адресата для переписки
            if (correspondence != null)
            {
                var correspondenceCustomer = _integrationDictionaryHelper.GetCustomerIdOrCreateNew(new DicCustomer
                {
                    TypeId   = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicCustomerType), DicCustomerTypeCodes.Undefined),
                    NameRu   = correspondence.CustomerName,
                    Phone    = correspondence.Phone,
                    PhoneFax = correspondence.Fax,
                    Email    = correspondence.Email
                });

                _niisWebContext.ContractCustomers.Add(new ContractCustomer
                {
                    CustomerId     = correspondenceCustomer.Id,
                    ContractId     = contract.Id,
                    DateCreate     = DateTimeOffset.Now,
                    CustomerRoleId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicCustomerRole), DicCustomerRole.Codes.Correspondence)
                });
                _niisWebContext.SaveChanges();
            }
            #endregion

            #region Добавление контрагентов

            foreach (var item in request.BlockCustomers)
            {
                if (item.CustomerType == null)
                {
                    continue;
                }

                if (item.CustomerType.Id == 0)
                {
                    item.CustomerType.Id =
                        _dictionaryHelper.GetDictionaryIdByCode(nameof(DicCustomerType),
                                                                DicCustomerTypeCodes.Undefined);
                }

                var dicCustomer = new DicCustomer
                {
                    TypeId            = _dictionaryHelper.GetDictionaryEntityByExternalId(nameof(DicCustomerType), item.CustomerType.Id).Id,
                    NameRu            = item.NameRu,
                    NameKz            = item.NameKz,
                    NameEn            = item.NameEn,
                    Phone             = item.Phone,
                    PhoneFax          = item.Fax,
                    Email             = item.Email,
                    Address           = $"{item.Region}, {item.Street}, {item.Index}",
                    CertificateNumber = item.CertificateNumber,
                    CertificateSeries = item.CertificateSeries,
                    Opf                  = item.Opf,
                    ApplicantsInfo       = item.ApplicantsInfo,
                    PowerAttorneyFullNum = item.PowerAttorneyFullNum,
                    ShortDocContent      = item.ShortDocContent,
                    Xin                  = item.Xin,
                    NotaryName           = item.NotaryName,
                    DateCreate           = DateTimeOffset.Now
                };

                if (item.RegistrationDate != DateTime.MinValue)
                {
                    dicCustomer.RegDate = new DateTimeOffset(item.RegistrationDate.GetValueOrDefault());
                }

                var contractCustomer = new ContractCustomer
                {
                    CustomerId     = _integrationDictionaryHelper.GetCustomerIdOrCreateNew(dicCustomer).Id,
                    ContractId     = contract.Id,
                    DateCreate     = DateTimeOffset.Now,
                    CustomerRoleId = _dictionaryHelper.GetDictionaryEntityByExternalId(nameof(DicCustomerRole), item.CustomerRole.Id)?.Id
                };

                _niisWebContext.ContractCustomers.Add(contractCustomer);
                _niisWebContext.SaveChanges();
            }

            #endregion

            #region Добавление прикрепленного документа заявления
            var document = new Document(_dictionaryHelper.GetDocumentType(typeId).type)
            {
                TypeId        = typeId,
                DateCreate    = DateTimeOffset.Now,
                AddresseeId   = addressee.Id,
                StatusId      = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicDocumentStatus), DicDocumentStatusCodes.InWork),
                ReceiveTypeId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicReceiveType), DicReceiveTypeCodes.ElectronicFeed)
            };
            _documentHelper.CreateDocument(document);

            _attachFileHelper.AttachFile(new AttachedFileModel
            {
                PageCount = request.RequisitionFile.PageCount.GetValueOrDefault(),
                CopyCount = request.RequisitionFile.CopyCount.GetValueOrDefault(),
                File      = request.RequisitionFile.Content,
                Length    = request.RequisitionFile.Content.Length,
                IsMain    = true,
                Name      = request.RequisitionFile.Name
            }, document);

            _niisWebContext.Documents.Update(document);
            _niisWebContext.SaveChanges();

            _niisWebContext.ContractsDocuments.Add(new ContractDocument
            {
                DocumentId = document.Id,
                ContractId = contract.Id
            });
            _niisWebContext.SaveChanges();
            #endregion

            #region Добавление документов
            foreach (var attachedFile in request.AttachmentFiles)
            {
                if (attachedFile.File == null)
                {
                    continue;
                }

                var documentType   = _dictionaryHelper.GetDocumentType(attachedFile.FileType.Id);
                var inWorkStatusId =
                    _dictionaryHelper.GetDictionaryIdByCode(nameof(DicDocumentStatus), DicDocumentStatusCodes.InWork);
                var completedStatusId =
                    _dictionaryHelper.GetDictionaryIdByCode(nameof(DicDocumentStatus), DicDocumentStatusCodes.Completed);

                var attachmentDocument = new Document(documentType.type)
                {
                    TypeId        = documentType.typeId,
                    DateCreate    = DateTimeOffset.Now,
                    StatusId      = documentType.type == DocumentType.DocumentRequest ? completedStatusId : inWorkStatusId,
                    AddresseeId   = addressee.Id,
                    ReceiveTypeId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicReceiveType), DicReceiveTypeCodes.ElectronicFeed)
                };
                _documentHelper.CreateDocument(attachmentDocument);
                var attached = new AttachedFileModel
                {
                    Length    = attachedFile.File.Content.Length,
                    PageCount = attachedFile.File.PageCount.GetValueOrDefault(),
                    File      = attachedFile.File?.Content,
                    Name      = attachedFile.File.Name,
                    IsMain    = true,
                    CopyCount = 1
                };

                _attachFileHelper.AttachFile(attached, document);
                _niisWebContext.ContractsDocuments.Add(new ContractDocument
                {
                    DocumentId = attachmentDocument.Id,
                    ContractId = contract.Id
                });
                _niisWebContext.SaveChanges();
            }
            #endregion

            #region Добавление связи с ОД
            foreach (var contractPatent in request.PatentNumbers)
            {
                //Получаем типа патента
                if (!(_dictionaryHelper.GetDictionaryByExternalId(nameof(DicProtectionDocType), contractPatent.PatentType.Id) is DicProtectionDocType type))
                {
                    throw new NotSupportedException($"Тип с идентефикатором {contractPatent.PatentType.Id} не найден");
                }

                var patentId = _niisWebContext
                               .ProtectionDocs
                               .Where(d => d.GosNumber == contractPatent.PatentNumber && d.Request.ProtectionDocTypeId == type.Id)
                               .Select(d => d.Id).FirstOrDefault();

                _niisWebContext.ContractProtectionDocRelations.Add(new ContractProtectionDocRelation
                {
                    ProtectionDocId = patentId,
                    ContractId      = contract.Id
                });
                _niisWebContext.SaveChanges();
            }
            #endregion

            #region Добавление этапа обработки
            var routeId = _integrationDictionaryHelper.GetRouteIdByProtectionDocType(protectionDocTypeId);
            var stage   = _integrationDictionaryHelper.GetRouteStage(routeId);

            var contractWorkflow = new ContractWorkflow
            {
                OwnerId        = contract.Id,
                DateCreate     = DateTimeOffset.Now,
                RouteId        = routeId,
                CurrentStageId = stage.Id,
                CurrentUserId  = _configuration.AuthorAttachmentDocumentId,
                IsComplete     = stage.IsLast,
                IsSystem       = stage.IsSystem,
                IsMain         = stage.IsMain
            };
            _niisWebContext.ContractWorkflows.Add(contractWorkflow);
            _niisWebContext.SaveChanges();

            contract.CurrentWorkflowId = contractWorkflow.Id;
            _niisWebContext.Contracts.Update(contract);
            _niisWebContext.SaveChanges();
            #endregion


            _integrationStatusUpdater.Add(contractWorkflow.Id);

            var onlineStatusId = 0;
            if (contractWorkflow.CurrentStageId != null)
            {
                onlineStatusId = _integrationDictionaryHelper.GetOnlineStatus(contractWorkflow.CurrentStageId.Value);
            }

            response.DocumentId        = contract.Barcode;
            response.DocumentNumber    = contract.IncomingNumber;
            response.RequisitionStatus = onlineStatusId;


            return(response);
        }