Пример #1
0
        private DicCustomer GetCustomer()
        {
            var         ownerType = (Owner.Type)(int) Parameters["OwnerType"];
            var         ownerId   = Convert.ToInt32(Parameters["RequestId"]);
            DicCustomer result    = null;

            switch (ownerType)
            {
            case Owner.Type.Request:
                var request = Executor.GetQuery <GetRequestByIdQuery>().Process(q => q.Execute(ownerId));
                result = request.Addressee;
                break;

            case Owner.Type.ProtectionDoc:
                var protectionDoc = Executor.GetQuery <GetProtectionDocByIdQuery>().Process(q => q.Execute(ownerId));
                result = protectionDoc.Addressee;
                break;

            case Owner.Type.Contract:
                var contract = Executor.GetQuery <GetContractByIdQuery>().Process(q => q.Execute(ownerId));
                result = contract.Addressee;
                break;

            default:
            case Owner.Type.Material:
                var material = Executor.GetQuery <GetDocumentByIdQuery>().Process(q => q.Execute(ownerId));
                result = material.Addressee;
                break;
            }

            return(result);
        }
 public static void SortAllDic()
 {
     try
     {
         DicArea             = DicArea.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicConnection       = DicConnection.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicConnectionStatus = DicConnectionStatus.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicConnectionType   = DicConnectionType.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicContract         = DicContract.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicContractStatus   = DicContractStatus.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicCustomer         = DicCustomer.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicCustomerFeedback = DicCustomerFeedback.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicDevice           = DicDevice.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicDeviceType       = DicDeviceType.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicEmployee         = DicEmployee.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicFee               = DicFee.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicImage             = DicImage.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicImportReceipt     = DicImportReceipt.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicManufacturer      = DicManufacturer.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicPayment           = DicPayment.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicProvider          = DicProvider.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicServiceForm       = DicServiceForm.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicServiceFormStatus = DicServiceFormStatus.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicServicePack       = DicServicePack.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
         DicStore             = DicStore.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
     }
     catch (Exception ex) { LogTo.Error(ex.ToString()); }
 }
Пример #3
0
        public async Task ExecuteAsync(DicCustomer customer)
        {
            var customerRepo = Uow.GetRepository <DicCustomer>();

            customerRepo.Update(customer);
            await Uow.SaveChangesAsync();
        }
 public static void ClearAllDic()
 {
     try
     {
         DicArea.Clear();
         DicConnection.Clear();
         DicConnectionStatus.Clear();
         DicConnectionType.Clear();
         DicContract.Clear();
         DicContractStatus.Clear();
         DicCustomer.Clear();
         DicCustomerFeedback.Clear();
         DicDetailImportReceipt.Clear();
         DicDevice.Clear();
         DicDeviceType.Clear();
         DicEmployee.Clear();
         DicFee.Clear();
         DicImage.Clear();
         DicImportReceipt.Clear();
         DicManufacturer.Clear();
         DicPayment.Clear();
         DicPaymentFee.Clear();
         DicProvider.Clear();
         DicServiceForm.Clear();
         DicServiceFormStatus.Clear();
         DicServicePack.Clear();
         DicServicePackFee.Clear();
         DicStore.Clear();
     }
     catch (Exception ex) { LogTo.Error(ex.ToString()); }
 }
 internal static void RemoveMemory(Customer objectValue)
 {
     if (DicCustomer.ContainsKey(objectValue.Id))
     {
         DicCustomer.Remove(objectValue.Id);
     }
 }
 public static bool IsExistCustomer(int id)
 {
     if (DicCustomer.ContainsKey(id))
     {
         return(true);
     }
     return(false);
 }
