示例#1
0
 protected BaseProcess(AppSettingsConfiguration appSettings, ContextManagement contextManagement, Logs logs)
 {
     AppSettings       = appSettings;
     ContextManagement = contextManagement;
     ProcessType       = logs.ProcessType;
     Logs = logs;
 }
示例#2
0
        private void CreateCancelationFiles()
        {
            FileInfo fileInfo = null;

            try
            {
                Logs.Add($"Inicio do processo de geração de arquivo para cancelamento de apólices");
                //var population = ContextManagement.GetCancelationPopulationData(EnumInsurer.Hdi).OrderByDescending(x=>x.PolicyIdentifier).Take(800).ToList();
                var population = ContextManagement.GetCancelationPopulationData(EnumInsurer.Hdi);

                if (population == null || !population.Any())
                {
                    Logs.Add($"Não foi retornado nenhum dado para cancelamento.", EnumLog.Error);
                    return;
                }
                else
                {
                    Logs.Add($"Foram encontrados {population.Count} registros de cancelamento.");
                }

                //ChangeCustomerDocumentsForTest(population);

                var cancelationFileModel = _cancelationFile.CreateContent(population);
                Logs.Add($"Conteudo do arquivo criado.");

                fileInfo = _fileManager.CreateCancelationFile(cancelationFileModel);
                Logs.Add($"O conteúdo do arquivo foi salvo no arquivo: [{fileInfo.FullName}]");
            }
            catch (Exception ex)
            {
                Logs.Add($"[Exception] A Aplicação gerou uma exceção não tratada.", EnumLog.Error);
                Logs.Add($"- [ExceptionMessage] - {ex.Message}", EnumLog.Error);
                if (ex.InnerException != null)
                {
                    Logs.Add($"- [InnerException] - {ex.InnerException.Message}", EnumLog.Error);
                }
                Logs.Add($"- [StackTrace] - {ex.StackTrace}", EnumLog.Error);

                if (fileInfo != null)
                {
                    _fileManager.MoveFile(fileInfo, ProcessType, true);
                }
            }
            finally
            {
                Logs.Add($"Termino do processamento.");
                Logs.Save(EnumInsurer.Hdi);
            }
        }
示例#3
0
 public Issuances(
     IssuanceFileConfiguration issuanceFileConfiguration,
     AppSettingsConfiguration appSettingsConfiguration,
     IcsModuleIntegration icsModuleIntegration,
     ContextManagement contextManagement,
     ValidationRules validationRules,
     FileManager fileManager,
     Logs logs)
     : base(appSettingsConfiguration, contextManagement, logs)
 {
     _issuanceFile         = new IssuanceFile(issuanceFileConfiguration);
     _icsModuleIntegration = icsModuleIntegration;
     _validationRules      = validationRules;
     _fileManager          = fileManager;
 }
示例#4
0
 public Cancelations(
     CancelationFileConfiguration cancelationFileConfiguration,
     HdiProcessConfiguration hdiConfiguration,
     IcsModuleIntegration icsModuleIntegration,
     ContextManagement contextManagement,
     ValidationRules validationRules,
     FileManager fileManager,
     Logs logs)
     : base(hdiConfiguration.AppSettingsConfiguration, contextManagement, logs)
 {
     _hdiProcessConfiguration = hdiConfiguration;
     _cancelationFile         = new CancelationFile(cancelationFileConfiguration, logs);
     _icsModuleIntegration    = icsModuleIntegration;
     _validationRules         = validationRules;
     _fileManager             = fileManager;
 }
 public Cancelations(AppSettingsConfiguration appSettings, ContextManagement contextManagement, Logs logs) : base(appSettings, contextManagement, logs)
 {
 }
示例#6
0
        public void ProcessFiles()
        {
            if (!AppSettings.ActiveIssuanceInsurers.Contains(EnumInsurer.Hdi))
            {
                return;
            }

            _fileManager.DownloadFiles(ProcessType);
            var files = _fileManager.ListDownloadedFiles(ProcessType);

            if (files.Any())
            {
                foreach (var file in files)
                {
                    Logs.Add($"Inicio do processamento do arquivo: [{file.FullName}]");
                    try
                    {
                        var issuanceFileContent = _issuanceFile.ReadFile(file);

                        if (!issuanceFileContent.Body.Content.Any())
                        {
                            continue;
                        }
                        else
                        {
                            Logs.Add(
                                $"Foi encontrado {issuanceFileContent.Body.Content.Count} registro(s) do tipo:[{_issuanceFile.Configuration.BusinessSettings.BodyIdentification}]");
                        }


                        if (!issuanceFileContent.VehiclesInformation.Any())
                        {
                            continue;
                        }
                        else
                        {
                            Logs.Add(
                                $"Foi encontrado {issuanceFileContent.VehiclesInformation.Count} registro(s) do tipo:[{_issuanceFile.Configuration.BusinessSettings.BodyVehicleInformationIdentification}]");
                        }


                        var policyProcess =
                            ContextManagement.CreatePolicyProcess(EnumInsurer.Hdi, EnumIntegration.TxtFile);

                        foreach (var issuance in issuanceFileContent.Body.Content)
                        {
                            try
                            {
                                if (_validationRules.ValidateIssuanceRules(issuance))
                                {
                                    var dsProposal = issuance.Fields["DS_PROPOSTA"].Value;
                                    if (!issuanceFileContent.VehiclesInformation.ContainsKey(dsProposal))
                                    {
                                        throw new Exception($"Não existe uma informação para o veículo com a proposta: [ {dsProposal}]");
                                    }

                                    var vehicleInformation = issuanceFileContent.VehiclesInformation[dsProposal];
                                    ContextManagement.CreatePolicyProcessData(
                                        policyProcess,
                                        ProcessType,
                                        dsProposal,
                                        issuance.Fields["DS_APOLICE"].Value,
                                        vehicleInformation.Fields["DS_CI"].Value,
                                        customerDocument: issuance.Fields["NR_CNPJ_CPF"].Value,
                                        vehicleChassi: vehicleInformation.Fields["DS_CHASSI"].Value
                                        );
                                }
                            }
                            catch (Exception ex)
                            {
                                Logs.Add($"Ocorreu um erro ao processar a linha: {issuance.LineNumber} " +
                                         $"DADOS:[DS_PROPOSTA = {issuance.Fields["DS_PROPOSTA"].Value}]" +
                                         $"[DS_APOLICE = {issuance.Fields["DS_APOLICE"].Value}]" +
                                         $"[DS_CI = {issuance.Fields["DS_CI"].Value}]");
                                Logs.Add($"- [ExceptionMessage] - {ex.Message}");
                                if (ex.InnerException != null)
                                {
                                    Logs.Add($"- [InnerException] - {ex.InnerException.Message}", EnumLog.Error);
                                }
                                Logs.Add($"- [StackTrace] - {ex.StackTrace}");
                            }
                        }

                        var processedFileInfo = _fileManager.MoveFile(file, ProcessType);
                        ContextManagement.UpdatePolicyProcess(policyProcess,
                                                              sourceData: processedFileInfo.FullName);
                    }
                    catch (Exception ex)
                    {
                        _fileManager.MoveFile(file, ProcessType, true);
                        Logs.Add($"[Exception] A Aplicação gerou uma exceção não tratada.", EnumLog.Error);
                        Logs.Add($"- [ExceptionMessage] - {ex.Message}", EnumLog.Error);
                        if (ex.InnerException != null)
                        {
                            Logs.Add($"- [InnerException] - {ex.InnerException.Message}", EnumLog.Error);
                        }
                        Logs.Add($"- [StackTrace] - {ex.StackTrace}", EnumLog.Error);
                    }
                    finally
                    {
                        Logs.Add($"Termino do processamento.");
                        Logs.Save(EnumInsurer.Hdi);
                    }
                }
            }
            else
            {
                Logs.Add($"Não existe nenhum arquivo baixado para ser processado.");
                Logs.Save(EnumInsurer.Hdi);
            }
        }
示例#7
0
 public UnitOfWorkFactory(ContextManagement contextService)
 {
     _contextManagement = contextService;
 }
示例#8
0
 public Issuances(AppSettingsConfiguration appSettings, ContextManagement contextManagement, Logs logs, IcsIsurerConfigManagement icsIsurerConfig, LibertyProcessConfiguration libertyConfiguration) : base(
         appSettings, contextManagement, logs)
 {
     _icsIsurerConfig  = icsIsurerConfig;
     _icsConfiguration = libertyConfiguration.AppSettingsConfiguration.IcsModuleConfigurations;
 }
