Compare commits
No commits in common. "36bd2ff4f329222d28490f28ec5f41509ef84b87" and "d51d3e1f02b3c766573aac1450889c0f21c1d205" have entirely different histories.
36bd2ff4f3
...
d51d3e1f02
3 changed files with 91 additions and 199 deletions
|
@ -21,11 +21,10 @@ namespace BLL.Recuperacion_DGA
|
||||||
|
|
||||||
public async Task<bool> RegistrarMedicionesAsync()
|
public async Task<bool> RegistrarMedicionesAsync()
|
||||||
{
|
{
|
||||||
try
|
WriteLineAndLog("Iniciando el proceso de recuperación DGA...");
|
||||||
{
|
|
||||||
await WriteLineAndLog("INICIO", "Inicio proceso de recuperación DGA", "");
|
|
||||||
WriteLineAndLog("Obteniendo Mediciones Scada", ConsoleColor.Green);
|
WriteLineAndLog("Obteniendo Mediciones Scada", ConsoleColor.Green);
|
||||||
var mediciones = await _dGAMedicionScadaRepository.ObtenerMedicionesAsync();
|
var mediciones = await _dGAMedicionScadaRepository.ObtenerMedicionesAsync();
|
||||||
|
|
||||||
foreach (var medicion in mediciones)
|
foreach (var medicion in mediciones)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -41,36 +40,12 @@ namespace BLL.Recuperacion_DGA
|
||||||
{
|
{
|
||||||
rutEmpresa = CredencialDGA.RutAv;
|
rutEmpresa = CredencialDGA.RutAv;
|
||||||
}
|
}
|
||||||
if (medicion.tipo_empresa == "EV")
|
if (medicion.tipo_empresa =="EV")
|
||||||
{
|
{
|
||||||
rutEmpresa = CredencialDGA.RutEsval;
|
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 body = new MedicionSubterraneaRequest
|
var body = new MedicionSubterraneaRequest
|
||||||
{
|
{
|
||||||
|
@ -89,100 +64,64 @@ namespace BLL.Recuperacion_DGA
|
||||||
Totalizador = medicion.Totalizador.ToString() ?? "",
|
Totalizador = medicion.Totalizador.ToString() ?? "",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
//await _registrarMedicion.EnviarMedicionAsync(medicion.Code, body, medicion.Id);
|
await _registrarMedicion.EnviarMedicionAsync(medicion.Code, body, medicion.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
FileLoggerHelper.LogError($"[Error] {ex.Message}.", ex);
|
FileLoggerHelper.LogError($"[Error] {ex.Message}.",ex);
|
||||||
WriteLineAndLog($"Error al enviar la medición con ID {medicion.Code}.", ConsoleColor.Red);
|
WriteLineAndLog($"Error al enviar la medición con ID {medicion.Code}.", ConsoleColor.Red);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await WriteLineAndLog("FIN","Fin proceso de recuperación DGA","");
|
|
||||||
|
|
||||||
await WriteLineAndLog("INICIO", "Inicio proceso de recuperación DGA los Vilos", "VILOS");
|
//var medicionesVilos = await _dgaMedicionScadaVilosRepository.ObtenerMedicionesVilosAsync();
|
||||||
WriteLineAndLog("Obteniendo Mediciones Scada los Vilos", ConsoleColor.Green);
|
//foreach (var medicionVilos in medicionesVilos)
|
||||||
var medicionesVilos = await _dgaMedicionScadaVilosRepository.ObtenerMedicionesVilosAsync();
|
//{
|
||||||
foreach (var medicionVilos in medicionesVilos)
|
// try
|
||||||
{
|
// {
|
||||||
try
|
// if (!string.IsNullOrEmpty(medicionVilos.Code))
|
||||||
{
|
// {
|
||||||
if (!string.IsNullOrEmpty(medicionVilos.Code))
|
// var rutEmpresa = string.Empty;
|
||||||
{
|
|
||||||
var rutEmpresa = string.Empty;
|
|
||||||
|
|
||||||
if (medicionVilos.tipo_empresa.Equals("AV"))
|
// if (medicionVilos.tipo_empresa.Equals("AV"))
|
||||||
{
|
// {
|
||||||
rutEmpresa = CredencialDGA.RutAv;
|
// rutEmpresa = CredencialDGA.RutAv;
|
||||||
}
|
// }
|
||||||
else if (medicionVilos.tipo_empresa.Equals("EV"))
|
// else if (medicionVilos.tipo_empresa.Equals("EV"))
|
||||||
{
|
// {
|
||||||
rutEmpresa = CredencialDGA.RutEsval;
|
// rutEmpresa = CredencialDGA.RutEsval;
|
||||||
}
|
// }
|
||||||
|
|
||||||
List<string> vacios = new List<string>();
|
// var body = new MedicionSubterraneaRequest
|
||||||
if (medicionVilos.Caudal == null || medicionVilos.Caudal.Equals(""))
|
// {
|
||||||
{
|
// Autenticacion = new Autenticacion
|
||||||
vacios.Add("caudal");
|
// {
|
||||||
}
|
// 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() ?? "",
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
if (medicionVilos.DateOrigen == null)
|
// await _registrarMedicion.EnviarMedicionAsync(medicionVilos.Code, body, medicionVilos.Id);
|
||||||
{
|
// }
|
||||||
vacios.Add("fecha origen");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (medicionVilos.nivelFreaticoDelPozo == null || medicionVilos.nivelFreaticoDelPozo.ToString().Equals(""))
|
// }
|
||||||
{
|
// catch (Exception ex)
|
||||||
vacios.Add("nivel freatico");
|
// {
|
||||||
}
|
// FileLoggerHelper.LogError($"[Error] {ex.Message}.", ex);
|
||||||
|
// WriteLineAndLog($"Error al enviar la medición vilos con ID {medicionVilos.Code}.", ConsoleColor.Red);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
if (medicionVilos.Totalizador == null || medicionVilos.Totalizador.Equals(""))
|
|
||||||
{
|
|
||||||
vacios.Add("totalizador");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vacios.Count > 0)
|
|
||||||
{
|
|
||||||
await FileLoggerHelper.InsertarLogsAsync("REGISTRAR", $"Medicion {medicionVilos.Code} no registra {string.Join(", ", vacios)}", "VILOS");
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await WriteLineAndLog("FIN", "Fin proceso de recuperación DGA los Vilos", "VILOS");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
FileLoggerHelper.LogError($"[Error] {ex.Message}.", ex);
|
|
||||||
WriteLineAndLog($"Error al procesar las mediciones.", ConsoleColor.Red);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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