ajustes
This commit is contained in:
parent
657fd50ac9
commit
b52be74bfa
9 changed files with 129 additions and 42 deletions
|
@ -1,4 +1,5 @@
|
|||
using DAL;
|
||||
using Serilog;
|
||||
using Shared.DTO.Envios_DGA;
|
||||
using Shared.DTO.VariablesEntorno;
|
||||
using System.Globalization;
|
||||
|
@ -21,41 +22,53 @@ namespace DAS
|
|||
|
||||
public async Task<LogMedicionEnvio> EnviarMedicionAsync(DatoDGA medicion, MedicionSubterraneaRequest request, DateTime fechaEnvio)
|
||||
{
|
||||
var timeStamp = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss-0000", CultureInfo.InvariantCulture);
|
||||
var json = JsonSerializer.Serialize(request);
|
||||
|
||||
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 log = new LogMedicionEnvio();
|
||||
|
||||
try
|
||||
{
|
||||
var timeStamp = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss-0000", CultureInfo.InvariantCulture);
|
||||
var json = JsonSerializer.Serialize(request);
|
||||
|
||||
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");
|
||||
|
||||
log.JSON_ENVIO = json;
|
||||
log.FECHA_ENVIO = DateTime.UtcNow;
|
||||
log.ID_DGA_DATO = medicion.ID;
|
||||
|
||||
using var response = await _httpClient.SendAsync(req);
|
||||
string jsonRecibido = await response.Content.ReadAsStringAsync();
|
||||
log.JSON_RESPUESTA = jsonRecibido;
|
||||
|
||||
if (response == null || !response.IsSuccessStatusCode)
|
||||
{
|
||||
|
||||
log.COMPROBANTE = null;
|
||||
log.ESTADO_ENVIO = "ERROR";
|
||||
}
|
||||
|
||||
var apiResponse = JsonSerializer.Deserialize<ApiResponse<MedicionSubterraneaResponse>>(jsonRecibido, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
|
||||
if (apiResponse == null || string.IsNullOrEmpty(apiResponse.Status) || apiResponse.Status != "00")
|
||||
{
|
||||
log.COMPROBANTE = null;
|
||||
log.ESTADO_ENVIO = "ERROR";
|
||||
}
|
||||
|
||||
|
||||
|
||||
log.COMPROBANTE = apiResponse.Data.NumeroComprobante ?? null;
|
||||
log.ESTADO_ENVIO = "EXITO";
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
|
||||
log.COMPROBANTE = null;
|
||||
log.ESTADO_ENVIO = "ERROR";
|
||||
}
|
||||
finally
|
||||
{
|
||||
await _logMedicionScadaRepository.InsertarLogEnvioAsync(log);
|
||||
}
|
||||
|
||||
return log;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue