diff --git a/PARR.BLL/ParrBllInstaller.cs b/PARR.BLL/ParrBllInstaller.cs index 0796fbdb..04e94e80 100644 --- a/PARR.BLL/ParrBllInstaller.cs +++ b/PARR.BLL/ParrBllInstaller.cs @@ -21,6 +21,7 @@ namespace PARR.BLL services.AddHttpClient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } diff --git a/PARR.BLL/Services/Implementations/CalendarService.cs b/PARR.BLL/Services/Implementations/CalendarService.cs new file mode 100644 index 00000000..be7904df --- /dev/null +++ b/PARR.BLL/Services/Implementations/CalendarService.cs @@ -0,0 +1,69 @@ +using PARR.BLL.Services.Interfaces; + +namespace PARR.BLL.Services.Implementations +{ + public delegate Task> GetWeekendsDelegate(DateOnly start, DateOnly end); + + + internal class CalendarService : ICalendarService + { + + private DateOnly GetEndPeriodDate(DateOnly startPeriod, TimeSpan distributionPeriod) + { + return startPeriod.AddDays(distributionPeriod.Days).AddDays(-1); + } + + + public async Task> GetWorkDatesForPeriodAsync(DateOnly startPeriod, TimeSpan distributionPeriod, GetWeekendsDelegate getWeekends) + { + var endPeriod = GetEndPeriodDate(startPeriod, distributionPeriod); + + + var weekends = await getWeekends.Invoke(startPeriod, endPeriod); + + //TODO: logic!!! + + //временно сделаем список руками рабочих дней + var workDates = new List(); + + + return workDates; + } + } + + + public class Test + { + private readonly ICalendarService calendarService; + + public Test(ICalendarService calendarService) + { + this.calendarService = calendarService; + } + + + public async void Ttt() + { + var tService = new TestService(); + // var endPeriod = calendarService.GetEndPeriodDate(new DateOnly(2024, 1, 1), TimeSpan.Parse("30:00:00:00")); + + var workDays = await calendarService.GetWorkDatesForPeriodAsync(new DateOnly(2024, 1, 1), TimeSpan.Parse("30:00:00:00"), tService.GetWeekendsAsync); + + + } + + + } + + + public class TestService + { + public async Task> GetWeekendsAsync(DateOnly start, DateOnly end) + { + + await Task.Delay(1000); + + return new List { new DateOnly(2024, 1, 12) }; + } + } +} diff --git a/PARR.BLL/Services/Interfaces/ICalendarService.cs b/PARR.BLL/Services/Interfaces/ICalendarService.cs new file mode 100644 index 00000000..82add0bd --- /dev/null +++ b/PARR.BLL/Services/Interfaces/ICalendarService.cs @@ -0,0 +1,13 @@ + +using PARR.BLL.Services.Implementations; + +namespace PARR.BLL.Services.Interfaces +{ + public interface ICalendarService + { + + Task> GetWorkDatesForPeriodAsync(DateOnly startPeriod, TimeSpan distributionPeriod, GetWeekendsDelegate getWeekends); + //Task> GetWorkDatesForPeriodAsync(DateOnly startPeriod, TimeSpan distributionPeriod, Action> getWeekends); + //Task> GetWorkDatesForPeriodAsync(DateOnly startPeriod, TimeSpan distributionPeriod, Action getWeekends); + } +} diff --git a/PARR.Test/Worker.cs b/PARR.Test/Worker.cs index 233dccbf..ac308c9b 100644 --- a/PARR.Test/Worker.cs +++ b/PARR.Test/Worker.cs @@ -11,16 +11,19 @@ namespace PARR.Test private readonly ILogger _logger; private readonly IEsppApiService esppApiService; private readonly IIntervalService intervalService; + private readonly ICalendarService calendarService; public Worker( ILogger logger, IEsppApiService esppApiService, - IIntervalService intervalService + IIntervalService intervalService, + ICalendarService calendarService ) { _logger = logger; this.esppApiService = esppApiService; this.intervalService = intervalService; + this.calendarService = calendarService; } protected override async Task ExecuteAsync(CancellationToken stoppingToken) @@ -33,7 +36,14 @@ namespace PARR.Test #endregion + #region Calendar + var testCalendar = new BLL.Services.Implementations.Test(calendarService); + + testCalendar.Ttt() ; + + + #endregion ////test interval