Minha alteração

This commit is contained in:
Eduardo 2026-02-12 10:03:21 -03:00
parent 2872de9f4b
commit bafa97cf3b
4 changed files with 22 additions and 1 deletions

View File

@ -4,5 +4,8 @@ public class NotificationOptions
{
public int CheckIntervalMinutes { get; set; } = 60;
public bool NotifyAllFutureDates { get; set; } = true;
// Limit how far ahead "A vencer" notifications can be generated.
// Prevents alerting contracts years in the future (e.g. 2028) when the system runs daily.
public int MaxFutureDays { get; set; } = 30;
public List<int> ReminderDays { get; set; } = new() { 30, 15, 7 };
}

View File

@ -64,6 +64,7 @@ public class VigenciaNotificationSyncService : IVigenciaNotificationSyncService
{
var today = DateTime.SpecifyKind(DateTime.UtcNow.Date, DateTimeKind.Utc);
var notifyAllFutureDates = _options.NotifyAllFutureDates;
var maxFutureDays = _options.MaxFutureDays <= 0 ? 30 : _options.MaxFutureDays;
var reminderDays = _options.ReminderDays
.Distinct()
.Where(d => d > 0)
@ -86,7 +87,7 @@ public class VigenciaNotificationSyncService : IVigenciaNotificationSyncService
.Where(v => v.DtTerminoFidelizacao != null)
.ToListAsync(cancellationToken);
await CleanupOutdatedNotificationsAsync(vigencias, notifyAllFutureDates, reminderDays, today, cancellationToken);
await CleanupOutdatedNotificationsAsync(vigencias, notifyAllFutureDates, reminderDays, today, maxFutureDays, cancellationToken);
var candidates = new List<Notification>();
foreach (var vigencia in vigencias)
@ -133,6 +134,10 @@ public class VigenciaNotificationSyncService : IVigenciaNotificationSyncService
}
var daysUntil = (endDate - today).Days;
if (daysUntil > maxFutureDays)
{
continue;
}
if (!notifyAllFutureDates && !reminderDays.Contains(daysUntil))
{
continue;
@ -213,8 +218,14 @@ public class VigenciaNotificationSyncService : IVigenciaNotificationSyncService
bool notifyAllFutureDates,
IReadOnlyCollection<int> reminderDays,
DateTime today,
int maxFutureDays,
CancellationToken cancellationToken)
{
if (maxFutureDays <= 0)
{
maxFutureDays = 30;
}
var vigenciasById = vigencias.ToDictionary(v => v.Id, v => v);
var vigenciasByLinha = vigencias
.Where(v => !string.IsNullOrWhiteSpace(v.Linha))
@ -253,6 +264,11 @@ public class VigenciaNotificationSyncService : IVigenciaNotificationSyncService
}
var daysUntil = (endDate - today).Days;
if (daysUntil > maxFutureDays)
{
idsToDelete.Add(notification.Id);
continue;
}
if (notification.Tipo == "Vencido")
{
idsToDelete.Add(notification.Id);

View File

@ -25,6 +25,7 @@
"Notifications": {
"CheckIntervalMinutes": 60,
"NotifyAllFutureDates": true,
"MaxFutureDays": 30,
"ReminderDays": [30, 15, 7]
},
"Seed": {

View File

@ -25,6 +25,7 @@
"Notifications": {
"CheckIntervalMinutes": 60,
"NotifyAllFutureDates": true,
"MaxFutureDays": 30,
"ReminderDays": [ 30, 15, 7 ]
},
"Seed": {