Added daily reminder

This commit is contained in:
romanskijdev 2026-07-13 10:25:13 +03:00
parent e51757cc2b
commit 9e41c9edd7
1 changed files with 15 additions and 6 deletions

View File

@ -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,