实现 猪舍相关路由组 和 猪圈相关路由组

This commit is contained in:
2025-10-03 18:27:53 +08:00
parent 5754a1d94c
commit 8cbe313c89
13 changed files with 840 additions and 47 deletions

View File

@@ -44,6 +44,10 @@ type PigBatch struct {
Pens []Pen `gorm:"foreignKey:PigBatchID;comment:所在圈舍ID"`
}
func (PigBatch) TableName() string {
return "pig_batches"
}
// LogChangeType 定义了猪批次数量变更的类型
type LogChangeType string
@@ -60,7 +64,7 @@ const (
// PigBatchLog 记录了猪批次数量或状态的每一次变更
type PigBatchLog struct {
gorm.Model
ID uint `gorm:"primaryKey"`
PigBatchID uint `gorm:"not null;index;comment:关联的猪批次ID"`
ChangeType LogChangeType `gorm:"size:20;not null;comment:变更类型"`
ChangeCount int `gorm:"not null;comment:数量变化,负数表示减少"`
@@ -70,5 +74,12 @@ type PigBatchLog struct {
BeforeSickCount int `gorm:"not null;comment:变更前病猪数"`
AfterSickCount int `gorm:"not null;comment:变更后病猪数"`
Operator string `gorm:"size:50;comment:操作员"`
HappenedAt time.Time `gorm:"not null;default:CURRENT_TIMESTAMP;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"
}