issue_29 #32
@@ -12,6 +12,17 @@ import (
|
|||||||
|
|
||||||
// executeTransferAndLog 是一个私有辅助方法,用于封装创建和记录迁移日志的通用逻辑。
|
// executeTransferAndLog 是一个私有辅助方法,用于封装创建和记录迁移日志的通用逻辑。
|
||||||
func (s *pigBatchService) executeTransferAndLog(tx *gorm.DB, fromBatchID, toBatchID, fromPenID, toPenID uint, quantity int, transferType models.PigTransferType, operatorID uint, remarks string) error {
|
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
|
// 1. 生成关联ID
|
||||||
correlationID := uuid.New().String()
|
correlationID := uuid.New().String()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user