/// <summary> /// Принятие материала /// </summary> /// <param name="argument">метаданные материала</param> /// <returns>Материал</returns> public Document CorrespondenceAdd(MessageSendArgument argument) { var document = DocumentAdd(argument); _egovPayHelper.CreatePay(argument.Pay); return(document); }
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); }