Ver código fonte

Merge branch 'test'

lyhzzz 1 ano atrás
pai
commit
d2c74d2f17

+ 2 - 0
src/main/java/com/cdf/service/IHotRecommendService.java

@@ -21,4 +21,6 @@ public interface IHotRecommendService extends IService<HotRecommend> {
     List<HotRecommend> getByNum(String num);
 
     HashMap<String, HotRecommend> getMapBySids(List<String> sidsList);
+
+    void updateRecomend(List<Integer> delIds, Integer type);
 }

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

@@ -236,17 +236,13 @@ 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,ProductSource> productMap = new HashMap<>();
 
         for (HashMap<Integer, String> map : excelRowList) {
             String sourceId = map.get(3);
-            if(StringUtils.isNotBlank(sourceId)){
-                ProductSource byMchId = productSourceService.getByMchId(sourceId);
-                productSourceHashMap.put(sourceId,byMchId);
-            }
             String pid = map.get(4);
             if(StringUtils.isNotBlank(pid)){
                 List<String> pidList = productSourceProductMap.computeIfAbsent(sourceId, k -> new ArrayList<>());
@@ -254,15 +250,17 @@ public class ExcelService {
             }
         }
         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());
+            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());
+                    }
                 }
             }
         }
@@ -282,11 +280,21 @@ public class ExcelService {
                 List<String> sidList = hotRelations.stream().map(HotRelation::getHotId).collect(Collectors.toList());
                 numMap.put(sceneNum,sidList);
             }
-            if(!numMap.get(sceneNum).contains(sid)){
+            if(productMap.get(sid) == null){
+                ProductSource productSource = productSourceService.getByMchId(mchId);
+                if(productSource == null){
+                    errorList.add(colum.toString());
+                    continue;
+                }
+                productMap.put(sid,productSource);
+            }
+            ProductSource productSource = productMap.get(sid);
+            if(!mchId.equals(productSource.getCdfMchId())){
                 errorList.add(colum.toString());
                 continue;
             }
-            if(!productSourceHashMap.containsKey(mchId)){
+
+            if(!numMap.get(sceneNum).contains(sid)){
                 errorList.add(colum.toString());
                 continue;
             }
@@ -397,6 +405,7 @@ public class ExcelService {
         Integer colum = 1;
         List<HashMap<Integer, String>> excelRowList = ExcelUtil.getExcelRowList(file);
         HashMap<String,HashMap<String,HashSet<String>>> numMap = new HashMap<>();
+        HashMap<String,ProductSource> sidProMap = new HashMap<>();
         for (HashMap<Integer, String> map : excelRowList) {
             colum ++;
             if(errorList.contains(colum.toString())){
@@ -410,10 +419,18 @@ public class ExcelService {
             if(StringUtils.isBlank(mchId) || StringUtils.isBlank(sceneNum)  || StringUtils.isBlank(pid) || StringUtils.isBlank(sid)){
                 continue;
             }
+
+            if(sidProMap.get(sid) == null){
+                ProductSource productSource = productSourceService.getByMchId(mchId);
+                if(productSource != null){
+                    sidProMap.put(sid,productSource);
+                }
+            }
             numMap.computeIfAbsent(sceneNum, k -> new HashMap<>());
             numMap.get(sceneNum).computeIfAbsent(sid,k -> new HashSet<>());
             numMap.get(sceneNum).get(sid).add(pid);
         }
+
         List<HotRelation> updateList = new ArrayList<>();
         for (String num : numMap.keySet()) {
             HashMap<String, HashSet<String>> sidMap = numMap.get(num);
@@ -422,8 +439,13 @@ public class ExcelService {
                 if(hotRelation == null){
                     continue;
                 }
+                ProductSource productSource = sidProMap.get(sid);
+                if(productSource == null){
+                    continue;
+                }
                 HashSet<String> pidSet = sidMap.get(sid);
                 hotRelation.setRelationIds(JSONArray.toJSONString(pidSet));
+                hotRelation.setProductSourceId(productSource.getId());
                 updateList.add(hotRelation);
             }
         }
@@ -482,7 +504,7 @@ public class ExcelService {
             }
         }
         if(!delIds.isEmpty()){
-            hotRecommendService.removeByIds(delIds);
+            hotRecommendService.updateRecomend(delIds,type);
         }
         for (String num : numMap.keySet()) {
             NumRegion numRegion = fdkkUserService.getRegionByNum(num);

+ 0 - 4
src/main/java/com/cdf/service/impl/FdkkSceneEditService.java

@@ -109,10 +109,6 @@ public class FdkkSceneEditService {
             if(hotRelation == null){
                  hotRelation = new HotRelation();
                  update = false;
-            }else {
-                if(hotRelation.getHotType() == 0 &&  !hotRelation.getProductSourceId().equals(fdkkHotData.getProductSourceId())){
-                    throw new BusinessException(ResultCode.HOT_PRODUCT_SOURCE_ERROR);
-                }
             }
             hotRelation.setHotId(sid);
             hotRelation.setHotType(type);

+ 14 - 0
src/main/java/com/cdf/service/impl/HotRecommendServiceImpl.java

@@ -1,6 +1,7 @@
 package com.cdf.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.cdf.entity.HotRecommend;
 import com.cdf.mapper.IHotRecommendMapper;
 import com.cdf.service.IHotRecommendService;
@@ -48,4 +49,17 @@ public class HotRecommendServiceImpl extends ServiceImpl<IHotRecommendMapper, Ho
         }
         return map;
     }
+
+    @Override
+    public void updateRecomend(List<Integer> delIds, Integer type) {
+        LambdaUpdateWrapper<HotRecommend> wrapper = new LambdaUpdateWrapper();
+        wrapper.in(HotRecommend::getId,delIds);
+        if(type == 2){
+            wrapper.set(HotRecommend::getRecommendSelection,0);
+        }
+        if(type == 3){
+            wrapper.set(HotRecommend::getRecommendBrand,0);
+        }
+        this.update(wrapper);
+    }
 }