2024-07-05 15:17:48 +10:00
using Microsoft.EntityFrameworkCore ;
using Microsoft.Extensions.DependencyInjection ;
using Microsoft.Extensions.Logging ;
2026-07-03 11:25:39 +10:00
using PARR.Core.Repositories.Interfaces.JobGroupRepositories ;
2026-06-15 16:56:23 +10:00
using PARR.Domain.Entities.JobGroupEntities ;
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
2026-04-30 10:35:31 +10:00
var service = scope . ServiceProvider . GetService < IJobGroupRepository > ( ) ;
2026-01-21 16:28:17 +10:00
if ( service = = null )
2026-04-30 10:35:31 +10:00
throw new Exception ( $"Н е найден сервис: {nameof(IJobGroupRepository)}" ) ;
2026-01-21 16:28:17 +10:00
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 ;
}
}
}
}