From 91acbe8b56194bbd834b1169b5578de8a5ed442c Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期六, 14 三月 2026 17:53:10 +0800
Subject: [PATCH] fix: BOM产品查询调整、重命名字段

---
 src/main/java/com/ruoyi/production/service/impl/ProductMaterialSkuServiceImpl.java |   78 +++++++++-----------------------------
 1 files changed, 19 insertions(+), 59 deletions(-)

diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductMaterialSkuServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductMaterialSkuServiceImpl.java
index e29b78c..770944b 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductMaterialSkuServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductMaterialSkuServiceImpl.java
@@ -11,7 +11,7 @@
 import com.ruoyi.production.mapper.ProductMaterialSkuMapper;
 import com.ruoyi.production.pojo.ProductMaterial;
 import com.ruoyi.production.pojo.ProductMaterialSku;
-import com.ruoyi.production.pojo.ProductMaterialSkuImportDto;
+import com.ruoyi.production.dto.ProductMaterialSkuImportDto;
 import com.ruoyi.production.service.ProductMaterialSkuService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -21,7 +21,6 @@
 
 import java.time.LocalDateTime;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -39,9 +38,7 @@
  */
 @Slf4j
 @Service
-public class ProductMaterialSkuServiceImpl
-        extends ServiceImpl<ProductMaterialSkuMapper, ProductMaterialSku>
-        implements ProductMaterialSkuService {
+public class ProductMaterialSkuServiceImpl extends ServiceImpl<ProductMaterialSkuMapper, ProductMaterialSku> implements ProductMaterialSkuService {
 
     @Autowired
     private ProductMaterialMapper productMaterialMapper;
@@ -50,45 +47,8 @@
      * 鏌ヨ鐗╂枡瑙勬牸鍒楄〃
      */
     @Override
-    public Page<ProductMaterialSkuDto> productMaterialSkuList(Page<ProductMaterialSku> page, ProductMaterialSkuDto dto) {
-        if (dto == null || dto.getMaterialId() == null) {
-            return new Page<>();
-        }
-        LambdaQueryWrapper<ProductMaterialSku> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(ProductMaterialSku::getMaterialId, dto.getMaterialId())
-                .like(StringUtils.isNotBlank(dto.getSpecification()),
-                        ProductMaterialSku::getSpecification, dto.getSpecification())
-                .like(StringUtils.isNotBlank(dto.getMaterialCode()),
-                        ProductMaterialSku::getMaterialCode, dto.getMaterialCode())
-                .orderByAsc(ProductMaterialSku::getId);
-
-        Page<ProductMaterialSku> skuPage = this.page(page, queryWrapper);
-        List<ProductMaterialSku> skuList = skuPage.getRecords();
-        if (skuList == null || skuList.isEmpty()) {
-            return new Page<>();
-        }
-
-        ProductMaterial material = productMaterialMapper.selectById(dto.getMaterialId());
-        String materialName = material != null ? material.getMaterialName() : null;
-        String baseUnit = material != null ? material.getBaseUnit() : null;
-        List<ProductMaterialSkuDto> result = new ArrayList<>(skuList.size());
-        for (ProductMaterialSku sku : skuList) {
-            ProductMaterialSkuDto productMaterialSkuDto = new ProductMaterialSkuDto();
-            productMaterialSkuDto.setMaterialId(dto.getMaterialId());
-            productMaterialSkuDto.setMaterialName(materialName);
-            productMaterialSkuDto.setMaterialCode(sku.getMaterialCode());
-            productMaterialSkuDto.setBaseUnit(baseUnit);
-            productMaterialSkuDto.setSkuId(sku.getId());
-            productMaterialSkuDto.setSpecification(sku.getSpecification());
-            productMaterialSkuDto.setSupplyType(sku.getSupplyType());
-            result.add(productMaterialSkuDto);
-        }
-        Page<ProductMaterialSkuDto> dtoPage = new Page<>();
-        dtoPage.setCurrent(skuPage.getCurrent());
-        dtoPage.setSize(skuPage.getSize());
-        dtoPage.setTotal(skuPage.getTotal());
-        dtoPage.setRecords(result);
-        return dtoPage;
+    public Page<ProductMaterialSkuDto> productMaterialSkuList(Page<ProductMaterialSkuDto> page, ProductMaterialSkuDto dto, Integer type) {
+        return baseMapper.selectSkuWithMaterialPage(page, dto, type);
     }
 
     /**
@@ -98,12 +58,12 @@
     public void addProductMaterialSku(ProductMaterialSku sku) {
         validateProductMaterialSku(sku, false);
         // 鏍¢獙鐗╂枡鏄惁瀛樺湪
-        ProductMaterial material = productMaterialMapper.selectById(sku.getMaterialId());
+        ProductMaterial material = productMaterialMapper.selectById(sku.getProductId());
         if (material == null) {
             throw new ServiceException("鐗╂枡涓嶅瓨鍦�");
         }
         // 鏍¢獙瑙勬牸鏄惁閲嶅
-        if (existsSameSpecification(sku.getMaterialId(), sku.getSpecification(), null)) {
+        if (existsSameSpecification(sku.getProductId(), sku.getModel(), null)) {
             throw new ServiceException("璇ョ墿鏂欏凡瀛樺湪鐩稿悓瑙勬牸");
         }
         LocalDateTime now = LocalDateTime.now();
@@ -115,7 +75,7 @@
         if (!this.save(sku)) {
             throw new ServiceException("鏂板鐗╂枡瑙勬牸澶辫触");
         }
-        log.info("鏂板鐗╂枡瑙勬牸鎴愬姛 materialId={}, specification={}", sku.getMaterialId(), sku.getSpecification());
+        log.info("鏂板鐗╂枡瑙勬牸鎴愬姛 materialId={}, specification={}", sku.getProductId(), sku.getModel());
     }
 
     /**
@@ -125,7 +85,7 @@
     public void updateProductMaterialSku(ProductMaterialSku sku) {
         validateProductMaterialSku(sku, true);
         // 鏍¢獙瑙勬牸鏄惁閲嶅
-        if (existsSameSpecification(sku.getMaterialId(), sku.getSpecification(), sku.getId())) {
+        if (existsSameSpecification(sku.getProductId(), sku.getModel(), sku.getId())) {
             throw new ServiceException("璇ョ墿鏂欏凡瀛樺湪鐩稿悓瑙勬牸");
         }
         sku.setUpdateTime(LocalDateTime.now());
@@ -159,10 +119,10 @@
         if (requireId && sku.getId() == null) {
             throw new ServiceException("涓婚敭ID涓嶈兘涓虹┖");
         }
-        if (sku.getMaterialId() == null) {
+        if (sku.getProductId() == null) {
             throw new ServiceException("鐗╂枡ID涓嶈兘涓虹┖");
         }
-        if (StringUtils.isEmpty(sku.getSpecification())) {
+        if (StringUtils.isEmpty(sku.getModel())) {
             throw new ServiceException("瑙勬牸涓嶈兘涓虹┖");
         }
     }
@@ -172,8 +132,8 @@
      */
     private boolean existsSameSpecification(Long materialId, String specification, Long excludeId) {
         LambdaQueryWrapper<ProductMaterialSku> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(ProductMaterialSku::getMaterialId, materialId)
-                .eq(ProductMaterialSku::getSpecification, specification);
+        queryWrapper.eq(ProductMaterialSku::getProductId, materialId)
+                .eq(ProductMaterialSku::getModel, specification);
         if (excludeId != null) {
             queryWrapper.ne(ProductMaterialSku::getId, excludeId);
         }
@@ -211,10 +171,10 @@
 
         Map<String, ProductMaterialSkuImportDto> specMap = new LinkedHashMap<>();
         for (ProductMaterialSkuImportDto dto : importList) {
-            if (dto == null || StringUtils.isEmpty(dto.getSpecification())) {
+            if (dto == null || StringUtils.isEmpty(dto.getModel())) {
                 continue;
             }
-            String specification = dto.getSpecification().trim();
+            String specification = dto.getModel().trim();
             if (specification.isEmpty()) {
                 continue;
             }
@@ -228,10 +188,10 @@
         Set<String> specifications = specMap.keySet();
 
         List<ProductMaterialSku> existList = this.list(new LambdaQueryWrapper<ProductMaterialSku>()
-                .eq(ProductMaterialSku::getMaterialId, materialId)
-                .in(ProductMaterialSku::getSpecification, specifications));
+                .eq(ProductMaterialSku::getProductId, materialId)
+                .in(ProductMaterialSku::getModel, specifications));
         Map<String, ProductMaterialSku> existMap = existList.stream()
-                .collect(Collectors.toMap(ProductMaterialSku::getSpecification, sku -> sku, (a, b) -> a));
+                .collect(Collectors.toMap(ProductMaterialSku::getModel, sku -> sku, (a, b) -> a));
 
         LocalDateTime now = LocalDateTime.now();
         List<ProductMaterialSku> saveList = new ArrayList<>();
@@ -245,8 +205,8 @@
             ProductMaterialSku exist = existMap.get(specification);
             if (exist == null) {
                 ProductMaterialSku sku = new ProductMaterialSku();
-                sku.setMaterialId(materialId);
-                sku.setSpecification(specification);
+                sku.setProductId(materialId);
+                sku.setModel(specification);
                 sku.setSupplyType(supplyType);
                 sku.setCreateTime(now);
                 sku.setUpdateTime(now);

--
Gitblit v1.9.3