feat(templateMatcher,dal): Первая реализация SyncTemplatesForJobGroup для сгруппированных типов групп регламентных работ.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
// ValidatorService.cs
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.Job;
|
||||
using PARR.DAL.Services.Interfaces.Unit;
|
||||
|
||||
@@ -9,22 +11,25 @@ namespace PARR.TemplateGeneratorWorker.Services
|
||||
private readonly ILogger<ValidatorService> logger;
|
||||
private readonly IJobService jobService;
|
||||
private readonly IUnitService unitService;
|
||||
private readonly ITemplateService templateService;
|
||||
|
||||
public ValidatorService(
|
||||
ILogger<ValidatorService> logger,
|
||||
IJobService jobService,
|
||||
IUnitService unitService
|
||||
IUnitService unitService,
|
||||
ITemplateService templateService
|
||||
)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.jobService = jobService;
|
||||
this.unitService = unitService;
|
||||
this.templateService = templateService;
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> IsValidAsync(Guid jobId, Guid unitId)
|
||||
public async Task<bool> IsValidAsync(Guid jobId, Guid unitId, int? index, List<Guid>? unitsInTemplate = null)
|
||||
{
|
||||
|
||||
// Проверяем JobId
|
||||
var job = await jobService
|
||||
.Get().AsNoTracking()
|
||||
.FirstOrDefaultAsync(t => t.Id == jobId);
|
||||
@@ -35,6 +40,7 @@ namespace PARR.TemplateGeneratorWorker.Services
|
||||
return false;
|
||||
}
|
||||
|
||||
// Проверяем UnitId (UnitId - это ID регионального юнита)
|
||||
var unit = await unitService
|
||||
.Get().AsNoTracking()
|
||||
.FirstOrDefaultAsync(t => t.Id == unitId);
|
||||
@@ -45,7 +51,35 @@ namespace PARR.TemplateGeneratorWorker.Services
|
||||
return false;
|
||||
}
|
||||
|
||||
// Проверяем уникальность (JobId, UnitId, Index)
|
||||
var existingTemplate = await templateService
|
||||
.Get().AsNoTracking()
|
||||
.FirstOrDefaultAsync(t => t.JobId == jobId && t.UnitId == unitId && t.Index == index);
|
||||
|
||||
if (existingTemplate != null)
|
||||
{
|
||||
logger.LogError("Шаблон с JobId={JobId}, UnitId={UnitId}, Index={Index} уже существует.", jobId, unitId, index);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Проверяем, что все UnitId в UnitsInTemplate существуют (если список не null и не пуст)
|
||||
if (unitsInTemplate != null && unitsInTemplate.Any())
|
||||
{
|
||||
var unitIdsToCheck = unitsInTemplate.ToHashSet();
|
||||
var existingUnitIdsCount = await unitService.Get()
|
||||
.AsNoTracking()
|
||||
.Where(u => unitIdsToCheck.Contains(u.Id))
|
||||
.Select(u => u.Id)
|
||||
.CountAsync();
|
||||
|
||||
if (existingUnitIdsCount != unitIdsToCheck.Count)
|
||||
{
|
||||
logger.LogError("Не все UnitId из UnitsInTemplate существуют в базе данных. Ожидается: {ExpectedCount}, Найдено: {FoundCount}", unitIdsToCheck.Count, existingUnitIdsCount);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user