From 5652acfd578f66353f59f398f42c88da901e245e Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 24 四月 2026 15:55:23 +0800
Subject: [PATCH] fix: 附件上传路径link,设备巡检附件去重

---
 src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java |   51 ++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 38 insertions(+), 13 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 c0b752d..be5746d 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -152,8 +152,8 @@
             List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectProduct();
             Map<String, SalesLedgerProduct> productMap = new HashMap<>();
             for (SalesLedgerProduct product : salesLedgerProducts) {
-                // 浣跨敤浜у搧绫诲埆鍜岃鏍煎瀷鍙蜂綔涓洪敭
-                String key = product.getProductCategory() + "|" + product.getSpecificationModel();
+                // 浣跨敤浜у搧鍚嶇О + 瑙勬牸鍨嬪彿 + 鍘氬害浣滀负閿�
+                String key = buildProductKey(product.getProductCategory(), product.getSpecificationModel(), product.getThickness());
                 productMap.put(key, product);
             }
 
@@ -166,7 +166,7 @@
 
             for (StockInventoryExportData dto : list) {
                 // 鏋勫缓鏌ユ壘閿�
-                String key = dto.getProductName() + "|" + dto.getModel();
+                String key = buildProductKey(dto.getProductName(), dto.getModel(), dto.getThickness());
                 SalesLedgerProduct matchedProduct = productMap.get(key);
                 
                 if (matchedProduct != null) {
@@ -217,7 +217,7 @@
                     }
                 } else {
                     // 璁板綍鏈尮閰嶇殑浜у搧
-                    String unmatchedRecord = "浜у搧鍚嶇О锛�" + dto.getProductName() + "锛屽瀷鍙凤細" + dto.getModel();
+                    String unmatchedRecord = "浜у搧鍚嶇О锛�" + dto.getProductName() + "锛屽瀷鍙凤細" + dto.getModel() + "锛屽帤搴︼細" + normalizeThickness(dto.getThickness());
                     unmatchedRecords.add(unmatchedRecord);
                 }
             }
@@ -261,24 +261,49 @@
     @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);
     }
+
+    private String buildProductKey(String productName, String model, BigDecimal thickness) {
+        String safeProductName = productName == null ? "" : productName.trim();
+        String safeModel = model == null ? "" : model.trim();
+        return safeProductName + "|" + safeModel + "|" + normalizeThickness(thickness);
+    }
+
+    private String normalizeThickness(BigDecimal thickness) {
+        if (thickness == null) {
+            return "";
+        }
+        return thickness.stripTrailingZeros().toPlainString();
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3