1. 增加新类型中继设备
2. 优化代码
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/model"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -15,6 +17,9 @@ type DeviceRepo interface {
|
||||
// FindByID 根据ID查找设备
|
||||
FindByID(id uint) (*model.Device, error)
|
||||
|
||||
// FindByIDString 根据ID字符串查找设备
|
||||
FindByIDString(id string) (*model.Device, error)
|
||||
|
||||
// FindByParentID 根据上级设备ID查找设备
|
||||
FindByParentID(parentID uint) ([]*model.Device, error)
|
||||
|
||||
@@ -83,6 +88,21 @@ func (r *deviceRepo) FindByID(id uint) (*model.Device, error) {
|
||||
return &device, nil
|
||||
}
|
||||
|
||||
// FindByIDString 根据ID字符串查找设备
|
||||
func (r *deviceRepo) FindByIDString(id string) (*model.Device, error) {
|
||||
deviceID, err := strconv.ParseUint(id, 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var device model.Device
|
||||
result := r.db.First(&device, deviceID)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
return &device, nil
|
||||
}
|
||||
|
||||
// FindByParentID 根据上级设备ID查找设备
|
||||
func (r *deviceRepo) FindByParentID(parentID uint) ([]*model.Device, error) {
|
||||
var devices []*model.Device
|
||||
|
||||
Reference in New Issue
Block a user