From 47c56f8e7bb10d17d849a20f5a970fefe8484993 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期三, 08 四月 2026 13:54:58 +0800
Subject: [PATCH] fix: 产品规格型号导入供应方式不能为空

---
 src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java |   52 ++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 38 insertions(+), 14 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 6fc0783..f54b264 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java
@@ -11,6 +11,7 @@
 import com.ruoyi.framework.util.AliDingUtils;
 import com.ruoyi.production.dto.ProductMaterialDto;
 import com.ruoyi.production.dto.ProductMaterialGroupDto;
+import com.ruoyi.production.dto.ProductMaterialSkuDto;
 import com.ruoyi.production.enums.MaterialConfigTypeEnum;
 import com.ruoyi.production.mapper.ProductMaterialMapper;
 import com.ruoyi.production.pojo.ProductMaterial;
@@ -82,8 +83,6 @@
         }
 
         try {
-
-
             JSONArray searchConditions = new JSONArray();
             JSONObject statusCondition = new JSONObject();
             statusCondition.put("key", "processInstanceStatus");
@@ -148,6 +147,9 @@
             material.setRemark(formData.getString("textareaField_l92f36f9"));
 
             String materialType = formData.getString("selectField_l92f36fb");
+            if ("鏉挎潗".equals(materialType) || "鐮屽潡".equals(materialType) || "鏍囩爾".equals(materialType)) {
+                materialType = "鎴愬搧";
+            }
             String inventoryCat = formData.getString("selectField_la154noy");
             material.setMaterialTypeId(getOrCreateConfigId(materialType, MaterialConfigTypeEnum.MATERIAL_TYPE.name()));
             material.setInventoryCategoryId(getOrCreateConfigId(inventoryCat, MaterialConfigTypeEnum.INVENTORY_CAT.name()));
@@ -224,10 +226,11 @@
         if (list == null || list.isEmpty()) {
             return 0;
         }
-        int affected = 0;
+
+        List<ProductMaterialSku> toSave = new ArrayList<>();
+        List<ProductMaterialSku> toUpdate = new ArrayList<>();
 
         for (ProductMaterialSku sku : list) {
-
             LambdaQueryWrapper<ProductMaterialSku> wrapper = new LambdaQueryWrapper<>();
             wrapper.eq(ProductMaterialSku::getProductId, sku.getProductId())
                     .eq(ProductMaterialSku::getModel, sku.getModel());
@@ -240,28 +243,35 @@
 
             ProductMaterialSku exist = productMaterialSkuService.getOne(wrapper);
             if (exist == null) {
-                productMaterialSkuService.save(sku);
-                affected++;
-                log.info("鏂板鐗╂枡瑙勬牸 {}", sku.getModel());
+                toSave.add(sku);
             } else {
                 if (exist.getFormModifiedTime() == null || !exist.getFormModifiedTime().equals(sku.getFormModifiedTime())) {
                     sku.setId(exist.getId());
                     sku.setCreateTime(exist.getCreateTime());
-                    productMaterialSkuService.updateById(sku);
-
-                    affected++;
-                    log.info("鏇存柊鐗╂枡瑙勬牸 {}", sku.getModel());
+                    toUpdate.add(sku);
                 }
             }
         }
+
+        int affected = 0;
+        if (!toSave.isEmpty()) {
+            productMaterialSkuService.saveBatch(toSave);
+            affected += toSave.size();
+            log.info("鎵归噺鏂板鐗╂枡瑙勬牸 {} 鏉�", toSave.size());
+        }
+        if (!toUpdate.isEmpty()) {
+            productMaterialSkuService.updateBatchById(toUpdate);
+            affected += toUpdate.size();
+            log.info("鎵归噺鏇存柊鐗╂枡瑙勬牸 {} 鏉�", toUpdate.size());
+        }
+
         return affected;
     }
 
     @Override
     public List<ProductMaterialGroupDto> ProductMaterialList(Integer type) {
         List<ProductMaterialConfig> configList = productMaterialConfigService.list(new LambdaQueryWrapper<ProductMaterialConfig>()
-                .eq(ProductMaterialConfig::getConfigType, MaterialConfigTypeEnum.MATERIAL_TYPE.name())
-        );
+                .eq(ProductMaterialConfig::getConfigType, MaterialConfigTypeEnum.MATERIAL_TYPE.name()));
         if (CollectionUtils.isEmpty(configList)) {
             return new ArrayList<>();
         }
@@ -273,7 +283,9 @@
                             ProductMaterial::getId,
                             ProductMaterial::getMaterialTypeId,
                             ProductMaterial::getInventoryCategoryId,
-                            ProductMaterial::getProductName
+                            ProductMaterial::getProductName,
+                            ProductMaterial::getUnit,
+                            ProductMaterial::getRemark
                     )
             );
             materialMap = materialList.stream()
@@ -348,6 +360,8 @@
         dto.setProductName(m.getProductName());
         dto.setMaterialTypeId(m.getMaterialTypeId());
         dto.setInventoryCategoryId(m.getInventoryCategoryId());
+        dto.setUnit(m.getUnit());
+        dto.setRemark(m.getRemark());
         return dto;
     }
 
@@ -399,6 +413,16 @@
         log.info("鍒犻櫎鐗╂枡鎴愬姛 ids={}", ids);
     }
 
+    @Override
+    public ProductMaterialSkuDto selectProductByModelId(Long productModelId) {
+        return baseMapper.selectProductByModelId(productModelId);
+    }
+
+    @Override
+    public ProductMaterialSkuDto selectProductByProductMainId(Long productOrderId) {
+        return baseMapper.selectProductByProductMainId(productOrderId);
+    }
+
     private void validateProductMaterial(ProductMaterial productMaterial, boolean requireId) {
         if (productMaterial == null) {
             throw new ServiceException("鍙傛暟涓嶈兘涓虹┖");

--
Gitblit v1.9.3