integración nueva tabla
This commit is contained in:
parent
5db07294f9
commit
657fd50ac9
22 changed files with 203 additions and 447 deletions
|
@ -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<bool> EnviarMedicionAsync(MedicionScada medicion, MedicionSubterraneaRequest request,DateTime fechaEnvio)
|
||||
public async Task<LogMedicionEnvio> 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<ApiResponse<MedicionSubterraneaResponse>>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue