feat(distributor): реализована логика распределения всех шаблонов в методе DistributeTemplatesAsync
This commit is contained in:
99
PARR.Test/NextRun/NextRunTest.cs
Normal file
99
PARR.Test/NextRun/NextRunTest.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using PARR.DAL.NextRunServices.Models;
|
||||
using PARR.DAL.NextRunServices.Subservices;
|
||||
|
||||
namespace PARR.Test.NextRun
|
||||
{
|
||||
internal class NextRunTest
|
||||
{
|
||||
private readonly ITemplateDistributor templateDistributor;
|
||||
|
||||
public NextRunTest(ITemplateDistributor templateDistributor)
|
||||
{
|
||||
this.templateDistributor = templateDistributor;
|
||||
}
|
||||
|
||||
int periodDays = 5;
|
||||
DateTimeOffset referenceDate = new DateTimeOffset(2025, 12, 1, 7, 0, 0, TimeSpan.Zero);
|
||||
|
||||
public async Task Test()
|
||||
{
|
||||
await DistributeTemplatesAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// распределить шаблоны
|
||||
/// </summary>
|
||||
private async Task DistributeTemplatesAsync()
|
||||
{
|
||||
var templates = await templateDistributor.DistributeTemplatesAsync(GetDateStart(), periodDays, referenceDate, GetTemplates());
|
||||
|
||||
//await GetValidNextRunForTemplateAsync(templates);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// получить nextRun
|
||||
/// </summary>
|
||||
private async Task GetValidNextRunForTemplateAsync(List<TemplateNextRunDto>? templates = null)
|
||||
{
|
||||
//var templateList = templates ?? GetTemplates();
|
||||
|
||||
//var targetTemplate = new TemplateNextRunDto { Id= Guid.Parse("4C2F61E9-7B47-4049-A881-9200D71303F7"), NextRun= new DateTimeOffset(2025, 12, 1, 3, 0, 0, TimeSpan.Zero) };
|
||||
|
||||
//var distribTemplates = await templateDistributor.GetValidNextRunForTemplateAsync(GetDateStart(), GetDateEnd(), referenceDate, targetTemplate, templateList);
|
||||
|
||||
//// еще раз
|
||||
//templateList.Add(targetTemplate);
|
||||
//var targetTemplate2 = new TemplateNextRunDto { Id = Guid.Parse("4C2F61E9-7B47-4049-A881-9200D71303F7"), NextRun = new DateTimeOffset(2025, 12, 1, 3, 0, 0, TimeSpan.Zero) };
|
||||
//var distribTemplates2 = await templateDistributor.GetValidNextRunForTemplateAsync(GetDateStart(), GetDateEnd(), referenceDate, targetTemplate2, templateList);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private DateOnly GetDateStart()
|
||||
{
|
||||
var today = DateOnly.FromDateTime(DateTime.UtcNow.Date);
|
||||
|
||||
var refDate = DateOnly.FromDateTime(referenceDate.Date);
|
||||
|
||||
return today < refDate ? refDate : today;
|
||||
}
|
||||
|
||||
//private DateOnly GetDateEnd()
|
||||
//{
|
||||
// return GetDateStart().AddDays(periodDays);
|
||||
//}
|
||||
|
||||
|
||||
private List<TemplateNextRunDto> GetTemplates()
|
||||
{
|
||||
var templates = new List<TemplateNextRunDto>();
|
||||
|
||||
templates.Add(new TemplateNextRunDto { Id = Guid.Parse("55F047E6-3631-4676-8959-FC75FF6BC963"), NextRun = new DateTimeOffset(2027, 1, 15, 3, 0, 0, TimeSpan.Zero) });
|
||||
templates.Add(new TemplateNextRunDto { Id = Guid.Parse("DD15E9F6-AAD4-4FE6-9441-7E7FF67781A3"), NextRun = new DateTimeOffset(2025, 12, 24, 3, 0, 0, TimeSpan.Zero) });
|
||||
|
||||
templates.Add(new TemplateNextRunDto { Id = Guid.Parse("78EE4A94-DBEE-41D1-B51A-CE3BD5AEE4D4"), NextRun = new DateTimeOffset(2025, 12, 29, 3, 0, 0, TimeSpan.Zero) });
|
||||
templates.Add(new TemplateNextRunDto { Id = Guid.Parse("B397F1FE-DF2B-4B50-B8D6-2DABECD3D5A1"), NextRun = new DateTimeOffset(2025, 12, 18, 3, 0, 0, TimeSpan.Zero) });
|
||||
templates.Add(new TemplateNextRunDto { Id = Guid.Parse("619D9621-2B45-4108-AF54-CF96862A8E9B"), NextRun = new DateTimeOffset(2025, 12, 18, 3, 0, 0, TimeSpan.Zero) });
|
||||
templates.Add(new TemplateNextRunDto { Id = Guid.Parse("D74D831C-D435-46BF-9B5F-A24884AAA7DC"), NextRun = new DateTimeOffset(2025, 12, 25, 3, 0, 0, TimeSpan.Zero) });
|
||||
templates.Add(new TemplateNextRunDto { Id = Guid.Parse("DE7241F1-5C62-4164-A3DC-99B946350E10"), NextRun = new DateTimeOffset(2025, 12, 18, 3, 0, 0, TimeSpan.Zero) });
|
||||
templates.Add(new TemplateNextRunDto { Id = Guid.Parse("94A7375E-D1BD-49B7-9186-D26E85F1CF74"), NextRun = new DateTimeOffset(2025, 12, 18, 3, 0, 0, TimeSpan.Zero) });
|
||||
templates.Add(new TemplateNextRunDto { Id = Guid.Parse("B3681F5F-10A5-425C-BBEA-EA2B85FE0967"), NextRun = new DateTimeOffset(2025, 12, 18, 3, 0, 0, TimeSpan.Zero) });
|
||||
templates.Add(new TemplateNextRunDto { Id = Guid.Parse("3259B408-48A3-4995-AF9A-097477ECAB81"), NextRun = new DateTimeOffset(2025, 12, 18, 3, 0, 0, TimeSpan.Zero) });
|
||||
templates.Add(new TemplateNextRunDto { Id = Guid.Parse("25F53A28-D657-4B9A-82F3-CE9AF4D53385"), NextRun = new DateTimeOffset(2025, 12, 30, 3, 0, 0, TimeSpan.Zero) });
|
||||
//templates.Add(new TemplateNextRunDto { Id = Guid.Parse("F75F6B1A-875F-4CB2-98C8-6721FD06C18C"), NextRun = new DateTimeOffset(2025, 12, 18, 3, 0, 0, TimeSpan.Zero) });
|
||||
//templates.Add(new TemplateNextRunDto { Id = Guid.Parse("2C06C63D-BE92-4312-98FB-0547E74B8A33"), NextRun = new DateTimeOffset(2025, 12, 18, 3, 0, 0, TimeSpan.Zero) });
|
||||
//templates.Add(new TemplateNextRunDto { Id = Guid.Parse("B22D314E-9F86-49BB-826F-20919EC55A7F"), NextRun = new DateTimeOffset(2025, 12, 18, 3, 0, 0, TimeSpan.Zero) });
|
||||
//templates.Add(new TemplateNextRunDto { Id = Guid.Parse("061CB58A-B350-456F-8E02-C937D488D6FC"), NextRun = null });
|
||||
|
||||
//templates.Add(new TemplateNextRunDto { Id = Guid.Parse("C51E2C3F-655D-4395-BF9D-D6D64DA314D9"), NextRun = null });
|
||||
//templates.Add(new TemplateNextRunDto { Id = Guid.Parse("C9A77DEF-0FB8-4903-87B7-16B8C3EC97A4"), NextRun = null });
|
||||
//templates.Add(new TemplateNextRunDto { Id = Guid.Parse("EC703575-B38F-4A7F-9010-BBB3F92EDEA9"), NextRun = null });
|
||||
//templates.Add(new TemplateNextRunDto { Id = Guid.Parse("188181C3-AACD-4205-BCB6-7414966CB33B"), NextRun = null });
|
||||
|
||||
|
||||
return templates;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
using PARR.BLL;
|
||||
using PARR.EsppApi;
|
||||
using PARR.DAL;
|
||||
using PARR.Test;
|
||||
using Serilog;
|
||||
using PARR.TemplateDistributor;
|
||||
using Elastic.CommonSchema.Serilog;
|
||||
using PARR.BLL;
|
||||
using PARR.DAL;
|
||||
using PARR.EsppApi;
|
||||
using PARR.TemplateDistributor;
|
||||
using PARR.Test;
|
||||
using PARR.Test.NextRun;
|
||||
using Serilog;
|
||||
|
||||
/*IHost host = Host.CreateDefaultBuilder(args)
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
@@ -48,6 +49,8 @@ builder.Services.InstallBllServices(builder.Configuration);
|
||||
builder.Configuration.AddDalConfigurations(builder.Services);
|
||||
builder.Services.AddDallSettings(builder.Configuration);
|
||||
|
||||
builder.Services.AddTransient<NextRunTest>();
|
||||
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
|
||||
var host = builder.Build();
|
||||
|
||||
@@ -6,6 +6,7 @@ using PARR.DAL.Services.Interfaces;
|
||||
using PARR.EsppApi;
|
||||
using PARR.EsppApi.Constants;
|
||||
using PARR.EsppApi.Models.Query;
|
||||
using PARR.Test.NextRun;
|
||||
|
||||
namespace PARR.Test
|
||||
{
|
||||
@@ -34,6 +35,19 @@ namespace PARR.Test
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
|
||||
#region NextRunTest
|
||||
|
||||
using (var scope = serviceProvider.CreateScope())
|
||||
{
|
||||
var service = scope.ServiceProvider.GetService<NextRunTest>();
|
||||
|
||||
await service!.Test();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region test
|
||||
//using (var scope = serviceProvider.CreateScope())
|
||||
//{
|
||||
|
||||
Reference in New Issue
Block a user