删除设备模板时检查和删除区域主控时检查
This commit is contained in:
		@@ -46,6 +46,9 @@ type DeviceRepository interface {
 | 
			
		||||
 | 
			
		||||
	// IsDeviceInUse 检查设备是否被任何任务使用
 | 
			
		||||
	IsDeviceInUse(deviceID uint) (bool, error)
 | 
			
		||||
 | 
			
		||||
	// IsAreaControllerInUse 检查区域主控是否被任何设备使用
 | 
			
		||||
	IsAreaControllerInUse(areaControllerID uint) (bool, error)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// gormDeviceRepository 是 DeviceRepository 的 GORM 实现
 | 
			
		||||
@@ -175,3 +178,12 @@ func (r *gormDeviceRepository) IsDeviceInUse(deviceID uint) (bool, error) {
 | 
			
		||||
	}
 | 
			
		||||
	return count > 0, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IsAreaControllerInUse 检查区域主控是否被任何设备使用
 | 
			
		||||
func (r *gormDeviceRepository) IsAreaControllerInUse(areaControllerID uint) (bool, error) {
 | 
			
		||||
	var count int64
 | 
			
		||||
	if err := r.db.Model(&models.Device{}).Where("area_controller_id = ?", areaControllerID).Count(&count).Error; err != nil {
 | 
			
		||||
		return false, fmt.Errorf("检查区域主控使用情况失败: %w", err)
 | 
			
		||||
	}
 | 
			
		||||
	return count > 0, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user