Files
rmser/internal/domain/ocr/entity.go
SERTY 542beafe0e Перевел на multi-tenant
Добавил поставщиков
Накладные успешно создаются из фронта
2025-12-18 03:56:21 +03:00

54 lines
2.5 KiB
Go
Raw Permalink 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
type ProductMatch struct {
// RawName больше не PrimaryKey, так как в разных серверах один текст может значить разное
// Делаем составной ключ или суррогатный ID.
// Для простоты GORM: ID - uuid, а уникальность через индекс (RawName + ServerID)
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()"`
RMSServerID uuid.UUID `gorm:"type:uuid;not null;index:idx_raw_server,unique"`
RawName string `gorm:"type:varchar(255);not null;index:idx_raw_server,unique" 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 тоже стоит делить, чтобы подсказывать пользователю только его нераспознанные,
// хотя глобальная база unmatched может быть полезна для аналитики.
// Сделаем раздельной для чистоты SaaS.
type UnmatchedItem struct {
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()"`
RMSServerID uuid.UUID `gorm:"type:uuid;not null;index:idx_unm_raw_server,unique"`
RawName string `gorm:"type:varchar(255);not null;index:idx_unm_raw_server,unique" json:"raw_name"`
Count int `gorm:"default:1" json:"count"`
LastSeen time.Time `json:"last_seen"`
}
type Repository interface {
SaveMatch(serverID uuid.UUID, rawName string, productID uuid.UUID, quantity decimal.Decimal, containerID *uuid.UUID) error
DeleteMatch(serverID uuid.UUID, rawName string) error
FindMatch(serverID uuid.UUID, rawName string) (*ProductMatch, error)
GetAllMatches(serverID uuid.UUID) ([]ProductMatch, error)
UpsertUnmatched(serverID uuid.UUID, rawName string) error
GetTopUnmatched(serverID uuid.UUID, limit int) ([]UnmatchedItem, error)
DeleteUnmatched(serverID uuid.UUID, rawName string) error
}