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

70 lines
2.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 catalog
import (
"time"
"github.com/google/uuid"
"github.com/shopspring/decimal"
)
// MeasureUnit - Единица измерения (kg, l, pcs)
type MeasureUnit struct {
ID uuid.UUID `gorm:"type:uuid;primary_key;" json:"id"`
RMSServerID uuid.UUID `gorm:"type:uuid;not null;index" json:"-"`
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"`
RMSServerID uuid.UUID `gorm:"type:uuid;not null;index" json:"-"`
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;" json:"id"`
RMSServerID uuid.UUID `gorm:"type:uuid;not null;index" json:"-"`
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"`
// Связь с единицей измерения
MainUnitID *uuid.UUID `gorm:"type:uuid;index" json:"main_unit_id"`
MainUnit *MeasureUnit `gorm:"foreignKey:MainUnitID" json:"main_unit,omitempty"`
// Фасовки
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
SaveContainer(container ProductContainer) error
Search(serverID uuid.UUID, query string) ([]Product, error)
GetActiveGoods(serverID uuid.UUID) ([]Product, error)
SaveStores(stores []Store) error
GetActiveStores(serverID uuid.UUID) ([]Store, error)
CountGoods(serverID uuid.UUID) (int64, error)
CountStores(serverID uuid.UUID) (int64, error)
}