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,9 +35,15 @@ 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>();
|
||||
|
||||
var pageNumber = 1;
|
||||
|
||||
while (true)
|
||||
{
|
||||
var mediciones = await _dGAMedicionRepository.ObtenerMedicionesPorLoteAsync(pageNumber);
|
||||
|
||||
if (mediciones == null || !mediciones.Any()){ break; }
|
||||
|
||||
foreach (var medicion in mediciones)
|
||||
{
|
||||
|
@ -64,18 +71,29 @@ namespace BLL.Recuperacion_DGA
|
|||
|
||||
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);
|
||||
logsEnviados.Add(response);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FileLoggerHelper.LogError($"[Error] {ex.Message}.", ex);
|
||||
ConsoleLoggerHelper.WriteLineAndLogInfo($"Error al enviar la medición con ID {medicion.CODIGO_DGA}.", ConsoleColor.Red);
|
||||
ConsoleLoggerHelper.WriteLineAndLogInfo($"[Error]: medicion[{medicion.ID}], mensaje: {ex.Message}");
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
var idMediciones = mediciones.Select(x => x.ID).ToList();
|
||||
await _dGAMedicionRepository.GuardarMedicionesEnviadasAsync(idMediciones);
|
||||
await _logEnvioRepository.InsertarLogRespuesta(logsEnviados);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ConsoleLoggerHelper.WriteLineAndLogInfo($"[Error] {e.Message}");
|
||||
}
|
||||
|
||||
//INSERTAR DATOS DE LOGS, ACTUALIZAR REGISTROS
|
||||
|
||||
logsEnviados.Clear();
|
||||
mediciones.Clear();
|
||||
pageNumber++;
|
||||
}
|
||||
|
||||
ConsoleLoggerHelper.WriteLineAndLogEventoAsync("FIN","Fin proceso de recuperación DGA","");
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
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