From ed6475eab358097a594c263a638011b36aa8bb41 Mon Sep 17 00:00:00 2001 From: Leonel Toro Date: Tue, 22 Jul 2025 10:17:30 -0400 Subject: [PATCH] feat:Se ajusta logica --- BLL/Recuperacion_DGA/EnvioDGA.cs | 15 ++++++++------- DAL/LogEnvioRepository.cs | 2 +- DAL/MedicionDGARepository.cs | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/BLL/Recuperacion_DGA/EnvioDGA.cs b/BLL/Recuperacion_DGA/EnvioDGA.cs index 4e481d9..eb200b3 100644 --- a/BLL/Recuperacion_DGA/EnvioDGA.cs +++ b/BLL/Recuperacion_DGA/EnvioDGA.cs @@ -35,15 +35,15 @@ namespace BLL.Recuperacion_DGA ConsoleLoggerHelper.WriteLineAndLogEventoAsync("INICIO", "Inicio proceso de recuperación DGA", ""); ConsoleLoggerHelper.WriteLineAndLogInfo("Obteniendo Mediciones Scada", ConsoleColor.Green); - var logsEnviados = new List(); + var logsEnviados = new LogMedicionEnvio(); var pageNumber = 1; var fechaInicio = DateTime.UtcNow; - + var cont = 1; while (true) { var mediciones = await _dGAMedicionRepository.ObtenerMedicionesPorLoteAsync(pageNumber, fechaInicio); - + var totalMediciones = await _dGAMedicionRepository.ObtenerTotalMediciones(fechaInicio); if (mediciones == null || mediciones.Count == 0) { break; @@ -54,7 +54,6 @@ namespace BLL.Recuperacion_DGA try { var fechaEnvio = DateTime.UtcNow; - var body = new MedicionSubterraneaRequest { Autenticacion = new Autenticacion @@ -73,9 +72,12 @@ namespace BLL.Recuperacion_DGA } }; + ConsoleLoggerHelper.WriteLineAndLogInfo($"Enviando medición DGA {cont} - {mediciones.Count}", ConsoleColor.Yellow); var response = await _registrarMedicion.EnviarMedicionAsync(medicion, body, fechaEnvio); - logsEnviados.Add(response); + logsEnviados = response; + await _logEnvioRepository.InsertarLogRespuesta(logsEnviados); + cont++; } catch (Exception ex) @@ -87,16 +89,15 @@ namespace BLL.Recuperacion_DGA { var idMediciones = mediciones.Select(x => x.ID).ToList(); await _dGAMedicionRepository.GuardarMedicionesEnviadasAsync(idMediciones); - await _logEnvioRepository.InsertarLogRespuesta(logsEnviados); } catch (Exception e) { ConsoleLoggerHelper.WriteLineAndLogInfo($"[Error] {e.Message}"); } - logsEnviados.Clear(); mediciones.Clear(); pageNumber++; + } ConsoleLoggerHelper.WriteLineAndLogEventoAsync("FIN","Fin proceso de recuperación DGA",""); diff --git a/DAL/LogEnvioRepository.cs b/DAL/LogEnvioRepository.cs index 45bae88..4dead55 100644 --- a/DAL/LogEnvioRepository.cs +++ b/DAL/LogEnvioRepository.cs @@ -36,7 +36,7 @@ namespace DAL } } - public async Task InsertarLogRespuesta(List logsEnviados) + public async Task InsertarLogRespuesta(LogMedicionEnvio logsEnviados) { await using var connection = new SqlConnection(BdConexion.StringConnection); try diff --git a/DAL/MedicionDGARepository.cs b/DAL/MedicionDGARepository.cs index 32db06b..278e3d9 100644 --- a/DAL/MedicionDGARepository.cs +++ b/DAL/MedicionDGARepository.cs @@ -40,5 +40,25 @@ namespace DAL } } + + public async Task ObtenerTotalMediciones(DateTime fechaInicio) + { + try + { + var parameters = new DynamicParameters(); + parameters.Add("@FechaInicio", fechaInicio); + using var connection = new SqlConnection(BdConexion.StringConnection); + var resultado = await connection.QuerySingleAsync( + "SP_OBTENER_TOTAL_MEDICIONES", + parameters, + commandType: CommandType.StoredProcedure); + + return resultado; + } + catch(Exception ex) + { + throw new Exception($"ERROR {ex.Message}"); + } + } } }