40 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package models
 | ||
| 
 | ||
| import (
 | ||
| 	"time"
 | ||
| 
 | ||
| 	"gorm.io/gorm"
 | ||
| )
 | ||
| 
 | ||
| // PigTransferType 定义了猪只迁移的类型
 | ||
| type PigTransferType string
 | ||
| 
 | ||
| const (
 | ||
| 	PigTransferTypeInternal             PigTransferType = "群内调栏" // 同一猪群内猪栏间的调动
 | ||
| 	PigTransferTypeCrossBatch           PigTransferType = "跨群调栏" // 不同猪群间的调动
 | ||
| 	PigTransferTypeSale                 PigTransferType = "销售"   // 猪只售出
 | ||
| 	PigTransferTypeDeath                PigTransferType = "死亡"   // 猪只死亡
 | ||
| 	PigTransferTypeCull                 PigTransferType = "淘汰"   // 猪只淘汰
 | ||
| 	PigTransferTypePurchase             PigTransferType = "新购入"  // 新购入猪只
 | ||
| 	PigTransferTypeDeliveryRoomTransfor 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"
 | ||
| }
 |