增加任务设备关联表
This commit is contained in:
@@ -178,6 +178,9 @@ type Task struct {
|
||||
ExecutionOrder int `gorm:"not null" json:"execution_order"` // 在计划中的执行顺序
|
||||
Type TaskType `gorm:"not null" json:"type"` // 任务的类型,对应 task 包中的具体动作
|
||||
Parameters datatypes.JSON `json:"parameters"` // 任务特定参数的JSON (例如: 设备ID, 值)
|
||||
|
||||
// Devices 是与此任务关联的设备列表,通过 DeviceTask 关联表实现多对多关系
|
||||
Devices []Device `gorm:"many2many:device_tasks;" json:"devices"`
|
||||
}
|
||||
|
||||
// TableName 自定义 GORM 使用的数据库表名
|
||||
@@ -197,3 +200,18 @@ func (t Task) ParseParameters(v interface{}) error {
|
||||
}
|
||||
return json.Unmarshal(t.Parameters, v)
|
||||
}
|
||||
|
||||
// DeviceTask 是设备和任务之间的关联模型,表示一个设备可以执行多个任务,一个任务可以被多个设备执行。
|
||||
type DeviceTask struct {
|
||||
gorm.Model
|
||||
DeviceID uint `gorm:"not null;index"` // 设备ID
|
||||
TaskID uint `gorm:"not null;index"` // 任务ID
|
||||
|
||||
// 可选:如果需要存储关联的额外信息,可以在这里添加字段,例如:
|
||||
// Configuration datatypes.JSON `json:"configuration"` // 任务在特定设备上的配置
|
||||
}
|
||||
|
||||
// TableName 自定义 GORM 使用的数据库表名
|
||||
func (DeviceTask) TableName() string {
|
||||
return "device_tasks"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user