定义model
This commit is contained in:
@@ -39,7 +39,6 @@ type PigBatch struct {
|
||||
InitialCount int `gorm:"not null;comment:初始数量"`
|
||||
CurrentCount int `gorm:"not null;comment:当前存栏数量"`
|
||||
CurrentSickCount int `gorm:"not null;default:0;comment:当前病猪数量"`
|
||||
AverageWeight float64 `gorm:"comment:平均体重 (kg)"`
|
||||
Status PigBatchStatus `gorm:"size:20;not null;index;comment:批次状态"`
|
||||
Pens []Pen `gorm:"foreignKey:PigBatchID;comment:所在圈舍ID"`
|
||||
}
|
||||
@@ -64,7 +63,7 @@ const (
|
||||
|
||||
// PigBatchLog 记录了猪批次数量或状态的每一次变更
|
||||
type PigBatchLog struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
gorm.Model
|
||||
PigBatchID uint `gorm:"not null;index;comment:关联的猪批次ID"`
|
||||
ChangeType LogChangeType `gorm:"size:20;not null;comment:变更类型"`
|
||||
ChangeCount int `gorm:"not null;comment:数量变化,负数表示减少"`
|
||||
@@ -75,11 +74,35 @@ type PigBatchLog struct {
|
||||
AfterSickCount int `gorm:"not null;comment:变更后病猪数"`
|
||||
Operator string `gorm:"size:50;comment:操作员"`
|
||||
HappenedAt time.Time `gorm:"primaryKey;comment:事件发生时间"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||
}
|
||||
|
||||
func (PigBatchLog) TableName() string {
|
||||
return "pig_batch_logs"
|
||||
}
|
||||
|
||||
// WeighingBatch 记录了一次批次称重的信息
|
||||
type WeighingBatch struct {
|
||||
gorm.Model
|
||||
WeighingTime time.Time `gorm:"primaryKey;comment:称重时间"`
|
||||
Description string `gorm:"size:255;comment:批次称重描述"`
|
||||
PigBatchID uint `gorm:"not null;index;comment:关联的猪批次ID"`
|
||||
}
|
||||
|
||||
func (WeighingBatch) TableName() string {
|
||||
return "weighing_batches"
|
||||
}
|
||||
|
||||
// WeighingRecord 记录了单次称重信息
|
||||
type WeighingRecord struct {
|
||||
gorm.Model
|
||||
Weight float64 `gorm:"not null;comment:单只猪重量 (kg)"`
|
||||
WeighingBatchID uint `gorm:"not null;index;comment:关联的批次称重ID"`
|
||||
PenID uint `gorm:"not null;index;comment:所在猪圈ID"`
|
||||
OperatorID uint `gorm:"not null;comment:操作员ID"`
|
||||
Remark string `gorm:"size:255;comment:备注"`
|
||||
WeighingTime time.Time `gorm:"primaryKey;comment:称重时间"`
|
||||
}
|
||||
|
||||
func (WeighingRecord) TableName() string {
|
||||
return "weighing_records"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user