feat(esppApi): метод FindOrdersAsync поиска нарядов в АСУ ЕСПП по свойствам
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
namespace PARR.EsppApi.Services
|
||||
{
|
||||
internal class Espp
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
public Espp(HttpClient httpClient)
|
||||
{
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
public async Task<string> Get()
|
||||
{
|
||||
//var req = new HttpRequestMessage(HttpMethod.Get, "https://www.google.com");
|
||||
|
||||
//if (req == null)
|
||||
// return;
|
||||
|
||||
var response = await httpClient.GetAsync("http://dvocor.dvgd.rzd");
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
|
||||
|
||||
|
||||
return content;
|
||||
}
|
||||
}
|
||||
}
|
||||
54
PARR.EsppApi/Services/EsppHttpService.cs
Normal file
54
PARR.EsppApi/Services/EsppHttpService.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.EsppApi.Models;
|
||||
using System;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace PARR.EsppApi
|
||||
{
|
||||
internal class EsppHttpService
|
||||
{
|
||||
private readonly ILogger<EsppHttpService> logger;
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
public EsppHttpService(ILogger<EsppHttpService> logger,HttpClient httpClient)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
public async Task<EsppResultBase<T>> SendAsync<T>(string query) where T : class
|
||||
{
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, "");
|
||||
request.Content = new StringContent(query);
|
||||
|
||||
try
|
||||
{
|
||||
logger.LogDebug($"Отправляю запрос в АСУ ЕСПП({query})");
|
||||
var response = await httpClient.SendAsync(request);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
logger.LogError($"Ошибка при получении данных из АСУ ЕСПП, StatusCode:{response.StatusCode}");
|
||||
|
||||
}
|
||||
|
||||
var responseString = await response.Content.ReadAsStringAsync();
|
||||
|
||||
logger.LogDebug($"Получил данные, строка: {responseString}");
|
||||
|
||||
var obj = JsonSerializer.Deserialize<T>(responseString);
|
||||
|
||||
return new EsppResultBase<T>(obj, true);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Ошибка при получении данных из АСУ ЕСПП");
|
||||
|
||||
return new EsppResultBase<T>(null, false, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user