diff --git a/BLL/Integracion_DGA/BusinessLogic.cs b/BLL/Integracion_DGA/ObtencionDatosDga.cs similarity index 67% rename from BLL/Integracion_DGA/BusinessLogic.cs rename to BLL/Integracion_DGA/ObtencionDatosDga.cs index fb22fe4..6d702b2 100644 --- a/BLL/Integracion_DGA/BusinessLogic.cs +++ b/BLL/Integracion_DGA/ObtencionDatosDga.cs @@ -7,33 +7,28 @@ using Shared.Helper; namespace BLL.Integracion_DGA { - public class BusinessLogic + public class ObtencionDatosDga { private readonly IConfiguration _configuration; private readonly ApiService _apiService; private readonly JobsDgaRepository _jobs; - private readonly JobsDgaSupFlujRepository _jobsSupFluj; - private readonly FileLoggerHelper _fileLoggerHelper; - public BusinessLogic(IConfiguration configuration, ApiService apiService, JobsDgaRepository jobs, JobsDgaSupFlujRepository jobsSupFluj) + public ObtencionDatosDga(IConfiguration configuration, ApiService apiService, JobsDgaRepository jobs) { _configuration = configuration; _apiService = apiService; _jobs = jobs; - _jobsSupFluj = jobsSupFluj; FileLoggerHelper.ConfigureLogger(_configuration); } - public async Task Run() + public async Task ObtenerDatosDga() { - DateTimeOffset dateEnd = DateTimeOffset.Now; DateTimeOffset dateStart = dateEnd.AddHours(-1); JsonSerializerOptions options = new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }; - //FileLoggerHelper.ConfigureLogger(_configuration); - WriteLineAndLog($"Inicia Proceso DGA"); + ConsoleLoggerHelper.WriteLineAndLogInfo($"INICIO OBTENER DATOS DGA"); try { string apiUrlBase = NexusApiUrl.ApiUrl; @@ -44,19 +39,25 @@ namespace BLL.Integracion_DGA { "accept", "application/json" } }; - WriteLineAndLog($"Obteniendo Documentos"); + ConsoleLoggerHelper.WriteLineAndLogInfo($"OBTENIENDO DOCUMENTOS"); string apiUrlDocuments = apiUrlBase + "/api/Documents"; // Utiliza el servicio para realizar la solicitud a la API con URL y encabezados personalizados string responseData = await _apiService.GetApiResponseAsync(apiUrlDocuments, headers); var documento = JsonSerializer.Deserialize>(responseData, options); + + if (documento == null || documento.Count == 0) + { + return; + } + foreach (DocumentResponse item in documento) { - WriteLineAndLog($"Obteniendo Tagviews"); + ConsoleLoggerHelper.WriteLineAndLogInfo($"OBTENIENDO TAGVIEWS"); string apiUrlTagViews = $"{apiUrlBase}/api/Documents/tagviews/{item.uid}"; responseData = await _apiService.GetApiResponseAsync(apiUrlTagViews, headers); - TagviewsResponse tagviews = JsonSerializer.Deserialize(responseData, options); + TagviewsResponse tagviews = JsonSerializer.Deserialize(responseData, options) ?? new TagviewsResponse(); List listTagsID = tagviews.Columns.Select(x => x.Uid).ToList(); @@ -69,15 +70,16 @@ namespace BLL.Integracion_DGA EndTs = dateEnd.ToUnixTimeSeconds() }; - WriteLineAndLog($"Obteniendo Tagviews Historic"); + ConsoleLoggerHelper.WriteLineAndLogInfo($"OBTENIENDO TAGVIEWS HISTORIC"); string apiUrlHistoric = $"{apiUrlBase}/api/Documents/tagviews/{item.uid}/historic"; responseData = await _apiService.PostApiResponseAsync(apiUrlHistoric, headers, historicRequest); - List historicResponse = JsonSerializer.Deserialize>(responseData, options); + List historicResponse = JsonSerializer.Deserialize>(responseData, options) ?? new List(); TimeZoneInfo zonaHorariaChile = TimeZoneInfo.FindSystemTimeZoneById("Pacific SA Standard Time"); if (item.name == "API - DGA - CAUDALES") { + ConsoleLoggerHelper.WriteLineAndLogInfo($"OBTENIENDO DATOS DGA CAUDAL"); var caudalData = tagviews.Columns .SelectMany(tag => historicResponse.Where(h => h.Uid == tag.Uid) @@ -95,6 +97,7 @@ namespace BLL.Integracion_DGA } else if (item.name == "API - DGA - NIVELES") { + ConsoleLoggerHelper.WriteLineAndLogInfo($"OBTENIENDO DATOS DGA NIVEL"); var nivelData = tagviews.Columns .SelectMany(tag => historicResponse.Where(h => h.Uid == tag.Uid) @@ -110,51 +113,17 @@ namespace BLL.Integracion_DGA await _jobs.InsertarDgaNivel(nivelData); } - else if (item.name == "API - DGA") - { - var nivelData = tagviews.Columns - .SelectMany(tag => - historicResponse.Where(h => h.Uid == tag.Uid) - .Select(h => new - { - TAG = tag.Name, - NIVEL_FREATICO = h.Value?.ToString(), - FECHAMEDICION = TimeZoneInfo.ConvertTimeFromUtc( - new DateTime(1970, 1, 1).AddSeconds(h.TimeStamp).ToUniversalTime(), - zonaHorariaChile) - }) - ).ToList(); - } } - WriteLineAndLog($"INICIO REGISTRO DE MEDICIONES DGA"); + ConsoleLoggerHelper.WriteLineAndLogInfo($"INICIO REGISTRO DE MEDICIONES DGA"); await _jobs.SpRegistrarMedicionesDga(); - WriteLineAndLog($"FIN REGISTRO DE MEDICIONES DGA"); - - WriteLineAndLog($"FIN PROCESO DGA"); + ConsoleLoggerHelper.WriteLineAndLogInfo($"FIN REGISTRO DE MEDICIONES DGA"); } catch (Exception ex) { FileLoggerHelper.LogError($"{ex.Message}", ex); - WriteLineAndLog($"{ex.Message}", ConsoleColor.Red); + ConsoleLoggerHelper.WriteLineAndLogInfo($"{ex.Message}", ConsoleColor.Red); } - - } - - static void WriteLineAndLog(string msj, ConsoleColor? color = null) - { - if (color.HasValue && Enum.IsDefined(typeof(ConsoleColor), color.Value)) - { - Console.ForegroundColor = (ConsoleColor)color; - Console.WriteLine(msj); - Console.ResetColor(); - } - else - { - Console.WriteLine($"{msj}"); - } - - FileLoggerHelper.LogInformation($"{msj}"); } } } diff --git a/BLL/Recuperacion_DGA/EnvioDGA.cs b/BLL/Recuperacion_DGA/EnvioDGA.cs index b26fc37..78471cf 100644 --- a/BLL/Recuperacion_DGA/EnvioDGA.cs +++ b/BLL/Recuperacion_DGA/EnvioDGA.cs @@ -9,12 +9,12 @@ namespace BLL.Recuperacion_DGA { public class EnvioDGA { - private readonly MedicionScadaRepository _dGAMedicionScadaRepository; + private readonly MedicionDGARepository _dGAMedicionRepository; private readonly RegistrarMedicion _registrarMedicion; - public EnvioDGA(MedicionScadaRepository dGAMedicionScadaRepository, RegistrarMedicion registrarMedicion) + public EnvioDGA(MedicionDGARepository dGAMedicionRepository, RegistrarMedicion registrarMedicion) { - _dGAMedicionScadaRepository = dGAMedicionScadaRepository; + _dGAMedicionRepository = dGAMedicionRepository; _registrarMedicion = registrarMedicion; } @@ -22,55 +22,16 @@ namespace BLL.Recuperacion_DGA { try { - await WriteLineAndLog("INICIO", "Inicio proceso de recuperación DGA", ""); - WriteLineAndLog("Obteniendo Mediciones Scada", ConsoleColor.Green); - var mediciones = await _dGAMedicionScadaRepository.ObtenerMedicionesAsync(); + ConsoleLoggerHelper.WriteLineAndLogEventoAsync("INICIO", "Inicio proceso de recuperación DGA", ""); + ConsoleLoggerHelper.WriteLineAndLogInfo("Obteniendo Mediciones Scada", ConsoleColor.Green); + + var mediciones = await _dGAMedicionRepository.ObtenerMedicionesAsync(); var listaMediciones = new List(); + foreach (var medicion in mediciones) { try { - if (!string.IsNullOrEmpty(medicion.Code)) - { - var rutEmpresa = string.Empty; - if (medicion.tipo_empresa == null) - { - continue; - } - if (medicion.tipo_empresa == "AV") - { - rutEmpresa = CredencialDGA.RutAv; - } - if (medicion.tipo_empresa == "EV") - { - rutEmpresa = CredencialDGA.RutEsval; - } - - List vacios = new List(); - 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 @@ -78,76 +39,44 @@ namespace BLL.Recuperacion_DGA Autenticacion = new Autenticacion { Password = CredencialDGA.Password, - RutEmpresa = rutEmpresa, + RutEmpresa = medicion.TIPO_EMPRESA == "EV" ? CredencialDGA.RutEsval : CredencialDGA.RutAv, 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() ?? "", + 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 ?? "", } }; 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}); - } + listaMediciones.Add(new {Id = medicion.ID,FechaEnvio = fechaEnvio.ToString("yyyy-MM-dd HH:mm:ss"), Enviado = medicion.ENVIADO + 1}); } catch (Exception ex) { FileLoggerHelper.LogError($"[Error] {ex.Message}.", ex); - WriteLineAndLog($"Error al enviar la medición con ID {medicion.Code}.", ConsoleColor.Red); + ConsoleLoggerHelper.WriteLineAndLogInfo($"Error al enviar la medición con ID {medicion.CODIGO_DGA}.", ConsoleColor.Red); } } var listaMedicionesJson = JsonSerializer.Serialize(listaMediciones); if (listaMediciones.Count > 0) { - await MedicionScadaRepository.ActualizarMedicionesAsync(listaMedicionesJson); + await MedicionDGARepository.ActualizarMedicionesAsync(listaMedicionesJson); } - await WriteLineAndLog("FIN","Fin proceso de recuperación DGA",""); + + ConsoleLoggerHelper.WriteLineAndLogEventoAsync("FIN","Fin proceso de recuperación DGA",""); } catch (Exception ex) { FileLoggerHelper.LogError($"[Error] {ex.Message}.", ex); - WriteLineAndLog($"Error al procesar las mediciones.", ConsoleColor.Red); + ConsoleLoggerHelper.WriteLineAndLogInfo($"Error al procesar las mediciones.", ConsoleColor.Red); return false; } return true; } - - static void WriteLineAndLog(string msj, ConsoleColor? color = null) - { - if (color.HasValue && Enum.IsDefined(typeof(ConsoleColor), color.Value)) - { - Console.ForegroundColor = (ConsoleColor)color; - Console.WriteLine(msj); - Console.ResetColor(); - } - else - { - Console.WriteLine($"{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); - } } } diff --git a/DAL/Encriptador.cs b/DAL/Encriptador.cs deleted file mode 100644 index 96812f0..0000000 --- a/DAL/Encriptador.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Security.Cryptography; -using System.Text; - -namespace DAL -{ - public static class Encriptador - { - private static readonly byte[] key = Encoding.ASCII.GetBytes("1234567891234567"); - private static readonly byte[] iv = Encoding.ASCII.GetBytes("Devjoker7.37hAES"); - - public static string Encripta(string Cadena) - { - - using Aes aesAlg = Aes.Create(); - aesAlg.Key = key; - aesAlg.IV = iv; - - ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV); - - using (MemoryStream msEncrypt = new MemoryStream()) - { - using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) - { - using (StreamWriter swEncrypt = new StreamWriter(csEncrypt)) - { - swEncrypt.Write(Cadena); - } - } - - return Convert.ToBase64String(msEncrypt.ToArray()); - } - } - - public static string Desencripta(string Cadena) - { - using Aes aesAlg = Aes.Create(); - aesAlg.Key = key; - aesAlg.IV = iv; - - ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV); - - using (MemoryStream msDecrypt = new MemoryStream(Convert.FromBase64String(Cadena))) - { - using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) - { - using (StreamReader srDecrypt = new StreamReader(csDecrypt)) - { - return srDecrypt.ReadToEnd(); - } - } - } - } - } -} diff --git a/DAL/JobsDgaSupFlujRepository.cs b/DAL/JobsDgaSupFlujRepository.cs deleted file mode 100644 index b217349..0000000 --- a/DAL/JobsDgaSupFlujRepository.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System.Data; -using Dapper; -using Microsoft.Data.SqlClient; -using Shared.DTO.Integracion_DGA; -using Shared.DTO.VariablesEntorno; - -namespace DAL -{ - public class JobsDgaSupFlujRepository - { - public async Task InsertarDgaMacroResultadoSupFluj(List dgaMacroResultadoSupFluj) - { - try - { - // Configurar la conexión a la base de datos - using (SqlConnection connection = new SqlConnection(BdConexion.StringConnection)) - { - await connection.OpenAsync(); - await connection.ExecuteAsync("TRUNCATE TABLE DGA_MACRO_RESULTADO_SUP_FLUJ"); - - await SpCalculoDgaSupFluj(); - - string sql = "INSERT INTO DGA_MACRO_RESULTADO_SUP_FLUJ (TagName, TimeStamp, Value, Quality) VALUES (@TagName, @TimeStamp, @Value, @Quality)"; - await connection.ExecuteAsync(sql, dgaMacroResultadoSupFluj); - return true; - } - } - catch (Exception ex) - { - throw new Exception($"Error: {ex.Message}"); - } - } - - public async Task SpCalculoDgaSupFluj() - { - try - { - using (var connection = new SqlConnection(BdConexion.StringConnection)) - { - await connection.OpenAsync(); - await connection.ExecuteAsync( - "SP_CALCULO_DGA_SUP_FLUJ", - commandType: CommandType.StoredProcedure - ); - } - return true; // Éxito - } - catch (Exception ex) - { - throw new Exception($"Error: {ex.Message}"); - } - } - - public async Task SpTraspasoDatosAchirdSupFluj() - { - try - { - using (var connection = new SqlConnection(BdConexion.StringConnection)) - { - await connection.OpenAsync(); - await connection.ExecuteAsync( - "SP_TRASPASO_DATOS_ACHIRD_SUP_FLUJ", - commandType: CommandType.StoredProcedure - ); - } - return true; // Éxito - } - catch (Exception ex) - { - throw new Exception($"Error: {ex.Message}"); - } - } - } -} diff --git a/DAL/LogMedicionScadaRepository.cs b/DAL/LogEnvioRepository.cs similarity index 88% rename from DAL/LogMedicionScadaRepository.cs rename to DAL/LogEnvioRepository.cs index 548f83a..62d00e2 100644 --- a/DAL/LogMedicionScadaRepository.cs +++ b/DAL/LogEnvioRepository.cs @@ -5,9 +5,9 @@ using Shared.DTO.VariablesEntorno; namespace DAL { - public class LogMedicionScadaRepository + public class LogEnvioRepository { - public async Task InsertarLogMedicionScadaAsync(LogMedicionScada logMedicionScada) + public async Task InsertarLogEnvioAsync(LogMedicionEnvio logMedicionScada) { try { diff --git a/DAL/MedicionScadaRepository.cs b/DAL/MedicionDGARepository.cs similarity index 79% rename from DAL/MedicionScadaRepository.cs rename to DAL/MedicionDGARepository.cs index 2781766..8945c4f 100644 --- a/DAL/MedicionScadaRepository.cs +++ b/DAL/MedicionDGARepository.cs @@ -6,14 +6,14 @@ using Shared.DTO.VariablesEntorno; namespace DAL { - public class MedicionScadaRepository + public class MedicionDGARepository { - public async Task> ObtenerMedicionesAsync() + public async Task> ObtenerMedicionesAsync() { await using var connection = new SqlConnection(BdConexion.StringConnection); - var result = await connection.QueryAsync( - "SP_OBTENER_MEDICION_SMARTSCADA_OPERACION", + var result = await connection.QueryAsync( + "SP_OBTENER_DGA_DATOS", commandType: CommandType.StoredProcedure); return result.ToList(); diff --git a/DAS/RegistrarMedicion.cs b/DAS/RegistrarMedicion.cs index c7058c7..93594ef 100644 --- a/DAS/RegistrarMedicion.cs +++ b/DAS/RegistrarMedicion.cs @@ -1,66 +1,61 @@ -using System.Text; -using System.Text.Json; -using DAL; +using DAL; using Shared.DTO.Envios_DGA; using Shared.DTO.VariablesEntorno; +using System.Globalization; +using System.Net; +using System.Text; +using System.Text.Json; namespace DAS { public class RegistrarMedicion { private readonly HttpClient _httpClient; - private readonly LogMedicionScadaRepository _logMedicionScadaRepository; + private readonly LogEnvioRepository _logMedicionScadaRepository; - public RegistrarMedicion(HttpClient httpClient, LogMedicionScadaRepository logMedicionScadaRepository) + public RegistrarMedicion(HttpClient httpClient, LogEnvioRepository logMedicionScadaRepository) { _httpClient = httpClient; _logMedicionScadaRepository = logMedicionScadaRepository; } - public async Task EnviarMedicionAsync(MedicionScada medicion, MedicionSubterraneaRequest request,DateTime fechaEnvio) + public async Task EnviarMedicionAsync(DatoDGA medicion, MedicionSubterraneaRequest request, DateTime fechaEnvio) { - 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", CultureInfo.InvariantCulture); var json = JsonSerializer.Serialize(request); - var content = new StringContent(json, Encoding.UTF8, "application/json"); - content.Headers.Add("codigoObra", medicion.Code); - content.Headers.Add("timeStampOrigen", timeStamp); + var req = new HttpRequestMessage(HttpMethod.Post, $"{SubterraneaApiUrl.BaseUrl}{SubterraneaApiUrl.EndPoint}SSSSS"); + req.Headers.Add("codigoObra", medicion.CODIGO_DGA); + req.Headers.Add("timeStampOrigen", timeStamp); + req.Content = new StringContent(json, Encoding.UTF8, "application/json"); - var response = await _httpClient.PostAsync($"{SubterraneaApiUrl.BaseUrl}{SubterraneaApiUrl.EndPoint}", content); - string jsonRecibido = await response.Content.ReadAsStringAsync(); - string estado = response.IsSuccessStatusCode ? "OK" : "ERROR"; - string comprobante = string.Empty; - if (response.IsSuccessStatusCode) + var log = new LogMedicionEnvio(); + + try { - try - { - using var doc = JsonDocument.Parse(jsonRecibido); - if (doc.RootElement.TryGetProperty("data", out var dataProp) && - dataProp.TryGetProperty("numeroComprobante", out var comprobanteProp)) - { - comprobante = comprobanteProp.GetString() ?? ""; - } - } - catch + using var response = await _httpClient.SendAsync(req); + string jsonRecibido = await response.Content.ReadAsStringAsync(); + + if (response == null || !response.IsSuccessStatusCode) { } + + var apiResponse = JsonSerializer.Deserialize>(jsonRecibido, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); + + + + } - - var logMedicionScada = new LogMedicionScada + catch (Exception ex) { - EstadoEnvio = estado, - JsonEnviado = json, - JsonRecibido = jsonRecibido, - Comprobante = comprobante, - FechaEnvio = fechaEnvio, - IdMedicionSmartscadaOperacion = medicion.Id - }; - - await _logMedicionScadaRepository.InsertarLogMedicionScadaAsync(logMedicionScada); - return true; + + } + finally + { + await _logMedicionScadaRepository.InsertarLogEnvioAsync(log); + } } } } diff --git a/Integracion_DGA/Program.cs b/Integracion_DGA/Program.cs index 27ec017..9e2de07 100644 --- a/Integracion_DGA/Program.cs +++ b/Integracion_DGA/Program.cs @@ -46,22 +46,21 @@ namespace Integracion_DGA .ConfigureServices((context, services) => { services.AddSingleton(configuration); - services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddHttpClient(); services.AddScoped(); - services.AddScoped(); - services.AddScoped(); + services.AddScoped(); services.AddScoped(); - services.AddScoped(); + services.AddScoped(); }) .Build(); var envioDGA = host.Services.GetRequiredService(); - var bussinessLogic = host.Services.GetRequiredService(); + var bussinessLogic = host.Services.GetRequiredService(); var apiService = host.Services.GetRequiredService(); - await bussinessLogic.Run(); + await bussinessLogic.ObtenerDatosDga(); } } } diff --git a/Recuperacion_DGA/Program.cs b/Recuperacion_DGA/Program.cs index 8f68902..7601d1e 100644 --- a/Recuperacion_DGA/Program.cs +++ b/Recuperacion_DGA/Program.cs @@ -46,10 +46,10 @@ namespace Recuperacion_DGA .ConfigureServices((context, services) => { services.AddSingleton(configuration); - services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddHttpClient(); - services.AddScoped(); + services.AddScoped(); }) .Build(); diff --git a/SHARED/DTO/Envios_DGA/ApiResponse.cs b/SHARED/DTO/Envios_DGA/ApiResponse.cs new file mode 100644 index 0000000..30fa87d --- /dev/null +++ b/SHARED/DTO/Envios_DGA/ApiResponse.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.DTO.Envios_DGA +{ + public class ApiResponse + { + public string? Status { get; set; } + public string? Message { get; set; } + public T? Data { get; set; } + } +} diff --git a/SHARED/DTO/Envios_DGA/DatoDGA.cs b/SHARED/DTO/Envios_DGA/DatoDGA.cs new file mode 100644 index 0000000..72160a6 --- /dev/null +++ b/SHARED/DTO/Envios_DGA/DatoDGA.cs @@ -0,0 +1,27 @@ +namespace Shared.DTO.Envios_DGA +{ + public class DatoDGA + { + public int ID { get; set; } + + public string? CODIGO_DGA { get; set; } + + public string? MACRO { get; set; } + + public string? SENSOR { 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 DateTime? FECHA_MEDICION_NIVEL { get; set; } + + public string? TIPO_EMPRESA { get; set; } + + public int ENVIADO { get; set; } = 0; + } +} diff --git a/SHARED/DTO/Envios_DGA/LogMedicionEnvio.cs b/SHARED/DTO/Envios_DGA/LogMedicionEnvio.cs new file mode 100644 index 0000000..a368626 --- /dev/null +++ b/SHARED/DTO/Envios_DGA/LogMedicionEnvio.cs @@ -0,0 +1,12 @@ +namespace Shared.DTO.Envios_DGA +{ + public class LogMedicionEnvio + { + public string EstadoEnvio { get; set; } + public string? JsonEnviado { get; set; } + public string? JsonRecibido { get; set; } + public string? Comprobante { get; set; } + public DateTime FechaEnvio { get; set; } + public long IdDgaDato { get; set; } + } +} diff --git a/SHARED/DTO/Envios_DGA/LogMedicionScada.cs b/SHARED/DTO/Envios_DGA/LogMedicionScada.cs deleted file mode 100644 index 9a3b079..0000000 --- a/SHARED/DTO/Envios_DGA/LogMedicionScada.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Shared.DTO.Envios_DGA -{ - public class LogMedicionScada - { - public string EstadoEnvio { get; set; } - public string JsonEnviado { get; set; } - public string JsonRecibido { get; set; } - public string Comprobante { get; set; } - public DateTime FechaEnvio { get; set; } - public long IdMedicionSmartscadaOperacion { get; set; } - } -} diff --git a/SHARED/DTO/Envios_DGA/MedicionScada.cs b/SHARED/DTO/Envios_DGA/MedicionScada.cs deleted file mode 100644 index f35f57d..0000000 --- a/SHARED/DTO/Envios_DGA/MedicionScada.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace Shared.DTO.Envios_DGA -{ - public class MedicionScada - { - public long Id { get; set; } - public string? Code { get; set; } - - public DateTime? DateOrigen { get; set; } - - public DateTime? DateMedicionSup { get; set; } - - public decimal? Caudal { get; set; } - - public decimal? Altura { get; set; } - - public DateTime? DateMedicionSub { get; set; } - - public decimal? Totalizador { get; set; } - - public decimal? Caudalsub { 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? nivelFreaticoDelPozo { get; set; } - } -} diff --git a/SHARED/DTO/Envios_DGA/MedicionSubterraneaRequest.cs b/SHARED/DTO/Envios_DGA/MedicionSubterraneaRequest.cs index 6cea0a9..001bb9e 100644 --- a/SHARED/DTO/Envios_DGA/MedicionSubterraneaRequest.cs +++ b/SHARED/DTO/Envios_DGA/MedicionSubterraneaRequest.cs @@ -2,24 +2,24 @@ { public class MedicionSubterraneaRequest { - public Autenticacion Autenticacion { get; set; } - public Medicion MedicionSubterranea { get; set; } + public Autenticacion Autenticacion { get; set; } = new(); + public Medicion MedicionSubterranea { get; set; } = new(); } public class Autenticacion { - public string Password { get; set; } - public string RutEmpresa { get; set; } - public string RutUsuario { get; set; } + public string Password { get; set; } = string.Empty; + public string RutEmpresa { get; set; } = string.Empty; + public string RutUsuario { get; set; } = string.Empty; } public class Medicion { - public string Caudal { get; set; } - public string FechaMedicion { get; set; } - public string HoraMedicion { get; set; } - public string NivelFreaticoDelPozo { get; set; } - public string Totalizador { get; set; } + public string? Caudal { get; set; } + public string? FechaMedicion { get; set; } + public string? HoraMedicion { get; set; } + public string? NivelFreaticoDelPozo { get; set; } + public string? Totalizador { get; set; } public string? TipoEmpresa { get; set; } } diff --git a/SHARED/DTO/Envios_DGA/MedicionSubterraneaResponse.cs b/SHARED/DTO/Envios_DGA/MedicionSubterraneaResponse.cs new file mode 100644 index 0000000..74edddf --- /dev/null +++ b/SHARED/DTO/Envios_DGA/MedicionSubterraneaResponse.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.DTO.Envios_DGA +{ + public class MedicionSubterraneaResponse + { + public string? NumeroComprobante { get; set; } + } +} diff --git a/SHARED/DTO/Integracion_DGA/DgaMacroResultado.cs b/SHARED/DTO/Integracion_DGA/DgaMacroResultado.cs deleted file mode 100644 index 07a735a..0000000 --- a/SHARED/DTO/Integracion_DGA/DgaMacroResultado.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Shared.DTO.Integracion_DGA; - -public partial class DgaMacroResultado -{ - public string TagName { get; set; } = null!; - - public DateTime TimeStamp { get; set; } - - public double? Value { get; set; } - - public string? Quality { get; set; } -} diff --git a/SHARED/DTO/Integracion_DGA/DgaMacroResultadoSupFluj.cs b/SHARED/DTO/Integracion_DGA/DgaMacroResultadoSupFluj.cs deleted file mode 100644 index 25558f6..0000000 --- a/SHARED/DTO/Integracion_DGA/DgaMacroResultadoSupFluj.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Shared.DTO.Integracion_DGA; - -public partial class DgaMacroResultadoSupFluj -{ - public string TagName { get; set; } = null!; - - public DateTime TimeStamp { get; set; } - - public double? Value { get; set; } - - public string? Quality { get; set; } -} diff --git a/SHARED/DTO/Integracion_DGA/DgaMacroResultadoSupFlujSuma.cs b/SHARED/DTO/Integracion_DGA/DgaMacroResultadoSupFlujSuma.cs deleted file mode 100644 index f1f5086..0000000 --- a/SHARED/DTO/Integracion_DGA/DgaMacroResultadoSupFlujSuma.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Shared.DTO.Integracion_DGA; - -public partial class DgaMacroResultadoSupFlujSuma -{ - public string TagName { get; set; } = null!; - - public DateTime TimeStamp { get; set; } - - public double? Value { get; set; } - - public string? Quality { get; set; } -} diff --git a/SHARED/DTO/Integracion_DGA/DgaSensorResultado.cs b/SHARED/DTO/Integracion_DGA/DgaSensorResultado.cs deleted file mode 100644 index 0f85fb4..0000000 --- a/SHARED/DTO/Integracion_DGA/DgaSensorResultado.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Shared.DTO.Integracion_DGA; - -public partial class DgaSensorResultado -{ - public string TagName { get; set; } = null!; - - public DateTime TimeStamp { get; set; } - - public double? Value { get; set; } - - public string? Quality { get; set; } -} diff --git a/SHARED/Helper/ConsoleLoggerHelper.cs b/SHARED/Helper/ConsoleLoggerHelper.cs new file mode 100644 index 0000000..3a0b4e2 --- /dev/null +++ b/SHARED/Helper/ConsoleLoggerHelper.cs @@ -0,0 +1,39 @@ +using System; + +namespace Shared.Helper +{ + public static class ConsoleLoggerHelper + { + public static void WriteLineAndLogInfo(string msj, ConsoleColor? color = null) + { + if (color.HasValue && Enum.IsDefined(typeof(ConsoleColor), color.Value)) + { + Console.ForegroundColor = color.Value; + Console.WriteLine(msj); + Console.ResetColor(); + } + else + { + Console.WriteLine(msj); + } + + FileLoggerHelper.LogInformation(msj); + } + + public static void WriteLineAndLogEventoAsync(string evento, string proceso, string operacion = "", ConsoleColor? color = null) + { + if (color.HasValue && Enum.IsDefined(typeof(ConsoleColor), color.Value)) + { + Console.ForegroundColor = color.Value; + Console.WriteLine(proceso); + Console.ResetColor(); + } + else + { + Console.WriteLine(proceso); + } + + FileLoggerHelper.LogInformation(proceso); + } + } +} diff --git a/SHARED/Helper/FileLoggerHelper.cs b/SHARED/Helper/FileLoggerHelper.cs index 767dd89..dd50d81 100644 --- a/SHARED/Helper/FileLoggerHelper.cs +++ b/SHARED/Helper/FileLoggerHelper.cs @@ -10,7 +10,7 @@ namespace Shared.Helper { public static void ConfigureLogger(IConfiguration configuration) { - var logFilePath = configuration.GetSection("Logging:LogFile:Path").Value; + var logFilePath = configuration.GetSection("Logging:LogFile:Path").Value ?? ""; var logFileFullPath = Path.Combine(Directory.GetCurrentDirectory(), logFilePath); Log.Logger = new LoggerConfiguration() @@ -28,31 +28,5 @@ namespace Shared.Helper { Log.Error(ex, message); } - - public static async Task 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; - } - } - } }