1. 增加程序启动时自动迁移表

2. 增加设备信息model和基础操作函数
This commit is contained in:
2025-09-08 10:58:26 +08:00
parent 0895cf42b2
commit bab44e7e3a
6 changed files with 168 additions and 10 deletions

View File

@@ -17,8 +17,46 @@ const (
// DeviceTypeWaterCurtain 水帘
DeviceTypeWaterCurtain DeviceType = "water_curtain"
// DeviceTypePigPenController 猪舍主控
DeviceTypePigPenController DeviceType = "pig_pen_controller"
// DeviceTypeFeedMillController 做料车间主控
DeviceTypeFeedMillController DeviceType = "feed_mill_controller"
)
// Device 代表设备信息
type Device struct {
// ID 设备ID
ID uint `gorm:"primaryKey;column:id" json:"id"`
// Name 设备名称
Name string `gorm:"not null;column:name" json:"name"`
// Type 设备类型
Type DeviceType `gorm:"not null;column:type" json:"type"`
// ParentID 上级设备ID(用于设备层级关系,指向区域主控设备)
ParentID *uint `gorm:"column:parent_id;index" json:"parent_id"`
// Status 设备状态
Status string `gorm:"not null;column:status" json:"status"`
// 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 指定Device模型对应的数据库表名
func (Device) TableName() string {
return "devices"
}
// DeviceControl 代表设备控制记录
type DeviceControl struct {
// ID 记录ID
@@ -27,8 +65,8 @@ type DeviceControl struct {
// 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"`
// Location 设备安装位置描述
Location string `gorm:"not null;column:location" json:"location"`
// DeviceType 设备类型
DeviceType DeviceType `gorm:"not null;column:device_type" json:"device_type"`