From 02cf72a4443db4f1a2406c3919718c38aa6367db Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 24 四月 2026 14:59:31 +0800
Subject: [PATCH] fix: 领用、冻结与解冻数量限制不能超过最大值

---
 src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java |   30 +++++++++++++++++++++---------
 1 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java b/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
index 48f3082..be5746d 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -261,24 +261,36 @@
     @Override
     public Boolean frozenStock(StockInventoryDto stockInventoryDto) {
         StockInventory stockInventory = stockInventoryMapper.selectById(stockInventoryDto.getId());
-        if (stockInventory.getQualitity().compareTo(stockInventoryDto.getLockedQuantity()) < 0) {
-            throw new RuntimeException("鍐荤粨鏁伴噺涓嶈兘瓒呰繃搴撳瓨鏁伴噺");
+        if (ObjectUtils.isEmpty(stockInventory)) {
+            throw new ServiceException("搴撳瓨璁板綍涓嶅瓨鍦�");
         }
-        if (ObjectUtils.isEmpty(stockInventory.getLockedQuantity())) {
-            stockInventory.setLockedQuantity(stockInventoryDto.getLockedQuantity());
-        } else {
-            stockInventory.setLockedQuantity(stockInventory.getLockedQuantity().add(stockInventoryDto.getLockedQuantity()));
+        if (ObjectUtils.isEmpty(stockInventoryDto.getLockedQuantity()) || stockInventoryDto.getLockedQuantity().compareTo(BigDecimal.ZERO) <= 0) {
+            throw new ServiceException("鍐荤粨鏁伴噺蹇呴』澶т簬0");
         }
+        BigDecimal totalQty = ObjectUtils.isEmpty(stockInventory.getQualitity()) ? BigDecimal.ZERO : stockInventory.getQualitity();
+        BigDecimal currentLockedQty = ObjectUtils.isEmpty(stockInventory.getLockedQuantity()) ? BigDecimal.ZERO : stockInventory.getLockedQuantity();
+        BigDecimal availableQty = totalQty.subtract(currentLockedQty);
+        if (stockInventoryDto.getLockedQuantity().compareTo(availableQty) > 0) {
+            throw new ServiceException("鍐荤粨鏁伴噺涓嶈兘瓒呰繃鍙喕缁撳簱瀛樻暟閲�");
+        }
+        stockInventory.setLockedQuantity(currentLockedQty.add(stockInventoryDto.getLockedQuantity()));
         return this.updateById(stockInventory);
     }
 
     @Override
     public Boolean thawStock(StockInventoryDto stockInventoryDto) {
         StockInventory stockInventory = stockInventoryMapper.selectById(stockInventoryDto.getId());
-        if (stockInventory.getLockedQuantity().compareTo(stockInventoryDto.getLockedQuantity()) < 0) {
-            throw new RuntimeException("瑙e喕鏁伴噺涓嶈兘瓒呰繃鍐荤粨鏁伴噺");
+        if (ObjectUtils.isEmpty(stockInventory)) {
+            throw new ServiceException("搴撳瓨璁板綍涓嶅瓨鍦�");
         }
-        stockInventory.setLockedQuantity(stockInventory.getLockedQuantity().subtract(stockInventoryDto.getLockedQuantity()));
+        if (ObjectUtils.isEmpty(stockInventoryDto.getLockedQuantity()) || stockInventoryDto.getLockedQuantity().compareTo(BigDecimal.ZERO) <= 0) {
+            throw new ServiceException("瑙e喕鏁伴噺蹇呴』澶т簬0");
+        }
+        BigDecimal currentLockedQty = ObjectUtils.isEmpty(stockInventory.getLockedQuantity()) ? BigDecimal.ZERO : stockInventory.getLockedQuantity();
+        if (currentLockedQty.compareTo(stockInventoryDto.getLockedQuantity()) < 0) {
+            throw new ServiceException("瑙e喕鏁伴噺涓嶈兘瓒呰繃鍐荤粨鏁伴噺");
+        }
+        stockInventory.setLockedQuantity(currentLockedQty.subtract(stockInventoryDto.getLockedQuantity()));
         return this.updateById(stockInventory);
     }
 

--
Gitblit v1.9.3