mirror of
https://github.com/serty2005/rmser.git
synced 2026-02-04 19:02:33 -06:00
0202-финиш перед десктопом
пересчет поправил редактирование с перепроведением галка автопроведения работает рекомендации починил
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package recommend
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"rmser/internal/domain/recommendations"
|
||||
@@ -20,56 +21,56 @@ func NewService(repo recommendations.Repository) *Service {
|
||||
return &Service{repo: repo}
|
||||
}
|
||||
|
||||
// RefreshRecommendations выполняет анализ и сохраняет результаты в БД
|
||||
func (s *Service) RefreshRecommendations() error {
|
||||
logger.Log.Info("Запуск пересчета рекомендаций...")
|
||||
// RefreshRecommendations выполняет анализ и сохраняет результаты в БД для конкретного сервера
|
||||
func (s *Service) RefreshRecommendations(serverID uuid.UUID) error {
|
||||
logger.Log.Info("Запуск пересчета рекомендаций...", zap.String("server_id", serverID.String()))
|
||||
|
||||
var all []recommendations.Recommendation
|
||||
|
||||
// 1. Unused
|
||||
if unused, err := s.repo.FindUnusedGoods(); err == nil {
|
||||
if unused, err := s.repo.FindUnusedGoods(serverID); err == nil {
|
||||
all = append(all, unused...)
|
||||
} else {
|
||||
logger.Log.Error("Ошибка unused", zap.Error(err))
|
||||
}
|
||||
|
||||
// 2. Purchased but Unused
|
||||
if purchUnused, err := s.repo.FindPurchasedButUnused(AnalyzeDaysNoIncoming); err == nil {
|
||||
if purchUnused, err := s.repo.FindPurchasedButUnused(serverID, AnalyzeDaysNoIncoming); err == nil {
|
||||
all = append(all, purchUnused...)
|
||||
} else {
|
||||
logger.Log.Error("Ошибка purchased_unused", zap.Error(err))
|
||||
}
|
||||
|
||||
// 3. No Incoming (Ингредиенты без закупок)
|
||||
if noInc, err := s.repo.FindNoIncomingIngredients(AnalyzeDaysNoIncoming); err == nil {
|
||||
if noInc, err := s.repo.FindNoIncomingIngredients(serverID, AnalyzeDaysNoIncoming); err == nil {
|
||||
all = append(all, noInc...)
|
||||
} else {
|
||||
logger.Log.Error("Ошибка no_incoming", zap.Error(err))
|
||||
}
|
||||
|
||||
// 4. Usage without Purchase (Расход без прихода) <-- НОВОЕ
|
||||
if usageNoPurch, err := s.repo.FindUsageWithoutPurchase(AnalyzeDaysNoIncoming); err == nil {
|
||||
// 4. Usage without Purchase (Расход без прихода)
|
||||
if usageNoPurch, err := s.repo.FindUsageWithoutPurchase(serverID, AnalyzeDaysNoIncoming); err == nil {
|
||||
all = append(all, usageNoPurch...)
|
||||
} else {
|
||||
logger.Log.Error("Ошибка usage_no_purchase", zap.Error(err))
|
||||
}
|
||||
|
||||
// 5. Stale (Неликвид)
|
||||
if stale, err := s.repo.FindStaleGoods(AnalyzeDaysStale); err == nil {
|
||||
if stale, err := s.repo.FindStaleGoods(serverID, AnalyzeDaysStale); err == nil {
|
||||
all = append(all, stale...)
|
||||
} else {
|
||||
logger.Log.Error("Ошибка stale", zap.Error(err))
|
||||
}
|
||||
|
||||
// 6. Dish in Recipe
|
||||
if dishInRec, err := s.repo.FindDishesInRecipes(); err == nil {
|
||||
if dishInRec, err := s.repo.FindDishesInRecipes(serverID); err == nil {
|
||||
all = append(all, dishInRec...)
|
||||
} else {
|
||||
logger.Log.Error("Ошибка dish_in_recipe", zap.Error(err))
|
||||
}
|
||||
|
||||
// Сохраняем
|
||||
if err := s.repo.SaveAll(all); err != nil {
|
||||
if err := s.repo.SaveAll(serverID, all); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -77,6 +78,7 @@ func (s *Service) RefreshRecommendations() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GetRecommendations() ([]recommendations.Recommendation, error) {
|
||||
return s.repo.GetAll()
|
||||
// GetRecommendations возвращает рекомендации для конкретного сервера
|
||||
func (s *Service) GetRecommendations(serverID uuid.UUID) ([]recommendations.Recommendation, error) {
|
||||
return s.repo.GetAll(serverID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user