cambios variables de ambiente
This commit is contained in:
parent
222d5fdc08
commit
0d67a44d36
20 changed files with 261 additions and 297 deletions
|
@ -1,6 +1,7 @@
|
|||
using DAL;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Shared.DTO.Envios_DGA;
|
||||
using Shared.DTO.VariablesEntorno;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
|
@ -9,32 +10,19 @@ namespace DAS
|
|||
public class RegistrarMedicion
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly IConfiguration _configuration;
|
||||
private static string? password;
|
||||
private static string? rutEmpresa;
|
||||
private static string? rutUsuario;
|
||||
private readonly LogMedicionScadaRepository _logMedicionScadaRepository;
|
||||
|
||||
public RegistrarMedicion(HttpClient httpClient, IConfiguration configuration,LogMedicionScadaRepository logMedicionScadaRepository)
|
||||
public RegistrarMedicion(HttpClient httpClient, LogMedicionScadaRepository logMedicionScadaRepository)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_configuration = configuration;
|
||||
rutUsuario = _configuration["Credenciales:rutEmpresa"] ?? "";
|
||||
rutEmpresa = _configuration["Credenciales:rutUsuario"] ?? "" ?? "";
|
||||
password = _configuration["Credenciales:password"] ?? "";
|
||||
_logMedicionScadaRepository = logMedicionScadaRepository;
|
||||
}
|
||||
|
||||
public async Task<bool> EnviarMedicionAsync(string codigoObra, MedicionSubterraneaRequest request, long idMedicion)
|
||||
{
|
||||
|
||||
request.Autenticacion.Password = password;
|
||||
request.Autenticacion.RutEmpresa = rutEmpresa;
|
||||
request.Autenticacion.RutUsuario = rutUsuario;
|
||||
|
||||
var baseUrl = _configuration["ApiSubterranea:BaseUrl"];
|
||||
var endpoint = _configuration["ApiSubterranea:Endpoint"];
|
||||
var url = $"{baseUrl}{endpoint}";
|
||||
request.Autenticacion.Password = CredencialDGA.Password;
|
||||
request.Autenticacion.RutEmpresa = CredencialDGA.RutEmpresa; //TODO: condicionar rut empresa
|
||||
request.Autenticacion.RutUsuario = CredencialDGA.RutUsuario;
|
||||
|
||||
var timeStamp = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss-0000");
|
||||
|
||||
|
@ -44,7 +32,7 @@ namespace DAS
|
|||
content.Headers.Add("codigoObra", codigoObra);
|
||||
content.Headers.Add("timeStampOrigen", timeStamp);
|
||||
|
||||
var response = await _httpClient.PostAsync(url, content);
|
||||
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;
|
||||
|
@ -56,7 +44,7 @@ namespace DAS
|
|||
if (doc.RootElement.TryGetProperty("data", out var dataProp) &&
|
||||
dataProp.TryGetProperty("numeroComprobante", out var comprobanteProp))
|
||||
{
|
||||
comprobante = comprobanteProp.GetString();
|
||||
comprobante = comprobanteProp.GetString() ?? "";
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
@ -65,14 +53,16 @@ namespace DAS
|
|||
}
|
||||
}
|
||||
|
||||
var logMedicionScada = new LogMedicionScada();
|
||||
logMedicionScada.EstadoEnvio = estado;
|
||||
logMedicionScada.JsonEnviado = json;
|
||||
logMedicionScada.JsonRecibido = jsonRecibido;
|
||||
logMedicionScada.Comprobante = comprobante;
|
||||
logMedicionScada.FechaEnvio = DateTime.UtcNow;
|
||||
logMedicionScada.IdMedicionSmartscadaOperacion = idMedicion;
|
||||
|
||||
var logMedicionScada = new LogMedicionScada
|
||||
{
|
||||
EstadoEnvio = estado,
|
||||
JsonEnviado = json,
|
||||
JsonRecibido = jsonRecibido,
|
||||
Comprobante = comprobante,
|
||||
FechaEnvio = DateTime.UtcNow,
|
||||
IdMedicionSmartscadaOperacion = idMedicion
|
||||
};
|
||||
|
||||
await _logMedicionScadaRepository.InsertarLogMedicionScadaAsync(logMedicionScada);
|
||||
|
||||
return response.IsSuccessStatusCode;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue