增加任务增删改查时对设备任务关联表的维护
This commit is contained in:
		@@ -17,7 +17,7 @@ type DeviceRepository interface {
 | 
			
		||||
	// FindByID 根据主键 ID 查找设备
 | 
			
		||||
	FindByID(id uint) (*models.Device, error)
 | 
			
		||||
 | 
			
		||||
	// FindByIDString 根据字符串形式的主键 ID 查找设备,方便控制器调用
 | 
			
		||||
	// FindByIDString 根据字符串形式的主键 ID 查找设备
 | 
			
		||||
	FindByIDString(id string) (*models.Device, error)
 | 
			
		||||
 | 
			
		||||
	// ListAll 获取所有设备的列表
 | 
			
		||||
@@ -26,7 +26,7 @@ type DeviceRepository interface {
 | 
			
		||||
	// ListAllSensors 获取所有传感器类型的设备列表
 | 
			
		||||
	ListAllSensors() ([]*models.Device, error)
 | 
			
		||||
 | 
			
		||||
	// ListByAreaControllerID 根据区域主控 ID 列出所有子设备。
 | 
			
		||||
	// ListByAreaControllerID 根据区域主控 ID 列出所有子设备
 | 
			
		||||
	ListByAreaControllerID(areaControllerID uint) ([]*models.Device, error)
 | 
			
		||||
 | 
			
		||||
	// FindByDeviceTemplateID 根据设备模板ID查找所有使用该模板的设备
 | 
			
		||||
@@ -40,6 +40,9 @@ type DeviceRepository interface {
 | 
			
		||||
 | 
			
		||||
	// FindByAreaControllerAndPhysicalAddress 根据区域主控ID和物理地址(总线号、总线地址)查找设备
 | 
			
		||||
	FindByAreaControllerAndPhysicalAddress(areaControllerID uint, busNumber int, busAddress int) (*models.Device, error)
 | 
			
		||||
 | 
			
		||||
	// GetDevicesByIDsTx 在指定事务中根据ID列表获取设备
 | 
			
		||||
	GetDevicesByIDsTx(tx *gorm.DB, ids []uint) ([]models.Device, error)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// gormDeviceRepository 是 DeviceRepository 的 GORM 实现
 | 
			
		||||
@@ -66,6 +69,18 @@ func (r *gormDeviceRepository) FindByID(id uint) (*models.Device, error) {
 | 
			
		||||
	return &device, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetDevicesByIDsTx 在指定事务中根据ID列表获取设备
 | 
			
		||||
func (r *gormDeviceRepository) GetDevicesByIDsTx(tx *gorm.DB, ids []uint) ([]models.Device, error) {
 | 
			
		||||
	var devices []models.Device
 | 
			
		||||
	if len(ids) == 0 {
 | 
			
		||||
		return devices, nil
 | 
			
		||||
	}
 | 
			
		||||
	if err := tx.Where("id IN ?", ids).Find(&devices).Error; err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return devices, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FindByIDString 根据字符串形式的主键 ID 查找设备
 | 
			
		||||
func (r *gormDeviceRepository) FindByIDString(id string) (*models.Device, error) {
 | 
			
		||||
	// 将字符串ID转换为uint64
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user