定义对应model

This commit is contained in:
2025-10-03 16:56:03 +08:00
parent 829f0a6253
commit 609aee2513
3 changed files with 132 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
package models
import (
"gorm.io/gorm"
)
/*
猪场固定资产相关模型
*/
// PigHouse 定义了猪舍,是猪栏的集合
type PigHouse struct {
gorm.Model
Name string `gorm:"size:100;not null;unique;comment:猪舍名称, 如 '育肥舍A栋'"`
Description string `gorm:"size:255;comment:描述信息"`
Pens []Pen `gorm:"foreignKey:HouseID"` // 一个猪舍包含多个猪栏
}
// PenStatus 定义了猪栏的当前状态
type PenStatus string
const (
PenStatusEmpty PenStatus = "空闲"
PenStatusOccupied PenStatus = "占用"
PenStatusSickPen PenStatus = "病猪栏"
PenStatusRecovering PenStatus = "康复栏"
PenStatusCleaning PenStatus = "清洗消毒"
PenStatusUnderMaint PenStatus = "维修中"
)
// Pen 是猪栏的物理实体模型, 是所有空间相关数据的“锚点”
type Pen struct {
gorm.Model
PenNumber string `gorm:"not null;comment:猪栏的唯一编号, 如 A-01"`
HouseID uint `gorm:"index;comment:所属猪舍ID"`
PigBatchID uint `gorm:"index;comment:关联的猪批次ID"`
Capacity int `gorm:"not null;comment:设计容量 (头)"`
Status PenStatus `gorm:"not null;index;comment:猪栏当前状态"`
}