浏览代码

批量更新商品sku时添加对pid的限制

macro 1 年之前
父节点
当前提交
0387c981d7
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. 5 1
      mall-admin/src/main/java/com/macro/mall/service/impl/PmsSkuStockServiceImpl.java

+ 5 - 1
mall-admin/src/main/java/com/macro/mall/service/impl/PmsSkuStockServiceImpl.java

@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 商品SKU库存管理Service实现类
@@ -34,6 +35,9 @@ public class PmsSkuStockServiceImpl implements PmsSkuStockService {
 
     @Override
     public int update(Long pid, List<PmsSkuStock> skuStockList) {
-        return skuStockDao.replaceList(skuStockList);
+        List<PmsSkuStock> filterSkuList = skuStockList.stream()
+                .filter(item -> pid.equals(item.getProductId()))
+                .collect(Collectors.toList());
+        return skuStockDao.replaceList(filterSkuList);
     }
 }