浏览代码

商品导入来源限制

lyhzzz 1 年之前
父节点
当前提交
76f06d7e33
共有 1 个文件被更改,包括 39 次插入19 次删除
  1. 39 19
      src/main/java/com/cdf/service/impl/ExcelService.java

+ 39 - 19
src/main/java/com/cdf/service/impl/ExcelService.java

@@ -236,35 +236,34 @@ public class ExcelService {
     private void checkUploadProduct(File file, List<String> errorList){
         List<HashMap<Integer, String>> excelRowList = ExcelUtil.getExcelRowList(file);
         Integer colum = 1;
-        HashMap<String,ProductSource> productSourceHashMap = new HashMap<>();
         HashMap<String, List<String>> productSourceProductMap = new HashMap<>();
         HashMap<String, List<String>> resultPMap = new HashMap<>();
         HashMap<String, List<String>> numMap = new HashMap<>();
+        HashMap<String, Integer> sourceMap = new HashMap<>();
+        HashMap<String,ProductSource> productMap = new HashMap<>();
 
         for (HashMap<Integer, String> map : excelRowList) {
             String sourceId = map.get(3);
-            if(StringUtils.isNotBlank(sourceId)){
-                ProductSource byMchId = productSourceService.getByMchId(sourceId);
-                if(byMchId!=null){
-                    productSourceHashMap.put(sourceId,byMchId);
-                }
-            }
             String pid = map.get(4);
             if(StringUtils.isNotBlank(pid)){
                 List<String> pidList = productSourceProductMap.computeIfAbsent(sourceId, k -> new ArrayList<>());
                 pidList.add(pid);
             }
         }
-        for (String mchId : productSourceProductMap.keySet()) {
-            ProductSource productSource = productSourceHashMap.get(mchId);
-            JSONArray ids = new JSONArray();
-            ids.addAll(productSourceProductMap.get(mchId));
-            CdfProductListByIdsRequest idsRequest = new CdfProductListByIdsRequest(ids);
-            CdfProductListByIdsVo vos = cdfHKClient.getProductListByIds(productSource.getCdfHost(), productSource.getCdfMchId(), idsRequest);
-            if(vos.getProductCardList()!=null && vos.getProductCardList().size() >0){
-                for (CdfProduct cdfProduct : vos.getProductCardList()) {
-                    List<String> pidList = resultPMap.computeIfAbsent(mchId, k -> new ArrayList<>());
-                    pidList.add(cdfProduct.getId());
+        if(productSourceProductMap.size()<=1){
+            for (String mchId : productSourceProductMap.keySet()) {
+                ProductSource productSource = productSourceService.getByMchId(mchId);
+                if(productSource !=null){
+                    JSONArray ids = new JSONArray();
+                    ids.addAll(productSourceProductMap.get(mchId));
+                    CdfProductListByIdsRequest idsRequest = new CdfProductListByIdsRequest(ids);
+                    CdfProductListByIdsVo vos = cdfHKClient.getProductListByIds(productSource.getCdfHost(), productSource.getCdfMchId(), idsRequest);
+                    if(vos.getProductCardList()!=null && vos.getProductCardList().size() >0){
+                        for (CdfProduct cdfProduct : vos.getProductCardList()) {
+                            List<String> pidList = resultPMap.computeIfAbsent(mchId, k -> new ArrayList<>());
+                            pidList.add(cdfProduct.getId());
+                        }
+                    }
                 }
             }
         }
@@ -281,14 +280,35 @@ public class ExcelService {
             }
             if(numMap.get(sceneNum) == null){
                 List<HotRelation> hotRelations = hotRelationService.getByNum(sceneNum);
+                for (HotRelation hotRelation : hotRelations) {
+                    sourceMap.put(hotRelation.getHotId(),hotRelation.getProductSourceId());
+                }
                 List<String> sidList = hotRelations.stream().map(HotRelation::getHotId).collect(Collectors.toList());
                 numMap.put(sceneNum,sidList);
             }
-            if(!numMap.get(sceneNum).contains(sid)){
+            if(sourceMap.get(sid) == null){
+                continue;
+            }
+            if(!productMap.isEmpty() && !productMap.containsKey(mchId)){
                 errorList.add(colum.toString());
                 continue;
             }
-            if(!productSourceHashMap.containsKey(mchId)){
+            if(productMap.get(mchId) == null){
+                ProductSource productSource = productSourceService.getByMchId(mchId);
+                if(productSource == null){
+                    errorList.add(colum.toString());
+                    continue;
+                }
+                productMap.put(mchId,productSource);
+            }
+            ProductSource productSource = productMap.get(mchId);
+            if(!productSource.getId().equals(sourceMap.get(sid))){
+                errorList.add(colum.toString());
+                continue;
+            }
+
+
+            if(!numMap.get(sceneNum).contains(sid)){
                 errorList.add(colum.toString());
                 continue;
             }