feat(bll): заготовка ICalendarService
This commit is contained in:
@@ -21,6 +21,7 @@ namespace PARR.BLL
|
||||
services.AddHttpClient<IMqAdminService, MqAdminService>();
|
||||
services.AddTransient<ITransformService, TransformService>();
|
||||
services.AddTransient<IIntervalService, IntervalService>();
|
||||
services.AddTransient<ICalendarService, CalendarService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
69
PARR.BLL/Services/Implementations/CalendarService.cs
Normal file
69
PARR.BLL/Services/Implementations/CalendarService.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using PARR.BLL.Services.Interfaces;
|
||||
|
||||
namespace PARR.BLL.Services.Implementations
|
||||
{
|
||||
public delegate Task<List<DateOnly>> 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<List<DateOnly>> 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<DateOnly>();
|
||||
|
||||
|
||||
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<List<DateOnly>> GetWeekendsAsync(DateOnly start, DateOnly end)
|
||||
{
|
||||
|
||||
await Task.Delay(1000);
|
||||
|
||||
return new List<DateOnly> { new DateOnly(2024, 1, 12) };
|
||||
}
|
||||
}
|
||||
}
|
||||
13
PARR.BLL/Services/Interfaces/ICalendarService.cs
Normal file
13
PARR.BLL/Services/Interfaces/ICalendarService.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
using PARR.BLL.Services.Implementations;
|
||||
|
||||
namespace PARR.BLL.Services.Interfaces
|
||||
{
|
||||
public interface ICalendarService
|
||||
{
|
||||
|
||||
Task<List<DateOnly>> GetWorkDatesForPeriodAsync(DateOnly startPeriod, TimeSpan distributionPeriod, GetWeekendsDelegate getWeekends);
|
||||
//Task<List<DateOnly>> GetWorkDatesForPeriodAsync(DateOnly startPeriod, TimeSpan distributionPeriod, Action<List<DateOnly>> getWeekends);
|
||||
//Task<List<DateOnly>> GetWorkDatesForPeriodAsync(DateOnly startPeriod, TimeSpan distributionPeriod, Action getWeekends);
|
||||
}
|
||||
}
|
||||
@@ -11,16 +11,19 @@ namespace PARR.Test
|
||||
private readonly ILogger<Worker> _logger;
|
||||
private readonly IEsppApiService esppApiService;
|
||||
private readonly IIntervalService intervalService;
|
||||
private readonly ICalendarService calendarService;
|
||||
|
||||
public Worker(
|
||||
ILogger<Worker> 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
|
||||
|
||||
Reference in New Issue
Block a user