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 DAL;
|
||||||
using DAS;
|
using DAS;
|
||||||
using Shared.DTO;
|
using Shared.DTO;
|
||||||
|
@ -34,49 +35,66 @@ 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 mediciones = await _dGAMedicionRepository.ObtenerMedicionesAsync();
|
var logsEnviados = new List<LogMedicionEnvio>();
|
||||||
var medicionesEnviadas = new List<Object>();
|
|
||||||
var logs = new List<Object>();
|
|
||||||
|
|
||||||
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
|
try
|
||||||
{
|
{
|
||||||
var fechaEnvio = DateTime.UtcNow;
|
var idMediciones = mediciones.Select(x => x.ID).ToList();
|
||||||
|
await _dGAMedicionRepository.GuardarMedicionesEnviadasAsync(idMediciones);
|
||||||
var body = new MedicionSubterraneaRequest
|
await _logEnvioRepository.InsertarLogRespuesta(logsEnviados);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
FileLoggerHelper.LogError($"[Error] {ex.Message}.", ex);
|
ConsoleLoggerHelper.WriteLineAndLogInfo($"[Error] {e.Message}");
|
||||||
ConsoleLoggerHelper.WriteLineAndLogInfo($"Error al enviar la medición con ID {medicion.CODIGO_DGA}.", ConsoleColor.Red);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logsEnviados.Clear();
|
||||||
|
mediciones.Clear();
|
||||||
|
pageNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//INSERTAR DATOS DE LOGS, ACTUALIZAR REGISTROS
|
|
||||||
|
|
||||||
|
|
||||||
ConsoleLoggerHelper.WriteLineAndLogEventoAsync("FIN","Fin proceso de recuperación DGA","");
|
ConsoleLoggerHelper.WriteLineAndLogEventoAsync("FIN","Fin proceso de recuperación DGA","");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
@ -36,5 +36,34 @@ namespace DAL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> InsertarLogRespuesta(List<LogMedicionEnvio> logsEnviados)
|
||||||
|
{
|
||||||
|
await using var connection = new SqlConnection(BdConexion.StringConnection);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sql = @"INSERT INTO DGA_LOGS_ENVIOS (
|
||||||
|
ESTADO_ENVIO,
|
||||||
|
JSON_ENVIO,
|
||||||
|
JSON_RESPUESTA,
|
||||||
|
COMPROBANTE,
|
||||||
|
FECHA_ENVIO,
|
||||||
|
ID_DGA_DATO)
|
||||||
|
VALUES (
|
||||||
|
@ESTADO_ENVIO,
|
||||||
|
@JSON_ENVIO,
|
||||||
|
@JSON_RESPUESTA,
|
||||||
|
@COMPROBANTE,
|
||||||
|
@FECHA_ENVIO,
|
||||||
|
@ID_DGA_DATO);";
|
||||||
|
|
||||||
|
await connection.ExecuteAsync(sql, logsEnviados);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception($"Error al insertar logs de respuesta {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,5 +18,37 @@ namespace DAL
|
||||||
|
|
||||||
return result.ToList();
|
return result.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<DatoDGATemporal>> ObtenerMedicionesPorLoteAsync(int pageNumber)
|
||||||
|
{
|
||||||
|
var nroPagina = new DynamicParameters();
|
||||||
|
nroPagina.Add("@PageNumber", pageNumber);
|
||||||
|
|
||||||
|
await using var connection = new SqlConnection(BdConexion.StringConnection);
|
||||||
|
|
||||||
|
var resultado = await connection.QueryAsync<DatoDGATemporal>(
|
||||||
|
"SP_OBTENER_LOTE_DGA_DATOS",
|
||||||
|
nroPagina,
|
||||||
|
commandType: CommandType.StoredProcedure);
|
||||||
|
|
||||||
|
return resultado.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> GuardarMedicionesEnviadasAsync(List<int> medicionesGuardadas)
|
||||||
|
{
|
||||||
|
await using var connection = new SqlConnection(BdConexion.StringConnection);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var query = @"UPDATE DGA_DATOS SET ENVIADO = 1 WHERE ID IN @Ids";
|
||||||
|
|
||||||
|
await connection.ExecuteAsync(query, new { Ids = medicionesGuardadas });
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception ex) {
|
||||||
|
|
||||||
|
throw new Exception($"Error {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace DAS
|
||||||
_logMedicionScadaRepository = logMedicionScadaRepository;
|
_logMedicionScadaRepository = logMedicionScadaRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<LogMedicionEnvio> EnviarMedicionAsync(DatoDGA medicion, MedicionSubterraneaRequest request, DateTime fechaEnvio)
|
public async Task<LogMedicionEnvio> EnviarMedicionAsync(DatoDGATemporal medicion, MedicionSubterraneaRequest request, DateTime fechaEnvio)
|
||||||
{
|
{
|
||||||
var log = new LogMedicionEnvio();
|
var log = new LogMedicionEnvio();
|
||||||
try
|
try
|
||||||
|
|
18
SHARED/DTO/Envios_DGA/DatoDGATemporal.cs
Normal file
18
SHARED/DTO/Envios_DGA/DatoDGATemporal.cs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
namespace Shared.DTO.Envios_DGA
|
||||||
|
{
|
||||||
|
public class DatoDGATemporal
|
||||||
|
{
|
||||||
|
public int ID { get; set; }
|
||||||
|
public string? CODIGO_DGA { get; set; }
|
||||||
|
|
||||||
|
public string? CAUDAL { get; set; }
|
||||||
|
|
||||||
|
public string? TOTALIZADOR_CAUDAL { get; set; }
|
||||||
|
|
||||||
|
public DateTime? FECHA_MEDICION_CAUDAL { get; set; }
|
||||||
|
|
||||||
|
public string? NIVEL_FREATICO_DEL_POZO { get; set; }
|
||||||
|
|
||||||
|
public string? TIPO_EMPRESA { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue