2025-12-22 17:03:41 +10:00
|
|
|
|
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2026-01-20 15:04:36 +10:00
|
|
|
|
using PARR.DAL.NextRunServices.Subservices;
|
2025-12-22 17:03:41 +10:00
|
|
|
|
using PARR.DAL.Services.Interfaces;
|
|
|
|
|
|
using PARR.DAL.Services.Interfaces.Job;
|
|
|
|
|
|
using PARR.DAL.TransformServices;
|
|
|
|
|
|
|
|
|
|
|
|
namespace PARR.DAL.NextRunServices
|
|
|
|
|
|
{
|
|
|
|
|
|
internal class NextRunService : INextRunService
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ILogger<NextRunService> logger;
|
|
|
|
|
|
private readonly ITemplateService templateService;
|
|
|
|
|
|
private readonly IJobGroupService jobGroupService;
|
|
|
|
|
|
private readonly IEsppScheduleTransformService esppScheduleTransformService;
|
2026-01-20 15:04:36 +10:00
|
|
|
|
private readonly ITemplateDistributor templateDistributor;
|
2025-12-22 17:03:41 +10:00
|
|
|
|
|
|
|
|
|
|
public NextRunService(
|
|
|
|
|
|
ILogger<NextRunService> logger,
|
|
|
|
|
|
ITemplateService templateService,
|
|
|
|
|
|
IJobGroupService jobGroupService,
|
2026-01-20 15:04:36 +10:00
|
|
|
|
IEsppScheduleTransformService esppScheduleTransformService,
|
|
|
|
|
|
ITemplateDistributor templateDistributor
|
2025-12-22 17:03:41 +10:00
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
|
this.templateService = templateService;
|
|
|
|
|
|
this.jobGroupService = jobGroupService;
|
|
|
|
|
|
this.esppScheduleTransformService = esppScheduleTransformService;
|
2026-01-20 15:04:36 +10:00
|
|
|
|
this.templateDistributor = templateDistributor;
|
2025-12-22 17:03:41 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-01-20 15:04:36 +10:00
|
|
|
|
public async Task<List<(Guid TemplateId, DateTimeOffset NextRun)>> GetNextRunForJobGroupWithAutoDistributionAsync(Guid jobGroupId)
|
2025-12-22 17:03:41 +10:00
|
|
|
|
{
|
|
|
|
|
|
//TODO:
|
|
|
|
|
|
throw new NotImplementedException();
|
2026-01-20 15:04:36 +10:00
|
|
|
|
//var ditributedTemplateList = await templateDistributor.DistributeTemplatesAsync();
|
2025-12-22 17:03:41 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<DateTimeOffset> GetNextRunForJobGroupWithEsppSchedulleAsync(Guid jobGroupId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var jobGroup = await jobGroupService.Get().AsNoTracking().FirstOrDefaultAsync(t => t.Id == jobGroupId);
|
|
|
|
|
|
|
|
|
|
|
|
if (jobGroup == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
logger.LogError("Не найдена группа работ с Id: {jobGroupId}.", jobGroupId);
|
|
|
|
|
|
throw new ArgumentNullException(nameof(jobGroupId), $"Не найдена группа работ с Id: {jobGroupId}");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Берем из обычного расписания ЕСПП
|
|
|
|
|
|
return await esppScheduleTransformService.GetNextDateAsync(jobGroupId, jobGroup.ReferenceDate);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-01-20 15:04:36 +10:00
|
|
|
|
public async Task<DateTimeOffset> GetNextRunForTemplate(Guid templateId, bool isNew)
|
2025-12-22 17:03:41 +10:00
|
|
|
|
{
|
|
|
|
|
|
var template = await templateService.Get()
|
|
|
|
|
|
.Include(t => t.Job).ThenInclude(t => t.Group)
|
|
|
|
|
|
.AsNoTracking()
|
|
|
|
|
|
.FirstOrDefaultAsync(t => t.Id == templateId);
|
|
|
|
|
|
|
|
|
|
|
|
if (template == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
logger.LogError("Не найдена шаблон с Id: {templateId}.", templateId);
|
|
|
|
|
|
throw new ArgumentNullException(nameof(templateId), $"Не найдена шаблон с Id: {templateId}");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (template.Job!.Group!.IsAutoDistributionEnabled == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
// включено автораспределение
|
|
|
|
|
|
//TODO: !!!!!!!!!!!!!!!! добавить метод рассчета с учетом распределения
|
2026-01-20 15:04:36 +10:00
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
//return await templateDistributor.GetValidNextRunForTemplateAsync();
|
2025-12-22 17:03:41 +10:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// считаем как ЕСПП
|
|
|
|
|
|
return await esppScheduleTransformService.GetNextDateAsync(template.Job.Group.Id, template.Job.Group.ReferenceDate);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|