删批次时释放猪栏

This commit is contained in:
2025-10-06 18:15:47 +08:00
parent 0576a790dd
commit 67b45d2e05
3 changed files with 73 additions and 19 deletions

View File

@@ -15,6 +15,7 @@ type PigBatchRepository interface {
UpdatePigBatch(batch *models.PigBatch) (*models.PigBatch, int64, error)
// DeletePigBatch 根据ID删除一个猪批次返回受影响的行数和错误
DeletePigBatch(id uint) (int64, error)
DeletePigBatchTx(tx *gorm.DB, id uint) (int64, error)
ListPigBatches(isActive *bool) ([]*models.PigBatch, error)
}
@@ -58,7 +59,11 @@ func (r *gormPigBatchRepository) UpdatePigBatch(batch *models.PigBatch) (*models
// DeletePigBatch 根据ID删除一个猪批次 (GORM 会执行软删除)
func (r *gormPigBatchRepository) DeletePigBatch(id uint) (int64, error) {
result := r.db.Delete(&models.PigBatch{}, id)
return r.DeletePigBatchTx(r.db, id)
}
func (r *gormPigBatchRepository) DeletePigBatchTx(tx *gorm.DB, id uint) (int64, error) {
result := tx.Delete(&models.PigBatch{}, id)
if result.Error != nil {
return 0, result.Error
}