Files
rmser/internal/domain/ocr/entity.go
2025-12-11 05:20:53 +03:00

47 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package ocr
import (
"time"
"rmser/internal/domain/catalog"
"github.com/google/uuid"
"github.com/shopspring/decimal"
)
// ProductMatch связывает текст из чека с конкретным товаром в iiko
type ProductMatch struct {
RawName string `gorm:"type:varchar(255);primary_key" json:"raw_name"`
ProductID uuid.UUID `gorm:"type:uuid;not null;index" json:"product_id"`
Product catalog.Product `gorm:"foreignKey:ProductID" json:"product"`
// Количество и фасовки
Quantity decimal.Decimal `gorm:"type:numeric(19,4);default:1" json:"quantity"`
ContainerID *uuid.UUID `gorm:"type:uuid;index" json:"container_id"`
// Для подгрузки данных о фасовке при чтении
Container *catalog.ProductContainer `gorm:"foreignKey:ContainerID" json:"container,omitempty"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt time.Time `json:"created_at"`
}
// UnmatchedItem хранит строки, которые не удалось распознать, для подсказок
type UnmatchedItem struct {
RawName string `gorm:"type:varchar(255);primary_key" json:"raw_name"`
Count int `gorm:"default:1" json:"count"` // Сколько раз встречалось
LastSeen time.Time `json:"last_seen"`
}
type Repository interface {
// SaveMatch теперь принимает quantity и containerID
SaveMatch(rawName string, productID uuid.UUID, quantity decimal.Decimal, containerID *uuid.UUID) error
FindMatch(rawName string) (*ProductMatch, error) // Возвращаем полную структуру, чтобы получить qty
GetAllMatches() ([]ProductMatch, error)
UpsertUnmatched(rawName string) error
GetTopUnmatched(limit int) ([]UnmatchedItem, error)
DeleteUnmatched(rawName string) error
}