Files
pig-farm-controller/internal/infra/models/recipe.go

30 lines
939 B
Go
Raw Normal View History

2025-11-22 20:52:15 +08:00
package models
// Recipe 配方模型
type Recipe struct {
Model
Name string `gorm:"size:100;not null;comment:配方名称"`
Description string `gorm:"size:255;comment:配方描述"`
// RecipeIngredients 关联此配方的所有原料组成
RecipeIngredients []RecipeIngredient `gorm:"foreignKey:RecipeID"`
}
func (Recipe) TableName() string {
return "recipes"
}
// RecipeIngredient 配方原料组成模型
type RecipeIngredient struct {
Model
RecipeID uint32 `gorm:"not null;comment:关联的配方ID"`
Recipe Recipe `gorm:"foreignKey:RecipeID"`
RawMaterialID uint32 `gorm:"not null;comment:关联的原料ID"`
RawMaterial RawMaterial `gorm:"foreignKey:RawMaterialID"`
// 重量百分比
Percentage float32 `gorm:"not null;comment:原料在配方中的百分比 (0-1之间的小数, 例如0.15代表15%)"`
}
func (RecipeIngredient) TableName() string {
return "recipe_ingredients"
}