This commit is contained in:
2025-10-04 01:31:35 +08:00
parent 8d9e4286b0
commit 740e14e6cc
9 changed files with 264 additions and 38 deletions

View File

@@ -16,8 +16,8 @@ var (
ErrHouseNotFound = errors.New("指定的猪舍不存在")
ErrPenInUse = errors.New("猪栏正在被活跃批次使用,无法删除")
ErrPenNotFound = errors.New("指定的猪栏不存在")
ErrPenStatusInvalidForOccupiedPen = errors.New("猪栏已被批次用,无法设置为非占用状态")
ErrPenStatusInvalidForUnoccupiedPen = errors.New("猪栏未被批次用,无法设置为占用状态")
ErrPenStatusInvalidForOccupiedPen = errors.New("猪栏已被批次使用,无法设置为非使用中状态")
ErrPenStatusInvalidForUnoccupiedPen = errors.New("猪栏未被批次使用,无法设置为使用中状态")
)
// PigFarmService 提供了猪场资产管理的业务逻辑
@@ -217,12 +217,12 @@ func (s *pigFarmService) UpdatePenStatus(id uint, newStatus models.PenStatus) (*
}
// 业务逻辑:根据猪栏的 PigBatchID 和当前状态,判断是否允许设置为 newStatus
if pen.PigBatchID != nil && *pen.PigBatchID != 0 { // 猪栏已被批次
if newStatus == models.PenStatusEmpty { // 猪栏已被批次用,不能直接设置为空闲
if pen.PigBatchID != nil && *pen.PigBatchID != 0 { // 猪栏已被批次使
if newStatus == models.PenStatusEmpty { // 猪栏已被批次使用,不能直接设置为空闲
return ErrPenStatusInvalidForOccupiedPen
}
} else { // 猪栏未被批次用 (PigBatchID == nil)
if newStatus == models.PenStatusOccupied { // 猪栏未被批次用,不能设置为占用
} else { // 猪栏未被批次使用 (PigBatchID == nil)
if newStatus == models.PenStatusOccupied { // 猪栏未被批次使用,不能设置为使用中
return ErrPenStatusInvalidForUnoccupiedPen
}
}