Example #1
0
        private IEnumerable <Document> GetRequests(DateTimeOffset dateBegin, DateTimeOffset dateEnd)
        {
            var documentList = new List <Document>();
            var requests     = _niisWebContext.ProtectionDocs
                               .Where(x => x.Request.DateUpdate.Date >= dateBegin.Date &&
                                      x.Request.DateUpdate.Date <= dateEnd.Date)
                               .Select(x => new
            {
                x.Request.Barcode,
                x.Request.DateCreate,
                x.Request.RequestNum,
                TypeName         = x.Request.ProtectionDocType.NameRu,
                TypeId           = x.Request.ProtectionDocTypeId,
                OnlineStatusName = x.Request.CurrentWorkflow.CurrentStage.OnlineRequisitionStatus.NameRu,
                OnlineStatusId   = x.Request.CurrentWorkflow.CurrentStage.OnlineRequisitionStatusId,
                ProtectionDocId  = x.Id,
                PlanProvDate     = DateTime.MinValue, //TODO позже узнать какое поле подставлять
                UserName         = x.Request.CurrentWorkflow.CurrentUser.NameRu
            });

            foreach (var request in requests)
            {
                var resultStatus = string.Empty;
                if (request.OnlineStatusId.HasValue)
                {
                    var onlineStatusCode = _dictionaryHelper.GetDictionaryCodeByExternalId(nameof(DicOnlineRequisitionStatus), request.OnlineStatusId.Value);
                    resultStatus = _integrationDictionaryHelper.GetResultStatus(onlineStatusCode);
                }

                documentList.Add(new Document
                {
                    UID          = request.Barcode,
                    Status       = request.OnlineStatusName,
                    User         = request.UserName,
                    DocTypeName  = request.TypeName,
                    DocDate      = request.DateCreate.DateTime,
                    DocNum       = request.RequestNum,
                    DocTypeID    = request.TypeId,
                    PatentUID    = request.ProtectionDocId,
                    PlanProvDate = request.PlanProvDate,
                    ResultStatus = resultStatus
                });
            }
            return(documentList);
        }
        public void Handle(GetAttachedFileMetadataArgument argument,
                           GetAttachedFileMetadataResult result)
        {
            var dicProtectionDocTypeCode =
                _dictionaryHelper.GetDictionaryCodeByExternalId(nameof(DicProtectionDocType), argument.MainDocumentType.UID);
            var list = new List <AttachedFileMetadata>();

            var fileTypes = GetFromDbAttachmentFileTypeUid(dicProtectionDocTypeCode);

            foreach (var fileType in fileTypes)
            {
                var required = Required(argument, fileType);
                list.Add(GetMetadata(fileType, required));
            }

            list.Sort((data1, data2) => data1.AttachedFileType.UID - data2.AttachedFileType.UID);
            result.Data = list.ToArray();
        }
Example #3
0
            public GetPayTarifResult Handle(Query message)
            {
                var protectionDocTypeCode = _dictionaryHelper.GetDictionaryCodeByExternalId(nameof(DicProtectionDocType),
                                                                                            message.Argument.PatentType);

                var protectionDoc = _getPayTariffService.GetProtectionDoc(protectionDocTypeCode,
                                                                          message.Argument.PatentN, message.Result);

                if (protectionDoc == null)
                {
                    message.Result.Result  = PayTarifResult.Error;
                    message.Result.Message = "Охранный документ не найден";
                }
                else
                {
                    message.Result.Result  = PayTarifResult.TarifFound;
                    message.Result.Message = "Охранный документ найден";

                    var discontinued = _getPayTariffService.GetDiscontinued(protectionDoc.StatusId,
                                                                            protectionDocTypeCode, protectionDoc?.ValidDate?.DateTime.AddMonths(6),
                                                                            protectionDoc.ExtensionDate?.DateTime);

                    if (discontinued)
                    {
                        message.Result.Result  = PayTarifResult.Info;
                        message.Result.Message = "Срок действия ОД прекращен";
                    }
                    else
                    {
                        _getPayTariffService.GetTariffId(protectionDocTypeCode, protectionDoc.Id,
                                                         message.Result);

                        message.Result.Status     = protectionDoc.Status.NameRu;
                        message.Result.PatentName = protectionDoc.NameRu;
                        message.Result.PatentUID  = protectionDoc.ExternalId.Value;
                        message.Result.Validity   =
                            _getPayTariffService.GetValidity(protectionDocTypeCode,
                                                             protectionDoc.ExtensionDate?.DateTime) ?? protectionDoc.ValidDate?.DateTime;
                        ;
                        if (protectionDoc.RegDate != null)
                        {
                            message.Result.RegDate = protectionDoc.RegDate.Value.DateTime;
                        }

                        if (protectionDoc.EarlyTerminationDate != null)
                        {
                            message.Result.DateTerminate = protectionDoc.EarlyTerminationDate.Value.DateTime;
                        }
                    }
                }

                return(message.Result);
            }
