示例#1
0
        public void RequisitionBlockFileAdd(AttachedFile[] blockFile, int requestId, string sender)
        {
            foreach (var attachedFile in blockFile.Where(d => d.Type.UID != 4421))
            {
                if (attachedFile.File == null)
                {
                    continue;
                }

                var documentType = _dictionaryHelper.GetDocumentType(attachedFile.Type.UID);
                var addresseeId  = _integrationDictionaryHelper.GetCustomerIdByRequestId(requestId);
                var document     = new Document(documentType.type)
                {
                    TypeId        = documentType.typeId,
                    DateCreate    = DateTimeOffset.Now,
                    StatusId      = documentType.type == DocumentType.DocumentRequest? Int32.Parse(DicDocumentStatusCodes.Completed): Int32.Parse(DicDocumentStatusCodes.InWork),
                    AddresseeId   = addresseeId,
                    ReceiveTypeId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicReceiveType), DicReceiveTypeCodes.ElectronicFeed)
                };
                _documentHelper.CreateDocument(document);
                var attached = new AttachedFileModel
                {
                    Length    = attachedFile.File.Content.Length,
                    PageCount = attachedFile.PageCount,
                    File      = attachedFile.File?.Content,
                    Name      = attachedFile.File.Name,
                    IsMain    = true,
                    CopyCount = 1
                };
                if (_validationHelper.SenderIsPep(sender))
                {
                    if (string.IsNullOrEmpty(attachedFile.File.ShepFile?.Name))
                    {
                        continue;
                    }
                    attached.Name = attachedFile.File.ShepFile.Name;
                    try
                    {
                        attached.File = _attachFileHelper.ShepFileDownload(attachedFile.File.ShepFile);
                    }
                    catch
                    {
                        Log.Warning($"Не удалось загрузить файл с ШЕПа, ID заявки = {requestId}");
                        continue;
                    }
                }
                else
                {
                    attached.Name = attachedFile.File.Name;
                    attached.File = attachedFile.File?.Content;
                }
                _attachFileHelper.AttachFile(attached, document);
                _niisContext.RequestsDocuments.Add(new RequestDocument
                {
                    DocumentId = document.Id,
                    RequestId  = requestId
                });
                _niisContext.SaveChanges();
            }
        }
示例#2
0
        public void AttachFile(AttachedFileModel attachedFile, int requestId)
        {
            var attachment = new Attachment
            {
                DateCreate   = DateTimeOffset.Now,
                RequestId    = requestId,
                IsMain       = attachedFile.IsMain,
                CopyCount    = attachedFile.CopyCount,
                Length       = attachedFile.Length,
                AuthorId     = _configuration.AuthorAttachmentDocumentId,
                PageCount    = attachedFile.PageCount,
                OriginalName = "integration/" + requestId + "/" + Guid.NewGuid(), //attachedFile.Name,
                ValidName    = attachedFile.Name.MakeValidFileName(),
                ContentType  = FileTypeHelper.GetContentType(attachedFile.Name),
                Hash         = _generateHash.GenerateFileHash(attachedFile.File),
                BucketName   = "requests"
            };

            CreateAttachment(attachment);
            Task.Run(() => _fileStorage.AddAsync(attachment.BucketName, attachment.OriginalName, attachedFile.File, attachment.ContentType)).Wait();
        }
示例#3
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);
        }