86 lines
3.6 KiB
C#
86 lines
3.6 KiB
C#
|
||
using Microsoft.EntityFrameworkCore;
|
||
using Microsoft.Extensions.Logging;
|
||
using PARR.DAL.NextRunServices.Subservices;
|
||
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;
|
||
private readonly ITemplateDistributor templateDistributor;
|
||
|
||
public NextRunService(
|
||
ILogger<NextRunService> logger,
|
||
ITemplateService templateService,
|
||
IJobGroupService jobGroupService,
|
||
IEsppScheduleTransformService esppScheduleTransformService,
|
||
ITemplateDistributor templateDistributor
|
||
)
|
||
{
|
||
this.logger = logger;
|
||
this.templateService = templateService;
|
||
this.jobGroupService = jobGroupService;
|
||
this.esppScheduleTransformService = esppScheduleTransformService;
|
||
this.templateDistributor = templateDistributor;
|
||
}
|
||
|
||
|
||
public async Task<List<(Guid TemplateId, DateTimeOffset NextRun)>> GetNextRunForJobGroupWithAutoDistributionAsync(Guid jobGroupId)
|
||
{
|
||
//TODO:
|
||
throw new NotImplementedException();
|
||
//var ditributedTemplateList = await templateDistributor.DistributeTemplatesAsync();
|
||
}
|
||
|
||
|
||
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);
|
||
}
|
||
|
||
|
||
public async Task<DateTimeOffset> GetNextRunForTemplate(Guid templateId, bool isNew)
|
||
{
|
||
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: !!!!!!!!!!!!!!!! добавить метод рассчета с учетом распределения
|
||
throw new NotImplementedException();
|
||
//return await templateDistributor.GetValidNextRunForTemplateAsync();
|
||
}
|
||
else
|
||
{
|
||
// считаем как ЕСПП
|
||
return await esppScheduleTransformService.GetNextDateAsync(template.Job.Group.Id, template.Job.Group.ReferenceDate);
|
||
}
|
||
}
|
||
}
|
||
}
|