From 5db07294f9a9400051e2e3c26316c4a632da471e Mon Sep 17 00:00:00 2001 From: bcastrogallardo Date: Tue, 15 Jul 2025 10:53:56 -0400 Subject: [PATCH] DGA solucion --- BLL/Integracion_DGA/BusinessLogic.cs | 9 +- DAL/JobsDgaRepository.cs | 160 +-------------------------- 2 files changed, 8 insertions(+), 161 deletions(-) diff --git a/BLL/Integracion_DGA/BusinessLogic.cs b/BLL/Integracion_DGA/BusinessLogic.cs index d380231..fb22fe4 100644 --- a/BLL/Integracion_DGA/BusinessLogic.cs +++ b/BLL/Integracion_DGA/BusinessLogic.cs @@ -92,7 +92,6 @@ namespace BLL.Integracion_DGA ).ToList(); await _jobs.InsertarDgaCaudal(caudalData); - await _jobs.InsertarMedicionOperacionCaudal(); } else if (item.name == "API - DGA - NIVELES") { @@ -110,7 +109,6 @@ namespace BLL.Integracion_DGA ).ToList(); await _jobs.InsertarDgaNivel(nivelData); - await _jobs.InsertarMedicionOperacionNivel(); } else if (item.name == "API - DGA") { @@ -128,7 +126,12 @@ namespace BLL.Integracion_DGA ).ToList(); } } - WriteLineAndLog($"FIN Proceso DGA"); + + WriteLineAndLog($"INICIO REGISTRO DE MEDICIONES DGA"); + await _jobs.SpRegistrarMedicionesDga(); + WriteLineAndLog($"FIN REGISTRO DE MEDICIONES DGA"); + + WriteLineAndLog($"FIN PROCESO DGA"); } catch (Exception ex) { diff --git a/DAL/JobsDgaRepository.cs b/DAL/JobsDgaRepository.cs index 20e39db..a9b8c67 100644 --- a/DAL/JobsDgaRepository.cs +++ b/DAL/JobsDgaRepository.cs @@ -9,83 +9,7 @@ namespace DAL { public class JobsDgaRepository { - public async Task InsertarDgaMacroResultado(List dgaMacroResultados) - { - try - { - using (SqlConnection connection = new SqlConnection(BdConexion.StringConnection)) - { - await connection.OpenAsync(); - // 1. Truncar la tabla antes de insertar - await connection.ExecuteAsync("TRUNCATE TABLE DGA_MACRO_RESULTADO"); - // 2. Insertar la lista de registros - string sql = "INSERT INTO DGA_MACRO_RESULTADO (TagName, TimeStamp, Value, Quality) VALUES (@TagName, @TimeStamp, @Value, @Quality)"; - // Esto inserta todos los elementos de la lista en la tabla - await connection.ExecuteAsync(sql, dgaMacroResultados); - return true; - } - } - catch (Exception ex) - { - throw new Exception($"Error: {ex.Message}"); - } - } - - public async Task InsertarDgaSensorResultado(List dgaSensorResultado) - { - try - { - using (var connection = new SqlConnection(BdConexion.StringConnection)) - { - await connection.OpenAsync(); - - // 1. Truncar la tabla DGA_SENSOR_RESULTADO - await connection.ExecuteAsync("TRUNCATE TABLE DGA_SENSOR_RESULTADO"); - - // 2. Llamar al stored procedure SP_CALCULO_DGA - await connection.ExecuteAsync("SP_CALCULO_DGA", commandType: System.Data.CommandType.StoredProcedure); - - // 3. Insertar todos los registros de la lista con Dapper - string sql = "INSERT INTO DGA_SENSOR_RESULTADO (TagName, TimeStamp, Value, Quality) VALUES (@TagName, @TimeStamp, @Value, @Quality)"; - await connection.ExecuteAsync(sql, dgaSensorResultado); - - return true; - } - } - catch (Exception ex) - { - throw new Exception($"Error: {ex.Message}"); - } - } - - public async Task InsertarDgaMacroResultadoSupFlujSuma(List dgaMacroResultadoSupFlujSuma) - { - try - { - // Configurar la conexión a la base de datos - using (SqlConnection connection = new SqlConnection(BdConexion.StringConnection)) - { - await connection.OpenAsync(); - // Truncar la tabla antes de insertar - await connection.ExecuteAsync("TRUNCATE TABLE DGA_MACRO_RESULTADO_SUP_FLUJ_SUMA"); - - // Crear un adaptador de datos - SqlDataAdapter adapter = new SqlDataAdapter(); - - // Configurar el comando de inserción - string sql = "INSERT INTO DGA_MACRO_RESULTADO_SUP_FLUJ_SUMA (TagName, TimeStamp, Value, Quality) VALUES (@TagName, @TimeStamp, @Value, @Quality)"; - await connection.ExecuteAsync(sql, dgaMacroResultadoSupFlujSuma); - - return true; // Éxito - } - } - catch (Exception ex) - { - throw new Exception($"Error: {ex.Message}"); - } - } - - public async Task SpCalculoDga() + public async Task SpRegistrarMedicionesDga() { try { @@ -93,47 +17,7 @@ namespace DAL { await connection.OpenAsync(); // Ejecuta el stored procedure sin parámetros - await connection.ExecuteAsync("SP_CALCULO_DGA", commandType: CommandType.StoredProcedure); - } - return true; // Éxito - } - catch (Exception ex) - { - throw new Exception($"Error: {ex.Message}"); - } - } - - public async Task SpCalculoDgaSupFlujSumaSnreversibilidad() - { - try - { - using (var connection = new SqlConnection(BdConexion.StringConnection)) - { - await connection.OpenAsync(); - await connection.ExecuteAsync( - "SP_CALCULO_DGA_SUP_FLUJ_SUMA_SNREVERSIBILIDAD", - commandType: CommandType.StoredProcedure - ); - } - return true; // Éxito - } - catch (Exception ex) - { - throw new Exception($"Error: {ex.Message}"); - } - } - - public async Task SpTraspasoDatosAchird() - { - try - { - using (var connection = new SqlConnection(BdConexion.StringConnection)) - { - await connection.OpenAsync(); - await connection.ExecuteAsync( - "SP_TRASPASO_DATOS_ACHIRD", - commandType: CommandType.StoredProcedure - ); + await connection.ExecuteAsync("SP_REGISTRAR_DATOS_DGA", commandType: CommandType.StoredProcedure); } return true; // Éxito } @@ -186,45 +70,5 @@ namespace DAL throw new Exception($"Error: {ex.Message}"); } } - - public async Task InsertarMedicionOperacionNivel() - { - try - { - using (SqlConnection connection = new SqlConnection(BdConexion.StringConnection)) - { - await connection.OpenAsync(); - await connection.ExecuteAsync( - "SP_CALCULO_NIVEL_MEDICION_SMARTSCADA_OPERACION", - commandType: CommandType.StoredProcedure - ); - return true; - } - } - catch (Exception ex) - { - throw new Exception($"Error: {ex.Message}"); - } - } - - public async Task InsertarMedicionOperacionCaudal() - { - try - { - using (SqlConnection connection = new SqlConnection(BdConexion.StringConnection)) - { - await connection.OpenAsync(); - await connection.ExecuteAsync( - "SP_CALCULO_CAUDAL_MEDICION_SMARTSCADA_OPERACION", - commandType: CommandType.StoredProcedure - ); - return true; - } - } - catch (Exception ex) - { - throw new Exception($"Error: {ex.Message}"); - } - } } }