定义对应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

@@ -66,3 +66,26 @@ type Medication struct {
Manufacturer string `gorm:"size:100;comment:生产厂家" json:"manufacturer"`
Instructions datatypes.JSON `gorm:"type:jsonb;comment:使用说明" json:"instructions"`
}
// MedicationReasonType 定义了用药原因
type MedicationReasonType string
const (
ReasonTypePreventive MedicationReasonType = "预防"
ReasonTypeTreatment MedicationReasonType = "治疗"
ReasonTypeHealthCare MedicationReasonType = "保健"
)
// GroupMedicationLog 记录了对整个猪批次的用药情况
type GroupMedicationLog struct {
gorm.Model
PigBatchID uint `gorm:"not null;index;comment:关联的猪批次ID"`
MedicationID uint `gorm:"not null;index;comment:关联的药品ID"`
Medication Medication `gorm:"foreignKey:MedicationID"` // 预加载药品信息
DosageUsed float64 `gorm:"not null;comment:使用的总剂量 (单位由药品决定,如g或ml)"`
TargetCount int `gorm:"not null;comment:用药对象数量"`
Reason MedicationReasonType `gorm:"size:20;not null;comment:用药原因"`
Description string `gorm:"size:255;comment:具体描述,如'治疗呼吸道病'"`
Operator string `gorm:"size:50;comment:操作员"`
HappenedAt time.Time `gorm:"not null;default:CURRENT_TIMESTAMP;comment:用药时间"`
}