Merge branch 'espp-api' into dev
# Conflicts: # PARR.EsppApi/Models/EsppOrder.cs
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.EsppApi.Models;
|
||||
using PARR.EsppApi.Models.Query;
|
||||
using PARR.EsppApi.Services;
|
||||
using PARR.EsppApi.Settings;
|
||||
|
||||
namespace PARR.EsppApi
|
||||
@@ -10,26 +9,37 @@ namespace PARR.EsppApi
|
||||
{
|
||||
private readonly ILogger<EsppApiService> logger;
|
||||
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.esppOrderSettings = esppOrderSettings;
|
||||
this.espp = espp;
|
||||
this.esppHttpService = esppHttpService;
|
||||
}
|
||||
|
||||
public async Task<EsppResultBase<IEnumerable<EsppOrder>>> FindOrdersAsync(FindOrdersQuery query)
|
||||
{
|
||||
logger.LogInformation("Привет!");
|
||||
var conditions = new List<string>();
|
||||
|
||||
// var url = esppOrderSettings.Url;
|
||||
var aaa = await espp.Get();
|
||||
logger.LogInformation($"asdasd: {aaa}");
|
||||
if (!string.IsNullOrEmpty(query.ShortDescriptionContains))
|
||||
conditions.Add($"title like \"*{query.ShortDescriptionContains}*\"");
|
||||
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,18 +1,23 @@
|
||||
namespace PARR.EsppApi.Models
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace PARR.EsppApi.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Модель наряда из еспп
|
||||
/// </summary>
|
||||
public class EsppOrder
|
||||
{
|
||||
[JsonPropertyName("recordid")]
|
||||
public string Number { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("assignment")]
|
||||
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>
|
||||
public string? ShortDescriptionContains { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаблон, содержит значение
|
||||
/// </summary>
|
||||
public string? TemplateNameContains { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата - "ПО"
|
||||
/// </summary>
|
||||
public DateTime? DateEnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата - "Открытия"
|
||||
/// </summary>
|
||||
public DateTime? DateOpen { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using PARR.EsppApi.Services;
|
||||
using PARR.EsppApi.Settings;
|
||||
|
||||
namespace PARR.EsppApi
|
||||
@@ -17,8 +16,12 @@ namespace PARR.EsppApi
|
||||
|
||||
services.AddTransient<IEsppApiService, EsppApiService>();
|
||||
|
||||
services.AddHttpClient<Espp>();
|
||||
//add other services
|
||||
services.AddHttpClient<EsppHttpService>(client =>
|
||||
{
|
||||
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
|
||||
{
|
||||
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>
|
||||
<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>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using PARR.EsppApi;
|
||||
using PARR.Test;
|
||||
using Serilog;
|
||||
|
||||
IHost host = Host.CreateDefaultBuilder(args)
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
@@ -8,6 +9,12 @@ IHost host = Host.CreateDefaultBuilder(args)
|
||||
|
||||
services.AddHostedService<Worker>();
|
||||
})
|
||||
.UseSerilog((hostContext, services, config) =>
|
||||
{
|
||||
config
|
||||
.WriteTo.Console()
|
||||
.ReadFrom.Configuration(hostContext.Configuration);
|
||||
})
|
||||
.Build();
|
||||
|
||||
host.Run();
|
||||
|
||||
@@ -28,8 +28,7 @@ namespace PARR.Test
|
||||
|
||||
private async Task TestEsppApi()
|
||||
{
|
||||
// var orders = await esppApiService.FindOrdersByPrefixAsync("ПАРР__");
|
||||
var result = await esppApiService.FindOrdersAsync(new FindOrdersQuery { });
|
||||
var result = await esppApiService.FindOrdersAsync(new FindOrdersQuery { ShortDescriptionContains = "описание", DateOpen = new DateTime(2023, 10, 10) });
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
|
||||
@@ -4,5 +4,29 @@
|
||||
"Default": "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"
|
||||
}
|
||||
},
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Debug",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Debug"
|
||||
}
|
||||
},
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "log/log-.txt",
|
||||
"rollingInterval": "Day"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"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