feat(esppApi): метод FindOrdersAsync поиска нарядов в АСУ ЕСПП по свойствам
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PARR.EsppApi.Models;
|
using PARR.EsppApi.Models;
|
||||||
using PARR.EsppApi.Models.Query;
|
using PARR.EsppApi.Models.Query;
|
||||||
using PARR.EsppApi.Services;
|
|
||||||
using PARR.EsppApi.Settings;
|
using PARR.EsppApi.Settings;
|
||||||
|
|
||||||
namespace PARR.EsppApi
|
namespace PARR.EsppApi
|
||||||
@@ -10,26 +9,37 @@ namespace PARR.EsppApi
|
|||||||
{
|
{
|
||||||
private readonly ILogger<EsppApiService> logger;
|
private readonly ILogger<EsppApiService> logger;
|
||||||
private readonly EsppOrderSettings esppOrderSettings;
|
private readonly EsppOrderSettings esppOrderSettings;
|
||||||
private readonly Espp espp;
|
private readonly EsppHttpService esppHttpService;
|
||||||
|
|
||||||
public EsppApiService(ILogger<EsppApiService> logger, EsppOrderSettings esppOrderSettings, Espp espp)
|
public EsppApiService(ILogger<EsppApiService> logger, EsppOrderSettings esppOrderSettings, EsppHttpService esppHttpService)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.esppOrderSettings = esppOrderSettings;
|
this.esppOrderSettings = esppOrderSettings;
|
||||||
this.espp = espp;
|
this.esppHttpService = esppHttpService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<EsppResultBase<IEnumerable<EsppOrder>>> FindOrdersAsync(FindOrdersQuery query)
|
public async Task<EsppResultBase<IEnumerable<EsppOrder>>> FindOrdersAsync(FindOrdersQuery query)
|
||||||
{
|
{
|
||||||
logger.LogInformation("Привет!");
|
var conditions = new List<string>();
|
||||||
|
|
||||||
// var url = esppOrderSettings.Url;
|
if (!string.IsNullOrEmpty(query.ShortDescriptionContains))
|
||||||
var aaa = await espp.Get();
|
conditions.Add($"title like \"*{query.ShortDescriptionContains}*\"");
|
||||||
logger.LogInformation($"asdasd: {aaa}");
|
if (!string.IsNullOrEmpty(query.TemplateNameContains))
|
||||||
|
conditions.Add($"templateName like \"*{query.TemplateNameContains}*\"");
|
||||||
|
if (query.DateOpen.HasValue)
|
||||||
|
conditions.Add($"open.time>='{query.DateOpen.Value.Day}/{query.DateOpen.Value.Month}/{query.DateOpen.Value.Year} 00:00:00'");
|
||||||
|
if (query.DateEnd.HasValue)
|
||||||
|
conditions.Add($"expirationDat<='{query.DateEnd.Value.Day}/{query.DateEnd.Value.Month}/{query.DateEnd.Value.Year} 00:00:00'");
|
||||||
|
|
||||||
var esppOrders = new List<EsppOrder>();
|
if (conditions.Count < 1)
|
||||||
|
{
|
||||||
|
logger.LogDebug("Пришёл пустой запрос в EsppHttpService.FindOrdersAsync");
|
||||||
|
return new EsppResultBase<IEnumerable<EsppOrder>>(null, false);
|
||||||
|
}
|
||||||
|
|
||||||
return new EsppResultBase<IEnumerable<EsppOrder>>(esppOrders, true);
|
var result = await esppHttpService.SendAsync<IEnumerable<EsppOrder>>($"<ROOT operation=\"GetTaskList\" returnFormat=\"json\">{{\"VIEW_QUERY\":\"{string.Join(" and ", conditions)}\"}}</ROOT>");
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,23 @@
|
|||||||
namespace PARR.EsppApi.Models
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace PARR.EsppApi.Models
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Модель наряда из еспп
|
/// Модель наряда из еспп
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EsppOrder
|
public class EsppOrder
|
||||||
{
|
{
|
||||||
|
[JsonPropertyName("recordid")]
|
||||||
public string Number { get; set; } = string.Empty;
|
public string Number { get; set; } = string.Empty;
|
||||||
|
[JsonPropertyName("assignment")]
|
||||||
public string? WorkGroup { get; set; }
|
public string? WorkGroup { get; set; }
|
||||||
|
[JsonPropertyName("status")]
|
||||||
|
public string Status { get; set; } = string.Empty;
|
||||||
|
[JsonPropertyName("title")]
|
||||||
|
public string ShortName { get; set; } = string.Empty;
|
||||||
|
[JsonPropertyName("templateName")]
|
||||||
|
public string TemplateName { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,19 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string? ShortDescriptionContains { get; set; }
|
public string? ShortDescriptionContains { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаблон, содержит значение
|
||||||
|
/// </summary>
|
||||||
|
public string? TemplateNameContains { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Дата - "ПО"
|
/// Дата - "ПО"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime? DateEnd { get; set; }
|
public DateTime? DateEnd { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Дата - "Открытия"
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? DateOpen { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using PARR.EsppApi.Services;
|
|
||||||
using PARR.EsppApi.Settings;
|
using PARR.EsppApi.Settings;
|
||||||
|
|
||||||
namespace PARR.EsppApi
|
namespace PARR.EsppApi
|
||||||
@@ -17,8 +16,12 @@ namespace PARR.EsppApi
|
|||||||
|
|
||||||
services.AddTransient<IEsppApiService, EsppApiService>();
|
services.AddTransient<IEsppApiService, EsppApiService>();
|
||||||
|
|
||||||
services.AddHttpClient<Espp>();
|
services.AddHttpClient<EsppHttpService>(client =>
|
||||||
//add other services
|
{
|
||||||
|
client.BaseAddress = new Uri(esppSettings.Url);
|
||||||
|
client.DefaultRequestHeaders.Add("EsppUser", esppSettings.UserName);
|
||||||
|
client.DefaultRequestHeaders.Add("EsppPassword", esppSettings.Password);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,8 +3,8 @@
|
|||||||
internal class EsppOrderSettings
|
internal class EsppOrderSettings
|
||||||
{
|
{
|
||||||
public string Url { get; set; } = string.Empty;
|
public string Url { get; set; } = string.Empty;
|
||||||
|
public string UserName { get; set; } = string.Empty;
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
|
||||||
//login, pass
|
|
||||||
//todo: add othe
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,10 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Hosting" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.1" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using PARR.EsppApi;
|
using PARR.EsppApi;
|
||||||
using PARR.Test;
|
using PARR.Test;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
IHost host = Host.CreateDefaultBuilder(args)
|
IHost host = Host.CreateDefaultBuilder(args)
|
||||||
.ConfigureServices((hostContext, services) =>
|
.ConfigureServices((hostContext, services) =>
|
||||||
@@ -8,6 +9,12 @@ IHost host = Host.CreateDefaultBuilder(args)
|
|||||||
|
|
||||||
services.AddHostedService<Worker>();
|
services.AddHostedService<Worker>();
|
||||||
})
|
})
|
||||||
|
.UseSerilog((hostContext, services, config) =>
|
||||||
|
{
|
||||||
|
config
|
||||||
|
.WriteTo.Console()
|
||||||
|
.ReadFrom.Configuration(hostContext.Configuration);
|
||||||
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
host.Run();
|
host.Run();
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ namespace PARR.Test
|
|||||||
|
|
||||||
private async Task TestEsppApi()
|
private async Task TestEsppApi()
|
||||||
{
|
{
|
||||||
// var orders = await esppApiService.FindOrdersByPrefixAsync("ПАРР__");
|
var result = await esppApiService.FindOrdersAsync(new FindOrdersQuery { ShortDescriptionContains = "описание", DateOpen = new DateTime(2023, 10, 10) });
|
||||||
var result = await esppApiService.FindOrdersAsync(new FindOrdersQuery { });
|
|
||||||
|
|
||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,5 +4,29 @@
|
|||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft.Hosting.Lifetime": "Information"
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"Serilog": {
|
||||||
|
"MinimumLevel": {
|
||||||
|
"Default": "Debug",
|
||||||
|
"Override": {
|
||||||
|
"Microsoft": "Warning",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Debug"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "log/log-.txt",
|
||||||
|
"rollingInterval": "Day"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
"EsppOrderSettings": {
|
||||||
|
"Url": "http://rzd-espp-t-rpa-app-1.gvc.oao.rzd:8080/espp_api/OperationExecutor/",
|
||||||
|
"UserName": "Auto-PTK-DVS",
|
||||||
|
"Password": "123456789"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,27 @@
|
|||||||
"Microsoft.Hosting.Lifetime": "Information"
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"Serilog": {
|
||||||
|
"MinimumLevel": {
|
||||||
|
"Default": "Debug",
|
||||||
|
"Override": {
|
||||||
|
"Microsoft": "Warning",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Debug"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "log/log-.txt",
|
||||||
|
"rollingInterval": "Day"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"EsppOrderSettings": {
|
"EsppOrderSettings": {
|
||||||
"Url": "http://dafsdf"
|
"Url": "http://rzd-espp-t-rpa-app-1.gvc.oao.rzd:8080/espp_api/OperationExecutor/",
|
||||||
|
"UserName": "Auto-PTK-DVS",
|
||||||
|
"Password": "123456789"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user