Files
pig-farm-controller/internal/infra/models/pig_transfer.go
2025-10-05 21:20:22 +08:00

38 lines
2.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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