diff --git a/BLL/Recuperacion_DGA/EnvioDGA.cs b/BLL/Recuperacion_DGA/EnvioDGA.cs index e23d140..4e481d9 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 LogMedicionEnvio(); + var logsEnviados = new List(); 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,6 +54,7 @@ namespace BLL.Recuperacion_DGA try { var fechaEnvio = DateTime.UtcNow; + var body = new MedicionSubterraneaRequest { Autenticacion = new Autenticacion @@ -72,12 +73,9 @@ namespace BLL.Recuperacion_DGA } }; - ConsoleLoggerHelper.WriteLineAndLogInfo($"Enviando medición DGA {cont} - {totalMediciones}", ConsoleColor.Yellow); var response = await _registrarMedicion.EnviarMedicionAsync(medicion, body, fechaEnvio); - logsEnviados = response; - await _logEnvioRepository.InsertarLogRespuesta(logsEnviados); - cont++; + logsEnviados.Add(response); } catch (Exception ex) @@ -89,15 +87,16 @@ 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 4dead55..45bae88 100644 --- a/DAL/LogEnvioRepository.cs +++ b/DAL/LogEnvioRepository.cs @@ -36,7 +36,7 @@ namespace DAL } } - public async Task InsertarLogRespuesta(LogMedicionEnvio logsEnviados) + public async Task InsertarLogRespuesta(List logsEnviados) { await using var connection = new SqlConnection(BdConexion.StringConnection); try diff --git a/DAL/MedicionDGARepository.cs b/DAL/MedicionDGARepository.cs index 278e3d9..32db06b 100644 --- a/DAL/MedicionDGARepository.cs +++ b/DAL/MedicionDGARepository.cs @@ -40,25 +40,5 @@ 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}"); - } - } } } diff --git a/DAS/RegistrarMedicion.cs b/DAS/RegistrarMedicion.cs index 7b78446..c9d97ed 100644 --- a/DAS/RegistrarMedicion.cs +++ b/DAS/RegistrarMedicion.cs @@ -57,11 +57,9 @@ namespace DAS log.COMPROBANTE = null; log.ESTADO_ENVIO = "ERROR"; } - else - { - log.COMPROBANTE = apiResponse!.Data!.NumeroComprobante ?? null; - log.ESTADO_ENVIO = "EXITO"; - } + + log.COMPROBANTE = apiResponse!.Data!.NumeroComprobante ?? null; + log.ESTADO_ENVIO = "EXITO"; } catch (Exception) {