feat: ajustes para las mediciones
This commit is contained in:
parent
7bc8400980
commit
747391eade
5 changed files with 133 additions and 36 deletions
|
@ -1,4 +1,5 @@
|
|||
using System.Text.Json;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using DAL;
|
||||
using DAS;
|
||||
using Shared.DTO;
|
||||
|
@ -34,49 +35,66 @@ namespace BLL.Recuperacion_DGA
|
|||
ConsoleLoggerHelper.WriteLineAndLogEventoAsync("INICIO", "Inicio proceso de recuperación DGA", "");
|
||||
ConsoleLoggerHelper.WriteLineAndLogInfo("Obteniendo Mediciones Scada", ConsoleColor.Green);
|
||||
|
||||
var mediciones = await _dGAMedicionRepository.ObtenerMedicionesAsync();
|
||||
var medicionesEnviadas = new List<Object>();
|
||||
var logs = new List<Object>();
|
||||
var logsEnviados = new List<LogMedicionEnvio>();
|
||||
|
||||
foreach (var medicion in mediciones)
|
||||
var pageNumber = 1;
|
||||
|
||||
while (true)
|
||||
{
|
||||
var mediciones = await _dGAMedicionRepository.ObtenerMedicionesPorLoteAsync(pageNumber);
|
||||
|
||||
if (mediciones == null || !mediciones.Any()){ break; }
|
||||
|
||||
foreach (var medicion in mediciones)
|
||||
{
|
||||
try
|
||||
{
|
||||
var fechaEnvio = DateTime.UtcNow;
|
||||
|
||||
var body = new MedicionSubterraneaRequest
|
||||
{
|
||||
Autenticacion = new Autenticacion
|
||||
{
|
||||
Password = CredencialDGA.Password,
|
||||
RutEmpresa = medicion.TIPO_EMPRESA == "EV" ? CredencialDGA.RutEsval : CredencialDGA.RutAv,
|
||||
RutUsuario = CredencialDGA.RutUsuario
|
||||
},
|
||||
MedicionSubterranea = new Medicion
|
||||
{
|
||||
Caudal = medicion.CAUDAL ?? "",
|
||||
FechaMedicion = medicion.FECHA_MEDICION_CAUDAL?.ToString("yyyy-MM-dd") ?? "",
|
||||
HoraMedicion = medicion.FECHA_MEDICION_CAUDAL?.ToString("HH:mm:ss") ?? "",
|
||||
NivelFreaticoDelPozo = medicion.NIVEL_FREATICO_DEL_POZO ?? "",
|
||||
Totalizador = medicion.TOTALIZADOR_CAUDAL ?? "",
|
||||
}
|
||||
};
|
||||
|
||||
var response = await _registrarMedicion.EnviarMedicionAsync(medicion, body, fechaEnvio);
|
||||
|
||||
logsEnviados.Add(response);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleLoggerHelper.WriteLineAndLogInfo($"[Error]: medicion[{medicion.ID}], mensaje: {ex.Message}");
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
var fechaEnvio = DateTime.UtcNow;
|
||||
|
||||
var body = new MedicionSubterraneaRequest
|
||||
{
|
||||
Autenticacion = new Autenticacion
|
||||
{
|
||||
Password = CredencialDGA.Password,
|
||||
RutEmpresa = medicion.TIPO_EMPRESA == "EV" ? CredencialDGA.RutEsval : CredencialDGA.RutAv,
|
||||
RutUsuario = CredencialDGA.RutUsuario
|
||||
},
|
||||
MedicionSubterranea = new Medicion
|
||||
{
|
||||
Caudal = medicion.CAUDAL ?? "",
|
||||
FechaMedicion = medicion.FECHA_MEDICION_CAUDAL?.ToString("yyyy-MM-dd") ?? "",
|
||||
HoraMedicion = medicion.FECHA_MEDICION_CAUDAL?.ToString("HH:mm:ss") ?? "",
|
||||
NivelFreaticoDelPozo = medicion.NIVEL_FREATICO_DEL_POZO ?? "",
|
||||
Totalizador = medicion.TOTALIZADOR_CAUDAL ?? "",
|
||||
}
|
||||
};
|
||||
|
||||
var response = await _registrarMedicion.EnviarMedicionAsync(medicion, body, fechaEnvio);
|
||||
|
||||
medicionesEnviadas.Add(new {Id = medicion.ID,FechaEnvio = fechaEnvio.ToString("yyyy-MM-dd HH:mm:ss"), Enviado = 1});
|
||||
logs.Add(response);
|
||||
var idMediciones = mediciones.Select(x => x.ID).ToList();
|
||||
await _dGAMedicionRepository.GuardarMedicionesEnviadasAsync(idMediciones);
|
||||
await _logEnvioRepository.InsertarLogRespuesta(logsEnviados);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception e)
|
||||
{
|
||||
FileLoggerHelper.LogError($"[Error] {ex.Message}.", ex);
|
||||
ConsoleLoggerHelper.WriteLineAndLogInfo($"Error al enviar la medición con ID {medicion.CODIGO_DGA}.", ConsoleColor.Red);
|
||||
ConsoleLoggerHelper.WriteLineAndLogInfo($"[Error] {e.Message}");
|
||||
}
|
||||
|
||||
logsEnviados.Clear();
|
||||
mediciones.Clear();
|
||||
pageNumber++;
|
||||
}
|
||||
|
||||
//INSERTAR DATOS DE LOGS, ACTUALIZAR REGISTROS
|
||||
|
||||
|
||||
ConsoleLoggerHelper.WriteLineAndLogEventoAsync("FIN","Fin proceso de recuperación DGA","");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue