增加设备模板列表
This commit is contained in:
@@ -26,6 +26,9 @@ type DeviceRepository interface {
|
||||
// ListByAreaControllerID 根据区域主控 ID 列出所有子设备。
|
||||
ListByAreaControllerID(areaControllerID uint) ([]*models.Device, error)
|
||||
|
||||
// FindByDeviceTemplateID 根据设备模板ID查找所有使用该模板的设备
|
||||
FindByDeviceTemplateID(deviceTemplateID uint) ([]*models.Device, error)
|
||||
|
||||
// Update 更新一个已有的设备信息
|
||||
Update(device *models.Device) error
|
||||
|
||||
@@ -91,6 +94,16 @@ func (r *gormDeviceRepository) ListByAreaControllerID(areaControllerID uint) ([]
|
||||
return devices, nil
|
||||
}
|
||||
|
||||
// FindByDeviceTemplateID 根据设备模板ID查找所有使用该模板的设备
|
||||
func (r *gormDeviceRepository) FindByDeviceTemplateID(deviceTemplateID uint) ([]*models.Device, error) {
|
||||
var devices []*models.Device
|
||||
err := r.db.Where("device_template_id = ?", deviceTemplateID).Find(&devices).Error
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("查询使用设备模板ID %d 的设备失败: %w", deviceTemplateID, err)
|
||||
}
|
||||
return devices, nil
|
||||
}
|
||||
|
||||
// Update 更新一个已有的设备信息
|
||||
// GORM 的 Save 方法会自动处理主键存在时更新,不存在时创建的逻辑,但这里我们明确用于更新。
|
||||
func (r *gormDeviceRepository) Update(device *models.Device) error {
|
||||
|
||||
Reference in New Issue
Block a user