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
|
||||
|
||||
@@ -20,6 +20,9 @@ type OperationHistoryRepo interface {
|
||||
|
||||
// List 获取操作历史记录列表(分页)
|
||||
List(offset, limit int) ([]*model.OperationHistory, error)
|
||||
|
||||
// ListByUserID 根据用户ID获取操作历史记录列表(分页)
|
||||
ListByUserID(userID uint, offset, limit int) ([]*model.OperationHistory, error)
|
||||
}
|
||||
|
||||
// operationHistoryRepo 操作历史仓库实现
|
||||
@@ -69,3 +72,13 @@ func (r *operationHistoryRepo) List(offset, limit int) ([]*model.OperationHistor
|
||||
}
|
||||
return histories, nil
|
||||
}
|
||||
|
||||
// ListByUserID 根据用户ID获取操作历史记录列表(分页)
|
||||
func (r *operationHistoryRepo) ListByUserID(userID uint, offset, limit int) ([]*model.OperationHistory, error) {
|
||||
var histories []*model.OperationHistory
|
||||
result := r.db.Where("user_id = ?", userID).Offset(offset).Limit(limit).Order("created_at DESC").Find(&histories)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
return histories, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user