feat:Se ajusta logica
This commit is contained in:
parent
e83a41cd54
commit
ed6475eab3
3 changed files with 29 additions and 8 deletions
|
@ -35,15 +35,15 @@ namespace BLL.Recuperacion_DGA
|
||||||
ConsoleLoggerHelper.WriteLineAndLogEventoAsync("INICIO", "Inicio proceso de recuperación DGA", "");
|
ConsoleLoggerHelper.WriteLineAndLogEventoAsync("INICIO", "Inicio proceso de recuperación DGA", "");
|
||||||
ConsoleLoggerHelper.WriteLineAndLogInfo("Obteniendo Mediciones Scada", ConsoleColor.Green);
|
ConsoleLoggerHelper.WriteLineAndLogInfo("Obteniendo Mediciones Scada", ConsoleColor.Green);
|
||||||
|
|
||||||
var logsEnviados = new List<LogMedicionEnvio>();
|
var logsEnviados = new LogMedicionEnvio();
|
||||||
|
|
||||||
var pageNumber = 1;
|
var pageNumber = 1;
|
||||||
var fechaInicio = DateTime.UtcNow;
|
var fechaInicio = DateTime.UtcNow;
|
||||||
|
var cont = 1;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
var mediciones = await _dGAMedicionRepository.ObtenerMedicionesPorLoteAsync(pageNumber, fechaInicio);
|
var mediciones = await _dGAMedicionRepository.ObtenerMedicionesPorLoteAsync(pageNumber, fechaInicio);
|
||||||
|
var totalMediciones = await _dGAMedicionRepository.ObtenerTotalMediciones(fechaInicio);
|
||||||
if (mediciones == null || mediciones.Count == 0)
|
if (mediciones == null || mediciones.Count == 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
@ -54,7 +54,6 @@ namespace BLL.Recuperacion_DGA
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var fechaEnvio = DateTime.UtcNow;
|
var fechaEnvio = DateTime.UtcNow;
|
||||||
|
|
||||||
var body = new MedicionSubterraneaRequest
|
var body = new MedicionSubterraneaRequest
|
||||||
{
|
{
|
||||||
Autenticacion = new Autenticacion
|
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);
|
var response = await _registrarMedicion.EnviarMedicionAsync(medicion, body, fechaEnvio);
|
||||||
|
|
||||||
logsEnviados.Add(response);
|
logsEnviados = response;
|
||||||
|
await _logEnvioRepository.InsertarLogRespuesta(logsEnviados);
|
||||||
|
cont++;
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -87,16 +89,15 @@ namespace BLL.Recuperacion_DGA
|
||||||
{
|
{
|
||||||
var idMediciones = mediciones.Select(x => x.ID).ToList();
|
var idMediciones = mediciones.Select(x => x.ID).ToList();
|
||||||
await _dGAMedicionRepository.GuardarMedicionesEnviadasAsync(idMediciones);
|
await _dGAMedicionRepository.GuardarMedicionesEnviadasAsync(idMediciones);
|
||||||
await _logEnvioRepository.InsertarLogRespuesta(logsEnviados);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
ConsoleLoggerHelper.WriteLineAndLogInfo($"[Error] {e.Message}");
|
ConsoleLoggerHelper.WriteLineAndLogInfo($"[Error] {e.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
logsEnviados.Clear();
|
|
||||||
mediciones.Clear();
|
mediciones.Clear();
|
||||||
pageNumber++;
|
pageNumber++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ConsoleLoggerHelper.WriteLineAndLogEventoAsync("FIN","Fin proceso de recuperación DGA","");
|
ConsoleLoggerHelper.WriteLineAndLogEventoAsync("FIN","Fin proceso de recuperación DGA","");
|
||||||
|
|
|
@ -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);
|
await using var connection = new SqlConnection(BdConexion.StringConnection);
|
||||||
try
|
try
|
||||||
|
|
|
@ -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}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue