移动业务逻辑

This commit is contained in:
2025-10-04 00:58:29 +08:00
parent 8bb0a54f18
commit 1bc36f5e10
4 changed files with 73 additions and 66 deletions

View File

@@ -133,11 +133,15 @@ func (s *pigBatchService) UpdatePigBatch(id uint, dto *dto.PigBatchUpdateDTO) (*
existingBatch.Status = *dto.Status
}
updatedBatch, err := s.pigBatchRepo.UpdatePigBatch(existingBatch)
updatedBatch, rowsAffected, err := s.pigBatchRepo.UpdatePigBatch(existingBatch)
if err != nil {
s.logger.Errorf("更新猪批次失败ID: %d, 错误: %v", id, err)
return nil, err
}
// 如果没有行受影响,则认为猪批次不存在
if rowsAffected == 0 {
return nil, ErrPigBatchNotFound
}
return s.toPigBatchResponseDTO(updatedBatch), nil
}
@@ -160,14 +164,16 @@ func (s *pigBatchService) DeletePigBatch(id uint) error {
}
// 3. 执行删除操作
err = s.pigBatchRepo.DeletePigBatch(id)
rowsAffected, err := s.pigBatchRepo.DeletePigBatch(id)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) || errors.New("未找到要删除的猪批次").Error() == err.Error() {
return ErrPigBatchNotFound
}
s.logger.Errorf("删除猪批次失败ID: %d, 错误: %v", id, err)
return err
}
// 如果没有行受影响,则认为猪批次不存在
if rowsAffected == 0 {
return ErrPigBatchNotFound
}
return nil
}