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 applyer. 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); }
public async Task <RequestWorkflow> ExecuteAsync(Request request, int userId) { var dicProtectionDocTypesRepository = Uow.GetRepository <DicProtectionDocType>(); var protectionDocType = await dicProtectionDocTypesRepository.AsQueryable().FirstOrDefaultAsync(t => t.Id == request.ProtectionDocTypeId); var dicRouteStagesRepository = Uow.GetRepository <DicRouteStage>(); var initialStage = await dicRouteStagesRepository.AsQueryable().FirstOrDefaultAsync(s => !s.IsDeleted && s.IsFirst && s.RouteId == protectionDocType.RouteId); if (initialStage == null) { return(null); } var requestWorkflow = new RequestWorkflow { CurrentUserId = userId, OwnerId = request.Id, CurrentStageId = initialStage.Id, RouteId = initialStage.RouteId, IsComplete = initialStage.IsLast, IsSystem = initialStage.IsSystem, IsMain = initialStage.IsMain, }; return(requestWorkflow); }
private RequestWorkflow CreateWorkflow(WtPtWorkoffice oldWorkoffice, int requestId) { try { var wf = new RequestWorkflow { 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 = requestId, RouteId = GetObjectId <DicRoute>(oldWorkoffice.TypeId), Timestamp = BitConverter.GetBytes(DateTime.Now.Ticks) }; return(wf); } catch (Exception) { return(null); } }
public async Task Handle(RequestWorkflow requestWorkflow, Request request) { //todo перенес из апплаера как есть. понятния не имею зачем это тут надо, скорее всго удалим if (request == null) { throw new ApplicationException($"Workflow has incorrect request id: {requestWorkflow.OwnerId}"); } var routeStage = requestWorkflow.CurrentStageId.HasValue ? Executor.GetQuery <GetDicRouteStageByIdQuery>().Process(q => q.Execute(requestWorkflow.CurrentStageId.Value)) : null; CheckStage(request, routeStage); await Executor.GetCommand <CreateRequestWorkflowCommand>().Process(c => c.ExecuteAsync(requestWorkflow)); request.CurrentWorkflowId = requestWorkflow.Id; request.StatusId = routeStage?.RequestStatusId ?? request.StatusId; request.IsComplete = requestWorkflow.IsComplete ?? request.IsComplete; request.MarkAsUnRead(); await Executor.GetCommand <UpdateRequestCommand>().Process(c => c.ExecuteAsync(request)); //todo: есть смысл переделать это на хендлеры //TODO: Рабочий процесс await _taskRegister.RegisterAsync(request.Id); // _notificationSender.ProcessContract(request.Id); }
public int Execute(RequestWorkflow requestWorkflow) { var requestWorkflowRepository = Uow.GetRepository <RequestWorkflow>(); requestWorkflowRepository.Create(requestWorkflow); Uow.SaveChanges(); return(requestWorkflow.Id); }
public void Execute(RequestWorkflow requestWorkflow) { var repo = Uow.GetRepository <RequestWorkflow>(); repo.Update(requestWorkflow); Uow.SaveChanges(); }
private static void ExecuteFlow(RequestStatus initial, RequestTrigger trigger, RequestStatus expectedEndStatus) { var workflow = new RequestWorkflow(initial); workflow.TriggerWorkflow(trigger); Assert.AreEqual(expectedEndStatus, workflow.Status); }
public async Task ExecuteAsync(RequestWorkflow workflow) { var repo = Uow.GetRepository <RequestWorkflow>(); repo.Update(workflow); await Uow.SaveChangesAsync(); }
public async Task <int> ExecuteAsync(RequestWorkflow requestWorkflow) { var requestWorkflowRepository = Uow.GetRepository <RequestWorkflow>(); await requestWorkflowRepository.CreateAsync(requestWorkflow); await Uow.SaveChangesAsync(); return(requestWorkflow.Id); }
private RequestWorkflow GetWorkflow(RequestWorkflow currentWorkflow, WorkflowTaskQueue task) { var taskResultStage = task.ResultStage ?? GetCalculatedResultStage(currentWorkflow); return(new RequestWorkflow { 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 }); }
private DicRouteStage GetCalculatedResultStage(RequestWorkflow currentWorkflow) { if (currentWorkflow.CurrentStage.Code.Equals("B03.3.1.1.0")) { if (currentWorkflow.FromStage.Code.Equals("B03.3.1.1")) { return(_context.DicRouteStages.Single(s => s.Code.Equals("B03.3.1.1.1"))); } if (currentWorkflow.FromStage.Code.Equals("B03.3.4.1")) { return(_context.DicRouteStages.Single(s => s.Code.Equals("B03.3.9"))); } } if (currentWorkflow.CurrentStage.Code.Equals("B03.3.1.1.1") && (AnyDocuments(currentWorkflow.OwnerId, DicDocumentType.Codes.NotificationOfAnswerlessPatentRequestFinalRecall, DicDocumentType.Codes.NotificationOfPaymentlessExaminationFinalRecall) || currentWorkflow.Owner.Workflows.Any(rw => rw.CurrentStage.Code.Equals("B03.2.4")))) { return(_context.DicRouteStages.Single(s => s.Code.Equals("B04.0"))); } if (currentWorkflow.CurrentStage.Code.Equals("B02.2.0") || currentWorkflow.CurrentStage.Code.Equals("B03.3.1.1") && (AnyDocuments(currentWorkflow.OwnerId, DicDocumentType.Codes.NotificationOfRevocationOfPatentApplication) || currentWorkflow.Owner.Workflows.Any(rw => rw.CurrentStage.Code.Equals("B03.2.4")))) { return(_context.DicRouteStages.Single(s => s.Code.Equals("B03.3.1.1.1"))); } if (currentWorkflow.CurrentStage.Code.Equals("TM03.3.7.1") && AnyDocuments(currentWorkflow.OwnerId, DicDocumentType.Codes.NotificationOfAnswerTimeExpiration) || currentWorkflow.CurrentStage.Code.Equals("TM03.3.7.3") && AnyDocuments(currentWorkflow.OwnerId, DicDocumentType.Codes.NotificationOfAnswerTimeExpiration) || currentWorkflow.CurrentStage.Code.Equals("TM03.2.2.0") && AnyDocuments(currentWorkflow.OwnerId, DicDocumentType.Codes.NotificationOfRegistrationExaminationTimeExpiration)) { return(_context.DicRouteStages.Single(s => s.Code.Equals("TM03.3.7.0"))); } if (currentWorkflow.CurrentStage.Code.Equals("TM03.3.7.0") && AnyDocuments(currentWorkflow.OwnerId, DicDocumentType.Codes.NotificationOfRefusal, DicDocumentType.Codes.NotificationOfPaymentlessOfficeWorkTermination) || currentWorkflow.CurrentStage.Code.Equals("TM03.3.7.3") && AnyDocuments(currentWorkflow.OwnerId, DicDocumentType.Codes.NotificationOfAnswerlessOfficeWorkTermination)) { return(_context.DicRouteStages.Single(s => s.Code.Equals("TM03.3.9"))); } return(_context.DicRouteStages.Single(s => s.Code.Equals("X01"))); }
public async Task Add(RequestWorkflow requestWorkflow) { var request = _context.Requests .First(r => r.Id == requestWorkflow.OwnerId); //TODO: уточнить у аналитиков тип этап маршрута т.к данный этап относиться к материалам var dicRouteStageSendingId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicRouteStage), RouteStageCodes.DocumentOutgoing_03_1); if (requestWorkflow.IsComplete == false && requestWorkflow.FromStageId == dicRouteStageSendingId) { var integrationDocument = _context.IntegrationDocuments .FirstOrDefault(x => x.RequestBarcode == request.Barcode); if (integrationDocument != null) { _context.IntegrationDocuments.Remove(integrationDocument); await _context.SaveChangesAsync(); } return; } var dicRouteStageTransferToPatentHolderId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicRouteStage), RouteStageCodes.OD01_5); var dicRouteStageCurrentTrademarkId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicRouteStage), RouteStageCodes.OD05_01); if (requestWorkflow.IsComplete == false && requestWorkflow.FromStageId == dicRouteStageTransferToPatentHolderId && requestWorkflow.CurrentStageId == dicRouteStageCurrentTrademarkId) { var dicReceiveTypeElectronicFeedId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicReceiveType), DicReceiveTypeCodes.ElectronicFeed); if (request.ReceiveTypeId == dicReceiveTypeElectronicFeedId) { var dicDocClassificationRequestMaterialsId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicDocumentClassification), DicDocumentClassificationCodes.RequestMaterialsOutgoing); var docClassifications = _dictionaryHelper.GetChildClass(new[] { dicDocClassificationRequestMaterialsId }); var document = _context.Requests .Where(x => x.Id == request.Id) .SelectMany(x => x.Documents) .Where(x => x.Document.OutgoingNumber != null && x.Document.MainAttachment != null && (x.Document.Type.ClassificationId == dicDocClassificationRequestMaterialsId || docClassifications.Contains(x.Document.Type.ClassificationId.Value))) .Select(x => x.Document) .FirstOrDefault(); if (document == null) { return; } var file = await _fileStorage.GetAsync(document.MainAttachment.BucketName, document.MainAttachment.OriginalName); if (file == null) { return; } await _context.IntegrationDocuments.AddAsync(new IntegrationDocument { DateCreate = DateTimeOffset.Now, DocumentBarcode = document.Barcode, DocumentTypeId = document.TypeId, File = file, Note = document.NameRu, FileName = document.MainAttachment.OriginalName, InOutDate = document.DateCreate, RequestBarcode = request.Barcode, InOutNumber = document.OutgoingNumber }); UpdateStatement(request, file, document.MainAttachment.OriginalName); _context.SaveChanges(); } } }
/// <summary> /// Преобразование заявки /// </summary> /// <param name="requestId">Идентификатор преобразуемой заявки</param> private void ConvertRequest(int requestId) { var request = Executor.GetQuery <GetRequestByIdQuery>().Process(q => q.Execute(requestId)); var workflows = Executor.GetQuery <GetRequestWorkflowsByRequestIdQuery>().Process(q => q.Execute(requestId)); #region Генерация уведомления var notificationCode = string.Empty; var hasBeenOnFullExam = workflows.Any(w => w.CurrentStage.Code == RouteStageCodes.TZFirstFullExpertizePerformerChoosing); var trademarkTypeCode = request.SpeciesTradeMark.Code; //Смерджили два справочника, получилось так, не стал трогать, мало ли прийдется вернуть if (hasBeenOnFullExam) { if (trademarkTypeCode == DicProtectionDocSubtypeCodes.CollectiveTrademark) { notificationCode = DicDocumentTypeCodes.OUT_UV_Pred_preobr_zayav_TZ_na_KTZ_v1_19; } else { notificationCode = DicDocumentTypeCodes.OUT_UV_Pred_preobr_zayav_TZ_na_KTZ_v1_19; } } else { if (trademarkTypeCode == DicProtectionDocSubtypeCodes.CollectiveTrademark) { notificationCode = DicDocumentTypeCodes.OUT_UV_Pred_preobr_zayav_TZ_na_KTZ_v1_19; } else { notificationCode = DicDocumentTypeCodes.OUT_UV_Pred_preobr_zayav_TZ_na_KTZ_v1_19; } } var userInputDto = new UserInputDto { Code = notificationCode, Fields = new List <KeyValuePair <string, string> >(), OwnerId = requestId, OwnerType = Owner.Type.Request }; Executor.GetHandler <CreateDocumentHandler>().Process(h => h.Execute(requestId, Owner.Type.Request, notificationCode, DocumentType.Outgoing, userInputDto)); #endregion #region Создание заявки var protectionDocTypeCode = request.ProtectionDocType.Code; var protectionDocSubtypeCode = request.RequestType.Code; DicProtectionDocType newProtectionDocType = null; DicProtectionDocSubType newProtectionDocSubType = null; string initialStageCode = null; switch (protectionDocTypeCode) { //todo перенести коды в классы case DicProtectionDocTypeCodes.RequestTypeUsefulModelCode: newProtectionDocType = Executor.GetQuery <GetDicProtectionDocTypebyCodeQuery>().Process(q => q.Execute(DicProtectionDocTypeCodes.RequestTypeInventionCode)); initialStageCode = RouteStageCodes.I_02_1; switch (protectionDocSubtypeCode) { case DicProtectionDocSubtypeCodes.NationalUsefulModel: newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute(DicProtectionDocSubtypeCodes.NationalInvention)); break; case "03_UsefulModel": newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute("03")); break; case "04_UsefulModel": newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute("04")); break; } break; case DicProtectionDocTypeCodes.RequestTypeInventionCode: newProtectionDocType = Executor.GetQuery <GetDicProtectionDocTypebyCodeQuery>().Process(q => q.Execute(DicProtectionDocTypeCodes.RequestTypeUsefulModelCode)); initialStageCode = RouteStageCodes.UM_02_1; switch (protectionDocSubtypeCode) { case DicProtectionDocSubtypeCodes.NationalInvention: newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute(DicProtectionDocSubtypeCodes.NationalUsefulModel)); break; case "03": newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute("03_UsefulModel")); break; case "04": newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute("04_UsefulModel")); break; } break; case DicProtectionDocTypeCodes.RequestTypeTrademarkCode: if (request.SpeciesTradeMark.Code == DicProtectionDocSubtypeCodes.CollectiveTrademark) { newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute(DicProtectionDocSubtypeCodes.RegularTradeMark)); } else { newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute(DicProtectionDocSubtypeCodes.CollectiveTrademark)); } request.SpeciesTradeMark = newProtectionDocSubType; request.SpeciesTradeMarkId = newProtectionDocSubType.Id; Executor.GetCommand <UpdateRequestCommand>().Process(c => c.Execute(request)); return; } if (initialStageCode == null) { return; } var newRequest = _mapper.Map <Request>(request); newRequest.ProtectionDocTypeId = newProtectionDocType?.Id ?? request.ProtectionDocTypeId; newRequest.RequestTypeId = newProtectionDocSubType?.Id ?? request.RequestTypeId; newRequest.DateCreate = DateTimeOffset.Now; Executor.GetHandler <GenerateRequestNumberHandler>().Process(h => h.Execute(newRequest)); var newRequestId = Executor.GetCommand <CreateRequestCommand>().Process(c => c.Execute(newRequest)); var initialStage = Executor.GetQuery <GetDicRouteStageByCodeQuery>() .Process(q => q.Execute(initialStageCode)); var initialWorkflow = new RequestWorkflow { CurrentUserId = WorkflowRequest.NextStageUserId, OwnerId = newRequestId, CurrentStageId = initialStage.Id, RouteId = initialStage.RouteId, IsComplete = initialStage.IsLast, IsSystem = initialStage.IsSystem, IsMain = initialStage.IsMain, }; Executor.GetCommand <CreateRequestWorkflowCommand>() .Process(c => c.Execute(initialWorkflow)); newRequest.CurrentWorkflowId = initialWorkflow.Id; newRequest.StatusId = initialStage.RequestStatusId; Executor.GetCommand <UpdateRequestCommand>().Process(c => c.Execute(newRequest)); #endregion #region Биб. данные var newConventionInfos = _mapper.Map <RequestConventionInfo[]>(request.RequestConventionInfos); foreach (var conventionInfo in newConventionInfos) { conventionInfo.RequestId = newRequestId; Executor.GetCommand <CreateConventionInfoCommand>().Process(c => c.Execute(conventionInfo)); } var newEarlyRegs = _mapper.Map <RequestEarlyReg[]>(request.EarlyRegs); foreach (var earlyReg in newEarlyRegs) { earlyReg.RequestId = newRequestId; Executor.GetCommand <CreateRequestEarlyRegCommand>().Process(c => c.Execute(earlyReg)); } var newIcgsRequests = _mapper.Map <ICGSRequest[]>(request.ICGSRequests); foreach (var icgsRequest in newIcgsRequests) { icgsRequest.RequestId = newRequestId; Executor.GetCommand <CreateRequestIcgsCommand>().Process(c => c.Execute(icgsRequest)); } var newIpcRequests = _mapper.Map <IPCRequest[]>(request.IPCRequests); foreach (var ipcRequest in newIpcRequests) { ipcRequest.RequestId = newRequestId; Executor.GetCommand <CreateIpcRequestCommand>().Process(c => c.Execute(ipcRequest)); } var newIcisRequests = _mapper.Map <ICISRequest[]>(request.ICISRequests); foreach (var icisRequest in newIcisRequests) { icisRequest.RequestId = newRequestId; Executor.GetCommand <CreateRequestIcisCommand>().Process(c => c.Execute(icisRequest)); } foreach (var colorTz in request.ColorTzs) { var newColorTz = new DicColorTZRequestRelation { ColorTzId = colorTz.ColorTzId, RequestId = newRequestId }; Executor.GetCommand <CreateRequestColorTzCommand>().Process(c => c.Execute(newColorTz)); } foreach (var icfem in request.Icfems) { var newIcfem = new DicIcfemRequestRelation { DicIcfemId = icfem.DicIcfemId, RequestId = newRequestId }; Executor.GetCommand <CreateRequestIcfemCommand>().Process(c => c.Execute(newIcfem)); } #endregion #region Контрагенты var newCustomers = _mapper.Map <RequestCustomer[]>(request.RequestCustomers); foreach (var customer in newCustomers) { customer.RequestId = newRequestId; Executor.GetCommand <CreateRequestCustomerCommand>().Process(c => c.Execute(customer)); } #endregion }
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); }
private void ConvertRequest(int requestId) { #region Создание заявки var request = Executor.GetQuery <WorkflowBusinessLogic.Requests.GetRequestByIdQuery>().Process(q => q.Execute(requestId)); var protectionDocTypeCode = request.ProtectionDocType.Code; DicProtectionDocType newProtectionDocType = null; DicProtectionDocSubType newProtectionDocSubType = null; string initialStageCode = null; switch (protectionDocTypeCode) { case DicProtectionDocTypeCodes.RequestTypeUsefulModelCode: newProtectionDocType = Executor.GetQuery <GetDicProtectionDocTypebyCodeQuery>().Process(q => q.Execute(DicProtectionDocTypeCodes.RequestTypeInventionCode)); initialStageCode = RouteStageCodes.I_02_1; break; case DicProtectionDocTypeCodes.RequestTypeInventionCode: newProtectionDocType = Executor.GetQuery <GetDicProtectionDocTypebyCodeQuery>().Process(q => q.Execute(DicProtectionDocTypeCodes.RequestTypeUsefulModelCode)); initialStageCode = RouteStageCodes.UM_02_1; break; case DicProtectionDocTypeCodes.RequestTypeTrademarkCode: initialStageCode = request.CurrentWorkflow.FromStage.Code; newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute(DicProtectionDocSubtypeCodes.CollectiveTrademark)); break; } if (initialStageCode == null) { return; } var newRequest = _mapper.Map <Request>(request); newRequest.ProtectionDocTypeId = newProtectionDocType?.Id ?? request.ProtectionDocTypeId; newRequest.RequestTypeId = newProtectionDocSubType?.Id ?? request.RequestTypeId; newRequest.DateCreate = DateTimeOffset.Now; Executor.GetHandler <GenerateRequestNumberHandler>().Process(h => h.Execute(newRequest)); var newRequestId = Executor.GetCommand <CreateRequestCommand>().Process(c => c.Execute(newRequest)); var initialStage = Executor.GetQuery <GetDicRouteStageByCodeQuery>() .Process(q => q.Execute(initialStageCode)); var initialWorkflow = new RequestWorkflow { CurrentUserId = request.CurrentWorkflow.FromUserId, OwnerId = newRequestId, CurrentStageId = initialStage.Id, RouteId = initialStage.RouteId, IsComplete = initialStage.IsLast, IsSystem = initialStage.IsSystem, IsMain = initialStage.IsMain, }; Executor.GetCommand <CreateRequestWorkflowCommand>() .Process(c => c.Execute(initialWorkflow)); newRequest.CurrentWorkflowId = initialWorkflow.Id; Executor.GetCommand <UpdateRequestCommand>().Process(c => c.Execute(newRequest)); #endregion #region Биб. данные var newConventionInfos = _mapper.Map <RequestConventionInfo[]>(request.RequestConventionInfos); foreach (var conventionInfo in newConventionInfos) { conventionInfo.RequestId = newRequestId; Executor.GetCommand <CreateConventionInfoCommand>().Process(c => c.Execute(conventionInfo)); } var newEarlyRegs = _mapper.Map <RequestEarlyReg[]>(request.EarlyRegs); foreach (var earlyReg in newEarlyRegs) { earlyReg.RequestId = newRequestId; Executor.GetCommand <CreateRequestEarlyRegCommand>().Process(c => c.Execute(earlyReg)); } var newIcgsRequests = _mapper.Map <ICGSRequest[]>(request.ICGSRequests); foreach (var icgsRequest in newIcgsRequests) { icgsRequest.RequestId = newRequestId; Executor.GetCommand <CreateRequestIcgsCommand>().Process(c => c.Execute(icgsRequest)); } var newIpcRequests = _mapper.Map <IPCRequest[]>(request.IPCRequests); foreach (var ipcRequest in newIpcRequests) { ipcRequest.RequestId = newRequestId; Executor.GetCommand <CreateIpcRequestCommand>().Process(c => c.Execute(ipcRequest)); } var newIcisRequests = _mapper.Map <ICISRequest[]>(request.ICISRequests); foreach (var icisRequest in newIcisRequests) { icisRequest.RequestId = newRequestId; Executor.GetCommand <CreateRequestIcisCommand>().Process(c => c.Execute(icisRequest)); } foreach (var colorTz in request.ColorTzs) { var newColorTz = new DicColorTZRequestRelation { ColorTzId = colorTz.ColorTzId, RequestId = newRequestId }; Executor.GetCommand <CreateRequestColorTzCommand>().Process(c => c.Execute(newColorTz)); } foreach (var icfem in request.Icfems) { var newIcfem = new DicIcfemRequestRelation { DicIcfemId = icfem.DicIcfemId, RequestId = newRequestId }; Executor.GetCommand <CreateRequestIcfemCommand>().Process(c => c.Execute(newIcfem)); } #endregion #region Контрагенты var newCustomers = _mapper.Map <RequestCustomer[]>(request.RequestCustomers); foreach (var customer in newCustomers) { customer.RequestId = newRequestId; Executor.GetCommand <CreateRequestCustomerCommand>().Process(c => c.Execute(customer)); } #endregion }
/// <summary> /// Обработка информации о МТЗ /// </summary> /// <param name="markgr">Данные из xml</param> /// <param name="loopState"></param> /// <param name="localContext">Конекст БД</param> /// <returns></returns> private NiisWebContext ProcessItem(MARKGR markgr, ParallelLoopState loopState, NiisWebContext localContext) { //foreach (MARKGR markgr in romarinDto.MARKGRS) //{ // Only for KZ var isKz = markgr.EXN?.Any(e => e.DESPG != null && e.DESPG.DCPCD.Contains(KZ) || e.DESPG2 != null && e.DESPG2.DCPCD.Contains(KZ)); isKz = isKz.HasValue && isKz.Value || markgr.LIN != null && markgr.LIN.Any(l => l.DCPCD.Contains(KZ)); if (!isKz.Value) { return(localContext); } var protectionDocIcfems = new List <DicIcfemProtectionDocRelation>(); var protectionDocIcgs = new List <ICGSProtectionDoc>(); // Получить статус // Охрана var statusCode = "D.TZ"; if (markgr.RFNP.Any() || markgr.RFNT.Any() || markgr.EXN != null && markgr.EXN.Any() || markgr.ENN.Any()) { //Обработка заявки statusCode = "W"; } if (markgr.R18NT.Any()) { // Окончательный отказ statusCode = "03.10"; } // Заявка var request = localContext.Requests.FirstOrDefault(r => r.RequestNum == markgr.INTREGN.Trim()) ?? new Request { Id = 0, DateCreate = DateTimeOffset.Now, UserId = _mainExecutorId }; if (request.Id == 0) { localContext.Requests.Add(request); } else { localContext.Requests.Update(request); } //try //{ #region Convert Data // 2 (21) Регистрационный номер заявки LogMsg(request.RequestNum, markgr.INTREGN.Trim(), $"(21) Регистрационный номер заявки {markgr.INTREGN.Trim()}"); request.RequestNum = markgr.INTREGN.Trim(); // 1 (54) Название на иностранном языке LogMsg(request.NameEn, markgr.CURRENT?.IMAGE.TEXT?.Trim(), $"(54) Название на иностранном языке Заявка № {request.RequestNum}"); request.NameEn = markgr.CURRENT?.IMAGE.TEXT?.Trim(); // 3 (22) Дата подачи заявки LogMsg(request.RequestDate?.ToString(), DateFromString(markgr.INTREGD)?.ToString(), $"(22) Дата подачи заявки Заявка № {request.RequestNum}"); request.RequestDate = DateFromString(markgr.INTREGD); // 5 (891) Дата распространения на РК var exn = markgr.EXN?.FirstOrDefault(e => e.DESPG?.DCPCD != null && e.DESPG.DCPCD.Contains(KZ) || e.DESPG2?.DCPCD != null && e.DESPG2.DCPCD.Contains(KZ)); LogMsg(request.DistributionDate?.ToString(), DateFromString(markgr.INTREGD)?.ToString(), $"(891) Дата распространения на РК Заявка № {request.RequestNum}"); request.DistributionDate = DateFromString(exn?.REGEDAT); // 6 Патентообладатель if (markgr.CURRENT?.HOLGR?.ADDRESS != null) { ProcessPatentHolder(localContext, markgr, request); } if (markgr.CURRENT != null) { // 7 Изображение ProcessImage(localContext, markgr, request); // 8 Транслитерация LogMsg(request.Transliteration, markgr.CURRENT.MARTRAN?.Trim(), $"Транслитерация Заявка № {request.RequestNum}"); request.Transliteration = markgr.CURRENT.MARTRAN?.Trim(); // 9 МКИЭТЗ if (markgr.CURRENT.VIENNAGR != null) { // только детальный уровень ProcessIcfem(localContext, markgr, request, statusCode, protectionDocIcfems); } // 10 МКТУ if (markgr.CURRENT.BASICGS != null) { ProcessIcgs(localContext, markgr, request, statusCode, protectionDocIcgs); } } // 11 (511) МКТУ- Описание отказа по классу if (markgr.LIN != null && markgr.LIN.Any(l => l.DCPCD.Contains(KZ))) { ProcessIcgsRefuse(localContext, markgr, request, statusCode, protectionDocIcgs); } if (markgr.CURRENT != null) { // 12 (591) Цвета if (markgr.CURRENT.COLCLAGR != null) { var colors = new[] { markgr.CURRENT.COLCLAGR.COLCLAEN, markgr.CURRENT.COLCLAGR.COLCLAES, markgr.CURRENT.COLCLAGR.COLCLAFR }.FirstOrDefault(ls => ls != null); var colorStr = string.Empty; foreach (var color in colors) { colorStr += color.Trim() + " "; } LogMsg(request.RomarinColor, colorStr, $"(591) Цвета Заявка № {request.RequestNum}"); request.RomarinColor = colorStr; } // 13 Приоритетные данные if (markgr.CURRENT.PRIGR != null) { var country = localContext.DicCountries.FirstOrDefault(dc => dc.Code.Trim().ToLower() == markgr.CURRENT.PRIGR.PRICP.Trim().ToLower()); if (country == null) { Log.Logger.Error("Приоритетные данные. Страна не найдена: {0}. {1}", markgr.CURRENT.PRIGR.PRICP.Trim().ToLower(), $"Заявка № {request.RequestNum}"); } else { var dicEarlyType = localContext.DicEarlyRegTypes.FirstOrDefault(dr => dr.Code == "30 - 300"); var requestEarly = localContext.RequestEarlyRegs.FirstOrDefault(rer => rer.RegNumber == markgr.CURRENT.PRIGR.PRIAPPD.Trim()) ?? new RequestEarlyReg { Id = 0, DateCreate = DateTimeOffset.Now, RegNumber = markgr.CURRENT.PRIGR.PRIAPPD.Trim(), EarlyRegType = dicEarlyType }; if (requestEarly.Id == 0) { localContext.RequestEarlyRegs.Add(requestEarly); } else { localContext.RequestEarlyRegs.Update(requestEarly); } requestEarly.RegCountry = country; requestEarly.RegCountryId = country.Id; //requestEarly.PriorityDate = DateFromString(markgr.CURRENT.PRIGR?.PRIAPPD); requestEarly.Request = request; var priorityData = new[] { markgr.CURRENT.PRIGR?.TEXTEN, markgr.CURRENT.PRIGR?.TEXTES, markgr.CURRENT.PRIGR?.TEXTFR }.FirstOrDefault(txn => !string.IsNullOrEmpty(txn)); LogMsg(requestEarly.ITMRawPriorityData, priorityData, $"Приоритетные данные Заявка № {request.RequestNum}"); requestEarly.ITMRawPriorityData = priorityData; } } // 14 (526) Дискламация var disclaimerRu = new[] { markgr.CURRENT.DISCLAIMGR?.DISCLAIMEREN, markgr.CURRENT.DISCLAIMGR?.DISCLAIMERES, markgr.CURRENT.DISCLAIMGR?.DISCLAIMERFR }.FirstOrDefault(str => !string.IsNullOrEmpty(str)); LogMsg(request.DisclaimerRu, disclaimerRu, $"Дискламация Заявка № {request.RequestNum}"); request.DisclaimerRu = disclaimerRu; } // 15 Статус request.Status = localContext.DicRequestStatuses.FirstOrDefault(drs => drs.Code == statusCode); LogMsg(null, request.Status?.NameRu, $"Статус Заявка № {request.RequestNum}"); // 16 Тип ОД var protectionDocType = localContext.DicProtectionDocTypes.FirstOrDefault(t => t.Code == "ITM"); request.ProtectionDocType = protectionDocType; // Охранный документ if (statusCode == "D.TZ") { //todo! Данный статус заявки в системе в данный момент не используется, не понятно как должно работать /*var protectionDoc = * localContext.ProtectionDocs.FirstOrDefault(r => r.GosNumber == markgr.INTREGN.Trim()) * ?? new ProtectionDoc * { * DateCreate = DateTimeOffset.Now * }; * protectionDoc.Request = request; * * protectionDoc.NameEn = request.NameEn; * protectionDoc.GosNumber = request.RequestNum; * protectionDoc.GosDate = request.RequestDate; * // 4 (180) Срок действия ОД * LogMsg(protectionDoc.ValidDate?.ToString(), DateFromString(markgr.EXPDATE)?.ToString(), * $"(180) Срок действия ОД Заявка № {request.RequestNum}"); * protectionDoc.ValidDate = DateFromString(markgr.EXPDATE); * protectionDoc.DistributionDate = request.DistributionDate; * protectionDoc.Transliteration = request.Transliteration; * protectionDoc.Type = request.ProtectionDocType; * protectionDoc.DisclaimerRu = request.DisclaimerRu; * * protectionDoc.Icfems = new List<DicIcfemProtectionDocRelation>(); * foreach (var icfem in protectionDocIcfems) * { * if (localContext.DicIcfemProtectionDocRelations.All(icf => * icf.DicIcfemId != icfem.DicIcfemId && icf.ProtectionDocId != protectionDoc.Id)) * { * protectionDoc.Icfems.Add(icfem); * } * } * * protectionDoc.IcgsProtectionDocs = new List<ICGSProtectionDoc>(); * foreach (var icgspd in protectionDocIcgs) * { * if (localContext.ICGSProtectionDocs.All(icf => * icf.IcgsId != icgspd.Id && icf.ProtectionDocId != protectionDoc.Id)) * { * protectionDoc.IcgsProtectionDocs.Add(icgspd); * } * }*/ } // if (int.TryParse(request.RequestNum, out var reqNumber)) { if (reqNumber >= 1316814) { // Ожидание срока рассмотрения заявки var dicRouteStage = localContext.DicRouteStages.FirstOrDefault(dr => dr.Code == "TMI03.1"); // Начальник управления экспертизы международных заявок на товарные знаки if (dicRouteStage != null) { var requestWorkflow = localContext.RequestWorkflows.FirstOrDefault(rw => rw.OwnerId == request.Id); if (requestWorkflow == null) { var workFlow = new RequestWorkflow { CurrentStageId = dicRouteStage.Id, DateCreate = DateTimeOffset.Now, CurrentUserId = _mainExecutorId, RouteId = dicRouteStage.RouteId, IsComplete = dicRouteStage.IsLast, IsSystem = dicRouteStage.IsSystem, IsMain = dicRouteStage.IsMain, Owner = request }; localContext.RequestWorkflows.Add(workFlow); localContext.SaveChanges(); request.CurrentWorkflowId = workFlow.Id; } } } else { // Публикация ВОИС var dicRouteStage = localContext.DicRouteStages.FirstOrDefault(dr => dr.Code == "TMI03.3.4.5"); if (dicRouteStage != null) { var requestWorkflow = localContext.RequestWorkflows.FirstOrDefault(rw => rw.OwnerId == request.Id); if (requestWorkflow == null) { var workFlow = new RequestWorkflow { CurrentStageId = dicRouteStage.Id, DateCreate = DateTimeOffset.Now, CurrentUserId = _mainExecutorId, RouteId = dicRouteStage.RouteId, IsComplete = dicRouteStage.IsLast, IsSystem = dicRouteStage.IsSystem, IsMain = dicRouteStage.IsMain, Owner = request }; localContext.RequestWorkflows.Add(workFlow); localContext.SaveChanges(); request.CurrentWorkflowId = workFlow.Id; } } // Начальник управления экспертизы международных заявок на товарные знаки } } // 17 By office request.AdditionalDocs = new List <AdditionalDoc>(); // 17.1 Registration if (markgr.ENN != null) { ProcessAdditionalDocs(markgr.ENN, AdditionalDocType.Registration, localContext, ref request); } // 17.2 Subsequent designation if (markgr.EXN != null) { ProcessAdditionalDocs(markgr.EXN, AdditionalDocType.SubsequentDesignation, localContext, ref request); } // 17.3 Continuation of effect if (markgr.CENS != null) { ProcessAdditionalDocs(markgr.CENS, AdditionalDocType.ContinuationOfEffect, localContext, ref request); } // 17.4 Total provisional refusal of protection if (markgr.RFNT != null) { ProcessAdditionalDocs(markgr.RFNT, AdditionalDocType.TotalProvisionalRefusalOfProtection, localContext, ref request); } // 17.5 Statement indicating that the mark is protected for all the goods and services requested if (markgr.FINV != null) { ProcessAdditionalDocs(markgr.FINV, AdditionalDocType.StatementIndicatingThatTheMarkIsProtected, localContext, ref request); } // 17.6 Renewal if (markgr.REN != null) { ProcessAdditionalDocs(markgr.REN, AdditionalDocType.Renewal, localContext, ref request); } // 17.7 Limitation if (markgr.LIN != null) { ProcessAdditionalDocs(markgr.LIN, AdditionalDocType.Limitation, localContext, ref request); } // 17.8 Statement of grant of protection made under Rule 18ter(1) if (markgr.GP18N != null) { ProcessAdditionalDocs(markgr.GP18N, AdditionalDocType.StatementOfGrantOfProtectionMadeUnderRule, localContext, ref request); } // 17.9 Ex Officio examination completed but opposition or observations by third parties still possible, under Rule 18bis(1) if (markgr.ISN != null) { ProcessAdditionalDocs(markgr.ISN, AdditionalDocType.ExOfficioExaminationCompleted, localContext, ref request); } // 17.10 Confirmation of total provisional refusal under Rule 18ter(3) if (markgr.R18NT != null) { ProcessAdditionalDocs(markgr.R18NT, AdditionalDocType.ConfirmationOfTotalProvisionalRefusal, localContext, ref request); } // 17.11 Partial invalidation if (markgr.INNP != null) { ProcessAdditionalDocs(markgr.INNP, AdditionalDocType.PartialInvalidation, localContext, ref request); } // 17.12 Statement indicating the goods and services for which protection of the mark is granted under Rule 18ter(2)(ii) if (markgr.R18NP != null) { ProcessAdditionalDocs(markgr.R18NP, AdditionalDocType.StatementIndicatingTheGoodsAndServices, localContext, ref request); } // 17.13 Further statement under Rule 18ter(4) indicating that protection of the mark is granted for all the goods and services requested if (markgr.FDNV != null) { ProcessAdditionalDocs(markgr.FDNV, AdditionalDocType.FurtherStatementUnderRule, localContext, ref request); } // 17.14 Opposition possible after the 18 months time limit if (markgr.OPN != null) { ProcessAdditionalDocs(markgr.OPN, AdditionalDocType.OppositionPossibleAfterTimeLimit, localContext, ref request); } // 17.15 Statement of grant of protection following a provisional refusal under Rule 18ter(2)(i) if (markgr.R18NV != null) { ProcessAdditionalDocs(markgr.R18NV, AdditionalDocType.StatementOfGrantOfProtectionFollowingProvisionalRefusal, localContext, ref request); } // 17.16 Partial provisional refusal of protection if (markgr.RFNP != null) { ProcessAdditionalDocs(markgr.RFNP, AdditionalDocType.StatementOfGrantOfProtectionFollowingProvisionalRefusal, localContext, ref request); } _numberGenerator.GenerateBarcode(request); #endregion //} //catch (Exception e) //{ // Debug.WriteLine(e); //} //localContext.ProtectionDocs.Add(protectionDoc); return(localContext); }