feat(bll, dal): WeekendDayService + БД. CalendarService - получение рабочих дней за период
This commit is contained in:
@@ -2,68 +2,92 @@
|
|||||||
|
|
||||||
namespace PARR.BLL.Services.Implementations
|
namespace PARR.BLL.Services.Implementations
|
||||||
{
|
{
|
||||||
public delegate Task<List<DateOnly>> GetWeekendsDelegate(DateOnly start, DateOnly end);
|
|
||||||
|
|
||||||
|
|
||||||
internal class CalendarService : ICalendarService
|
internal class CalendarService : ICalendarService
|
||||||
{
|
{
|
||||||
|
|
||||||
private DateOnly GetEndPeriodDate(DateOnly startPeriod, TimeSpan distributionPeriod)
|
private DateOnly GetEndPeriodDate(DateOnly startPeriod, TimeSpan distributionPeriod)
|
||||||
{
|
{
|
||||||
return startPeriod.AddDays(distributionPeriod.Days).AddDays(-1);
|
return startPeriod.AddDays(distributionPeriod.Days).AddDays(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<List<DateOnly>> GetWorkDatesForPeriodAsync(DateOnly startPeriod, TimeSpan distributionPeriod, GetWeekendsDelegate getWeekends)
|
public List<DateOnly> GetWorkDatesForPeriod(DateOnly startPeriod, TimeSpan distributionPeriod, GetWeekendsDelegate getWeekends)
|
||||||
{
|
{
|
||||||
var endPeriod = GetEndPeriodDate(startPeriod, distributionPeriod);
|
var endPeriod = GetEndPeriodDate(startPeriod, distributionPeriod);
|
||||||
|
|
||||||
|
//не получилось сделать асинхронным
|
||||||
|
var weekends = getWeekends.Invoke(startPeriod, endPeriod).ToList(); //.ToListAsync();
|
||||||
|
|
||||||
var weekends = await getWeekends.Invoke(startPeriod, endPeriod);
|
|
||||||
|
|
||||||
//TODO: logic!!!
|
|
||||||
|
|
||||||
|
//TODO: переделать метод получения рабочих дней, получать актуальные рабочие дни за период
|
||||||
|
//не стали реализовывать сразу, так как повысится нагрузка на робота
|
||||||
|
// на следующий месяц будет много изменений
|
||||||
//временно сделаем список руками рабочих дней
|
//временно сделаем список руками рабочих дней
|
||||||
var workDates = new List<DateOnly>();
|
var workDays = GetMockWorkDays(startPeriod, endPeriod);
|
||||||
|
|
||||||
|
workDays = workDays.Where(t => weekends.Any(x => x != t)).ToList();
|
||||||
|
|
||||||
return workDates;
|
return workDays;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class Test
|
/// <summary>
|
||||||
|
/// Временные данные пока не реализован сервис и логика
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="startPeriod"></param>
|
||||||
|
/// <param name="EndPeriod"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private List<DateOnly> GetMockWorkDays(DateOnly startPeriod, DateOnly EndPeriod)
|
||||||
{
|
{
|
||||||
private readonly ICalendarService calendarService;
|
var workDaysList = new List<DateOnly>();
|
||||||
|
|
||||||
public Test(ICalendarService calendarService)
|
var currentDay = startPeriod;
|
||||||
|
while (currentDay <= EndPeriod)
|
||||||
{
|
{
|
||||||
this.calendarService = calendarService;
|
// 29 дней, потому что в феврале 28, чтоб не париться, сделали так
|
||||||
|
if (currentDay.Day < 29)
|
||||||
|
workDaysList.Add(currentDay);
|
||||||
|
|
||||||
|
|
||||||
|
currentDay = currentDay.AddDays(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return workDaysList.OrderBy(t => t).ToList();
|
||||||
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) };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//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) };
|
||||||
|
// }
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
|
namespace PARR.BLL.Services.Interfaces
|
||||||
using PARR.BLL.Services.Implementations;
|
|
||||||
|
|
||||||
namespace PARR.BLL.Services.Interfaces
|
|
||||||
{
|
{
|
||||||
|
public delegate IQueryable<DateOnly> GetWeekendsDelegate(DateOnly start, DateOnly end);
|
||||||
|
|
||||||
public interface ICalendarService
|
public interface ICalendarService
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
Task<List<DateOnly>> GetWorkDatesForPeriodAsync(DateOnly startPeriod, TimeSpan distributionPeriod, GetWeekendsDelegate getWeekends);
|
/// Получить только рабочие дни за период
|
||||||
//Task<List<DateOnly>> GetWorkDatesForPeriodAsync(DateOnly startPeriod, TimeSpan distributionPeriod, Action<List<DateOnly>> getWeekends);
|
/// </summary>
|
||||||
//Task<List<DateOnly>> GetWorkDatesForPeriodAsync(DateOnly startPeriod, TimeSpan distributionPeriod, Action getWeekends);
|
/// <param name="startPeriod"></param>
|
||||||
|
/// <param name="distributionPeriod"></param>
|
||||||
|
/// <param name="getWeekends"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
List<DateOnly> GetWorkDatesForPeriod(DateOnly startPeriod, TimeSpan distributionPeriod, GetWeekendsDelegate getWeekends);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ namespace PARR.DAL.Context
|
|||||||
public DbSet<Models.Role> Roles { get; set; }
|
public DbSet<Models.Role> Roles { get; set; }
|
||||||
public DbSet<UsersInRole> UsersInRoles { get; set; }
|
public DbSet<UsersInRole> UsersInRoles { get; set; }
|
||||||
|
|
||||||
|
public DbSet<WeekendDay> WeekendDays { get; set; }
|
||||||
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
|||||||
2778
PARR.DAL/Migrations/20240701003839_tblWeekendDaysCreate.Designer.cs
generated
Normal file
2778
PARR.DAL/Migrations/20240701003839_tblWeekendDaysCreate.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
34
PARR.DAL/Migrations/20240701003839_tblWeekendDaysCreate.cs
Normal file
34
PARR.DAL/Migrations/20240701003839_tblWeekendDaysCreate.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace PARR.DAL.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class tblWeekendDaysCreate : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "WeekendDays",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
Date = table.Column<DateOnly>(type: "date", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_WeekendDays", x => x.Id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "WeekendDays");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2204,6 +2204,20 @@ namespace PARR.DAL.Migrations
|
|||||||
b.ToTable("UsersInRoles");
|
b.ToTable("UsersInRoles");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PARR.DAL.Models.WeekendDay", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateOnly>("Date")
|
||||||
|
.HasColumnType("date");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("WeekendDays");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("PARR.DAL.Models.Work", b =>
|
modelBuilder.Entity("PARR.DAL.Models.Work", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
|
|||||||
21
PARR.DAL/Models/WeekendDay.cs
Normal file
21
PARR.DAL/Models/WeekendDay.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using PARR.DAL.Models.Base;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace PARR.DAL.Models
|
||||||
|
{
|
||||||
|
[Table("WeekendDays")]
|
||||||
|
public class WeekendDay : IBase
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public DateTimeOffset DateCreated { get; set; }
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public DateTimeOffset? DateModified { get; set; }
|
||||||
|
|
||||||
|
public DateOnly Date { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -80,6 +80,7 @@ namespace PARR.DAL
|
|||||||
services.AddTransient<ITaskStatusService, TaskStatusService>();
|
services.AddTransient<ITaskStatusService, TaskStatusService>();
|
||||||
services.AddTransient<IEkStatusService, EkStatusService>();
|
services.AddTransient<IEkStatusService, EkStatusService>();
|
||||||
services.AddTransient<IEsppSchTypeScheduleService, EsppSchTypeScheduleService>();
|
services.AddTransient<IEsppSchTypeScheduleService, EsppSchTypeScheduleService>();
|
||||||
|
services.AddTransient<IWeekendDayService, WeekendDayService>();
|
||||||
|
|
||||||
// TransformServices
|
// TransformServices
|
||||||
services.AddTransient<IEsppScheduleTransformService, EsppScheduleTransformService>();
|
services.AddTransient<IEsppScheduleTransformService, EsppScheduleTransformService>();
|
||||||
|
|||||||
32
PARR.DAL/Services/Implementations/WeekendDayService.cs
Normal file
32
PARR.DAL/Services/Implementations/WeekendDayService.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using PARR.DAL.Context;
|
||||||
|
using PARR.DAL.Models;
|
||||||
|
using PARR.DAL.Services.Abstracts;
|
||||||
|
using PARR.DAL.Services.Interfaces;
|
||||||
|
|
||||||
|
namespace PARR.DAL.Services.Implementations
|
||||||
|
{
|
||||||
|
internal class WeekendDayService : BaseService<WeekendDay>, IWeekendDayService
|
||||||
|
{
|
||||||
|
private readonly DataContext dataContext;
|
||||||
|
private readonly ILogger<WeekendDayService> logger;
|
||||||
|
|
||||||
|
protected override DbSet<WeekendDay> EntitySet => dataContext.WeekendDays;
|
||||||
|
|
||||||
|
protected override DataContext EntitiContext => dataContext;
|
||||||
|
|
||||||
|
public WeekendDayService(DataContext dataContext, ILogger<WeekendDayService> logger) : base(logger)
|
||||||
|
{
|
||||||
|
this.dataContext = dataContext;
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public IQueryable<DateOnly> GetWeekends(DateOnly start, DateOnly end)
|
||||||
|
{
|
||||||
|
return EntitySet.Where(t => t.Date >= start && t.Date <= end).Select(t => t.Date);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
10
PARR.DAL/Services/Interfaces/IWeekendDayService.cs
Normal file
10
PARR.DAL/Services/Interfaces/IWeekendDayService.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using PARR.DAL.Models;
|
||||||
|
using PARR.DAL.Services.Interfaces.Base;
|
||||||
|
|
||||||
|
namespace PARR.DAL.Services.Interfaces
|
||||||
|
{
|
||||||
|
public interface IWeekendDayService : IBaseService<WeekendDay>
|
||||||
|
{
|
||||||
|
IQueryable<DateOnly> GetWeekends(DateOnly start, DateOnly end);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\PARR.BLL\PARR.BLL.csproj" />
|
<ProjectReference Include="..\PARR.BLL\PARR.BLL.csproj" />
|
||||||
|
<ProjectReference Include="..\PARR.DAL\PARR.DAL.csproj" />
|
||||||
<ProjectReference Include="..\PARR.EsppApi\PARR.EsppApi.csproj" />
|
<ProjectReference Include="..\PARR.EsppApi\PARR.EsppApi.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using PARR.BLL;
|
using PARR.BLL;
|
||||||
using PARR.EsppApi;
|
using PARR.EsppApi;
|
||||||
|
using PARR.DAL;
|
||||||
using PARR.Test;
|
using PARR.Test;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
@@ -8,6 +9,7 @@ IHost host = Host.CreateDefaultBuilder(args)
|
|||||||
{
|
{
|
||||||
services.InstallEsppApiServices(hostContext.Configuration);
|
services.InstallEsppApiServices(hostContext.Configuration);
|
||||||
services.InstallBllServices(hostContext.Configuration);
|
services.InstallBllServices(hostContext.Configuration);
|
||||||
|
services.InstallDalServices(hostContext.Configuration);
|
||||||
|
|
||||||
services.AddHostedService<Worker>();
|
services.AddHostedService<Worker>();
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using PARR.BLL.Services.Interfaces;
|
using PARR.BLL.Services.Interfaces;
|
||||||
using PARR.Constants;
|
using PARR.Constants;
|
||||||
|
using PARR.DAL.Services.Interfaces;
|
||||||
using PARR.EsppApi;
|
using PARR.EsppApi;
|
||||||
using PARR.EsppApi.Constants;
|
using PARR.EsppApi.Constants;
|
||||||
using PARR.EsppApi.Models.Query;
|
using PARR.EsppApi.Models.Query;
|
||||||
@@ -12,18 +13,21 @@ namespace PARR.Test
|
|||||||
private readonly IEsppApiService esppApiService;
|
private readonly IEsppApiService esppApiService;
|
||||||
private readonly IIntervalService intervalService;
|
private readonly IIntervalService intervalService;
|
||||||
private readonly ICalendarService calendarService;
|
private readonly ICalendarService calendarService;
|
||||||
|
private readonly IServiceProvider serviceProvider;
|
||||||
|
|
||||||
public Worker(
|
public Worker(
|
||||||
ILogger<Worker> logger,
|
ILogger<Worker> logger,
|
||||||
IEsppApiService esppApiService,
|
IEsppApiService esppApiService,
|
||||||
IIntervalService intervalService,
|
IIntervalService intervalService,
|
||||||
ICalendarService calendarService
|
ICalendarService calendarService,
|
||||||
|
IServiceProvider serviceProvider
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
this.esppApiService = esppApiService;
|
this.esppApiService = esppApiService;
|
||||||
this.intervalService = intervalService;
|
this.intervalService = intervalService;
|
||||||
this.calendarService = calendarService;
|
this.calendarService = calendarService;
|
||||||
|
this.serviceProvider = serviceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
@@ -38,9 +42,18 @@ namespace PARR.Test
|
|||||||
|
|
||||||
#region Calendar
|
#region Calendar
|
||||||
|
|
||||||
var testCalendar = new BLL.Services.Implementations.Test(calendarService);
|
//var testCalendar = new BLL.Services.Implementations.Test(calendarService);
|
||||||
|
|
||||||
|
//testCalendar.Ttt() ;
|
||||||
|
//using (var scope = serviceProvider.CreateScope())
|
||||||
|
//{
|
||||||
|
// var weekendDayService = scope.ServiceProvider.GetService<IWeekendDayService>();
|
||||||
|
|
||||||
|
// var workDays = calendarService.GetWorkDatesForPeriod(new DateOnly(2024, 07, 01), TimeSpan.Parse("30:00:00:00"), weekendDayService!.GetWeekends);
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
testCalendar.Ttt() ;
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
{
|
{
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"DefaultConnection": "Server=10.99.253.184;Database=parr;User Id=app_parr; Password=PosdfkhT&)%sdfligL&%5546;"
|
||||||
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
|
|||||||
Reference in New Issue
Block a user