mirror of
https://github.com/serty2005/rmser.git
synced 2026-02-05 03:12:34 -06:00
added front - react+ts
ocr improved
This commit is contained in:
@@ -7,27 +7,51 @@ import (
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// MeasureUnit - Единица измерения (kg, l, pcs)
|
||||
type MeasureUnit struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;" json:"id"`
|
||||
Name string `gorm:"type:varchar(50);not null" json:"name"`
|
||||
Code string `gorm:"type:varchar(50)" json:"code"`
|
||||
}
|
||||
|
||||
// ProductContainer - Фасовка (упаковка) товара
|
||||
type ProductContainer struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;" json:"id"`
|
||||
ProductID uuid.UUID `gorm:"type:uuid;index;not null" json:"product_id"`
|
||||
Name string `gorm:"type:varchar(100);not null" json:"name"`
|
||||
Count decimal.Decimal `gorm:"type:numeric(19,4);not null" json:"count"` // Коэфф. пересчета
|
||||
}
|
||||
|
||||
// Product - Номенклатура
|
||||
type Product struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;"`
|
||||
ParentID *uuid.UUID `gorm:"type:uuid;index"`
|
||||
Name string `gorm:"type:varchar(255);not null"`
|
||||
Type string `gorm:"type:varchar(50);index"` // GOODS, DISH, PREPARED, etc.
|
||||
Num string `gorm:"type:varchar(50)"`
|
||||
Code string `gorm:"type:varchar(50)"`
|
||||
UnitWeight decimal.Decimal `gorm:"type:numeric(19,4)"`
|
||||
UnitCapacity decimal.Decimal `gorm:"type:numeric(19,4)"`
|
||||
IsDeleted bool `gorm:"default:false"`
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;" json:"id"`
|
||||
ParentID *uuid.UUID `gorm:"type:uuid;index" json:"parent_id"`
|
||||
Name string `gorm:"type:varchar(255);not null" json:"name"`
|
||||
Type string `gorm:"type:varchar(50);index" json:"type"` // GOODS, DISH, PREPARED
|
||||
Num string `gorm:"type:varchar(50)" json:"num"`
|
||||
Code string `gorm:"type:varchar(50)" json:"code"`
|
||||
UnitWeight decimal.Decimal `gorm:"type:numeric(19,4)" json:"unit_weight"`
|
||||
UnitCapacity decimal.Decimal `gorm:"type:numeric(19,4)" json:"unit_capacity"`
|
||||
|
||||
Parent *Product `gorm:"foreignKey:ParentID"`
|
||||
Children []*Product `gorm:"foreignKey:ParentID"`
|
||||
// Связь с единицей измерения
|
||||
MainUnitID *uuid.UUID `gorm:"type:uuid;index" json:"main_unit_id"`
|
||||
MainUnit *MeasureUnit `gorm:"foreignKey:MainUnitID" json:"main_unit,omitempty"`
|
||||
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
// Фасовки
|
||||
Containers []ProductContainer `gorm:"foreignKey:ProductID;constraint:OnDelete:CASCADE" json:"containers,omitempty"`
|
||||
|
||||
IsDeleted bool `gorm:"default:false" json:"is_deleted"`
|
||||
|
||||
Parent *Product `gorm:"foreignKey:ParentID" json:"-"`
|
||||
Children []*Product `gorm:"foreignKey:ParentID" json:"-"`
|
||||
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// Repository интерфейс для каталога
|
||||
type Repository interface {
|
||||
SaveMeasureUnits(units []MeasureUnit) error
|
||||
SaveProducts(products []Product) error
|
||||
GetAll() ([]Product, error)
|
||||
GetActiveGoods() ([]Product, error)
|
||||
|
||||
@@ -3,32 +3,44 @@ package ocr
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"rmser/internal/domain/catalog"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// ProductMatch связывает текст из чека с конкретным товаром в iiko
|
||||
type ProductMatch struct {
|
||||
// RawName - распознанный текст (ключ).
|
||||
// Лучше хранить в нижнем регистре и без лишних пробелов.
|
||||
RawName string `gorm:"type:varchar(255);primary_key"`
|
||||
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"`
|
||||
|
||||
ProductID uuid.UUID `gorm:"type:uuid;not null;index"`
|
||||
// Количество и фасовки
|
||||
Quantity decimal.Decimal `gorm:"type:numeric(19,4);default:1" json:"quantity"`
|
||||
ContainerID *uuid.UUID `gorm:"type:uuid;index" json:"container_id"`
|
||||
|
||||
// Product - связь для GORM
|
||||
Product catalog.Product `gorm:"foreignKey:ProductID"`
|
||||
// Для подгрузки данных о фасовке при чтении
|
||||
Container *catalog.ProductContainer `gorm:"foreignKey:ContainerID" json:"container,omitempty"`
|
||||
|
||||
UpdatedAt time.Time
|
||||
CreatedAt time.Time
|
||||
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 сохраняет или обновляет привязку
|
||||
SaveMatch(rawName string, productID uuid.UUID) error
|
||||
// SaveMatch теперь принимает quantity и containerID
|
||||
SaveMatch(rawName string, productID uuid.UUID, quantity decimal.Decimal, containerID *uuid.UUID) error
|
||||
|
||||
// FindMatch ищет товар по точному совпадению названия
|
||||
FindMatch(rawName string) (*uuid.UUID, error)
|
||||
|
||||
// GetAllMatches возвращает все существующие привязки
|
||||
FindMatch(rawName string) (*ProductMatch, error) // Возвращаем полную структуру, чтобы получить qty
|
||||
GetAllMatches() ([]ProductMatch, error)
|
||||
|
||||
UpsertUnmatched(rawName string) error
|
||||
GetTopUnmatched(limit int) ([]UnmatchedItem, error)
|
||||
DeleteUnmatched(rawName string) error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user