Example #1
0
        public void GetMessageFile(GetMessageFileArgument argument, GetMessageFileResult result)
        {
            var dicReceiveTypeElectronicFeedId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicReceiveType), DicReceiveTypeCodes.ElectronicFeed);
            var childClass =
                _dictionaryHelper.GetChildClass(new[]
                                                { dicReceiveTypeElectronicFeedId });
            var docInfo = _niisWebContext.DocumentDocumentRelations
                          .Include(x => x.Child)
                          .Include(x => x.Parent)
                          .Include(x => x.Child.Type)
                          .Include(x => x.Child.Workflows)
                          .Include(x => x.Child.MainAttachment)
                          .Where(x => x.Parent.Barcode == argument.MainDocumentID &&
                                 (childClass.Contains(x.Child.Type.ClassificationId ?? 0) ||
                                  x.Child.Type.ClassificationId ==
                                  dicReceiveTypeElectronicFeedId) &&
                                 x.Child.Workflows.Count(w => w.IsComplete == true) > 0)
                          .OrderBy(x => x.Child.CurrentWorkflows.Select(d => d.DateCreate).Max())
                          .Select(x => new
            {
                Id = x.Child.Barcode,
                x.Child.TypeId,
                x.Child.OutgoingNumber,
                x.Child.DateCreate,
                DocTypeName = x.Child.Type.NameRu,
                x.Child.MainAttachment.PageCount,
                x.Child.MainAttachment.OriginalName,
                x.Child.MainAttachment.BucketName
            })
                          .FirstOrDefault();

            if (docInfo == null)
            {
                return;
            }
            result.DocDate            = docInfo.DateCreate.Date;
            result.DocNumber          = docInfo.OutgoingNumber;
            result.MainDocumentID     = argument.MainDocumentID;
            result.PageCount          = docInfo.PageCount ?? 0;
            result.CorrespondenceType = new RefKey {
                UID = docInfo.TypeId, Note = docInfo.DocTypeName
            };
            result.DocumentID = docInfo.Id;
            var file = _attachFileHelper.GetFile(docInfo.BucketName, docInfo.OriginalName);

            if (_validationHelper.SenderIsPep(argument.SystemInfo.Sender))
            {
                var shepFile = _attachFileHelper.ShepFileUpload(file, docInfo.OriginalName);
                result.File = new File {
                    ShepFile = shepFile
                };
            }
            else
            {
                result.File = new File {
                    Name = docInfo.OriginalName, Content = file
                };
            }
        }
        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();
                }
            }
        }