diff --git a/PARR.API/Contracts/V1/ApiRoutes.cs b/PARR.API/Contracts/V1/ApiRoutes.cs index aef688e4..62ed8bf3 100644 --- a/PARR.API/Contracts/V1/ApiRoutes.cs +++ b/PARR.API/Contracts/V1/ApiRoutes.cs @@ -50,6 +50,13 @@ public static class Test { public const string GetMyIp = Base + "/tests/my-ip"; + + public const string GetNextScheduleDate = Base + "/tests/next-schedule-date/" + paramApplicationInWorkId + "/" + paramDate; + + public const string GetNextSchedule = Base + "/tests/next-schedule/" + paramApplicationInWorkId + "/" + paramDate; + + public const string paramDate = "{lastRunDate}"; + public const string paramApplicationInWorkId = "{applicationInWorkId}"; } public static class Template diff --git a/PARR.API/Controllers/V1/TestController.cs b/PARR.API/Controllers/V1/TestController.cs index 5de24fa7..1d6087a1 100644 --- a/PARR.API/Controllers/V1/TestController.cs +++ b/PARR.API/Controllers/V1/TestController.cs @@ -3,16 +3,19 @@ using PARR.API.Contracts.V1; using PARR.API.Contracts.V1.Responses.Base; using PARR.API.Controllers.V1.Base; using PARR.API.Services.Interfaces; +using PARR.DAL.TransformServices; namespace PARR.API.Controllers.V1 { public class TestController : BaseApiController { private readonly IClientService clientService; + private readonly IEsppScheduleTransformService esppScheduleTransformService; - public TestController(IClientService clientService) + public TestController(IClientService clientService, IEsppScheduleTransformService esppScheduleTransformService) { this.clientService = clientService; + this.esppScheduleTransformService = esppScheduleTransformService; } @@ -31,5 +34,33 @@ namespace PARR.API.Controllers.V1 return Ok(new Response(new { ip }, true)); } + + + /// + /// Получить следующую дату запуска + /// + /// + /// + /// + [HttpGet(ApiRoutes.Test.GetNextScheduleDate)] + public async Task GetNextScheduleDate([FromRoute] Guid applicationInWorkId, [FromRoute] DateTimeOffset lastRunDate) + { + var result = await esppScheduleTransformService.GetNextDateAsync(applicationInWorkId, lastRunDate); + return Ok(result); + } + + + /// + /// Получить следующее расписание + /// + /// + /// + /// + [HttpGet(ApiRoutes.Test.GetNextSchedule)] + public async Task GetNextSchedule([FromRoute] Guid applicationInWorkId, [FromRoute] DateTimeOffset lastRunDate) + { + var result = await esppScheduleTransformService.GetNextScheduleAsync(applicationInWorkId, lastRunDate); + return Ok(result); + } } } diff --git a/PARR.DAL/ParrDalInstaller.cs b/PARR.DAL/ParrDalInstaller.cs index c42ae526..137b34f8 100644 --- a/PARR.DAL/ParrDalInstaller.cs +++ b/PARR.DAL/ParrDalInstaller.cs @@ -11,6 +11,7 @@ using PARR.DAL.Services.Implementations.V1; using PARR.DAL.Services.Interfaces; using PARR.DAL.Services.Interfaces.AIHIT; using PARR.DAL.Services.Interfaces.V1; +using PARR.DAL.TransformServices; namespace PARR.DAL { @@ -56,6 +57,10 @@ namespace PARR.DAL services.AddTransient(); services.AddTransient(); services.AddTransient(); + + + // TransformServices + services.AddTransient(); } /// diff --git a/PARR.DAL/TransformServices/EsppScheduleTransformService.cs b/PARR.DAL/TransformServices/EsppScheduleTransformService.cs new file mode 100644 index 00000000..7c871a8f --- /dev/null +++ b/PARR.DAL/TransformServices/EsppScheduleTransformService.cs @@ -0,0 +1,64 @@ +using Microsoft.Extensions.Logging; +using PARR.DAL.DomainModels; +using PARR.DAL.Services.Interfaces; + +namespace PARR.DAL.TransformServices +{ + internal class EsppScheduleTransformService : IEsppScheduleTransformService + { + private readonly IEsppSchTypeConfigService esppSchTypeConfigService; + private readonly ILogger logger; + + public EsppScheduleTransformService(IEsppSchTypeConfigService esppSchTypeConfigService, ILogger logger) + { + this.esppSchTypeConfigService = esppSchTypeConfigService; + this.logger = logger; + } + + + public DateTimeOffset GetNextDate(EsppScheduleDto esppSchedule, DateTimeOffset lastRun) + { + //todo: + + return lastRun; + } + + + public List GetNextSchedule(EsppScheduleDto esppSchedule, DateTimeOffset lastRun) + { + var schedules = new List(); + + //todo: + schedules.Add(lastRun); + + + + return schedules.OrderBy(t => t).ToList(); + } + + + public async Task GetNextDateAsync(Guid applicationInWorkId, DateTimeOffset lastRun) + { + return GetNextDate(await GetEsppSchedule(applicationInWorkId), lastRun); + } + + + public async Task> GetNextScheduleAsync(Guid applicationInWorkId, DateTimeOffset lastRun) + { + return GetNextSchedule(await GetEsppSchedule(applicationInWorkId), lastRun); + } + + + private async Task GetEsppSchedule(Guid applicationInWorkId) + { + var esppSchedule = await esppSchTypeConfigService.GetEsppScheduleDtoAsync(applicationInWorkId); + if (esppSchedule == null) + { + logger.LogError($"Не найдено расписание в БД, applicationInWorkId: {applicationInWorkId}"); + throw new Exception($"Не найдено расписание в БД, applicationInWorkId: {applicationInWorkId}"); + } + + return esppSchedule; + } + } +} diff --git a/PARR.DAL/TransformServices/IEsppScheduleTransformService.cs b/PARR.DAL/TransformServices/IEsppScheduleTransformService.cs new file mode 100644 index 00000000..00456299 --- /dev/null +++ b/PARR.DAL/TransformServices/IEsppScheduleTransformService.cs @@ -0,0 +1,42 @@ +using PARR.DAL.DomainModels; + +namespace PARR.DAL.TransformServices +{ + /// + /// Сервис трансформации расписания ЕСПП в дату/расписание + /// + public interface IEsppScheduleTransformService + { + /// + /// Получить следующую дату согласно расписания + /// + /// + /// + /// + DateTimeOffset GetNextDate(EsppScheduleDto esppSchedule, DateTimeOffset lastRun); + + /// + /// Получить расписание + /// + /// + /// + /// + List GetNextSchedule(EsppScheduleDto esppSchedule, DateTimeOffset lastRun); + + /// + /// Получить следующую дату по applicationInWorkId + /// + /// + /// + /// + Task GetNextDateAsync(Guid applicationInWorkId, DateTimeOffset lastRun); + + /// + /// Получить расписание по applicationInWorkId + /// + /// + /// + /// + Task> GetNextScheduleAsync(Guid applicationInWorkId, DateTimeOffset lastRun); + } +}