Compare commits
No commits in common. "fee40a25a4ed5400ed285d3f71660379e51c0405" and "d51d3e1f02b3c766573aac1450889c0f21c1d205" have entirely different histories.
fee40a25a4
...
d51d3e1f02
13 changed files with 287 additions and 156 deletions
|
@ -12,14 +12,16 @@ namespace BLL.Integracion_DGA
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
private readonly ApiService _apiService;
|
private readonly ApiService _apiService;
|
||||||
private readonly JobsDgaRepository _jobs;
|
private readonly JobsDgaRepository _jobs;
|
||||||
|
private readonly JobsDgaVilosRepository _jobsVilos;
|
||||||
private readonly JobsDgaSupFlujRepository _jobsSupFluj;
|
private readonly JobsDgaSupFlujRepository _jobsSupFluj;
|
||||||
private readonly FileLoggerHelper _fileLoggerHelper;
|
private readonly FileLoggerHelper _fileLoggerHelper;
|
||||||
|
|
||||||
public BusinessLogic(IConfiguration configuration, ApiService apiService, JobsDgaRepository jobs, JobsDgaSupFlujRepository jobsSupFluj)
|
public BusinessLogic(IConfiguration configuration, ApiService apiService, JobsDgaRepository jobs, JobsDgaVilosRepository jobsVilos, JobsDgaSupFlujRepository jobsSupFluj)
|
||||||
{
|
{
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_apiService = apiService;
|
_apiService = apiService;
|
||||||
_jobs = jobs;
|
_jobs = jobs;
|
||||||
|
_jobsVilos = jobsVilos;
|
||||||
_jobsSupFluj = jobsSupFluj;
|
_jobsSupFluj = jobsSupFluj;
|
||||||
FileLoggerHelper.ConfigureLogger(_configuration);
|
FileLoggerHelper.ConfigureLogger(_configuration);
|
||||||
}
|
}
|
||||||
|
@ -136,6 +138,38 @@ namespace BLL.Integracion_DGA
|
||||||
WriteLineAndLog($"Fin Envio DGA", ConsoleColor.Green);
|
WriteLineAndLog($"Fin Envio DGA", ConsoleColor.Green);
|
||||||
/**************/
|
/**************/
|
||||||
/**************/
|
/**************/
|
||||||
|
WriteLineAndLog($"Inicio Envio DGA Vilos", ConsoleColor.Green);
|
||||||
|
WriteLineAndLog($"\t Descargar datos historian: Insertar InsertarDgaMacroResultadoVilos");
|
||||||
|
List<DgaMacroResultadoVilos> listDgaMacroResultadoVilos = listDgaMacroResultados.Select(item => new DgaMacroResultadoVilos
|
||||||
|
{
|
||||||
|
TagName = item.TagName,
|
||||||
|
TimeStamp = item.TimeStamp,
|
||||||
|
Value = item.Value,
|
||||||
|
Quality = item.Quality
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
var resultVilos = await _jobsVilos.InsertarDgaMacroResultadoVilos(listDgaMacroResultadoVilos);
|
||||||
|
|
||||||
|
WriteLineAndLog($"\t Descargar datos historian: Insertar InsertarDgaSensorResultadoVilos");
|
||||||
|
List<DgaSensorResultadoVilos> listDgaSensorResultadoVilos = listDgaMacroResultados.Select(item => new DgaSensorResultadoVilos
|
||||||
|
{
|
||||||
|
TagName = item.TagName,
|
||||||
|
TimeStamp = item.TimeStamp,
|
||||||
|
Value = item.Value,
|
||||||
|
Quality = item.Quality
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
var resultSensorVilos = await _jobsVilos.InsertarDgaSensorResultadoVilos(listDgaSensorResultadoVilos);
|
||||||
|
|
||||||
|
WriteLineAndLog($"\t Calculo Suma");
|
||||||
|
var resultCalculoVilos = await _jobsVilos.SpCalculoDgaVilos();
|
||||||
|
|
||||||
|
|
||||||
|
WriteLineAndLog($"\t Traspaso datos achird");
|
||||||
|
var resultAchirdVilos = await _jobsVilos.SpTraspasoDatosAchirdVilos();
|
||||||
|
WriteLineAndLog($"Fin Envio DGA Vilos", ConsoleColor.Green);
|
||||||
|
/**************/
|
||||||
|
/**************/
|
||||||
WriteLineAndLog($"Inicio Envio DGA Sup Fluj", ConsoleColor.Green);
|
WriteLineAndLog($"Inicio Envio DGA Sup Fluj", ConsoleColor.Green);
|
||||||
WriteLineAndLog($"\t Descargar datos historian: Insertar InsertarDgaMacroResultadoSupFluj");
|
WriteLineAndLog($"\t Descargar datos historian: Insertar InsertarDgaMacroResultadoSupFluj");
|
||||||
List<DgaMacroResultadoSupFluj> listDgaMacroResultadoSupFluj = listDgaMacroResultados.Select(item => new DgaMacroResultadoSupFluj
|
List<DgaMacroResultadoSupFluj> listDgaMacroResultadoSupFluj = listDgaMacroResultados.Select(item => new DgaMacroResultadoSupFluj
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System.Text.Json;
|
using DAL;
|
||||||
using DAL;
|
|
||||||
using DAS;
|
using DAS;
|
||||||
using Shared.DTO.Envios_DGA;
|
using Shared.DTO.Envios_DGA;
|
||||||
using Shared.DTO.VariablesEntorno;
|
using Shared.DTO.VariablesEntorno;
|
||||||
|
@ -10,111 +9,119 @@ namespace BLL.Recuperacion_DGA
|
||||||
public class EnvioDGA
|
public class EnvioDGA
|
||||||
{
|
{
|
||||||
private readonly MedicionScadaRepository _dGAMedicionScadaRepository;
|
private readonly MedicionScadaRepository _dGAMedicionScadaRepository;
|
||||||
|
private readonly MedicionScadaVilosRepository _dgaMedicionScadaVilosRepository;
|
||||||
private readonly RegistrarMedicion _registrarMedicion;
|
private readonly RegistrarMedicion _registrarMedicion;
|
||||||
|
|
||||||
public EnvioDGA(MedicionScadaRepository dGAMedicionScadaRepository, RegistrarMedicion registrarMedicion)
|
public EnvioDGA(MedicionScadaRepository dGAMedicionScadaRepository, RegistrarMedicion registrarMedicion, MedicionScadaVilosRepository dgaMedicionScadaVilosRepository)
|
||||||
{
|
{
|
||||||
_dGAMedicionScadaRepository = dGAMedicionScadaRepository;
|
_dGAMedicionScadaRepository = dGAMedicionScadaRepository;
|
||||||
_registrarMedicion = registrarMedicion;
|
_registrarMedicion = registrarMedicion;
|
||||||
|
_dgaMedicionScadaVilosRepository = dgaMedicionScadaVilosRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> RegistrarMedicionesAsync()
|
public async Task<bool> RegistrarMedicionesAsync()
|
||||||
{
|
{
|
||||||
try
|
WriteLineAndLog("Iniciando el proceso de recuperación DGA...");
|
||||||
|
WriteLineAndLog("Obteniendo Mediciones Scada", ConsoleColor.Green);
|
||||||
|
var mediciones = await _dGAMedicionScadaRepository.ObtenerMedicionesAsync();
|
||||||
|
|
||||||
|
foreach (var medicion in mediciones)
|
||||||
{
|
{
|
||||||
await WriteLineAndLog("INICIO", "Inicio proceso de recuperación DGA", "");
|
try
|
||||||
WriteLineAndLog("Obteniendo Mediciones Scada", ConsoleColor.Green);
|
|
||||||
var mediciones = await _dGAMedicionScadaRepository.ObtenerMedicionesAsync();
|
|
||||||
var listaMediciones = new List<Object>();
|
|
||||||
foreach (var medicion in mediciones)
|
|
||||||
{
|
{
|
||||||
try
|
if (!string.IsNullOrEmpty(medicion.Code))
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(medicion.Code))
|
var rutEmpresa = string.Empty;
|
||||||
|
if (medicion.tipo_empresa == null)
|
||||||
{
|
{
|
||||||
var rutEmpresa = string.Empty;
|
continue;
|
||||||
if (medicion.tipo_empresa == null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (medicion.tipo_empresa == "AV")
|
|
||||||
{
|
|
||||||
rutEmpresa = CredencialDGA.RutAv;
|
|
||||||
}
|
|
||||||
if (medicion.tipo_empresa == "EV")
|
|
||||||
{
|
|
||||||
rutEmpresa = CredencialDGA.RutEsval;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<string> vacios = new List<string>();
|
|
||||||
if (medicion.Caudal == null || medicion.Caudal.Equals(""))
|
|
||||||
{
|
|
||||||
vacios.Add("caudal");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (medicion.DateOrigen == null)
|
|
||||||
{
|
|
||||||
vacios.Add("fecha origen");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (medicion.nivelFreaticoDelPozo == null || medicion.nivelFreaticoDelPozo.ToString().Equals(""))
|
|
||||||
{
|
|
||||||
vacios.Add("nivel freatico");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (medicion.Totalizador == null || medicion.Totalizador.Equals(""))
|
|
||||||
{
|
|
||||||
vacios.Add("totalizador");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vacios.Count > 0)
|
|
||||||
{
|
|
||||||
await FileLoggerHelper.InsertarLogsAsync("REGISTRAR", $"Medicion {medicion.Code} no registra {string.Join(", ", vacios)}","");
|
|
||||||
}
|
|
||||||
var fechaEnvio = DateTime.UtcNow;
|
|
||||||
|
|
||||||
var body = new MedicionSubterraneaRequest
|
|
||||||
{
|
|
||||||
Autenticacion = new Autenticacion
|
|
||||||
{
|
|
||||||
Password = CredencialDGA.Password,
|
|
||||||
RutEmpresa = rutEmpresa,
|
|
||||||
RutUsuario = CredencialDGA.RutUsuario
|
|
||||||
},
|
|
||||||
MedicionSubterranea = new Medicion
|
|
||||||
{
|
|
||||||
Caudal = medicion.Caudal.ToString() ?? "",
|
|
||||||
FechaMedicion = medicion.DateOrigen?.ToString("yyyy-MM-dd") ?? "",
|
|
||||||
HoraMedicion = medicion.DateOrigen?.ToString("HH:mm:ss") ?? "",
|
|
||||||
NivelFreaticoDelPozo = medicion.nivelFreaticoDelPozo?.ToString() ?? "",
|
|
||||||
Totalizador = medicion.Totalizador.ToString() ?? "",
|
|
||||||
}
|
|
||||||
};
|
|
||||||
await _registrarMedicion.EnviarMedicionAsync(medicion, body, fechaEnvio);
|
|
||||||
listaMediciones.Add(new {Id = medicion.Id,FechaEnvio = fechaEnvio.ToString("yyyy-MM-dd HH:mm:ss"), Enviado = medicion.Enviado + 1});
|
|
||||||
}
|
}
|
||||||
|
if (medicion.tipo_empresa == "AV")
|
||||||
|
{
|
||||||
|
rutEmpresa = CredencialDGA.RutAv;
|
||||||
|
}
|
||||||
|
if (medicion.tipo_empresa =="EV")
|
||||||
|
{
|
||||||
|
rutEmpresa = CredencialDGA.RutEsval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var body = new MedicionSubterraneaRequest
|
||||||
|
{
|
||||||
|
Autenticacion = new Autenticacion
|
||||||
|
{
|
||||||
|
Password = CredencialDGA.Password,
|
||||||
|
RutEmpresa = rutEmpresa,
|
||||||
|
RutUsuario = CredencialDGA.RutUsuario
|
||||||
|
},
|
||||||
|
MedicionSubterranea = new Medicion
|
||||||
|
{
|
||||||
|
Caudal = medicion.Caudal.ToString() ?? "",
|
||||||
|
FechaMedicion = medicion.DateOrigen?.ToString("yyyy-MM-dd") ?? "",
|
||||||
|
HoraMedicion = medicion.DateOrigen?.ToString("HH:mm:ss") ?? "",
|
||||||
|
NivelFreaticoDelPozo = medicion.nivelFreaticoDelPozo?.ToString() ?? "",
|
||||||
|
Totalizador = medicion.Totalizador.ToString() ?? "",
|
||||||
|
}
|
||||||
|
};
|
||||||
|
await _registrarMedicion.EnviarMedicionAsync(medicion.Code, body, medicion.Id);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
FileLoggerHelper.LogError($"[Error] {ex.Message}.", ex);
|
|
||||||
WriteLineAndLog($"Error al enviar la medición con ID {medicion.Code}.", ConsoleColor.Red);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var listaMedicionesJson = JsonSerializer.Serialize(listaMediciones);
|
catch (Exception ex)
|
||||||
|
|
||||||
if (listaMediciones.Count > 0)
|
|
||||||
{
|
{
|
||||||
await MedicionScadaRepository.ActualizarMedicionesAsync(listaMedicionesJson);
|
FileLoggerHelper.LogError($"[Error] {ex.Message}.",ex);
|
||||||
|
WriteLineAndLog($"Error al enviar la medición con ID {medicion.Code}.", ConsoleColor.Red);
|
||||||
}
|
}
|
||||||
await WriteLineAndLog("FIN","Fin proceso de recuperación DGA","");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
FileLoggerHelper.LogError($"[Error] {ex.Message}.", ex);
|
|
||||||
WriteLineAndLog($"Error al procesar las mediciones.", ConsoleColor.Red);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//var medicionesVilos = await _dgaMedicionScadaVilosRepository.ObtenerMedicionesVilosAsync();
|
||||||
|
//foreach (var medicionVilos in medicionesVilos)
|
||||||
|
//{
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// if (!string.IsNullOrEmpty(medicionVilos.Code))
|
||||||
|
// {
|
||||||
|
// var rutEmpresa = string.Empty;
|
||||||
|
|
||||||
|
// if (medicionVilos.tipo_empresa.Equals("AV"))
|
||||||
|
// {
|
||||||
|
// rutEmpresa = CredencialDGA.RutAv;
|
||||||
|
// }
|
||||||
|
// else if (medicionVilos.tipo_empresa.Equals("EV"))
|
||||||
|
// {
|
||||||
|
// rutEmpresa = CredencialDGA.RutEsval;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// var body = new MedicionSubterraneaRequest
|
||||||
|
// {
|
||||||
|
// Autenticacion = new Autenticacion
|
||||||
|
// {
|
||||||
|
// Password = CredencialDGA.Password,
|
||||||
|
// RutEmpresa = rutEmpresa,
|
||||||
|
// RutUsuario = CredencialDGA.RutUsuario
|
||||||
|
// },
|
||||||
|
// MedicionSubterranea = new Medicion
|
||||||
|
// {
|
||||||
|
// Caudal = medicionVilos.Caudal.ToString() ?? "",
|
||||||
|
// FechaMedicion = medicionVilos.DateOrigen?.ToString("yyyy-MM-dd") ?? "",
|
||||||
|
// HoraMedicion = medicionVilos.DateOrigen?.ToString("HH:mm:ss") ?? "",
|
||||||
|
// NivelFreaticoDelPozo = medicionVilos?.nivelFreaticoDelPozo.ToString() ?? "",
|
||||||
|
// Totalizador = medicionVilos.Totalizador.ToString() ?? "",
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// await _registrarMedicion.EnviarMedicionAsync(medicionVilos.Code, body, medicionVilos.Id);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
// catch (Exception ex)
|
||||||
|
// {
|
||||||
|
// FileLoggerHelper.LogError($"[Error] {ex.Message}.", ex);
|
||||||
|
// WriteLineAndLog($"Error al enviar la medición vilos con ID {medicionVilos.Code}.", ConsoleColor.Red);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,21 +140,5 @@ namespace BLL.Recuperacion_DGA
|
||||||
|
|
||||||
FileLoggerHelper.LogInformation($"{msj}");
|
FileLoggerHelper.LogInformation($"{msj}");
|
||||||
}
|
}
|
||||||
|
|
||||||
static async Task WriteLineAndLog(string evento, string proceso, string operacion = null, ConsoleColor? color = null)
|
|
||||||
{
|
|
||||||
if (color.HasValue && Enum.IsDefined(typeof(ConsoleColor), color.Value))
|
|
||||||
{
|
|
||||||
Console.ForegroundColor = (ConsoleColor)color;
|
|
||||||
Console.WriteLine($"{proceso}");
|
|
||||||
Console.ResetColor();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine($"{proceso}");
|
|
||||||
}
|
|
||||||
FileLoggerHelper.LogInformation($"{proceso}");
|
|
||||||
await FileLoggerHelper.InsertarLogsAsync(evento,proceso,operacion);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
103
DAL/JobsDgaVilosRepository.cs
Normal file
103
DAL/JobsDgaVilosRepository.cs
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
using System.Data;
|
||||||
|
using Dapper;
|
||||||
|
using Microsoft.Data.SqlClient;
|
||||||
|
using Shared.DTO.Integracion_DGA;
|
||||||
|
using Shared.DTO.VariablesEntorno;
|
||||||
|
|
||||||
|
namespace DAL
|
||||||
|
{
|
||||||
|
public class JobsDgaVilosRepository
|
||||||
|
{
|
||||||
|
|
||||||
|
public async Task<bool> InsertarDgaMacroResultadoVilos(List<DgaMacroResultadoVilos> dgaMacroResultadoVilos)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
||||||
|
{
|
||||||
|
await connection.OpenAsync();
|
||||||
|
|
||||||
|
// 1. Truncar la tabla antes de insertar
|
||||||
|
await connection.ExecuteAsync("TRUNCATE TABLE DGA_MACRO_RESULTADO_VILOS");
|
||||||
|
|
||||||
|
// 2. Llamar al stored procedure
|
||||||
|
await connection.ExecuteAsync("SP_CALCULO_DGA_VILOS", commandType: System.Data.CommandType.StoredProcedure);
|
||||||
|
|
||||||
|
// 3. Insertar todos los datos de la lista usando Dapper
|
||||||
|
string sql = "INSERT INTO DGA_MACRO_RESULTADO_VILOS (TagName, TimeStamp, Value, Quality) VALUES (@TagName, @TimeStamp, @Value, @Quality)";
|
||||||
|
await connection.ExecuteAsync(sql, dgaMacroResultadoVilos);
|
||||||
|
|
||||||
|
return true; // Éxito
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception($"Error: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> InsertarDgaSensorResultadoVilos(List<DgaSensorResultadoVilos> dgaSensorResultadoVilos)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
||||||
|
{
|
||||||
|
await connection.OpenAsync();
|
||||||
|
|
||||||
|
// 1. Truncar la tabla antes de insertar
|
||||||
|
await connection.ExecuteAsync("TRUNCATE TABLE DGA_SENSOR_RESULTADO_VILOS");
|
||||||
|
|
||||||
|
// 2. Insertar todos los datos de la lista usando Dapper
|
||||||
|
string sql = "INSERT INTO DGA_SENSOR_RESULTADO_VILOS (TagName, TimeStamp, Value, Quality) VALUES (@TagName, @TimeStamp, @Value, @Quality)";
|
||||||
|
await connection.ExecuteAsync(sql, dgaSensorResultadoVilos);
|
||||||
|
|
||||||
|
return true; // Éxito
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception($"Error: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> SpCalculoDgaVilos()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
||||||
|
{
|
||||||
|
await connection.OpenAsync();
|
||||||
|
await connection.ExecuteAsync(
|
||||||
|
"SP_CALCULO_DGA_VILOS",
|
||||||
|
commandType: CommandType.StoredProcedure
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return true; // Éxito
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception($"Error: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> SpTraspasoDatosAchirdVilos()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
||||||
|
{
|
||||||
|
await connection.OpenAsync();
|
||||||
|
await connection.ExecuteAsync(
|
||||||
|
"SP_TRASPASO_DATOS_ACHIRD_VILOS",
|
||||||
|
commandType: CommandType.StoredProcedure
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return true; // Éxito
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception($"Error: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,19 +18,5 @@ namespace DAL
|
||||||
|
|
||||||
return result.ToList();
|
return result.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<bool> ActualizarMedicionesAsync(string medicionesJson)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await using var connection = new SqlConnection(BdConexion.StringConnection);
|
|
||||||
await connection.ExecuteAsync("SP_ACTUALIZAR_MEDICION_SMARTSCADA_OPERACION", new { JsonMediciones = medicionesJson }, commandType: CommandType.StoredProcedure);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new Exception($"Error: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
22
DAL/MedicionScadaVilosRepository.cs
Normal file
22
DAL/MedicionScadaVilosRepository.cs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
using System.Data;
|
||||||
|
using Dapper;
|
||||||
|
using Microsoft.Data.SqlClient;
|
||||||
|
using Shared.DTO.Envios_DGA;
|
||||||
|
using Shared.DTO.VariablesEntorno;
|
||||||
|
|
||||||
|
namespace DAL
|
||||||
|
{
|
||||||
|
public class MedicionScadaVilosRepository
|
||||||
|
{
|
||||||
|
public async Task<List<MedicionScada>> ObtenerMedicionesVilosAsync()
|
||||||
|
{
|
||||||
|
await using var connection = new SqlConnection(BdConexion.StringConnection);
|
||||||
|
|
||||||
|
var result = await connection.QueryAsync<MedicionScada>(
|
||||||
|
"SP_OBTENER_MEDICION_SMARTSCADA_OPERACION_VILOS",
|
||||||
|
commandType: CommandType.StoredProcedure);
|
||||||
|
|
||||||
|
return result.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,14 +17,14 @@ namespace DAS
|
||||||
_logMedicionScadaRepository = logMedicionScadaRepository;
|
_logMedicionScadaRepository = logMedicionScadaRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> EnviarMedicionAsync(MedicionScada medicion, MedicionSubterraneaRequest request,DateTime fechaEnvio)
|
public async Task<bool> EnviarMedicionAsync(string codigoObra, MedicionSubterraneaRequest request, long idMedicion)
|
||||||
{
|
{
|
||||||
var timeStamp = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss-0000");
|
var timeStamp = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss-0000");
|
||||||
|
|
||||||
var json = JsonSerializer.Serialize(request);
|
var json = JsonSerializer.Serialize(request);
|
||||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
content.Headers.Add("codigoObra", medicion.Code);
|
content.Headers.Add("codigoObra", codigoObra);
|
||||||
content.Headers.Add("timeStampOrigen", timeStamp);
|
content.Headers.Add("timeStampOrigen", timeStamp);
|
||||||
|
|
||||||
var response = await _httpClient.PostAsync($"{SubterraneaApiUrl.BaseUrl}{SubterraneaApiUrl.EndPoint}SSSSSSSSSSSSSSSSS", content);
|
var response = await _httpClient.PostAsync($"{SubterraneaApiUrl.BaseUrl}{SubterraneaApiUrl.EndPoint}SSSSSSSSSSSSSSSSS", content);
|
||||||
|
@ -54,8 +54,8 @@ namespace DAS
|
||||||
JsonEnviado = json,
|
JsonEnviado = json,
|
||||||
JsonRecibido = jsonRecibido,
|
JsonRecibido = jsonRecibido,
|
||||||
Comprobante = comprobante,
|
Comprobante = comprobante,
|
||||||
FechaEnvio = fechaEnvio,
|
FechaEnvio = DateTime.UtcNow,
|
||||||
IdMedicionSmartscadaOperacion = medicion.Id
|
IdMedicionSmartscadaOperacion = idMedicion
|
||||||
};
|
};
|
||||||
|
|
||||||
await _logMedicionScadaRepository.InsertarLogMedicionScadaAsync(logMedicionScada);
|
await _logMedicionScadaRepository.InsertarLogMedicionScadaAsync(logMedicionScada);
|
||||||
|
|
|
@ -42,10 +42,12 @@ namespace Integracion_DGA
|
||||||
services.AddScoped<EnvioDGA>();
|
services.AddScoped<EnvioDGA>();
|
||||||
services.AddHttpClient<RegistrarMedicion>();
|
services.AddHttpClient<RegistrarMedicion>();
|
||||||
services.AddScoped<JobsDgaRepository>();
|
services.AddScoped<JobsDgaRepository>();
|
||||||
|
services.AddScoped<JobsDgaVilosRepository>();
|
||||||
services.AddScoped<JobsDgaSupFlujRepository>();
|
services.AddScoped<JobsDgaSupFlujRepository>();
|
||||||
services.AddScoped<LogMedicionScadaRepository>();
|
services.AddScoped<LogMedicionScadaRepository>();
|
||||||
services.AddScoped<ApiService>();
|
services.AddScoped<ApiService>();
|
||||||
services.AddScoped<BusinessLogic>();
|
services.AddScoped<BusinessLogic>();
|
||||||
|
services.AddScoped<MedicionScadaVilosRepository>();
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ namespace Recuperacion_DGA
|
||||||
services.AddSingleton<IConfiguration>(configuration);
|
services.AddSingleton<IConfiguration>(configuration);
|
||||||
|
|
||||||
services.AddScoped<MedicionScadaRepository>();
|
services.AddScoped<MedicionScadaRepository>();
|
||||||
|
services.AddScoped<MedicionScadaVilosRepository>();
|
||||||
services.AddScoped<EnvioDGA>();
|
services.AddScoped<EnvioDGA>();
|
||||||
services.AddHttpClient<RegistrarMedicion>();
|
services.AddHttpClient<RegistrarMedicion>();
|
||||||
services.AddScoped<LogMedicionScadaRepository>();
|
services.AddScoped<LogMedicionScadaRepository>();
|
||||||
|
|
|
@ -20,8 +20,7 @@
|
||||||
public decimal? Caudalsub { get; set; }
|
public decimal? Caudalsub { get; set; }
|
||||||
|
|
||||||
public decimal? Nivel { get; set; }
|
public decimal? Nivel { get; set; }
|
||||||
public DateTime? FechaEnvio { get; set; }
|
|
||||||
public int Enviado { get; set; }
|
|
||||||
public string? tipo_empresa { get; set; }
|
public string? tipo_empresa { get; set; }
|
||||||
public string? nivelFreaticoDelPozo { get; set; }
|
public string? nivelFreaticoDelPozo { get; set; }
|
||||||
}
|
}
|
||||||
|
|
12
SHARED/DTO/Integracion_DGA/DgaMacroResultadoVilos.cs
Normal file
12
SHARED/DTO/Integracion_DGA/DgaMacroResultadoVilos.cs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
namespace Shared.DTO.Integracion_DGA;
|
||||||
|
|
||||||
|
public partial class DgaMacroResultadoVilos
|
||||||
|
{
|
||||||
|
public string TagName { get; set; } = null!;
|
||||||
|
|
||||||
|
public DateTime TimeStamp { get; set; }
|
||||||
|
|
||||||
|
public double? Value { get; set; }
|
||||||
|
|
||||||
|
public string? Quality { get; set; }
|
||||||
|
}
|
12
SHARED/DTO/Integracion_DGA/DgaSensorResultadoVilos.cs
Normal file
12
SHARED/DTO/Integracion_DGA/DgaSensorResultadoVilos.cs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
namespace Shared.DTO.Integracion_DGA;
|
||||||
|
|
||||||
|
public partial class DgaSensorResultadoVilos
|
||||||
|
{
|
||||||
|
public string TagName { get; set; } = null!;
|
||||||
|
|
||||||
|
public DateTime TimeStamp { get; set; }
|
||||||
|
|
||||||
|
public double? Value { get; set; }
|
||||||
|
|
||||||
|
public string? Quality { get; set; }
|
||||||
|
}
|
|
@ -1,8 +1,5 @@
|
||||||
using Dapper;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Data.SqlClient;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using Shared.DTO.VariablesEntorno;
|
|
||||||
|
|
||||||
namespace Shared.Helper
|
namespace Shared.Helper
|
||||||
{
|
{
|
||||||
|
@ -28,31 +25,5 @@ namespace Shared.Helper
|
||||||
{
|
{
|
||||||
Log.Error(ex, message);
|
Log.Error(ex, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<bool> InsertarLogsAsync(string evento, string proceso, string operacion)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using var connection = new SqlConnection(BdConexion.StringConnection);
|
|
||||||
await connection.OpenAsync();
|
|
||||||
|
|
||||||
string sql = @"INSERT INTO DGA_LOGS_REGISTROS_ENVIOS (evento, proceso, operacion)
|
|
||||||
VALUES (@evento, @proceso, @operacion)";
|
|
||||||
|
|
||||||
await connection.ExecuteAsync(sql, new
|
|
||||||
{
|
|
||||||
evento,
|
|
||||||
proceso,
|
|
||||||
operacion
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LogError("Error al insertar logs", e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,6 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Dapper" Version="2.1.66" />
|
|
||||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.2" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.6" />
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.6" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
|
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||||
|
|
Loading…
Add table
Reference in a new issue