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

38 lines
2.2 KiB
Go
Raw Normal View History

package models
import (
"time"
)
2025-10-05 21:20:22 +08:00
// PigTransferType 定义了猪只迁移的类型
type PigTransferType string
const (
2025-10-05 21:25:13 +08:00
PigTransferTypeInternal PigTransferType = "群内调栏" // 同一猪群内猪栏间的调动
PigTransferTypeCrossBatch PigTransferType = "跨群调栏" // 不同猪群间的调动
PigTransferTypeSale PigTransferType = "销售" // 猪只售出
PigTransferTypeDeath PigTransferType = "死亡" // 猪只死亡
2025-10-06 22:22:10 +08:00
PigTransferTypeCull PigTransferType = "淘汰" // 猪只淘汰
2025-10-05 21:25:13 +08:00
PigTransferTypePurchase PigTransferType = "新购入" // 新购入猪只
PigTransferTypeDeliveryRoomTransfor PigTransferType = "产房转入" // 产房转入
// 可以根据业务需求添加更多类型,例如:转出到其他农场等
2025-10-05 21:20:22 +08:00
)
// PigTransferLog 记录了每一次猪只数量在猪栏间的变动事件。
// 它作为事件溯源的基础,用于推算任意时间点猪栏的猪只数量。
type PigTransferLog struct {
2025-11-10 22:23:31 +08:00
Model
2025-10-05 21:20:22 +08:00
TransferTime time.Time `gorm:"primaryKey;comment:迁移发生时间" json:"transfer_time"` // 迁移发生时间,作为联合主键
2025-11-10 22:23:31 +08:00
PigBatchID uint32 `gorm:"primaryKey;comment:关联的猪群ID" json:"pig_batch_id"` // 关联的猪群ID作为联合主键
PenID uint32 `gorm:"primaryKey;comment:发生变动的猪栏ID" json:"pen_id"` // 发生变动的猪栏ID作为联合主键
2025-10-05 21:20:22 +08:00
Quantity int `gorm:"not null;comment:变动数量(正数表示增加,负数表示减少)" json:"quantity"` // 变动数量(正数表示增加,负数减少)
Type PigTransferType `gorm:"not null;comment:变动类型" json:"type"` // 变动类型,使用枚举类型
CorrelationID string `gorm:"comment:用于关联一次完整操作(如一次调栏会产生两条日志)" json:"correlation_id"` // 用于关联一次完整操作
2025-11-10 22:23:31 +08:00
OperatorID uint32 `gorm:"not null;comment:操作员ID" json:"operator_id"` // 操作员ID
2025-10-05 21:20:22 +08:00
Remarks string `gorm:"comment:备注" json:"remarks"`
}
func (p PigTransferLog) TableName() string {
return "pig_transfer_logs"
}