示例#9
0
 public int SaveDb()
 {
     return(ContextManagement.Save());
 }
示例#10
0
        private void CreateTestCancelationProcessData(FileInfo fileInfo)
        {
            try
            {
                var cancelationFileContent = _cancelationFile.ReadFile(fileInfo);
                var policyIdentifiers      = cancelationFileContent.Body.Content.Select(p => p.Fields["NUMERO_CONTROLE_ITURAN"].Value.ToInt()).ToList();
                var population             = ContextManagement.GetCancelationPopulationData(policyIdentifiers);

                if (population == null || !population.Any())
                {
                    throw new Exception($"Não é possível gerar uma população de testes, pois não foi encontrado nenhum registro no banco de dados correspondente aos CD_APOLICES no arquivo");
                }
                var policyProcess =
                    ContextManagement.CreatePolicyProcess(EnumInsurer.Hdi, EnumIntegration.TxtFile);
                foreach (var cancelation in cancelationFileContent.Body.Content)
                {
                    try
                    {
                        var policyIdentifier = cancelation.Fields["NUMERO_CONTROLE_ITURAN"].Value.ToInt();
                        var cancelationModel = population.FirstOrDefault(p => p.PolicyIdentifier == policyIdentifier);
                        if (cancelationModel != null)
                        {
                            ContextManagement
                            .CreatePolicyProcessData(policyProcess, ProcessType,
                                                     cancelationModel.PolicyProposalIdentifier,
                                                     cancelation.Fields["DOCUMENTO"].Value,
                                                     cancelationModel.IdentificationCode,
                                                     EnumPolicyProcessDataStatus.PendingCancelationConfirmation);
                            _icsModuleIntegration.SetPolicyPendingCancelation(policyIdentifier);
                        }
                        else
                        {
                            Logs.Add(
                                $"Não foi encontrado uma apólice na população, retornada do banco de dados, referente ao CD_APOLICE:{policyIdentifier} escrito no arquivo");
                        }
                    }
                    catch (Exception ex)
                    {
                        Logs.Add($"Ocorreu um erro ao processar a linha: {cancelation.LineNumber} " +
                                 $"DADOS:[DS_PROPOSTA = {cancelation.Fields["DS_PROPOSTA"].Value}]" +
                                 $"[DS_APOLICE = {cancelation.Fields["DS_APOLICE"].Value}]" +
                                 $"[DS_CI = {cancelation.Fields["DS_CI"].Value}]");
                        Logs.Add($"- [ExceptionMessage] - {ex.Message}");
                        if (ex.InnerException != null)
                        {
                            Logs.Add($"- [InnerException] - {ex.InnerException.Message}", EnumLog.Error);
                        }
                        Logs.Add($"- [StackTrace] - {ex.StackTrace}");
                    }
                }
                ContextManagement.UpdatePolicyProcess(policyProcess, sourceData: fileInfo.FullName);
            }
            catch (Exception ex)
            {
                Logs.Add($"[Exception] A Aplicação gerou uma exceção não tratada ao tentar simular a criação de registros de dados de cancelamento.", EnumLog.Error);
                Logs.Add($"- [ExceptionMessage] - {ex.Message}", EnumLog.Error);
                if (ex.InnerException != null)
                {
                    Logs.Add($"- [InnerException] - {ex.InnerException.Message}", EnumLog.Error);
                }
                Logs.Add($"- [StackTrace] - {ex.StackTrace}", EnumLog.Error);
            }
        }
