From 189d532ac97614137f68bdb801acc3feef62ad80 Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Mon, 6 Oct 2025 16:31:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E6=A0=8F=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/domain/pig/pig_batch_service_pen_transfer.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/domain/pig/pig_batch_service_pen_transfer.go b/internal/domain/pig/pig_batch_service_pen_transfer.go index 0a216b5..d50244a 100644 --- a/internal/domain/pig/pig_batch_service_pen_transfer.go +++ b/internal/domain/pig/pig_batch_service_pen_transfer.go @@ -12,6 +12,17 @@ import ( // executeTransferAndLog 是一个私有辅助方法,用于封装创建和记录迁移日志的通用逻辑。 func (s *pigBatchService) executeTransferAndLog(tx *gorm.DB, fromBatchID, toBatchID, fromPenID, toPenID uint, quantity int, transferType models.PigTransferType, operatorID uint, remarks string) error { + // 通用校验:任何调出操作都不能超过源猪栏的当前存栏数 + if quantity < 0 { // 当调出时才需要检查 + currentPigsInFromPen, err := s.transferSvc.GetCurrentPigsInPen(tx, fromPenID) + if err != nil { + return fmt.Errorf("获取源猪栏 %d 当前猪只数失败: %w", fromPenID, err) + } + if currentPigsInFromPen+quantity < 0 { + return fmt.Errorf("调出数量 %d 超过源猪栏 %d 当前存栏数 %d", -quantity, fromPenID, currentPigsInFromPen) + } + } + // 1. 生成关联ID correlationID := uuid.New().String()