定义猪的模型和营养需求模型

This commit is contained in:
2025-11-20 14:38:36 +08:00
parent c697e668e3
commit 6ca101727a
6 changed files with 121 additions and 4 deletions

View File

@@ -56,6 +56,10 @@ func GetAllModels() []interface{} {
&WeighingRecord{},
&PigTransferLog{},
&PigSickLog{},
&PigBreed{},
&PigAgeStage{},
&PigType{},
&PigNutrientRequirement{},
// Pig Buy & Sell
&PigPurchase{},
@@ -119,7 +123,7 @@ func (a *UintArray) Scan(src interface{}) error {
case string:
srcStr = v
default:
return errors.New("无法扫描非字符串或字节类型的源到 UintArray")
return errors.New("无法将值 %v (类型 %T) 扫描为 UintArray")
}
// 去掉花括号

View File

@@ -0,0 +1,43 @@
package models
// PigBreed 猪品种模型
type PigBreed struct {
Model
Name string `gorm:"size:50;not null;comment:品种名称"`
Description string `gorm:"size:255;comment:品种描述"`
}
func (PigBreed) TableName() string {
return "pig_breeds"
}
// PigAgeStage 猪年龄阶段模型
type PigAgeStage struct {
Model
Name string `gorm:"size:50;not null;comment:年龄阶段名称 (如: 仔猪, 生长猪, 育肥猪)"`
Description string `gorm:"size:255;comment:阶段描述"`
}
func (PigAgeStage) TableName() string {
return "pig_age_stages"
}
// PigType 猪类型模型,代表特定品种和年龄阶段的组合
type PigType struct {
Model
BreedID uint32 `gorm:"not null;index;comment:关联的猪品种ID"`
Breed PigBreed `gorm:"foreignKey:BreedID"`
AgeStageID uint32 `gorm:"not null;index;comment:关联的猪年龄阶段ID"`
AgeStage PigAgeStage `gorm:"foreignKey:AgeStageID"`
Description string `gorm:"size:255;comment:该猪类型的描述或特点"`
DailyFeedIntake float32 `gorm:"comment:理论日均食量 (g/天)"`
DailyGainWeight float32 `gorm:"comment:理论日增重 (g/天)"`
MinDays uint32 `gorm:"comment:该猪类型在该年龄阶段的最小日龄"`
MaxDays uint32 `gorm:"comment:该猪类型在该年龄阶段的最大日龄"`
MinWeight float32 `gorm:"comment:该猪类型在该年龄阶段的最小体重 (g)"`
MaxWeight float32 `gorm:"comment:该猪类型在该年龄阶段的最大体重 (g)"`
}
func (PigType) TableName() string {
return "pig_types"
}

View File

@@ -0,0 +1,16 @@
package models
// PigNutrientRequirement 猪营养需求模型
type PigNutrientRequirement struct {
Model
PigTypeID uint32 `gorm:"not null;index;comment:关联的猪类型ID"`
PigType PigType `gorm:"foreignKey:PigTypeID"`
NutrientID uint32 `gorm:"not null;index;comment:关联的营养素ID"`
Nutrient Nutrient `gorm:"foreignKey:NutrientID"`
MinRequirement float32 `gorm:"not null;comment:最低营养需求量"`
MaxRequirement float32 `gorm:"not null;comment:最高营养需求量"`
}
func (PigNutrientRequirement) TableName() string {
return "pig_nutrient_requirements"
}