2024-07-05 15:17:48 +10:00
using Microsoft.EntityFrameworkCore ;
using Microsoft.Extensions.DependencyInjection ;
using Microsoft.Extensions.Logging ;
2026-01-21 16:28:17 +10:00
using PARR.DAL.Models.Job ;
2024-07-05 15:17:48 +10:00
using PARR.DAL.Services.Interfaces ;
2026-01-21 16:28:17 +10:00
using PARR.DAL.Services.Interfaces.Job ;
2024-07-05 15:17:48 +10:00
namespace PARR.TemplateDistributor.Services
{
internal class ValidatorService : IValidatorService
{
private readonly IServiceProvider serviceProvider ;
private readonly ILogger < ValidatorService > logger ;
public ValidatorService ( IServiceProvider serviceProvider ,
ILogger < ValidatorService > logger
)
{
this . serviceProvider = serviceProvider ;
this . logger = logger ;
}
2026-01-21 16:28:17 +10:00
public async Task < bool > IsValidJobGroupAsync ( Guid jobGroupId )
2024-07-05 15:17:48 +10:00
{
using ( var scope = serviceProvider . CreateScope ( ) )
{
2026-01-21 16:28:17 +10:00
var service = scope . ServiceProvider . GetService < IJobGroupService > ( ) ;
if ( service = = null )
throw new Exception ( $"Н е найден сервис: {nameof(IJobGroupService)}" ) ;
var jobGroup = await service . Get ( ) . Include ( t = > t . DistributionConfig ) . FirstOrDefaultAsync ( t = > t . Id = = jobGroupId ) ;
if ( jobGroup = = null )
{
logger . LogError ( $"Н е найдена группа работ с Id: {jobGroupId}" , jobGroupId ) ;
return false ;
}
if ( ! jobGroup . IsAutoDistributionEnabled | | jobGroup . DistributionConfig = = null )
{
logger . LogError ( "Для группы работ {jobGroupId} отсутствуют настройки автораспределения. " +
"IsAutoDistributionEnabled: {IsAutoDistributionEnabled}, есть настройки в таблице {DistributionConfig}, {existConfig}" , jobGroupId , jobGroup . IsAutoDistributionEnabled , nameof ( JobGroupDistributionConfig ) , jobGroup . DistributionConfig ! = null ) ;
return false ;
}
2024-07-05 15:17:48 +10:00
return true ;
}
}
}
}