Пример #7
0
        //private CustomerAttorneyInfo CreateCustomerInfo(int customerId, CustomerAddressStringExtension oldCustomer)
        //{
        //    var attorneyInfo = new CustomerAttorneyInfo
        //    {
        //        CustomerId = customerId,
        //        DateBeginStop = GetNullableDate(oldCustomer.AttDateBeginStop),
        //        DateCard = GetNullableDate(oldCustomer.AttDateCard),
        //        DateCreate = DateTimeOffset.Now,
        //        DateDisCard = GetNullableDate(oldCustomer.AttDateDiscard),
        //        DateEndStop = GetNullableDate(oldCustomer.AttDateEndStop),
        //        DateUpdate = DateTimeOffset.Now,
        //        Education = oldCustomer.AttEducation,
        //        ExternalId = oldCustomer.Id,
        //        FieldOfActivity = oldCustomer.AttSphereWork,
        //        FieldOfKnowledge = oldCustomer.AttSphereKnow,
        //        GovReg = oldCustomer.AttStatReg,
        //        GovRegDate = GetNullableDate(oldCustomer.AttStatRegDate),
        //        Language = oldCustomer.AttLang,
        //        PaymentOrder = oldCustomer.AttPlatpor,
        //        PublicRedefine = oldCustomer.AttPublicRedefine,
        //        Redefine = oldCustomer.AttRedefine,
        //        RegCode = oldCustomer.AttCode,
        //        SomeDate = oldCustomer.AttSomeDate,
        //        Timestamp = BitConverter.GetBytes(DateTime.Now.Ticks),
        //        WorkPlace = oldCustomer.AttWorkPlace
        //    };

        //    return attorneyInfo;
        //}

        private DicCustomer CreateCustomer(CustomerAddressStringExtension oldCustomer)
        {
            var typeId = GetObjectId <DicCustomerType>(oldCustomer.TypeId);

            if (typeId == null || typeId == 0)
            {
                return(null);
            }

            var customer = new DicCustomer
            {
                Address           = oldCustomer.AddresNameRu,
                ApplicantsInfo    = oldCustomer.FlApplicantsInfo,
                CertificateNumber = oldCustomer.FlCertificateNumber,
                CertificateSeries = oldCustomer.FlCertificateSeries,
                ContactName       = oldCustomer.ContactFace,
                CountryId         = GetObjectId <DicCountry>(oldCustomer.CountryId),
                DateCreate        = new DateTimeOffset(oldCustomer.DateCreate.GetValueOrDefault(DateTime.Now)),
                DateUpdate        = new DateTimeOffset(oldCustomer.Stamp.GetValueOrDefault(DateTime.Now)),
                Email             = oldCustomer.Email,
                ExternalId        = oldCustomer.Id,
                IsBeneficiary     = false,
                IsNotMention      = false,
                IsSMB             = GenerateHelper.StringToNullableBool(oldCustomer.FlIsSmb),
                JurRegNumber      = oldCustomer.JurRegNumber,
                Login             = oldCustomer.Login,
                NameEn            = oldCustomer.CusNameMlEn,
                NameEnLong        = oldCustomer.CusNameMlEnLong,
                NameKz            = oldCustomer.CusNameMlKz,
                NameKzLong        = oldCustomer.CusNameMlKzLong,
                NameRu            = oldCustomer.CusNameMlRu,
                NameRuLong        = oldCustomer.CusNameMlRuLong,
                NotaryName        = oldCustomer.FlNotaryName,
                Opf      = oldCustomer.FlOpf,
                Password = oldCustomer.Password,
                Phone    = oldCustomer.Phone,
                PhoneFax = oldCustomer.Fax,
                PowerAttorneyDateIssue = GetNullableDate(oldCustomer.FlPowerAttorneyDateIssue),
                PowerAttorneyFullNum   = oldCustomer.FlPowerAttorneyFullNum,
                RegDate         = GetNullableDate(oldCustomer.FlRegDate),
                Rnn             = oldCustomer.Rtn,
                ShortDocContent = oldCustomer.FlShortDocContent,
                Subscript       = oldCustomer.Subscript,
                Timestamp       = BitConverter.GetBytes(DateTime.Now.Ticks),
                Xin             = oldCustomer.Xin,
                TypeId          = typeId.Value,
                AddressEn       = oldCustomer.AddresNameEn,
                AddressKz       = oldCustomer.AddresNameKz,
                City            = oldCustomer.City,
                Oblast          = oldCustomer.Oblast,
                Republic        = oldCustomer.Republic,
                IsDeleted       = false,
                Region          = oldCustomer.Region,
                ShortAddress    = oldCustomer.AddresNameRu
            };

            return(customer);
        }
 public static Customer GetCustomer(int id)
 {
     if (DicCustomer.ContainsKey(id))
     {
         return(DicCustomer[id].Clone() as Customer);
     }
     LogTo.Error("Not get Customer by id = " + id);
     return(null);
 }