Example #4
0
        public (int requestId, int onlineStatusId, string incomingNum, int barcode) RequisitionDocumentAdd(RequisitionSendArgument argument)
        {
            var protectionDocTypeId = argument.PatentType.UID;
            //var protectionDocTypeCode = _dictionaryHelper.GetDictionaryCodeById(nameof(DicProtectionDocType), protectionDocTypeId);
            var         protectionDocTypeCode = _dictionaryHelper.GetDictionaryCodeByExternalId(nameof(DicProtectionDocType), protectionDocTypeId);
            var         receiveRypeCode       = _integrationDictionaryHelper.GetReceiveTypeCode(argument.SystemInfo.Sender);
            var         receiveTypeId         = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicReceiveType), receiveRypeCode);
            var         departmentCode        = _integrationEnumMapper.MapToDepartment(protectionDocTypeCode);
            var         departmentId          = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicDepartment), departmentCode);
            var         speciesTradeMarkId    = _dictionaryHelper.GetSpeciesTradeMarkId(argument.IsCollectiveTradeMark);
            var         typeTrademarkId       = _dictionaryHelper.GetNullableDictionaryIdByCode(nameof(DicTypeTrademark), argument.PatentSubType);
            DicCustomer customer = null;

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

            var addressee = _integrationDictionaryHelper.GetCustomerIdOrCreateNew(customer);

            var subTypeCode   = GetSubType(protectionDocTypeCode);
            var requestTypeId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicProtectionDocSubType), subTypeCode);

            //if (int.TryParse(argument.PatentSubType, out var patentSubType))
            //{
            //    _dictionaryHelper.ChechDictionaryId(nameof(DicProtectionDocSubType), patentSubType);
            //    requestTypeId = patentSubType;
            //}

            var request = new Request
            {
                ProtectionDocTypeId = protectionDocTypeId,
                ReceiveTypeId       = receiveTypeId,
                DepartmentId        = departmentId,
                DivisionId          = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicDivision), DicDivisionCodes.RGP_NIIS),
                FlDivisionId        = _integrationDictionaryHelper.GetDivisionId(_configuration.MainExecutorIds[protectionDocTypeCode]),
                IsComplete          = false,
                AddresseeId         = addressee.Id,
                AddresseeAddress    = addressee.Address,
                UserId             = _configuration.MainExecutorIds[protectionDocTypeCode],
                SpeciesTradeMarkId = speciesTradeMarkId,
                TypeTrademarkId    = typeTrademarkId,
                RequestTypeId      = requestTypeId,
                IsFromLk           = true
            };

            if (argument.BlockFile.Any(d => d.Type.UID == 292))
            {
                request.Referat = argument.BlockFile.First(d => d.Type.UID == 292).Type.Note;
            }

            if (argument.BlockFile != null)
            {
                var imageFile = _attachFileHelper.GetImageFile(argument.BlockFile,
                                                               _validationHelper.SenderIsPep(argument.SystemInfo.Sender));
                if (imageFile != null)
                {
                    request.Image           = imageFile;
                    request.IsImageFromName = false;
                }
            }

            CreateRequest(Mapper.Map(argument, request));

            if (argument.BlockFile != null)
            {
                var meidaFile = argument.BlockFile.Where(d => d.Type.UID == 4421).ToList();
                if (meidaFile.Any())
                {
                    foreach (var attachedFile in meidaFile)
                    {
                        _attachFileHelper.AttachFile(new AttachedFileModel
                        {
                            PageCount = attachedFile.PageCount,
                            CopyCount = 0,
                            File      = attachedFile.File.Content,
                            Length    = attachedFile.File.Content.Length,
                            IsMain    = false,
                            Name      = attachedFile.File.Name
                        }, request.Id);
                    }
                }
            }

            var requestInfo = new RequestInfo
            {
                RequestId            = request.Id,
                FlagTth              = false,
                IsConventionPriority = false,
                IsExhibitPriority    = false,
                IsStandardFont       = false,
                IsTransliteration    = false,
                IsTranslation        = false,
                IsVolumeTZ           = false,
                IsColorPerformance   = false,
                AcceptAgreement      = false,
                BreedCountryId       = argument.BreedCountry != null ? (argument.BreedCountry.UID > 0 ? _dictionaryHelper.GetDictionaryIdByExternalId(nameof(DicCountry), argument.BreedCountry.UID) : (int?)null) : null
            };

            _niisContext.RequestInfos.Add(Mapper.Map(argument, requestInfo));
            _niisContext.SaveChanges();

            var dicDocTypeCode = _integrationEnumMapper.MapProtectionDocTypeToDocumentType(protectionDocTypeCode);
            var docTypeId      = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicDocumentType), dicDocTypeCode);

            var document = new Document(_dictionaryHelper.GetDocumentType(docTypeId).type)
            {
                TypeId        = docTypeId,
                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 = argument.PageCount,
                CopyCount = argument.CopyCount,
                File      = argument.RequisitionFile.Content,
                Length    = argument.RequisitionFile.Content.Length,
                IsMain    = true,
                Name      = argument.RequisitionFile.Name
            }, document);


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

            _niisContext.RequestsDocuments.Add(new RequestDocument
            {
                DocumentId = document.Id,
                RequestId  = request.Id
            });
            _niisContext.SaveChanges();

            var routeId = _integrationDictionaryHelper.GetRouteIdByProtectionDocType(protectionDocTypeId);
            var stage   = _integrationDictionaryHelper.GetRouteStage(routeId);

            var requestWorkflow = new RequestWorkflow
            {
                OwnerId        = request.Id,
                DateCreate     = DateTimeOffset.Now,
                RouteId        = routeId,
                CurrentStageId = stage.Id,
                CurrentUserId  = _configuration.MainExecutorIds[protectionDocTypeCode],
                IsComplete     = stage.IsLast,
                IsSystem       = stage.IsSystem,
                IsMain         = stage.IsMain
            };

            _niisContext.RequestWorkflows.Add(requestWorkflow);
            _niisContext.SaveChanges();

            request.CurrentWorkflowId = requestWorkflow.Id;
            _niisContext.Requests.Update(request);
            _niisContext.SaveChanges();

            _integrationStatusUpdater.Add(requestWorkflow.Id);

            var dicCustomer = _integrationDictionaryHelper.GetCustomerIdOrCreateNew(new DicCustomer
            {
                TypeId   = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicCustomerType), DicCustomerTypeCodes.Undefined),
                NameRu   = argument.AdrCustomerName,
                Phone    = argument.AdrPhone,
                PhoneFax = argument.AdrFax,
                Email    = argument.AdrEmail,
                Address  = $"{argument.AdrRegion}, {argument.AdrStreet}, {argument.AdrPostCode}"
            });

            _niisContext.RequestCustomers.Add(new RequestCustomer
            {
                CustomerId     = dicCustomer.Id,
                RequestId      = request.Id,
                DateCreate     = DateTimeOffset.Now,
                CustomerRoleId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicCustomerRole), DicCustomerRole.Codes.Correspondence)
            });
            _niisContext.SaveChanges();

            _egovPayHelper.CreatePay(argument.Pay);

            var onlineStatusId = 0;

            if (requestWorkflow.CurrentStageId != null)
            {
                onlineStatusId = _integrationDictionaryHelper.GetOnlineStatus(requestWorkflow.CurrentStageId.Value);
            }

            return(requestId : request.Id, onlineStatusId : onlineStatusId, incomingNum : request.IncomingNumber, barcode : request.Barcode);
        }
        public string GetValidationErrors(RequisitionSendArgument argument)
        {
            if (argument.PatentType == null)
            {
                return("Не указан ExternalPatentType!");
            }

            var errors = new List <string>();

            if (string.IsNullOrEmpty(argument.AdrCustomerName))
            {
                errors.Add("AdrCustomerName не указан!");
            }

            if (argument.AdrCountry == null)
            {
                errors.Add("AdrCountry не указан!");
            }

            if (argument.AdrStreet == null)
            {
                errors.Add("AdrStreet не указан!");
            }

            if (argument.AdrEmail == null)
            {
                errors.Add("AdrEmail не указан!");
            }

            var applicants = 0;
            var attorney   = 0;
            var authors    = 0;
            var errRefKey  = false;
            var errCusType = false;

            foreach (var customer in argument.BlockCustomer)
            {
                if (customer.PatentLinkType == null)
                {
                    errRefKey = true;
                }
                else
                {
                    switch (customer.PatentLinkType.UID)
                    {
                    case 1:
                        applicants++;
                        break;

                    case 479:
                    case 4:
                        attorney++;
                        break;

                    case 2:
                        authors++;
                        break;
                    }
                }

                if (customer.Type == null)
                {
                    errCusType = true;
                }
            }

            if (errRefKey)
            {
                errors.Add("BlockCustomer: Customer.PatentLinkType не указан!");
            }

            if (errCusType)
            {
                errors.Add("BlockCustomer: Customer.Type не указан!");
            }

            if (applicants <= 0)
            {
                errors.Add("Нужно добавить как минимум одного заявителя!");
            }
            else
            {
                var cusType = GetErrApplicatTypeForPatentType(argument.PatentType.UID, argument.BlockCustomer);
                if (!string.IsNullOrEmpty(cusType))
                {
                    errors.Add("Для заявки ExternalPatentType.UID = " + argument.PatentType.UID +
                               ", заявитель не может быть BlockCustomer: Customer.Type.UID = " + cusType);
                }
            }


            var dicProtectionDocTypeCode =
                _dictionaryHelper.GetDictionaryCodeByExternalId(nameof(DicProtectionDocType), argument.PatentType.UID);

            if (dicProtectionDocTypeCode == DicProtectionDocType.Codes.Trademark)
            {
                if (argument.BlockClassification.Length <= 0)
                {
                    errors.Add("Нужно указать как минимум один МКТУ!");
                }
            }

            if (authors <= 0 && (
                    dicProtectionDocTypeCode == DicProtectionDocType.Codes.Invention ||
                    dicProtectionDocTypeCode == DicProtectionDocType.Codes.IndustrialModel ||
                    dicProtectionDocTypeCode == DicProtectionDocType.Codes.UsefulModel ||
                    dicProtectionDocTypeCode == DicProtectionDocType.Codes.SelectiveAchievement
                    ))
            {
                errors.Add("Нужно добавить как минимум одного автора!");
            }

            var patentLinkType  = false;
            var customerType    = false;
            var errCustomerName = false;

            foreach (var customer in argument.BlockCustomer)
            {
                if (customer.PatentLinkType == null)
                {
                    patentLinkType = true;
                }

                if (customer.Type == null)
                {
                    customerType = true;
                }

                if (string.IsNullOrEmpty(customer.NameRu))
                {
                    errCustomerName = true;
                }
            }

            if (errCustomerName)
            {
                errors.Add("Не указан ФИО/Полное наименование на русском языке BlockCustomer: Customer.NameRu");
            }

            if (patentLinkType)
            {
                errors.Add("Не указан тип связки контрагента BlockCustomer: Customer.PatentLinkType");
            }

            if (customerType)
            {
                errors.Add("Не указан тип контрагента BlockCustomer: Customer.Type");
            }

            if (!patentLinkType && !customerType)
            {
                errors.AddRange(GetArgumentErrorRequisitionSendAttachedFiles(argument, argument));
            }

            if (!_validationHelper.SenderIsPep(argument.SystemInfo.Sender) &&
                _validationHelper.FileIsEmpty(argument.RequisitionFile, argument))
            {
                errors.Add("RequisitionFile. Заявление не может быть пустым");
            }

            if (_validationHelper.SenderIsPep(argument.SystemInfo.Sender) && argument.RequisitionFile != null)
            {
                errors.Add("ПЭП должен отправлять RequisitionFile = null");
            }

            if (_validationHelper.SenderIsPep(argument.SystemInfo.Sender) && argument.RequisitionFile == null)
            {
                argument.RequisitionFile = new File {
                    Name = argument.SystemInfo.ChainId + ".pdf"
                };

                try
                {
                    argument.RequisitionFile.Content =
                        _attachFileHelper.DownloadPepRequisitionFile(argument.SystemInfo.ChainId, argument.Xin);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, ex.Message);
                    errors.Add("Не удалось получить pdf файл заявки. Заявка " + argument.SystemInfo.ChainId);
                    errors.Add(ex.Message);
                }
            }

            if (argument.RequisitionFile != null && argument.RequisitionFile.Content != null)
            {
                if (argument.RequisitionFile.Content.Length < 10)
                {
                    errors.Add("Файл заявки пуст. Заявка " + argument.SystemInfo.ChainId);
                }
                else
                {
                    const string textPdf  = "%PDF";
                    var          textFile = Encoding.UTF8.GetString(argument.RequisitionFile.Content, 0, 4);

                    if (textFile != textPdf)
                    {
                        errors.Add("Файл заявки не является PDF-документом. Заявка " + argument.SystemInfo.ChainId);
                    }
                }
            }

            if (errors.Count == 0)
            {
                return(null);
            }

            return(string.Join(Environment.NewLine, errors.ToArray()));
        }