feat(templateMatcher): реализован функционал переиспользования неиспользуемых шаблонов, пока без обезличивания имени шаблона.

This commit is contained in:
Mikhail Kuznetsov
2025-12-04 14:24:42 +10:00
parent 219dadda1e
commit 336cf90deb
4 changed files with 227 additions and 140 deletions

View File

@@ -3,10 +3,8 @@ using Microsoft.Extensions.Logging;
using PARR.DAL.Contracts;
using PARR.DAL.DomainServices.Interfaces;
using PARR.DAL.Models.Job;
using PARR.DAL.Services.Interfaces;
using PARR.DAL.Services.Interfaces.Job;
using PARR.DAL.Services.Interfaces.Unit;
using System.Net.NetworkInformation;
using System.Text.RegularExpressions;
@@ -17,19 +15,16 @@ namespace PARR.DAL.DomainServices.Implementations
private readonly ILogger<UnitFilterService> logger;
private readonly IJobService jobService;
private readonly IUnitService unitService;
private readonly ITemplateService templateService;
public UnitFilterService(
ILogger<UnitFilterService> logger,
IJobService jobService,
IUnitService unitService,
ITemplateService templateService
IUnitService unitService
)
{
this.logger = logger;
this.jobService = jobService;
this.unitService = unitService;
this.templateService = templateService;
}
@@ -287,35 +282,5 @@ namespace PARR.DAL.DomainServices.Implementations
return result;
}
public async Task<IEnumerable<Guid>> GetUnitsIdByJobFilterWithTemplateStatusAsync(
Guid jobId,
bool mustHaveTemplate,
int? takeCount = null
)
{
var unitIds = await GetUnitsIdByJobFilterAsync(jobId, takeCount);
if (unitIds == null || !unitIds.Any())
return Array.Empty<Guid>();
var unitIdSet = unitIds.ToHashSet();
// Получаем UnitId, для которых уже есть шаблоны по этому jobId
var existingUnitIds = await templateService
.Get()
.AsNoTracking()
.Where(template =>
template.JobId == jobId &&
unitIdSet.Contains(template.UnitId))
.Select(template => template.UnitId)
.ToListAsync();
var existingSet = existingUnitIds.ToHashSet();
return mustHaveTemplate
? existingSet
: unitIdSet.Except(existingSet);
}
}
}

View File

@@ -18,18 +18,5 @@ namespace PARR.DAL.DomainServices.Interfaces
/// <param name="job">Job обязательно должен содержать UnitFilter, Group и GroupType</param>
/// <returns></returns>
Task<IEnumerable<Guid>?> GetUnitsIdByJobFilterAsync(Job job, int? takeCount = null);
/// <summary>
/// Получить список Id ЭК в зависимости от параметра mustHaveTemplate
/// </summary>
/// <param name="jobId"></param>
/// <param name="mustHaveTemplate">
/// true - ЭК, которые имеют связанные шаблоны
/// false - ЭК, для которых шаблоны не созданы
/// </param>
/// <param name="takeCount"></param>
/// <returns>Лист Id ЭК</returns>
Task<IEnumerable<Guid>> GetUnitsIdByJobFilterWithTemplateStatusAsync(Guid jobId, bool mustHaveTemplate, int? takeCount = null);
}
}