Пример #9
0
        public async Task <int> ExecuteAsync(DicCustomer customer)
        {
            var customerRepo = Uow.GetRepository <DicCustomer>();
            await customerRepo.CreateAsync(customer);

            await Uow.SaveChangesAsync();

            return(customer.Id);
        }
Пример #10
0
        public void RequisitionBlockCustomerAdd(Customer[] customers, int requestId)
        {
            foreach (var item in customers)
            {
                if (item.Type == null)
                {
                    continue;
                }
                var customer = new DicCustomer
                {
                    TypeId            = _dictionaryHelper.GetDictionaryEntityByExternalId(nameof(DicCustomerType), item.Type.UID).Id,
                    NameRu            = item.NameRu,
                    NameKz            = item.NameKz,
                    NameEn            = item.NameEn,
                    Phone             = item.Phone,
                    PhoneFax          = item.Fax,
                    Email             = item.Email,
                    Address           = $"{item.AdrObl}, {item.AdrStreet}, {item.AdrPostCode}",
                    CertificateNumber = item.CertificateNumber,
                    CertificateSeries = item.CertificateSeries,
                    Opf                  = item.Opf,
                    ApplicantsInfo       = item.ApplicantsInfo,
                    PowerAttorneyFullNum = item.PowerAttorneyFullNum,
                    ShortDocContent      = item.ShortDocContent,
                    Xin                  = item.Xin,
                    NotaryName           = item.NotaryName,
                    DateCreate           = DateTimeOffset.Now
                };

                if (item.RegDate != DateTime.MinValue)
                {
                    customer.RegDate = new DateTimeOffset(item.RegDate);
                }

                var requestCustomer = new RequestCustomer
                {
                    CustomerId     = _integrationDictionaryHelper.GetCustomerIdOrCreateNew(customer).Id,
                    RequestId      = requestId,
                    DateCreate     = DateTimeOffset.Now,
                    CustomerRoleId = _dictionaryHelper.GetDictionaryEntityByExternalId(nameof(DicCustomerRole), item.PatentLinkType.UID)?.Id
                };

                _niisContext.RequestCustomers.Add(requestCustomer);
                _niisContext.SaveChanges();
            }
        }
Пример #11
0
        /// <summary>
        /// Получить Адресата для переписки из контрагента.
        /// </summary>
        /// <param name="customer">Контрагент.</param>
        /// <param name="fieldName">Поле для получение объекта.</param>
        /// <param name="subFieldName">Поле из выбранного объекта.</param>
        /// <returns></returns>
        private static TResult GetCustomerCorrespondence <TResult>(DicCustomer customer, string fieldName, string subFieldName)
        {
            var property = customer.GetType().GetProperty(fieldName);

            var result = property?.GetValue(customer, null);

            if (result is null)
            {
                return(default(TResult));
            }

            var subFieldProperty = result.GetType().GetProperty(subFieldName);

            if (subFieldProperty != null)
            {
                result = subFieldProperty.GetValue(result, null);
            }

            return((TResult)result);
        }
Пример #12
0
        private DicCustomer GetCustomerBy(NiisWebContext context, string xin, string rnn)
        {
            DicCustomer customer = null;

            if (string.IsNullOrWhiteSpace(xin))
            {
                customer = context.DicCustomers.FirstOrDefault(c => c.Xin == xin);
            }

            if (customer != null)
            {
                return(customer);
            }

            if (!string.IsNullOrWhiteSpace(rnn))
            {
                customer = context.DicCustomers.FirstOrDefault(c => c.Rnn == rnn);
            }

            return(customer);
        }
Пример #13
0
        public void Update(DicCustomer customer)
        {
            var originalCustomer = GetCustomer(customer.Id);

            if (originalCustomer == null)
            {
                return;
            }

            originalCustomer.NameRu            = customer.NameRu;
            originalCustomer.NameEn            = customer.NameEn;
            originalCustomer.NameKz            = customer.NameKz;
            originalCustomer.ShortAddress      = customer.ShortAddress;
            originalCustomer.Address           = customer.Address;
            originalCustomer.AddressKz         = customer.AddressKz;
            originalCustomer.AddressEn         = customer.AddressEn;
            originalCustomer.IsBeneficiary     = customer.IsBeneficiary;
            originalCustomer.TypeId            = customer.TypeId;
            originalCustomer.CountryId         = customer.CountryId;
            originalCustomer.JurRegNumber      = customer.JurRegNumber;
            originalCustomer.IsNotMention      = customer.IsNotMention;
            originalCustomer.Apartment         = customer.Apartment;
            originalCustomer.BeneficiaryTypeId = customer.BeneficiaryTypeId;
            originalCustomer.City     = customer.City;
            originalCustomer.Oblast   = customer.Oblast;
            originalCustomer.Republic = customer.Republic;
            originalCustomer.Region   = customer.Region;
            originalCustomer.Street   = customer.Street;
            foreach (var contactInfo in originalCustomer.ContactInfos)
            {
                _context.ContactInfos.Remove(contactInfo);
            }

            originalCustomer.ContactInfos = customer.ContactInfos;
            _context.SaveChanges();
        }
