From 9e41c9edd7f0a9c19f901c1e54ea3c4b1a2bc139 Mon Sep 17 00:00:00 2001 From: romanskijdev Date: Mon, 13 Jul 2026 10:25:13 +0300 Subject: [PATCH] Added daily reminder --- .../scheduler/daily_reminder.go | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/service/telegram_service/scheduler/daily_reminder.go b/service/telegram_service/scheduler/daily_reminder.go index 5dcc3ca..e4f6ce0 100644 --- a/service/telegram_service/scheduler/daily_reminder.go +++ b/service/telegram_service/scheduler/daily_reminder.go @@ -47,6 +47,8 @@ func (dr *DailyReminder) scheduleLoop() { next = next.AddDate(0, 0, 1) } + next = dr.skipWeekends(next) + duration := time.Until(next) logrus.Infof("DailyReminder: следующее напоминание запланировано на %s (через %v)", next.Format("02.01.2006 15:04 MSK"), duration.Round(time.Second)) @@ -59,6 +61,19 @@ func (dr *DailyReminder) scheduleLoop() { } } +// skipWeekends переносит дату на ближайший будний день, +// если она выпадает на субботу или воскресенье +func (dr *DailyReminder) skipWeekends(t time.Time) time.Time { + switch t.Weekday() { + case time.Saturday: + return t.AddDate(0, 0, 2) + case time.Sunday: + // Воскресенье → понедельник (+1 день) + return t.AddDate(0, 0, 1) + } + return t +} + // sendReminders отправляет напоминания всем пользователям func (dr *DailyReminder) sendReminders() { ctx := context.Background() @@ -78,9 +93,6 @@ func (dr *DailyReminder) sendReminders() { if user.TelegramID == nil || user.ID == nil { continue } - if *user.TelegramID != 493325176 && *user.TelegramID != 8571473232 { - continue - } if dr.sendReminderToUser(bot, ctx, user) { sentCount++ @@ -99,7 +111,6 @@ func (dr *DailyReminder) sendReminderToUser(bot *tgbotapi.BotAPI, ctx context.Co userID := *user.ID telegramID := *user.TelegramID - // 1. Заявки на доработке (роль инициатора) revisions, _, err := dr.ipc.Database.Approval.GetApprovalsListDB(ctx, typescore.ListDbOptions{ Filtering: &typescore.Approval{ InitiatorID: &userID, @@ -123,8 +134,6 @@ func (dr *DailyReminder) sendReminderToUser(bot *tgbotapi.BotAPI, ctx context.Co } tasksCount := len(tasks) - // 3. Согласования к принятию (роль согласующего) - // Проверяем основные шаги согласования steps, _, err := dr.ipc.Database.ApprovalStep.GetApprovalStepsListDB(ctx, typescore.ListDbOptions{ Filtering: &typescore.ApprovalStep{ ApproverID: &userID, -- 2.43.0