Add InterstitialGroups service and enhance SlotWriter and related components for interstitial handling
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:
+17
-5
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user