Compare commits

..

2 commits

Author SHA1 Message Date
Leonel Toro
30ebaed959 feat ajustes 2025-07-22 10:22:44 -04:00
Leonel Toro
ed6475eab3 feat:Se ajusta logica 2025-07-22 10:17:30 -04:00
4 changed files with 34 additions and 11 deletions

View file

@ -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<LogMedicionEnvio>();
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} - {totalMediciones}", 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","");

View file

@ -36,7 +36,7 @@ namespace DAL
}
}
public async Task<bool> InsertarLogRespuesta(List<LogMedicionEnvio> logsEnviados)
public async Task<bool> InsertarLogRespuesta(LogMedicionEnvio logsEnviados)
{
await using var connection = new SqlConnection(BdConexion.StringConnection);
try

View file

@ -40,5 +40,25 @@ namespace DAL
}
}
public async Task<int> ObtenerTotalMediciones(DateTime fechaInicio)
{
try
{
var parameters = new DynamicParameters();
parameters.Add("@FechaInicio", fechaInicio);
using var connection = new SqlConnection(BdConexion.StringConnection);
var resultado = await connection.QuerySingleAsync<int>(
"SP_OBTENER_TOTAL_MEDICIONES",
parameters,
commandType: CommandType.StoredProcedure);
return resultado;
}
catch(Exception ex)
{
throw new Exception($"ERROR {ex.Message}");
}
}
}
}

View file

@ -57,10 +57,12 @@ namespace DAS
log.COMPROBANTE = null;
log.ESTADO_ENVIO = "ERROR";
}
else
{
log.COMPROBANTE = apiResponse!.Data!.NumeroComprobante ?? null;
log.ESTADO_ENVIO = "EXITO";
}
}
catch (Exception)
{
log.COMPROBANTE = null;