示例#11
0
        private void ProcessCancelationsReturn()
        {
            Logs.Add($"Inicio do processamento de arquivos de retorno de cancelamento de apólices");
            _fileManager.DownloadFiles(ProcessType);
            var files = _fileManager.ListDownloadedFiles(ProcessType);

            if (files.Any())
            {
                foreach (var file in files)
                {
                    var policyProcess = ContextManagement.FileName(file.Name.Replace("RET_", string.Empty));
#if DEBUG
                    //Usado para criar dados no modo debug, caso não exista esses registros no banco.
                    //if (policyProcess == null)
                    //{
                    //	CreateTestCancelationProcessData(file);
                    //	policyProcess = ContextManagement.FileName(file.FullName);
                    //}
#endif


                    Logs.Add($"Inicio do processamento do arquivo: [{file.FullName}]");

                    try
                    {
                        var cancelationFileContent = _cancelationFile.ReadFile(file);
                        var policyIdentifiers      = cancelationFileContent.Body.Content.Select(p => p.Fields["NUMERO_CONTROLE_ITURAN"].Value.ToInt()).ToList();
                        var population             = ContextManagement.GetCancelationPopulationData(policyIdentifiers);
                        if (population == null || !population.Any())
                        {
                            Logs.Add($"Não foi retornado nenhum dado para cancelamento.", EnumLog.Error);
                            return;
                        }
                        else
                        {
                            Logs.Add($"Foram encontrados {population.Count} registros de cancelamento.");
                        }

                        foreach (var cancelation in cancelationFileContent.Body.Content)
                        {
                            try
                            {
                                var policyIdentifier = cancelation.Fields["NUMERO_CONTROLE_ITURAN"].Value.ToInt();
                                var cancelationModel = population.FirstOrDefault(p =>
                                                                                 p.PolicyIdentifier == policyIdentifier);

                                if (cancelationModel != null)
                                {
                                    if (cancelation.Fields["STATUS_CANCELAMENTO"].Value == "1")
                                    {
                                        ContextManagement.UpdatePolicyProcessData(
                                            cancelationModel.PolicyProposalIdentifier,
                                            policyProcess.CD_APOLICE_PROCESSAMENTO,
                                            EnumPolicyProcessDataStatus.PendingProcess);
                                    }

                                    if (cancelation.Fields["STATUS_CANCELAMENTO"].Value == "2")
                                    {
                                        ContextManagement.UpdatePolicyProcessData(
                                            cancelationModel.PolicyProposalIdentifier,
                                            policyProcess.CD_APOLICE_PROCESSAMENTO,
                                            EnumPolicyProcessDataStatus.ErrorCancelationResponse,
                                            errorCode: cancelation.Fields["CODIGO_OBSERVACAO"].Value,
                                            errorDescription: cancelation.Fields["OBSERVACAO"].Value,
                                            endorsementValue: cancelation.Fields["VALOR_PREMIO"].Value.ToDecimal()
                                            );
                                    }
                                }
                                else
                                {
                                    Logs.Add(
                                        $"Não foi encontrado uma apólice no banco de dados referente ao CD_APOLICE:{policyIdentifier} escrito no arquivo");
                                }
                            }
                            catch (Exception ex)
                            {
                                Logs.Add($"[Exception] A Aplicação gerou uma exceção não tratada ao tentar processar a linha {cancelation.LineNumber}", EnumLog.Error);
                                Logs.Add($"- [ExceptionMessage] - {ex.Message}", EnumLog.Error);
                                if (ex.InnerException != null)
                                {
                                    Logs.Add($"- [InnerException] - {ex.InnerException.Message}", EnumLog.Error);
                                }
                                Logs.Add($"- [StackTrace] - {ex.StackTrace}", EnumLog.Error);
                            }
                        }
                        var fileInfo = _fileManager.MoveFile(file, ProcessType);
                        ContextManagement.UpdatePolicyProcess(policyProcess, sourceData: fileInfo.FullName);
                    }
                    catch (Exception ex)
                    {
                        var fileInfo = _fileManager.MoveFile(file, ProcessType, true);
                        ContextManagement.UpdatePolicyProcess(policyProcess, sourceData: fileInfo.FullName);
                    }
                    finally
                    {
                        Logs.Add($"Termino do processamento.");
                        Logs.Save(EnumInsurer.Hdi);
                    }
                }
            }
            else
            {
                Logs.Add($"Não existe nenhum arquivo baixado para ser processado.");
                Logs.Save(EnumInsurer.Hdi);
            }
        }