Пример #14
0
        public DicCustomer GetCustomerIdOrCreateNew(DicCustomer customer)
        {
            if (string.IsNullOrEmpty(customer.NameRu))
            {
                throw new Exception("Имя контрагента не может быть пустым");
            }

            var dicCustomer = _niisContext.DicCustomers
                              .Where(x =>
                                     !string.IsNullOrEmpty(customer.Xin) && x.Xin == customer.Xin && x.TypeId == customer.TypeId ||
                                     !string.IsNullOrEmpty(customer.Xin) && customer.Xin.Equals(x.Xin, StringComparison.CurrentCultureIgnoreCase) ||
                                     !string.IsNullOrEmpty(customer.NameRu) && customer.NameRu.Equals(x.NameRu, StringComparison.CurrentCultureIgnoreCase)
                                     )
                              .OrderByDescending(x => x.Id)
                              .FirstOrDefault();

            if (dicCustomer != null)
            {
                dicCustomer.Login        = customer.Login;
                dicCustomer.Phone        = customer.Phone;
                dicCustomer.PhoneFax     = customer.PhoneFax;
                dicCustomer.Address      = customer.Address;
                dicCustomer.ShortAddress = customer.ShortAddress;
                dicCustomer.Email        = customer.Email;
                dicCustomer.NameRu       = customer.NameRu;

                _niisContext.DicCustomers.Update(dicCustomer);
                _niisContext.SaveChanges();

                return(dicCustomer);
            }

            _niisContext.DicCustomers.Add(customer);
            _niisContext.SaveChanges();
            return(customer);
        }
Пример #15
0
 private static string GetAttorneyGovReg(DicCustomer src)
 {
     return(src.CustomerAttorneyInfos.Select(a => a.CertNum).ToArray().Join());
 }
Пример #16
0
 private string GetPhones(DicCustomer customer)
 {
     return(string.Join(Environment.NewLine, customer.ContactInfos.Where(d => d.Type.Code == DicContactInfoType.Codes.MobilePhone).Select(d => d.Info)));
 }
 public static List <Customer> GetAllCustomer()
 {
     return(DicCustomer.Select(obj => obj.Value.Clone() as Customer).ToList());
 }
Пример #18
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);
        }
Пример #19
0
        private async Task SaveNewCustomer(DicCustomer customerJur)
        {
            await _context.DicCustomers.AddAsync(customerJur);

            await _context.SaveChangesAsync();
        }
