Integracion_DGA/BLL/Recuperacion_DGA/EnvioDGA.cs

65 lines
2.2 KiB
C#
Raw Normal View History

2025-06-24 14:46:32 -04:00
using Microsoft.Extensions.Configuration;
using Shared.DTO;
using DAL;
2025-06-24 16:02:27 -04:00
using DAS;
using Shared.DTO.Envios_DGA;
2025-06-24 14:46:32 -04:00
namespace BLL.Recuperacion_DGA
2025-06-24 14:46:32 -04:00
{
public class EnvioDGA
{
private readonly MedicionScadaRepository _dGAMedicionScadaRepository;
2025-06-24 16:02:27 -04:00
private readonly RegistrarMedicion _registrarMedicion;
2025-06-24 14:46:32 -04:00
public EnvioDGA(MedicionScadaRepository dGAMedicionScadaRepository, RegistrarMedicion registrarMedicion)
2025-06-24 14:46:32 -04:00
{
_dGAMedicionScadaRepository = dGAMedicionScadaRepository;
2025-06-24 16:02:27 -04:00
_registrarMedicion = registrarMedicion;
2025-06-24 14:46:32 -04:00
}
2025-07-01 09:59:59 -04:00
public async Task<bool>RegistrarMedicionesAsync()
2025-06-24 14:46:32 -04:00
{
2025-06-24 16:02:27 -04:00
var mediciones = await _dGAMedicionScadaRepository.ObtenerMedicionesAsync();
foreach (var medicion in mediciones)
{
2025-07-01 09:59:59 -04:00
try
2025-06-24 16:02:27 -04:00
{
2025-07-01 09:59:59 -04:00
if (!string.IsNullOrEmpty(medicion.Code))
2025-06-24 16:02:27 -04:00
{
2025-07-01 09:59:59 -04:00
var body = new MedicionSubterraneaRequest
2025-06-24 16:02:27 -04:00
{
2025-07-01 09:59:59 -04:00
Autenticacion = new Autenticacion
{
Password = string.Empty,
RutEmpresa = string.Empty,
RutUsuario = string.Empty
},
MedicionSubterranea = new Medicion
{
Caudal = medicion.Caudal.ToString() ?? "",
FechaMedicion = medicion.DateOrigen?.ToString("yyyy-MM-dd") ?? "",
HoraMedicion = medicion.DateOrigen?.ToString("HH:mm:ss") ?? "",
NivelFreaticoDelPozo = "",
Totalizador = medicion.Totalizador.ToString() ?? "",
}
};
//TODO: Agregar log texto
2025-06-24 16:02:27 -04:00
2025-07-01 09:59:59 -04:00
await _registrarMedicion.EnviarMedicionAsync(medicion.Code, body,medicion.Id);
}
2025-06-24 16:02:27 -04:00
2025-07-01 09:59:59 -04:00
}
catch (Exception)
{
//TODO: Agregar log texto
throw;
}
}
2025-06-24 16:02:27 -04:00
2025-07-01 09:59:59 -04:00
return true;
2025-06-24 14:46:32 -04:00
}
}
}