// Package model 提供数据模型定义 // 包含设备控制等相关数据结构 package model import ( "time" "gorm.io/gorm" ) // DeviceType 设备类型枚举 type DeviceType string const ( // DeviceTypeFan 风机 DeviceTypeFan DeviceType = "fan" // DeviceTypeWaterCurtain 水帘 DeviceTypeWaterCurtain DeviceType = "water_curtain" ) // DeviceControl 代表设备控制记录 type DeviceControl struct { // ID 记录ID ID uint `gorm:"primaryKey;column:id" json:"id"` // UserID 用户ID UserID uint `gorm:"not null;column:user_id;index" json:"user_id"` // PigPenID 猪舍编号 PigPenID string `gorm:"not null;column:pig_pen_id" json:"pig_pen_id"` // DeviceType 设备类型 DeviceType DeviceType `gorm:"not null;column:device_type" json:"device_type"` // DeviceID 设备编号 DeviceID string `gorm:"not null;column:device_id" json:"device_id"` // Action 控制动作(开/关) Action string `gorm:"not null;column:action" json:"action"` // Status 控制状态(成功/失败) Status string `gorm:"not null;column:status" json:"status"` // Result 控制结果详情(可选) Result string `gorm:"column:result" json:"result"` // 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:"-"` } // TableName 指定DeviceControl模型对应的数据库表名 func (DeviceControl) TableName() string { return "device_controls" }