Пример #20
0
        /// <summary>
        /// Добавление договора
        /// </summary>
        /// <param name="request">Входные параметры</param>
        /// <param name="response">Данные для ответа</param>
        /// <returns></returns>
        public ContractResponse AddContract(ContractRequest request, ContractResponse response)
        {
            var         typeId = _dictionaryHelper.GetDictionaryIdByExternalId(nameof(DicDocumentType), request.DocumentType.Id);
            DicCustomer customer;

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

            customer.CountryId = _dictionaryHelper.GetDictionaryIdByExternalId(nameof(DicCountry), request.Addressee.CountryInfo.Id);

            var addressee = _integrationDictionaryHelper.GetCustomerIdOrCreateNew(customer);


            var correspondence      = request.CorrespondenceAddress;
            var protectionDocTypeId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicProtectionDocType),
                                                                              DicProtectionDocTypeCodes.ProtectionDocTypeContractCode);

            #region Добавление договора
            var contract = new Contract
            {
                ProtectionDocTypeId = protectionDocTypeId,
                Description         = request.DocumentDescriptionRu,
                ReceiveTypeId       = int.Parse(DicReceiveTypeCodes.ElectronicFeed),
                DivisionId          = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicDivision), DicDivisionCodes.RGP_NIIS),
                AddresseeId         = addressee.Id,
                AddresseeAddress    = addressee.Address,
                StatusId            = 1
            };

            CreateContract(Mapper.Map(request, contract));
            #endregion

            #region Добавление адресата для переписки
            if (correspondence != null)
            {
                var correspondenceCustomer = _integrationDictionaryHelper.GetCustomerIdOrCreateNew(new DicCustomer
                {
                    TypeId   = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicCustomerType), DicCustomerTypeCodes.Undefined),
                    NameRu   = correspondence.CustomerName,
                    Phone    = correspondence.Phone,
                    PhoneFax = correspondence.Fax,
                    Email    = correspondence.Email
                });

                _niisWebContext.ContractCustomers.Add(new ContractCustomer
                {
                    CustomerId     = correspondenceCustomer.Id,
                    ContractId     = contract.Id,
                    DateCreate     = DateTimeOffset.Now,
                    CustomerRoleId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicCustomerRole), DicCustomerRole.Codes.Correspondence)
                });
                _niisWebContext.SaveChanges();
            }
            #endregion

            #region Добавление контрагентов

            foreach (var item in request.BlockCustomers)
            {
                if (item.CustomerType == null)
                {
                    continue;
                }

                if (item.CustomerType.Id == 0)
                {
                    item.CustomerType.Id =
                        _dictionaryHelper.GetDictionaryIdByCode(nameof(DicCustomerType),
                                                                DicCustomerTypeCodes.Undefined);
                }

                var dicCustomer = new DicCustomer
                {
                    TypeId            = _dictionaryHelper.GetDictionaryEntityByExternalId(nameof(DicCustomerType), item.CustomerType.Id).Id,
                    NameRu            = item.NameRu,
                    NameKz            = item.NameKz,
                    NameEn            = item.NameEn,
                    Phone             = item.Phone,
                    PhoneFax          = item.Fax,
                    Email             = item.Email,
                    Address           = $"{item.Region}, {item.Street}, {item.Index}",
                    CertificateNumber = item.CertificateNumber,
                    CertificateSeries = item.CertificateSeries,
                    Opf                  = item.Opf,
                    ApplicantsInfo       = item.ApplicantsInfo,
                    PowerAttorneyFullNum = item.PowerAttorneyFullNum,
                    ShortDocContent      = item.ShortDocContent,
                    Xin                  = item.Xin,
                    NotaryName           = item.NotaryName,
                    DateCreate           = DateTimeOffset.Now
                };

                if (item.RegistrationDate != DateTime.MinValue)
                {
                    dicCustomer.RegDate = new DateTimeOffset(item.RegistrationDate.GetValueOrDefault());
                }

                var contractCustomer = new ContractCustomer
                {
                    CustomerId     = _integrationDictionaryHelper.GetCustomerIdOrCreateNew(dicCustomer).Id,
                    ContractId     = contract.Id,
                    DateCreate     = DateTimeOffset.Now,
                    CustomerRoleId = _dictionaryHelper.GetDictionaryEntityByExternalId(nameof(DicCustomerRole), item.CustomerRole.Id)?.Id
                };

                _niisWebContext.ContractCustomers.Add(contractCustomer);
                _niisWebContext.SaveChanges();
            }

            #endregion

            #region Добавление прикрепленного документа заявления
            var document = new Document(_dictionaryHelper.GetDocumentType(typeId).type)
            {
                TypeId        = typeId,
                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 = request.RequisitionFile.PageCount.GetValueOrDefault(),
                CopyCount = request.RequisitionFile.CopyCount.GetValueOrDefault(),
                File      = request.RequisitionFile.Content,
                Length    = request.RequisitionFile.Content.Length,
                IsMain    = true,
                Name      = request.RequisitionFile.Name
            }, document);

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

            _niisWebContext.ContractsDocuments.Add(new ContractDocument
            {
                DocumentId = document.Id,
                ContractId = contract.Id
            });
            _niisWebContext.SaveChanges();
            #endregion

            #region Добавление документов
            foreach (var attachedFile in request.AttachmentFiles)
            {
                if (attachedFile.File == null)
                {
                    continue;
                }

                var documentType   = _dictionaryHelper.GetDocumentType(attachedFile.FileType.Id);
                var inWorkStatusId =
                    _dictionaryHelper.GetDictionaryIdByCode(nameof(DicDocumentStatus), DicDocumentStatusCodes.InWork);
                var completedStatusId =
                    _dictionaryHelper.GetDictionaryIdByCode(nameof(DicDocumentStatus), DicDocumentStatusCodes.Completed);

                var attachmentDocument = new Document(documentType.type)
                {
                    TypeId        = documentType.typeId,
                    DateCreate    = DateTimeOffset.Now,
                    StatusId      = documentType.type == DocumentType.DocumentRequest ? completedStatusId : inWorkStatusId,
                    AddresseeId   = addressee.Id,
                    ReceiveTypeId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicReceiveType), DicReceiveTypeCodes.ElectronicFeed)
                };
                _documentHelper.CreateDocument(attachmentDocument);
                var attached = new AttachedFileModel
                {
                    Length    = attachedFile.File.Content.Length,
                    PageCount = attachedFile.File.PageCount.GetValueOrDefault(),
                    File      = attachedFile.File?.Content,
                    Name      = attachedFile.File.Name,
                    IsMain    = true,
                    CopyCount = 1
                };

                _attachFileHelper.AttachFile(attached, document);
                _niisWebContext.ContractsDocuments.Add(new ContractDocument
                {
                    DocumentId = attachmentDocument.Id,
                    ContractId = contract.Id
                });
                _niisWebContext.SaveChanges();
            }
            #endregion

            #region Добавление связи с ОД
            foreach (var contractPatent in request.PatentNumbers)
            {
                //Получаем типа патента
                if (!(_dictionaryHelper.GetDictionaryByExternalId(nameof(DicProtectionDocType), contractPatent.PatentType.Id) is DicProtectionDocType type))
                {
                    throw new NotSupportedException($"Тип с идентефикатором {contractPatent.PatentType.Id} не найден");
                }

                var patentId = _niisWebContext
                               .ProtectionDocs
                               .Where(d => d.GosNumber == contractPatent.PatentNumber && d.Request.ProtectionDocTypeId == type.Id)
                               .Select(d => d.Id).FirstOrDefault();

                _niisWebContext.ContractProtectionDocRelations.Add(new ContractProtectionDocRelation
                {
                    ProtectionDocId = patentId,
                    ContractId      = contract.Id
                });
                _niisWebContext.SaveChanges();
            }
            #endregion

            #region Добавление этапа обработки
            var routeId = _integrationDictionaryHelper.GetRouteIdByProtectionDocType(protectionDocTypeId);
            var stage   = _integrationDictionaryHelper.GetRouteStage(routeId);

            var contractWorkflow = new ContractWorkflow
            {
                OwnerId        = contract.Id,
                DateCreate     = DateTimeOffset.Now,
                RouteId        = routeId,
                CurrentStageId = stage.Id,
                CurrentUserId  = _configuration.AuthorAttachmentDocumentId,
                IsComplete     = stage.IsLast,
                IsSystem       = stage.IsSystem,
                IsMain         = stage.IsMain
            };
            _niisWebContext.ContractWorkflows.Add(contractWorkflow);
            _niisWebContext.SaveChanges();

            contract.CurrentWorkflowId = contractWorkflow.Id;
            _niisWebContext.Contracts.Update(contract);
            _niisWebContext.SaveChanges();
            #endregion


            _integrationStatusUpdater.Add(contractWorkflow.Id);

            var onlineStatusId = 0;
            if (contractWorkflow.CurrentStageId != null)
            {
                onlineStatusId = _integrationDictionaryHelper.GetOnlineStatus(contractWorkflow.CurrentStageId.Value);
            }

            response.DocumentId        = contract.Barcode;
            response.DocumentNumber    = contract.IncomingNumber;
            response.RequisitionStatus = onlineStatusId;


            return(response);
        }
