diff --git a/service/telegram_service/handlers/approval/handler_delegation_tasks.go b/service/telegram_service/handlers/approval/handler_delegation_tasks.go index bedbe02..6166ec4 100644 --- a/service/telegram_service/handlers/approval/handler_delegation_tasks.go +++ b/service/telegram_service/handlers/approval/handler_delegation_tasks.go @@ -243,19 +243,19 @@ func (h *Handler) HandleTaskDelegationMenu(bot *tgbotapi.BotAPI, chatID int64, t func (h *Handler) HandleTaskDelegationMenuPage(bot *tgbotapi.BotAPI, chatID int64, telegramID int64, page int, prevMessageID int) { ctx := context.Background() - // Получаем список всех активных категорий - categories, _, err := h.ipc.Database.ApprovalTopicCategory.GetApprovalTopicCategoryListDB(ctx, typescore.ListDbOptions{ - Filtering: &typescore.ApprovalTopicCategory{IsActive: utilscore.PointerToBool(true)}, - }) - if err != nil { - logrus.Errorf("HandleTaskDelegationMenuPage: GetApprovalTopicCategoryListDB err=%v", err) - sendText(bot, chatID, "Ошибка при получении списка категорий.") + user, err := h.ipc.Database.User.GetUserByTelegramIDDB(ctx, telegramID) + if err != nil || user == nil || user.ID == nil { + return + } + + categories, err := h.getExecutorCategories(ctx, *user.ID) + if err != nil || len(categories) == 0 { + sendText(bot, chatID, "У вас нет категорий с настроенными задачами для делегирования.") return } if prevMessageID != 0 { - bot.Request(tgbotapi.NewCallback(fmt.Sprintf("%d", prevMessageID), "")) //nolint:errcheck - bot.Request(tgbotapi.NewDeleteMessage(chatID, prevMessageID)) //nolint:errcheck + bot.Request(tgbotapi.NewDeleteMessage(chatID, prevMessageID)) //nolint:errcheck } msg := tgbotapi.NewMessage(chatID, "📋 Делегирование задач\n\nВыберите, какие задачи вы хотите делегировать:") diff --git a/service/telegram_service/handlers/approval/handler_executor.go b/service/telegram_service/handlers/approval/handler_executor.go index acbb048..c15838e 100644 --- a/service/telegram_service/handlers/approval/handler_executor.go +++ b/service/telegram_service/handlers/approval/handler_executor.go @@ -604,3 +604,55 @@ func (h *Handler) HandleExecutorAttachStart(bot *tgbotapi.BotAPI, cq *tgbotapi.C msg.ReplyMarkup = keyboard.BuildAttachSessionKeyboard(approvalID, 0) bot.Send(msg) //nolint:errcheck } + +func (h *Handler) getExecutorCategories(ctx context.Context, userID uint64) ([]*typescore.ApprovalTopicCategory, error) { + categoryIDs := make(map[uint64]bool) + + // 1. Проверяем напрямую через исполнителей тем (ApprovalTopicExecutor) + executors, _, err := h.ipc.Database.ApprovalTopicExecutor.GetApprovalTopicExecutorListDB(ctx, typescore.ListDbOptions{ + Filtering: &typescore.ApprovalTopicExecutor{ + UserID: &userID, + IsActive: utilscore.PointerToBool(true), + }, + }) + if err == nil { + for _, exec := range executors { + if exec.TopicID != nil { + topic, _ := h.ipc.Database.ApprovalTopic.GetApprovalTopicByIDDB(ctx, *exec.TopicID) + if topic != nil && topic.CategoryID != nil { + categoryIDs[*topic.CategoryID] = true + } + } + } + } + + // 2. Проверяем через иерархию (UserHierarchy) + hierarchies, _, err := h.ipc.Database.UserHierarchy.GetUserHierarchyListDB(ctx, typescore.ListDbOptions{ + Filtering: &typescore.UserHierarchy{ + ApproverID: &userID, + }, + }) + if err == nil { + for _, hier := range hierarchies { + if hier.TopicID != nil { + topic, _ := h.ipc.Database.ApprovalTopic.GetApprovalTopicByIDDB(ctx, *hier.TopicID) + if topic != nil && topic.CategoryID != nil { + categoryIDs[*topic.CategoryID] = true + } + } + if hier.TopicCategoryID != nil { + categoryIDs[*hier.TopicCategoryID] = true + } + } + } + + var categories []*typescore.ApprovalTopicCategory + for categoryID := range categoryIDs { + category, err := h.ipc.Database.ApprovalTopicCategory.GetApprovalTopicCategoryByIDDB(ctx, categoryID) + if err == nil && category != nil { + categories = append(categories, category) + } + } + + return categories, nil +}