Files
parr_api/PARR.Test/Worker.cs

81 lines
3.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using PARR.BLL.Services.Interfaces;
using PARR.EsppApi;
using PARR.EsppApi.Constants;
using PARR.EsppApi.Models.Query;
namespace PARR.Test
{
public class Worker : BackgroundService
{
private readonly ILogger<Worker> _logger;
private readonly IEsppApiService esppApiService;
private readonly IIntervalService intervalService;
public Worker(ILogger<Worker> logger, IEsppApiService esppApiService, IIntervalService intervalService)
{
_logger = logger;
this.esppApiService = esppApiService;
this.intervalService = intervalService;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
////test interval
//await intervalService.IntervalInitAsync(async () =>
//{
// _logger.LogInformation("---Выполняю метод---");
// await Task.Delay(29*1000);
// _logger.LogInformation("===Выполнил метод===");
//}, new TimeSpan(0, 0, 30));
await TestEsppApi();
}
private async Task TestEsppApi()
{
//var result = await esppApiService.FindOrdersAsync(new FindOrdersQuery { DescriptionContains = "Полное", GenerateDateStart = new DateTime(2023, 10, 10) , GenerateDateEnd = new DateTime(2023, 10, 24) });
var recordId = "НАР23-00046650";
var result = await esppApiService.FindOrderByRecordIdAsync(recordId);
if (result.IsSuccess && (result.Data != null && result.Data.Number.Any()))
{
//var orders = result.Data;
var inWorkResult = await esppApiService.SetStatusInWorkAsync(recordId, "Решение...\nС новой строки");
if (!inWorkResult.IsSuccess)
{
_logger.LogError(inWorkResult.Exception, $"Не удалось взять в работу наряда{recordId}");
return;
}
var tnk = new AddMtnkQuery { RecordId = recordId, JobOperation = "Не учтена в перечне ТНК", Time = "00:05" };
var addMtnkResult = await esppApiService.AddMTnkAsync(tnk);
if (!addMtnkResult.IsSuccess)
{
_logger.LogError(addMtnkResult.Exception, $"Не удалось списать трудозатраты наряда {recordId}");
return;
}
var resFinish = await esppApiService.SetStatusIsDoneAsync(recordId, "Решение...", EsppOrderClosingCodeEnum.Auto);
if (!resFinish.IsSuccess)
{
_logger.LogError(resFinish.Exception, $"Не удалось обновить статус наряда {recordId}");
return;
}
}
else
{
_logger.LogWarning($"не найден наряд {recordId}");
}
}
}
}