feat: se agregan logs, y se hacen cambios en el modulo registrar mediciones
This commit is contained in:
parent
5bd9c2a1a6
commit
4b6204d9e7
32 changed files with 648 additions and 625 deletions
|
@ -1,24 +1,28 @@
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Shared.DTO;
|
||||
using DAL;
|
||||
using DAL;
|
||||
using DAS;
|
||||
using Shared.DTO.Envios_DGA;
|
||||
using Shared.DTO.VariablesEntorno;
|
||||
using Shared.Helper;
|
||||
|
||||
namespace BLL.Recuperacion_DGA
|
||||
{
|
||||
public class EnvioDGA
|
||||
{
|
||||
private readonly MedicionScadaRepository _dGAMedicionScadaRepository;
|
||||
private readonly MedicionScadaVilosRepository _dgaMedicionScadaVilosRepository;
|
||||
private readonly RegistrarMedicion _registrarMedicion;
|
||||
|
||||
public EnvioDGA(MedicionScadaRepository dGAMedicionScadaRepository, RegistrarMedicion registrarMedicion)
|
||||
public EnvioDGA(MedicionScadaRepository dGAMedicionScadaRepository, RegistrarMedicion registrarMedicion, MedicionScadaVilosRepository dgaMedicionScadaVilosRepository)
|
||||
{
|
||||
_dGAMedicionScadaRepository = dGAMedicionScadaRepository;
|
||||
_registrarMedicion = registrarMedicion;
|
||||
_dgaMedicionScadaVilosRepository = dgaMedicionScadaVilosRepository;
|
||||
}
|
||||
|
||||
public async Task<bool>RegistrarMedicionesAsync()
|
||||
public async Task<bool> RegistrarMedicionesAsync()
|
||||
{
|
||||
WriteLineAndLog("Iniciando el proceso de recuperación DGA...");
|
||||
WriteLineAndLog("Obteniendo Mediciones Scada", ConsoleColor.Green);
|
||||
var mediciones = await _dGAMedicionScadaRepository.ObtenerMedicionesAsync();
|
||||
|
||||
foreach (var medicion in mediciones)
|
||||
|
@ -27,38 +31,114 @@ namespace BLL.Recuperacion_DGA
|
|||
{
|
||||
if (!string.IsNullOrEmpty(medicion.Code))
|
||||
{
|
||||
var rutEmpresa = string.Empty;
|
||||
if (medicion.tipo_empresa == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (medicion.tipo_empresa == "AV")
|
||||
{
|
||||
rutEmpresa = CredencialDGA.RutAv;
|
||||
}
|
||||
if (medicion.tipo_empresa =="EV")
|
||||
{
|
||||
rutEmpresa = CredencialDGA.RutEsval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
var body = new MedicionSubterraneaRequest
|
||||
{
|
||||
Autenticacion = new Autenticacion
|
||||
{
|
||||
Password = string.Empty,
|
||||
RutEmpresa = string.Empty,
|
||||
RutUsuario = string.Empty
|
||||
Password = CredencialDGA.Password,
|
||||
RutEmpresa = rutEmpresa,
|
||||
RutUsuario = CredencialDGA.RutUsuario
|
||||
},
|
||||
MedicionSubterranea = new Medicion
|
||||
{
|
||||
Caudal = medicion.Caudal.ToString() ?? "",
|
||||
FechaMedicion = medicion.DateOrigen?.ToString("yyyy-MM-dd") ?? "",
|
||||
HoraMedicion = medicion.DateOrigen?.ToString("HH:mm:ss") ?? "",
|
||||
NivelFreaticoDelPozo = "",
|
||||
NivelFreaticoDelPozo = medicion.Nivel.ToString() ?? "",
|
||||
Totalizador = medicion.Totalizador.ToString() ?? "",
|
||||
}
|
||||
};
|
||||
|
||||
//TODO: Agregar log texto
|
||||
|
||||
await _registrarMedicion.EnviarMedicionAsync(medicion.Code, body,medicion.Id);
|
||||
await _registrarMedicion.EnviarMedicionAsync(medicion.Code, body, medicion.Id);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
//TODO: Agregar log texto
|
||||
throw;
|
||||
FileLoggerHelper.LogError($"[Error] {ex.Message}.",ex);
|
||||
WriteLineAndLog($"Error al enviar la medición con ID {medicion.Code}.", ConsoleColor.Red);
|
||||
}
|
||||
}
|
||||
|
||||
var medicionesVilos = await _dgaMedicionScadaVilosRepository.ObtenerMedicionesVilosAsync();
|
||||
foreach (var medicionVilos in medicionesVilos)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(medicionVilos.Code))
|
||||
{
|
||||
var rutEmpresa = string.Empty;
|
||||
|
||||
if (medicionVilos.tipo_empresa.Equals("AV"))
|
||||
{
|
||||
rutEmpresa = CredencialDGA.RutAv;
|
||||
}
|
||||
else if (medicionVilos.tipo_empresa.Equals("EV"))
|
||||
{
|
||||
rutEmpresa = CredencialDGA.RutEsval;
|
||||
}
|
||||
|
||||
var body = new MedicionSubterraneaRequest
|
||||
{
|
||||
Autenticacion = new Autenticacion
|
||||
{
|
||||
Password = CredencialDGA.Password,
|
||||
RutEmpresa = rutEmpresa,
|
||||
RutUsuario = CredencialDGA.RutUsuario
|
||||
},
|
||||
MedicionSubterranea = new Medicion
|
||||
{
|
||||
Caudal = medicionVilos.Caudal.ToString() ?? "",
|
||||
FechaMedicion = medicionVilos.DateOrigen?.ToString("yyyy-MM-dd") ?? "",
|
||||
HoraMedicion = medicionVilos.DateOrigen?.ToString("HH:mm:ss") ?? "",
|
||||
NivelFreaticoDelPozo = medicionVilos.Nivel.ToString() ?? "",
|
||||
Totalizador = medicionVilos.Totalizador.ToString() ?? "",
|
||||
}
|
||||
};
|
||||
|
||||
await _registrarMedicion.EnviarMedicionAsync(medicionVilos.Code, body, medicionVilos.Id);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FileLoggerHelper.LogError($"[Error] {ex.Message}.", ex);
|
||||
WriteLineAndLog($"Error al enviar la medición vilos con ID {medicionVilos.Code}.", ConsoleColor.Red);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void WriteLineAndLog(string msj, ConsoleColor? color = null)
|
||||
{
|
||||
if (color.HasValue && Enum.IsDefined(typeof(ConsoleColor), color.Value))
|
||||
{
|
||||
Console.ForegroundColor = (ConsoleColor)color;
|
||||
Console.WriteLine(msj);
|
||||
Console.ResetColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"{msj}");
|
||||
}
|
||||
|
||||
FileLoggerHelper.LogInformation($"{msj}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue