From c3b81ea987501dc2f5dc3c8db23038eeb8f290e9 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期四, 12 三月 2026 17:56:16 +0800
Subject: [PATCH] fix: 产品保存时唯一性导致数据丢失

---
 src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java |   29 ++++++++++++++++-------------
 1 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java
index 76a52d3..41aa10f 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java
@@ -302,10 +302,17 @@
 
         for (ProductMaterialSku sku : list) {
 
-            ProductMaterialSku exist =
-                    productMaterialSkuService.getOne(new LambdaQueryWrapper<ProductMaterialSku>()
-                            .eq(ProductMaterialSku::getMaterialId, sku.getMaterialId())
-                            .eq(ProductMaterialSku::getSpecification, sku.getSpecification()));
+            LambdaQueryWrapper<ProductMaterialSku> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(ProductMaterialSku::getMaterialId, sku.getMaterialId())
+                    .eq(ProductMaterialSku::getSpecification, sku.getSpecification());
+
+            if (StringUtils.isNotEmpty(sku.getMaterialCode())) {
+                wrapper.eq(ProductMaterialSku::getMaterialCode, sku.getMaterialCode());
+            } else {
+                wrapper.isNull(ProductMaterialSku::getMaterialCode);
+            }
+
+            ProductMaterialSku exist = productMaterialSkuService.getOne(wrapper);
             if (exist == null) {
                 productMaterialSkuService.save(sku);
                 affected++;
@@ -350,17 +357,13 @@
         for (ProductMaterialConfig materialConfig : materialConfigList) {
             LambdaQueryWrapper<ProductMaterial> wrapper = new LambdaQueryWrapper<>();
             wrapper.eq(ProductMaterial::getMaterialTypeId, materialConfig.getId())
-                    .select(ProductMaterial::getId, ProductMaterial::getMaterialName)
                     .like(materialName != null && !materialName.isEmpty(), ProductMaterial::getMaterialName, materialName);
             List<ProductMaterial> productMaterialList = list(wrapper);
-
-            if (productMaterialList != null && !productMaterialList.isEmpty()) {
-                ProductMaterialGroupDto dto = new ProductMaterialGroupDto();
-                dto.setConfigId(materialConfig.getId());
-                dto.setConfigName(materialConfig.getConfigName());
-                dto.setMaterialList(productMaterialList);
-                productMaterialMap.add(dto);
-            }
+            ProductMaterialGroupDto dto = new ProductMaterialGroupDto();
+            dto.setConfigId(materialConfig.getId());
+            dto.setConfigName(materialConfig.getConfigName());
+            dto.setMaterialList(productMaterialList);
+            productMaterialMap.add(dto);
         }
         return productMaterialMap;
     }

--
Gitblit v1.9.3