From f42e5b5ea8bf887d9f86c658e4cdb1429a7a5926 Mon Sep 17 00:00:00 2001 From: Mikhail Kuznetsov Date: Thu, 27 Nov 2025 14:21:27 +1000 Subject: [PATCH] =?UTF-8?q?fix(dal):=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=20=D1=80=D0=B0=D1=81=D1=87=D0=B5=D1=82?= =?UTF-8?q?=20=D1=81=D0=BB=D0=B5=D0=B4=D1=83=D1=8E=D1=89=D0=B5=D0=B3=D0=BE?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B0=20Regularly=20?= =?UTF-8?q?=D0=B2=20EsppScheduleTransformService.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implementations/UnitFilterService.cs | 24 +++++++++++++------ PARR.DAL/Models/UnitsInTemplate.cs | 3 --- .../EsppScheduleTransformService.cs | 7 +++--- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/PARR.DAL/DomainServices/Implementations/UnitFilterService.cs b/PARR.DAL/DomainServices/Implementations/UnitFilterService.cs index 34086b15..2c7eeb17 100644 --- a/PARR.DAL/DomainServices/Implementations/UnitFilterService.cs +++ b/PARR.DAL/DomainServices/Implementations/UnitFilterService.cs @@ -94,16 +94,22 @@ namespace PARR.DAL.DomainServices.Implementations try { + logger.LogDebug("Применяем фильтр #{Index} (Id={FilterId})", filterNumber, filter.Id); + // Стартуем с базового условия — имя Unit'а var query = unitService.Get().AsNoTracking() .Where(unit => EF.Functions.ILike(unit.Name, filter.UnitFilter)); - // 1. Фильтры по полям (UnitValues) + logger.LogDebug("Базовый фильтр по Name: {NameFilter}", filter.UnitFilter); + + // 1. Фильтры по полям (UnitValues) foreach (var fieldFilter in filter.FieldFilters) { var fieldId = fieldFilter.FieldId; var valueMask = fieldFilter.ValueMask; + logger.LogDebug("Фильтр по полю: FieldId={FieldId}, ValueMask={ValueMask}", fieldId, valueMask); + query = query.Where(unit => unit.UnitValues.Any(value => value.FieldId == fieldId @@ -112,18 +118,19 @@ namespace PARR.DAL.DomainServices.Implementations && EF.Functions.ILike(value.Value.Value, valueMask))); } - // 2. Фильтры по связям (родителям и детям) + // 2. Фильтры по связям (родителям и детям) foreach (var relFilter in filter.RelationshipFilters) { var fieldId = relFilter.FieldId; var valueMask = relFilter.ValueMask; + logger.LogDebug("Фильтр по связи: IsParent={IsParent}, IsInverse={IsInverse}, IsFullMatch={IsFullMatch}, FieldId={FieldId}, ValueMask={ValueMask}", + relFilter.IsParent, relFilter.IsInverse, relFilter.IsFullMatch, relFilter.FieldId, relFilter.ValueMask); + if (relFilter.IsParent) { - // Работаем с ParentUnits → pu.ParentUnit if (relFilter.IsInverse) { - // "Обратный фильтр": ищем Unit'ы, у которых связанные Unit'ы НЕ имеют указанного значения if (relFilter.IsFullMatch) { // Все родители НЕ должны иметь такое значение @@ -138,7 +145,7 @@ namespace PARR.DAL.DomainServices.Implementations } else { - // Хотя бы один родитель НЕ имеет такого значения + // Хотя бы один родитель НЕ должен иметь такое значение query = query.Where(unit => !unit.ParentUnits.Any() || unit.ParentUnits.Any(parentLink => @@ -238,6 +245,8 @@ namespace PARR.DAL.DomainServices.Implementations int min = job.MinValueRelationships.GetValueOrDefault(0); int max = job.MaxValueRelationships.GetValueOrDefault(int.MaxValue); + logger.LogDebug("Фильтр по количеству связей: Min={Min}, Max={Max}, IsParent={IsParent}", min, max, job.IsParentRelationships); + if (job.IsParentRelationships == true) { query = query.Where(unit => @@ -250,12 +259,14 @@ namespace PARR.DAL.DomainServices.Implementations } } - // Запрашиваем в БД с учётом оставшегося лимита + // Выполняем — только Id, с учётом оставшегося лимита var newIds = await query .Select(unit => unit.Id) .Take(remaining) .ToListAsync(); + logger.LogDebug("Фильтр #{Index}: найдено {Count} Unit'ов", filterNumber, newIds.Count); + collectedIds.UnionWith(newIds); logger.LogDebug( @@ -267,7 +278,6 @@ namespace PARR.DAL.DomainServices.Implementations { logger.LogError(ex, "Ошибка при обработке фильтра {FilterId} (#{Index}) для Job {JobId}", filter.Id, filterNumber, job.Id); - // Продолжаем — другие фильтры могут сработать } } diff --git a/PARR.DAL/Models/UnitsInTemplate.cs b/PARR.DAL/Models/UnitsInTemplate.cs index 75c02948..e2457eba 100644 --- a/PARR.DAL/Models/UnitsInTemplate.cs +++ b/PARR.DAL/Models/UnitsInTemplate.cs @@ -18,8 +18,5 @@ namespace PARR.DAL.Models [ForeignKey(nameof(UnitId))] public Unit.Unit? Unit { get; set; } - - - } } diff --git a/PARR.DAL/TransformServices/EsppScheduleTransformService.cs b/PARR.DAL/TransformServices/EsppScheduleTransformService.cs index fc78ecb9..06ed46b6 100644 --- a/PARR.DAL/TransformServices/EsppScheduleTransformService.cs +++ b/PARR.DAL/TransformServices/EsppScheduleTransformService.cs @@ -5,7 +5,6 @@ using PARR.DAL.Contracts; using PARR.DAL.DomainModels; using PARR.DAL.Extensions; using PARR.DAL.Services.Interfaces; -using PARR.DAL.Services.Interfaces.Job; namespace PARR.DAL.TransformServices { @@ -206,7 +205,9 @@ namespace PARR.DAL.TransformServices throw new ArgumentException($"Неизвестное значение: {values[0].Value.Value}"); } - var calcDay = referenceDate.AddHours(regNum); + var calcDay = referenceDate; + if (calcDay < DateTimeOffset.UtcNow) + calcDay = calcDay.AddHours(regNum); //TODO: вот это повторяется от метода к методу //Если итоговая дата указывает на прошлое, то повторяем расчёт и уходим в рекурсию @@ -305,7 +306,7 @@ namespace PARR.DAL.TransformServices return calcDay; } - + private DateTimeOffset GetNextDateAnnually(List values, DateTimeOffset referenceDate) {