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 _logger; private readonly IEsppApiService esppApiService; private readonly IIntervalService intervalService; public Worker(ILogger 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 = "НАР24-00007352"; 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}"); } } } }