Beispiel #1
0
        /// <summary>
        /// Выполнение команды.
        /// </summary>
        /// <param name="requestProtectionDocSimilar">Связь между заявкой и охранным документом.</param>
        public void Execute(RequestProtectionDocSimilar requestProtectionDocSimilar)
        {
            var requestProtectionDocSimilarRepository = Uow.GetRepository <RequestProtectionDocSimilar>();

            requestProtectionDocSimilarRepository.Create(requestProtectionDocSimilar);

            Uow.SaveChanges();
        }
Beispiel #2
0
        /// <summary>
        /// Создание Охранного документа(ОД)
        /// </summary>
        private void GenerateProtectionDocument(RequestWorkFlowRequest workflowRequest)
        {
            var request = Executor.GetQuery <GetRequestByIdQuery>().Process(r => r.Execute(workflowRequest.RequestId));
            var dicProtectionDocStatus = Executor.GetQuery <GetDicProtectionDocStatusByCodeQuery>().Process(r => r.Execute(DicProtectionDocStatusCodes.D));
            var defaultSendType        = Executor.GetQuery <GetSendTypeByCodeQuery>()
                                         .Process(q => q.Execute(DicSendTypeCodes.ByHand));

            if (dicProtectionDocStatus == null)
            {
                return;
            }

            //int addYears = 0;
            string protectionDocTypeCode = "";

            switch (request?.ProtectionDocType?.Code)
            {
            case DicProtectionDocTypeCodes.RequestTypeTrademarkCode:
                //addYears = 10;
                protectionDocTypeCode = DicProtectionDocTypeCodes.ProtectionDocTypeTrademarkCode;
                break;

            case DicProtectionDocTypeCodes.RequestTypeNameOfOriginCode:
                protectionDocTypeCode = DicProtectionDocTypeCodes.ProtectionDocTypeNameOfOriginCode;
                //addYears = 10;
                break;

            case DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode:
                protectionDocTypeCode = DicProtectionDocTypeCodes.ProtectionDocTypeSelectionAchieveCode;
                switch (request.SelectionAchieveType.Code)
                {
                case DicSelectionAchieveTypeCodes.Agricultural:
                    //addYears = 25;
                    break;

                case DicSelectionAchieveTypeCodes.AnimalHusbandry:
                    //addYears = 30;
                    break;

                case DicSelectionAchieveTypeCodes.VarietiesPlant:
                    //addYears = 35;
                    break;
                }
                break;

            case DicProtectionDocTypeCodes.RequestTypeUsefulModelCode:
                protectionDocTypeCode = DicProtectionDocTypeCodes.ProtectionDocTypeUsefulModelCode;
                //addYears = 5;
                break;

            case DicProtectionDocTypeCodes.RequestTypeInventionCode:
                protectionDocTypeCode = DicProtectionDocTypeCodes.ProtectionDocTypeInventionCode;
                //addYears = 20;
                break;

            case DicProtectionDocTypeCodes.RequestTypeIndustrialSampleCode:
                protectionDocTypeCode = DicProtectionDocTypeCodes.ProtectionDocTypeIndustrialSampleCode;
                //addYears = 15;
                break;
            }
            //var validDate = request?.RequestDate?.AddYears(addYears);
            var protectionDocType = Executor.GetQuery <GetDicProtectionDocTypebyCodeQuery>()
                                    .Process(q => q.Execute(protectionDocTypeCode));

            //todo вынести новые коды в класс
            var protectionDocSubtype = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>()
                                       .Process(q => q.Execute(request?.RequestType?.Code + "_PD"));

            //Создаем ОД
            var protectionDocument = new ProtectionDoc
            {
                TypeId    = protectionDocType?.Id ?? 0,
                SubTypeId = protectionDocSubtype?.Id ?? 0,
                StatusId  = dicProtectionDocStatus.Id,
                SelectionAchieveTypeId = request?.SelectionAchieveTypeId,
                ConventionTypeId       = request?.ConventionTypeId,
                BeneficiaryTypeId      = request?.BeneficiaryTypeId,
                TypeTrademarkId        = request?.TypeTrademarkId,
                RegNumber = request?.RequestNum,
                RegDate   = request?.RequestDate,
                GosDate   = NiisAmbientContext.Current.DateTimeProvider.Now,
                //ЦValidDate = validDate,
                Referat         = request?.Referat,
                NameRu          = request?.NameRu,
                NameKz          = request?.NameKz,
                NameEn          = request?.NameEn,
                SelectionFamily = request?.SelectionFamily,
                Image           = request?.Image,
                PreviewImage    = request?.PreviewImage,
                IsImageFromName = request?.IsImageFromName ?? false,
                DisclaimerRu    = request?.DisclaimerRu,
                DisclaimerKz    = request?.DisclaimerKz,
                RequestId       = workflowRequest.RequestId,
                AddresseeId     = request?.AddresseeId,
                SendTypeId      = defaultSendType?.Id
            };

            Executor.GetHandler <GenerateBarcodeHandler>().Process <object>(h => h.Execute(protectionDocument));
            Executor.GetCommand <CreateProtectionDocCommand>().Process(r => r.Execute(protectionDocument));

            var requestProtectionDocSimilar = new RequestProtectionDocSimilar
            {
                RequestId       = workflowRequest.RequestId,
                ProtectionDocId = protectionDocument.Id,
                DateCreate      = DateTimeOffset.Now
            };

            Executor.GetCommand <CreateRequestProtectionDocSimilarCommand>().Process(r => r.Execute(requestProtectionDocSimilar));

            string initialStageCode;

            if (protectionDocType.Code == DicProtectionDocTypeCodes.ProtectionDocTypeNameOfOriginCode)
            {
                initialStageCode = RouteStageCodes.PD_NMPT_AssignmentRegistrationNumber;
            }
            else if (protectionDocType.Code == DicProtectionDocTypeCodes.ProtectionDocTypeTrademarkCode)
            {
                initialStageCode = RouteStageCodes.PD_TM_AssignmentRegistrationNumber;
            }
            else
            {
                initialStageCode = RouteStageCodes.OD01_1;
            }

            var initialStage          = Executor.GetQuery <GetDicRouteStageByCodeQuery>().Process(r => r.Execute(initialStageCode));
            var protectionDocWorkflow = new ProtectionDocWorkflow
            {
                CurrentUserId  = workflowRequest.NextStageUserId,
                OwnerId        = protectionDocument.Id,
                CurrentStageId = initialStage.Id,
                RouteId        = initialStage.RouteId,
                IsComplete     = initialStage.IsLast,
                IsSystem       = initialStage.IsSystem,
                IsMain         = initialStage.IsMain,
            };

            //Создали этап
            Executor.GetCommand <CreateProtectionDocWorkflowCommand>().Process(r => r.Execute(protectionDocWorkflow));

            //Добавили и обновили текущий этап у ОД
            protectionDocument.CurrentWorkflowId = protectionDocWorkflow.Id;
            Executor.GetCommand <UpdateProtectionDocCommand>().Process(r => r.Execute(protectionDocument));

            //Платежи заявки теперь относятся и к ОД (новое требование: не наследовать платежи)
            Executor.GetCommand <UpdateRequestPaymentInvoicesByProtectionDocIdCommand>().Process(r => r.Execute(request.Id, protectionDocument.Id));

            #region Перенос биб. данных

            var mapper          = NiisAmbientContext.Current.Mapper;
            var protectionDocId = protectionDocument.Id;
            var requestId       = request.Id;

            //TODO: реализовать перенос TODO! тянуть только то, что нужно в зависимости от типа ОД
            var requestConventionInfos       = Executor.GetQuery <GetConventionInfosByRequestIdQuery>().Process(q => q.Execute(requestId));
            var protectionDocConventionInfos = mapper.Map <List <RequestConventionInfo>, List <ProtectionDocConventionInfo> >(requestConventionInfos);
            Executor.GetCommand <AddProtectionDocConventionInfosRangeCommand>().Process(c => c.Execute(protectionDocId, protectionDocConventionInfos));

            var requestEarlyRegs       = Executor.GetQuery <GetEarlyRegsByRequestIdQuery>().Process(q => q.Execute(requestId));
            var protectionDocEarlyRegs = mapper.Map <List <RequestEarlyReg>, List <ProtectionDocEarlyReg> >(requestEarlyRegs);
            Executor.GetCommand <AddProtectionDocEarlyRegsRangeCommand>().Process(c => c.Execute(protectionDocId, protectionDocEarlyRegs));

            var icgsRequests       = Executor.GetQuery <GetIcgsByRequestIdQuery>().Process(q => q.Execute(requestId));
            var icgsProtectionDocs = mapper.Map <List <ICGSRequest>, List <ICGSProtectionDoc> >(icgsRequests);
            Executor.GetCommand <AddIcgsProtectionDocRangeCommand>().Process(c => c.Execute(protectionDocId, icgsProtectionDocs));

            var icisRequests       = Executor.GetQuery <GetIcisByRequestIdQuery>().Process(q => q.Execute(requestId));
            var icisProtectionDocs = mapper.Map <List <ICISRequest>, List <ICISProtectionDoc> >(icisRequests);
            Executor.GetCommand <AddIcisProtectionDocRelationsCommand>().Process(c => c.Execute(protectionDocId, icisProtectionDocs.Select(icis => icis.IcisId).ToList()));

            var ipcRequests = Executor.GetQuery <GetIpcByRequestIdQuery>().Process(q => q.Execute(requestId));
            Executor.GetCommand <AddIpcProtectionDocRelationsCommand>().Process(c => c.Execute(protectionDocId, ipcRequests.ToList()));

            var requestColorTzs = Executor.GetQuery <GetColorTzsByRequestIdQuery>().Process(q => q.Execute(requestId));
            var colorTzIds      = requestColorTzs.Select(color => color.ColorTzId).ToList();
            Executor.GetCommand <AddColorTzProtectionDocRelationsCommand>().Process(c => c.Execute(protectionDocId, colorTzIds));

            var icfemRequests       = Executor.GetQuery <GetIcfemByRequestIdQuery>().Process(q => q.Execute(requestId));
            var icfemProtectionDocs = mapper.Map <List <DicIcfemRequestRelation>, List <DicIcfemProtectionDocRelation> >(icfemRequests);
            Executor.GetCommand <AddIcfemProtectionDocRelationsCommand>().Process(c => c.Execute(protectionDocId, icfemProtectionDocs.Select(icfem => icfem.DicIcfemId).ToList()));

            var protectionDocInfo = mapper.Map <RequestInfo, ProtectionDocInfo>(request.RequestInfo);
            Executor.GetCommand <CreateProtectionDocInfoCommand>().Process(c => c.Execute(protectionDocId, protectionDocInfo));

            #endregion

            var protectionDocCustomers = mapper.Map <List <RequestCustomer>, List <ProtectionDocCustomer> >(request.RequestCustomers.ToList());
            Executor.GetCommand <AddProtectionDocCustomersCommand>().Process(c => c.Execute(protectionDocId, protectionDocCustomers));
        }
        public async Task <IActionResult> SplitProtectionDoc(int id, [FromBody] IcgsDto[] icgsDtos)
        {
            var protectionDoc = await Executor.GetQuery <GetProtectionDocByIdQuery>().Process(q => q.ExecuteAsync(id));

            var newProtectionDoc = Mapper.Map <ProtectionDoc>(protectionDoc);

            #region Создание охранного документа

            newProtectionDoc.TypeId          = protectionDoc.TypeId;
            newProtectionDoc.SubTypeId       = protectionDoc.SubTypeId;
            newProtectionDoc.DateCreate      = DateTimeOffset.Now;
            newProtectionDoc.RequestId       = protectionDoc.RequestId;
            newProtectionDoc.Transliteration = protectionDoc.Transliteration;
            await Executor.GetHandler <GenerateNumberForSplitProtectionDocsHandler>().Process(h => h.ExecuteAsync(protectionDoc, newProtectionDoc));

            Executor.GetHandler <GenerateBarcodeHandler>().Process(h => h.Execute(newProtectionDoc));
            var newProtectionDocId = await Executor.GetCommand <CreateProtectionDocCommand>().Process(c => c.ExecuteAsync(newProtectionDoc));

            if (newProtectionDoc.RequestId != null)
            {
                //Создаем связь между заявкой и охранным документом.
                var requestProtectionDocSimilar = new RequestProtectionDocSimilar
                {
                    RequestId       = (int)newProtectionDoc.RequestId,
                    ProtectionDocId = newProtectionDoc.Id,
                    DateCreate      = DateTimeOffset.Now
                };

                Executor.GetCommand <CreateRequestProtectionDocSimilarCommand>().Process(r => r.Execute(requestProtectionDocSimilar));
            }

            var newWorkflows = Mapper.Map <ProtectionDocWorkflow[]>(protectionDoc.Workflows).OrderBy(w => w.DateCreate);
            foreach (var newWorkflow in newWorkflows)
            {
                newWorkflow.OwnerId = newProtectionDocId;
                Executor.GetCommand <CreateProtectionDocWorkflowCommand>().Process(c => c.Execute(newWorkflow));
            }

            var initialStage = await Executor.GetQuery <GetDicRouteStageByCodeQuery>().Process(q => q.ExecuteAsync(protectionDoc.CurrentWorkflow.FromStage.Code));

            var initialWorkflow = new ProtectionDocWorkflow()
            {
                CurrentUserId  = NiisAmbientContext.Current.User.Identity.UserId,
                OwnerId        = newProtectionDocId,
                CurrentStageId = initialStage.Id,
                RouteId        = initialStage.RouteId,
                IsComplete     = initialStage.IsLast,
                IsSystem       = initialStage.IsSystem,
                IsMain         = initialStage.IsMain,
            };
            var initialWorkflowId = Executor.GetCommand <CreateProtectionDocWorkflowCommand>().Process(c => c.Execute(initialWorkflow));

            newProtectionDoc.CurrentWorkflowId = initialWorkflowId;
            await Executor.GetCommand <UpdateProtectionDocCommand>().Process(c => c.ExecuteAsync(newProtectionDocId, newProtectionDoc));

            #endregion

            await CreatePatentOrCertificate(newProtectionDocId, null);

            #region МКТУ

            var newIcgsProtectionDocs = Mapper.Map <ICGSProtectionDoc[]>(icgsDtos);
            foreach (var newIcgsRequest in newIcgsProtectionDocs)
            {
                newIcgsRequest.ProtectionDocId = newProtectionDocId;
            }
            await Executor.GetCommand <UpdateIcgsProtectionDocRangeCommand>()
            .Process(c => c.ExecuteAsync(id, newIcgsProtectionDocs.ToList()));

            #endregion

            #region Биб. данные

            var newConventionInfos = Mapper.Map <ProtectionDocConventionInfo[]>(protectionDoc.ProtectionDocConventionInfos);
            await Executor.GetCommand <AddProtectionDocConventionInfosRangeCommand>()
            .Process(c => c.ExecuteAsync(newProtectionDocId, newConventionInfos.ToList()));

            var newProtectionDocEarlyRegs = Mapper.Map <ProtectionDocEarlyReg[]>(protectionDoc.EarlyRegs);
            await Executor.GetCommand <AddProtectionDocEarlyRegsRangeCommand>()
            .Process(c => c.ExecuteAsync(newProtectionDocId, newProtectionDocEarlyRegs.ToList()));

            var newIpcProtectionDocs = Mapper.Map <IPCProtectionDoc[]>(protectionDoc.IpcProtectionDocs);
            await Executor.GetCommand <AddIpcProtectionDocRelationsCommand>().Process(c =>
                                                                                      c.ExecuteAsync(newProtectionDocId, newIpcProtectionDocs.Select(i => i.IpcId).ToList()));

            var newIcisProtectionDocs = Mapper.Map <ICISProtectionDoc[]>(protectionDoc.IcisProtectionDocs);
            await Executor.GetCommand <AddIcisProtectionDocRelationsCommand>().Process(c =>
                                                                                       c.ExecuteAsync(newProtectionDocId, newIcisProtectionDocs.Select(i => i.IcisId).ToList()));

            await Executor.GetCommand <AddColorTzProtectionDocRelationsCommand>().Process(c => c.ExecuteAsync(newProtectionDocId, protectionDoc.ColorTzs.Select(color => color.ColorTzId).ToList()));

            await Executor.GetCommand <AddIcfemProtectionDocRelationsCommand>().Process(c =>
                                                                                        c.ExecuteAsync(newProtectionDocId, protectionDoc.Icfems.Select(i => i.DicIcfemId).ToList()));

            #endregion

            #region Контрагенты

            var newCustomers = Mapper.Map <ProtectionDocCustomer[]>(protectionDoc.ProtectionDocCustomers);
            await Executor.GetCommand <AddProtectionDocCustomersCommand>().Process(c => c.ExecuteAsync(newProtectionDocId, newCustomers.ToList()));

            #endregion

            var protectionDocumentWorkFlowRequest = new ProtectionDocumentWorkFlowRequest()
            {
                ProtectionDocId = id,
                NextStageUserId = protectionDoc.CurrentWorkflow?.FromUserId ?? 0,
                NextStageCode   = protectionDoc.CurrentWorkflow?.FromStage.Code ?? "",
            };

            NiisWorkflowAmbientContext.Current.ProtectionDocumentWorkflowService.Process(protectionDocumentWorkFlowRequest);

            return(Ok(newProtectionDocId));
        }