This commit is contained in:
bcastrogallardo 2025-07-17 09:22:55 -04:00
parent 657fd50ac9
commit b52be74bfa
9 changed files with 129 additions and 42 deletions

View file

@ -1,5 +1,7 @@
using Dapper;
using Microsoft.Data.SqlClient;
using Serilog;
using Shared.DTO;
using Shared.DTO.Envios_DGA;
using Shared.DTO.VariablesEntorno;
@ -11,22 +13,63 @@ namespace DAL
{
try
{
using (var connection = new SqlConnection(BdConexion.StringConnection))
await using (var connection = new SqlConnection(BdConexion.StringConnection))
{
await connection.OpenAsync();
// Insertar todos los datos de la lista usando Dapper
var sql = @"INSERT INTO dbo.DGA_LOGS_OPERACION
(estado_envio, json_enviado, json_recibido, comprobante, fecha_envio, id_medicion_smartscada_operacion)
VALUES
(@EstadoEnvio, @JsonEnviado, @JsonRecibido, @Comprobante, @FechaEnvio, @IdMedicionSmartscadaOperacion)";
await connection.ExecuteAsync(sql, logMedicionScada);
// No es necesario hacer OpenAsync: Dapper lo abre si hace falta
var sql = @"
INSERT INTO dbo.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
);";
return true; // Éxito
await connection.ExecuteAsync(sql, logMedicionScada);
return true;
}
}
catch (Exception ex)
{
throw new Exception($"Error: {ex.Message}");
return false;
}
}
public async Task<bool> InsertarLogProcesoAsync(LogProceso log)
{
try
{
await using var connection = new SqlConnection(BdConexion.StringConnection);
var sql = @"
INSERT INTO dbo.DGA_LOGS_PROCESOS
(
NOMBRE_PROCESO,
FECHA_EJECUCION
)
VALUES
(
@NombreProceso,
@FechaEjecucion
);";
await connection.ExecuteAsync(sql, log);
return true;
}
catch (Exception ex)
{
return false;
}
}

View file

@ -21,6 +21,7 @@ namespace DAL
public static async Task<bool> ActualizarMedicionesAsync(string medicionesJson)
{
//TODO: ACTUALIZAR REGISTROS
try
{
await using var connection = new SqlConnection(BdConexion.StringConnection);