// Package model 提供数据模型定义 // 包含用户、猪舍、饲料等相关数据结构 package model import ( "time" "gorm.io/gorm" ) // User 代表系统用户 type User struct { // ID 用户ID ID uint `gorm:"primaryKey;column:id" json:"id"` // Username 用户名 Username string `gorm:"uniqueIndex;not null;column:username" json:"username"` // PasswordHash 密码哈希值 PasswordHash string `gorm:"not null;column:password_hash" json:"-"` // CreatedAt 创建时间 CreatedAt time.Time `gorm:"column:created_at" json:"created_at"` // UpdatedAt 更新时间 UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"` // DeletedAt 删除时间(用于软删除) DeletedAt gorm.DeletedAt `gorm:"index;column:deleted_at" json:"-"` // OperationHistories 用户的操作历史记录 OperationHistories []OperationHistory `gorm:"foreignKey:UserID" json:"-"` } // TableName 指定User模型对应的数据库表名 func (User) TableName() string { return "users" }