示例#12
0
        private void SendCancelationFiles()
        {
            Logs.Add($"Inicio do processo de envio do arquivo para cancelamento de apólices");
            var cancelationFiles = _fileManager.GetApprovedCancelationFiles();

            if (cancelationFiles.Any())
            {
                foreach (var cancelationFile in cancelationFiles)
                {
                    var fileInfo = cancelationFile;
                    try
                    {
                        Logs.Add($"Inicio do processo de envio do arquivo [{cancelationFile.FullName}] para cancelamento de apólices");
                        Logs.Add($"Retornar dados do arquivo escrito para inserção das informações no banco de dados.");
                        var cancelationFileContent = _cancelationFile.ReadFile(cancelationFile);
                        var policyIdentifiers      = cancelationFileContent.Body.Content.Select(p => p.Fields["NUMERO_CONTROLE_ITURAN"].Value.ToInt()).ToList();
                        var population             = ContextManagement.GetCancelationPopulationData(policyIdentifiers);
                        var policyProcess          = ContextManagement.CreatePolicyProcess(EnumInsurer.Hdi, EnumIntegration.TxtFile);

                        foreach (var cancelation in cancelationFileContent.Body.Content)
                        {
                            try
                            {
                                var policyIdentifier = cancelation.Fields["NUMERO_CONTROLE_ITURAN"].Value.ToInt();
                                var cancelationModel = population.FirstOrDefault(p =>
                                                                                 p.PolicyIdentifier == policyIdentifier);

                                if (cancelationModel != null)
                                {
                                    var policeProcessData = ContextManagement.CreatePolicyProcessData(
                                        policyProcess,
                                        ProcessType,
                                        cancelationModel.PolicyProposalIdentifier,
                                        cancelationModel.PolicyInsurerIdentifier,
                                        //cancelation.Fields["DOCUMENTO"].Value,
                                        cancelationModel.IdentificationCode,
                                        EnumPolicyProcessDataStatus.PendingCancelationConfirmation,
                                        cancelation.Fields["NR_CNPJ_CPF"].Value.RemoveDocumentSpecialCharacters(),
                                        cancelationModel.CarChassis);
                                    if (policeProcessData != null)
                                    {
                                        _icsModuleIntegration.SetPolicyPendingCancelation(policyIdentifier);
                                    }
                                }
                                else
                                {
                                    Logs.Add($"Não foi encontrado uma apólice na população, retornada do banco de dados, referente ao CD_APOLICE:{policyIdentifier} escrito no arquivo");
                                }
                            }
                            catch (Exception ex)
                            {
                                Logs.Add($"Ocorreu um erro ao processar a linha: {cancelation.LineNumber} " +
                                         $"DADOS:[DS_PROPOSTA = {cancelation.Fields["DS_PROPOSTA"].Value}]" +
                                         $"[DS_APOLICE = {cancelation.Fields["DS_APOLICE"].Value}]" +
                                         $"[DS_CI = {cancelation.Fields["DS_CI"].Value}]");
                                Logs.Add($"- [ExceptionMessage] - {ex.Message}");
                                if (ex.InnerException != null)
                                {
                                    Logs.Add($"- [InnerException] - {ex.InnerException.Message}", EnumLog.Error);
                                }
                                Logs.Add($"- [StackTrace] - {ex.StackTrace}");
                            }
                        }
                        _fileManager.UploadFile(cancelationFile, ProcessType);
                        fileInfo = _fileManager.MoveFile(cancelationFile, ProcessType);
                        ContextManagement.UpdatePolicyProcess(policyProcess, sourceData: fileInfo.FullName);
                    }
                    catch (Exception ex)
                    {
                        Logs.Add($"[Exception] A Aplicação gerou uma exceção não tratada.", EnumLog.Error);
                        Logs.Add($"- [ExceptionMessage] - {ex.Message}", EnumLog.Error);
                        if (ex.InnerException != null)
                        {
                            Logs.Add($"- [InnerException] - {ex.InnerException.Message}", EnumLog.Error);
                        }
                        Logs.Add($"- [StackTrace] - {ex.StackTrace}", EnumLog.Error);

                        if (fileInfo != null)
                        {
                            _fileManager.MoveFile(fileInfo, ProcessType, true);
                        }
                    }
                    finally
                    {
                        Logs.Add($"Termino do processamento.");
                        Logs.Save(EnumInsurer.Hdi);
                    }
                }
            }
            else
            {
                Logs.Add($"Não existe nenhum arquivo na pasta [{_hdiProcessConfiguration.SendCancelationFilesFolder}]  para ser enviado.");
                Logs.Add($"Termino do processamento.");
                Logs.Save(EnumInsurer.Hdi);
            }
        }
示例#13
0
 public UnitOfWork(ContextManagement contextManagement)
 {
     _contextManagement = contextManagement;
 }
示例#14
0
 public SaveChangesActionFilter(ContextManagement contextService)
 {
     _contextService = contextService;
 }