Пример #21
0
        public async Task <int> ImportPaymentsAsync(
            DateTimeOffset fromDate,
            DateTimeOffset toDate,
            int?userId          = null,
            string userName     = null,
            string userPosition = null)
        {
            using (var serviceScope = _serviceScopeFactory.CreateScope())
            {
                var context              = serviceScope.ServiceProvider.GetRequiredService <NiisWebContext>();
                var logService           = serviceScope.ServiceProvider.GetRequiredService <ILogRecordService>();
                var notDistributedStatus = context.DicPaymentStatuses.First(s => s.Code == DicPaymentStatusCodes.NotDistributed);

                LogRecord     log;
                StringBuilder logMessage;

                var importedCounter = 0;

                var payments1c = await LoadPaymentsAsync(fromDate, toDate);

                foreach (var p1c in payments1c)
                {
                    var paymentExist = context.Payments.Any(p =>
                                                            p.Payment1CNumber == p1c.Payment1CNumber &&
                                                            p.PayerBinOrInn == p1c.PayerBinOrInn &&
                                                            p.Payer == p1c.Payer &&
                                                            p.PayerRNN == p1c.PayerRNN &&
                                                            p.Amount == p1c.Amount &&
                                                            p.PaymentDate == p1c.PaymentDate);

                    if (paymentExist)
                    {
                        logMessage = new StringBuilder()
                                     .Append($"Сбой сохранения платежа {DateTimeOffset.Now.ToString("dd.MM.yyyy HH:mm:ss")}, ")
                                     .Append("Дубликат, ")
                                     .Append($"{p1c.Payment1CNumber}, ")
                                     .Append($"{p1c.PayerBinOrInn}, ")
                                     .Append($"{p1c.PayerRNN}, ")
                                     .Append($"{p1c.Amount}, ")
                                     .Append($"{p1c.PaymentDate?.ToString("dd.MM.yyyy")}, ")
                                     .Append($"{p1c.PaymentCNumberBVU}. ")
                                     .Append($"{p1c.PurposeDescription}");

                        log = new LogRecord
                        {
                            LogType      = LogType.ImportFrom1C,
                            LogErrorType = LogErrorType.Warning,
                            Message      = logMessage.ToString()
                        };

                        logService.Log(log);

                        continue;
                    }

                    var customer = GetCustomerBy(context, p1c.PayerBinOrInn, p1c.PayerRNN);
                    if (customer == null)
                    {
                        customer = new DicCustomer
                        {
                            NameRuLong = p1c.Payer,
                            Xin        = p1c.PayerBinOrInn,
                            Rnn        = p1c.PayerRNN,
                            TypeId     = GetCustomerTypeId(p1c.CustomerType)
                        };

                        context.DicCustomers.Add(customer);
                    }

                    var payment = new Payment
                    {
                        Payment1CNumber    = p1c.Payment1CNumber,
                        PurposeDescription = p1c.PurposeDescription,
                        Payer                = p1c.Payer,
                        Amount               = p1c.Amount,
                        PaymentCNumberBVU    = p1c.PaymentCNumberBVU,
                        PaymentDate          = p1c.PaymentDate,
                        PayerBinOrInn        = p1c.PayerBinOrInn,
                        PayerRNN             = p1c.PayerRNN,
                        IsForeignCurrency    = p1c.CurrencyType != KZT,
                        CurrencyType         = p1c.CurrencyType,
                        CustomerId           = customer.Id,
                        DateCreate           = DateTimeOffset.Now,
                        ImportedDate         = DateTimeOffset.Now,
                        UserImportedId       = userId,
                        UserNameImported     = userName,
                        UserPositionImported = userPosition,
                        PaymentStatusId      = notDistributedStatus.Id,
                        IsAdvancePayment     = p1c.IsAdvancePayment
                    };

                    context.Payments.Add(payment);
                    context.SaveChanges();

                    logMessage = new StringBuilder()
                                 .Append($"Платеж успешно сохранен {DateTimeOffset.Now.ToString("dd.MM.yyyy HH:mm:ss")}, ")
                                 .Append($"{p1c.Payment1CNumber}, ")
                                 .Append($"{p1c.PaymentCNumberBVU}. ")
                                 .Append($"{p1c.PurposeDescription}, ")
                                 .Append($"{p1c.PayerBinOrInn}, ")
                                 .Append($"{p1c.PayerRNN}, ")
                                 .Append($"{p1c.Amount}, ")
                                 .Append($"{p1c.PaymentDate?.ToString("dd.MM.yyyy")}");

                    log = new LogRecord
                    {
                        LogType      = LogType.ImportFrom1C,
                        LogErrorType = LogErrorType.Information,
                        Message      = logMessage.ToString()
                    };

                    logService.Log(log);

                    importedCounter++;
                }

                return(importedCounter);
            }
        }