还原改动, bmad真难用

This commit is contained in:
2025-11-02 15:07:19 +08:00
parent 548d3eae00
commit 8e97922012
453 changed files with 4 additions and 81231 deletions

View File

@@ -1,7 +1,6 @@
package repository
import (
"errors"
"fmt"
"strconv"
@@ -45,22 +44,12 @@ type DeviceRepository interface {
// gormDeviceRepository 是 DeviceRepository 的 GORM 实现
type gormDeviceRepository struct {
db *gorm.DB
deviceCommandLogRepo DeviceCommandLogRepository
pendingCollectionRepo PendingCollectionRepository
db *gorm.DB
}
// NewGormDeviceRepository 创建一个新的 DeviceRepository GORM 实现实例
func NewGormDeviceRepository(
db *gorm.DB,
deviceCommandLogRepo DeviceCommandLogRepository,
pendingCollectionRepo PendingCollectionRepository,
) DeviceRepository {
return &gormDeviceRepository{
db: db,
deviceCommandLogRepo: deviceCommandLogRepo,
pendingCollectionRepo: pendingCollectionRepo,
}
func NewGormDeviceRepository(db *gorm.DB) DeviceRepository {
return &gormDeviceRepository{db: db}
}
// Create 创建一个新的设备记录
@@ -140,24 +129,6 @@ func (r *gormDeviceRepository) Update(device *models.Device) error {
// Delete 根据 ID 删除一个设备
// GORM 使用软删除,记录不会从数据库中物理移除,而是设置 DeletedAt 字段。
func (r *gormDeviceRepository) Delete(id uint) error {
// 检查是否有相关的设备命令日志
logs, err := r.deviceCommandLogRepo.FindByDeviceID(id)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return fmt.Errorf("查询设备 %d 的命令日志失败: %w", id, err)
}
if len(logs) > 0 {
return errors.New("设备有相关的命令日志,不能删除")
}
// 检查是否有相关的待处理采集请求
pendingCollections, err := r.pendingCollectionRepo.FindByDeviceID(id)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return fmt.Errorf("查询设备 %d 的待处理采集请求失败: %w", id, err)
}
if len(pendingCollections) > 0 {
return errors.New("设备有相关的待处理采集请求,不能删除")
}
return r.db.Delete(&models.Device{}, id).Error
}