实现原材料的增删改查和仓库层的原料库存记录表增查
This commit is contained in:
@@ -23,9 +23,8 @@ type RawMaterial struct {
|
||||
Model
|
||||
Name string `gorm:"size:100;unique;not null;comment:原料名称"`
|
||||
Description string `gorm:"size:255;comment:描述"`
|
||||
// Quantity 是当前库存的快照值,用于提供高性能的库存查询。
|
||||
// 注意:此字段的值必须在数据库事务中与 RawMaterialStockLog 同步更新,以保证数据一致性。
|
||||
Quantity float32 `gorm:"not null;default:0;comment:当前库存快照, 单位: g"`
|
||||
// RawMaterialNutrients 关联此原料的所有营养素含量信息
|
||||
RawMaterialNutrients []RawMaterialNutrient `gorm:"foreignKey:RawMaterialID"`
|
||||
}
|
||||
|
||||
func (RawMaterial) TableName() string {
|
||||
@@ -39,6 +38,8 @@ type Nutrient struct {
|
||||
Model
|
||||
Name string `gorm:"size:100;unique;not null;comment:营养素名称"`
|
||||
Description string `gorm:"size:255;comment:描述"`
|
||||
// RawMaterialNutrients 记录营养在哪些原料中存在且比例是多少
|
||||
RawMaterialNutrients []RawMaterialNutrient `gorm:"foreignKey:NutrientID"`
|
||||
}
|
||||
|
||||
func (Nutrient) TableName() string {
|
||||
@@ -66,9 +67,11 @@ func (RawMaterialNutrient) TableName() string {
|
||||
// 它是保证数据一致性和可审计性的核心。
|
||||
type RawMaterialStockLog struct {
|
||||
Model
|
||||
RawMaterialID uint32 `gorm:"not null;index;comment:关联的原料ID"`
|
||||
RawMaterial RawMaterial `gorm:"foreignKey:RawMaterialID"`
|
||||
ChangeAmount float32 `gorm:"not null;comment:变动数量, 正数为入库, 负数为出库, 单位: g"`
|
||||
RawMaterialID uint32 `gorm:"not null;index;comment:关联的原料ID"`
|
||||
RawMaterial RawMaterial `gorm:"foreignKey:RawMaterialID"`
|
||||
ChangeAmount float32 `gorm:"not null;comment:变动数量, 正数为入库, 负数为出库, 单位: g"`
|
||||
BeforeQuantity float32 `gorm:"not null;comment:变动前库存数量, 单位: g"`
|
||||
AfterQuantity float32 `gorm:"not null;comment:变动后库存数量, 单位: g"`
|
||||
// SourceType 告知 SourceID 关联的是哪种类型的业务单据。
|
||||
SourceType StockLogSourceType `gorm:"size:50;not null;index;comment:库存变动来源类型"`
|
||||
// SourceID 是一个多态外键,关联到触发此次变动的业务单据ID (如采购单ID)。
|
||||
|
||||
Reference in New Issue
Block a user