Add InterstitialGroups service and enhance SlotWriter and related components for interstitial handling
ci / build-backend (push) Successful in 1m18s
ci / build-frontend (push) Successful in 43s
ci / tests (push) Successful in 3m38s
ci / sonar (push) Successful in 3m38s

Introduced the InterstitialGroups service to manage interstitial group logic, preventing their inclusion in slots and fallback groups. Updated the SlotWriter class to utilize this service, ensuring proper validation during slot creation and updates. Enhanced error handling for interstitial groups in the ImportGridCommandHandler and UpdateTemplateCommandHandler, providing warnings instead of failures when interstitials are detected. Updated related tests to verify the correct behavior of these changes, ensuring robust handling of interstitials in the scheduling process.
This commit is contained in:
Leonid Pershin
2026-07-30 12:48:51 +03:00
parent 398b60facc
commit 926a20020f
15 changed files with 370 additions and 39 deletions
@@ -22,7 +22,8 @@ namespace TeleWave.Application.Programming.Templates.Transfer;
public sealed class ImportGridCommandHandler(
IAppDbContext dbContext,
SlotWriter writer,
GroupStatsService stats
GroupStatsService stats,
InterstitialGroups interstitials
) : ICommandHandler<ImportGridCommand, Result<GridImportResultDto>>
{
public async Task<Result<GridImportResultDto>> Handle(
@@ -74,7 +75,7 @@ public sealed class ImportGridCommandHandler(
skipped += dropped;
}
Apply(template, command.Config, groups, junctions, warnings);
await ApplyAsync(template, command.Config, groups, junctions, warnings, cancellationToken);
template.MarkChanged();
return Result.Success(
@@ -303,12 +304,13 @@ public sealed class ImportGridCommandHandler(
}
/// <summary>Настройки шаблона из файла. Пустые поля не трогают то, что уже стоит на канале.</summary>
private static void Apply(
private async Task ApplyAsync(
ScheduleTemplate template,
GridConfig config,
IReadOnlyDictionary<string, Guid> groups,
IReadOnlyDictionary<string, Guid> junctions,
List<string> warnings
List<string> warnings,
CancellationToken cancellationToken
)
{
if (config.Rules is { } rules)
@@ -318,7 +320,17 @@ public sealed class ImportGridCommandHandler(
config.FallbackGroup is { Length: > 0 } fallback
&& Resolve(fallback, groups, "Группа", warnings) is { } groupId
)
template.SetFallbackGroup(groupId);
{
// Аварийной группой из роликов файл превращает в рекламу каждую паузу эфира. Замечанием,
// а не отказом: остальная сетка из файла корректна, и терять её из-за одного поля нельзя.
if (await interstitials.IsInterstitialAsync(groupId, cancellationToken))
warnings.Add(
$"Аварийная группа «{fallback}» собрана из роликов — она не проставлена: "
+ "паузы эфира стали бы рекламой."
);
else
template.SetFallbackGroup(groupId);
}
if (
config.DefaultJunction is { Length: > 0 } junction