mirror of
https://github.com/serty2005/rmser.git
synced 2026-02-04 19:02:33 -06:00
2512-есть Maintenance режим, но бот всё равно отвечает фульно
This commit is contained in:
@@ -19,6 +19,11 @@ import (
|
||||
"rmser/internal/infrastructure/ocr_client"
|
||||
)
|
||||
|
||||
// DevNotifier - интерфейс для уведомления разработчиков
|
||||
type DevNotifier interface {
|
||||
NotifyDevs(devIDs []int64, photoPath string, serverName string, serverID string)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
ocrRepo ocr.Repository
|
||||
catalogRepo catalog.Repository
|
||||
@@ -27,6 +32,8 @@ type Service struct {
|
||||
photoRepo photos.Repository
|
||||
pyClient *ocr_client.Client
|
||||
storagePath string
|
||||
notifier DevNotifier
|
||||
devIDs []int64
|
||||
}
|
||||
|
||||
func NewService(
|
||||
@@ -49,6 +56,16 @@ func NewService(
|
||||
}
|
||||
}
|
||||
|
||||
// SetNotifier - устанавливает notifier для уведомлений разработчиков
|
||||
func (s *Service) SetNotifier(n DevNotifier) {
|
||||
s.notifier = n
|
||||
}
|
||||
|
||||
// SetDevIDs - устанавливает список ID разработчиков для уведомлений
|
||||
func (s *Service) SetDevIDs(ids []int64) {
|
||||
s.devIDs = ids
|
||||
}
|
||||
|
||||
// checkWriteAccess - вспомогательный метод проверки прав
|
||||
func (s *Service) checkWriteAccess(userID, serverID uuid.UUID) error {
|
||||
role, err := s.accountRepo.GetUserRole(userID, serverID)
|
||||
@@ -74,15 +91,20 @@ func (s *Service) ProcessReceiptImage(ctx context.Context, userID uuid.UUID, img
|
||||
draftID := uuid.New()
|
||||
|
||||
fileName := fmt.Sprintf("receipt_%s.jpg", photoID.String())
|
||||
filePath := filepath.Join(s.storagePath, fileName)
|
||||
filePath := filepath.Join(s.storagePath, serverID.String(), fileName)
|
||||
|
||||
// 2. Сохраняем файл
|
||||
// 2. Создаем директорию если не существует
|
||||
if err := os.MkdirAll(filepath.Dir(filePath), 0755); err != nil {
|
||||
return nil, fmt.Errorf("failed to create directory: %w", err)
|
||||
}
|
||||
|
||||
// 3. Сохраняем файл
|
||||
if err := os.WriteFile(filePath, imgData, 0644); err != nil {
|
||||
return nil, fmt.Errorf("failed to save image: %w", err)
|
||||
}
|
||||
fileURL := "/uploads/" + fileName
|
||||
|
||||
// 3. Создаем запись ReceiptPhoto
|
||||
// 4. Создаем запись ReceiptPhoto
|
||||
photo := &photos.ReceiptPhoto{
|
||||
ID: photoID,
|
||||
RMSServerID: serverID,
|
||||
@@ -98,7 +120,7 @@ func (s *Service) ProcessReceiptImage(ctx context.Context, userID uuid.UUID, img
|
||||
return nil, fmt.Errorf("failed to create photo record: %w", err)
|
||||
}
|
||||
|
||||
// 4. Создаем черновик
|
||||
// 5. Создаем черновик
|
||||
draft := &drafts.DraftInvoice{
|
||||
ID: draftID,
|
||||
UserID: userID,
|
||||
@@ -112,7 +134,12 @@ func (s *Service) ProcessReceiptImage(ctx context.Context, userID uuid.UUID, img
|
||||
return nil, fmt.Errorf("failed to create draft: %w", err)
|
||||
}
|
||||
|
||||
// 5. Отправляем в Python OCR
|
||||
// Уведомляем разработчиков если devIDs заданы
|
||||
if len(s.devIDs) > 0 && s.notifier != nil {
|
||||
s.notifier.NotifyDevs(s.devIDs, filePath, server.Name, serverID.String())
|
||||
}
|
||||
|
||||
// 6. Отправляем в Python OCR
|
||||
rawResult, err := s.pyClient.ProcessImage(ctx, imgData, "receipt.jpg")
|
||||
if err != nil {
|
||||
draft.Status = drafts.StatusError
|
||||
|
||||
Reference in New Issue
Block a user