浏览代码

fix: 导入商品的时候导入仓库代码

xdd 2 周之前
父节点
当前提交
8e36099f9e

+ 5 - 0
fs-service-system/src/main/java/com/fs/store/mapper/FsWarehousesMapper.java

@@ -1,10 +1,12 @@
 package com.fs.store.mapper;
 
 import com.fs.store.domain.FsWarehouses;
+import org.apache.ibatis.annotations.MapKey;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 仓库Mapper接口
@@ -22,6 +24,9 @@ public interface FsWarehousesMapper
      */
     public FsWarehouses selectFsWarehousesById(Long id);
 
+    @Select("select id,warehouse_code where is_active=1")
+    @MapKey("warehouseCode")
+    Map<String,FsWarehouses> selectFsWarehousesMap();
     /**
      * 查询仓库列表
      *

+ 16 - 2
fs-service-system/src/main/java/com/fs/store/service/impl/FsStoreProductServiceImpl.java

@@ -5,6 +5,7 @@ import java.util.*;
 import java.util.stream.Collectors;
 
 import cn.hutool.core.collection.ListUtil;
+import cn.hutool.core.lang.Assert;
 import cn.hutool.core.util.ArrayUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
@@ -631,7 +632,8 @@ public class FsStoreProductServiceImpl implements IFsStoreProductService
     public List<FsStoreProductExportVO> selectFsStoreProductExportList(FsStoreProduct fsStoreProduct) {
         return fsStoreProductMapper.selectFsStoreProductExportList(fsStoreProduct);
     }
-
+    @Autowired
+    private FsWarehousesMapper fsWarehousesMapper;
     @Override
     public String importStoreProduct(List<FsStoreProductExportVO> list, boolean updateSupport) {
         if (com.fs.common.utils.StringUtils.isNull(list) || list.size() == 0)
@@ -642,13 +644,25 @@ public class FsStoreProductServiceImpl implements IFsStoreProductService
         int failureNum = 0;
         StringBuilder successMsg = new StringBuilder();
         StringBuilder failureMsg = new StringBuilder();
+        Map<String, FsWarehouses> warehousesMap = fsWarehousesMapper.selectFsWarehousesMap();
+
         for (FsStoreProductExportVO productVO : list){
             try
             {
                 FsStoreProduct product = BeanCopyUtils.copy(productVO, FsStoreProduct.class);
-                if (product.getBarCode()==null || product.getBarCode()==""){
+                Assert.notNull(product,"产品不能为空");
+                if (StringUtils.isBlank(product.getBarCode())){
                     throw new CustomException("商品编号为空");
                 }
+
+                if(StringUtils.isNotBlank(product.getWarehouseCode())){
+                    FsWarehouses fsWarehouses = warehousesMap.get(product.getWarehouseCode());
+                    if(fsWarehouses == null) {
+                        throw new CustomException("对应的仓库代码找不到!");
+                    }
+                    product.setWarehouseId(fsWarehouses.getId());
+                }
+
                 this.insertFsStoreProduct(product);
                 ProductArrtDTO formatDetailDto = ProductArrtDTO.builder()
                         .value("规格")