Files
parr_api/PARR.DAL/NextRunServices/NextRunService.cs

80 lines
3.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
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;
public NextRunService(
ILogger<NextRunService> logger,
ITemplateService templateService,
IJobGroupService jobGroupService,
IEsppScheduleTransformService esppScheduleTransformService
)
{
this.logger = logger;
this.templateService = templateService;
this.jobGroupService = jobGroupService;
this.esppScheduleTransformService = esppScheduleTransformService;
}
public Task<List<(Guid TemplateId, DateTimeOffset NextRun)>> GetNextRunForJobGroupWithAutoDistributionAsync(Guid jobGroupId)
{
//TODO:
throw new NotImplementedException();
}
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)
{
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("добавить метод рассчета с учетом распределения");
}
else
{
// считаем как ЕСПП
return await esppScheduleTransformService.GetNextDateAsync(template.Job.Group.Id, template.Job.Group.ReferenceDate);
}
}
}
}