浏览代码

fix:商品分类查询

liujunchi 3 年之前
父节点
当前提交
c350e359da

+ 26 - 1
cooleshow-mall/mall-portal/src/main/java/com/yonge/cooleshow/portal/service/impl/PmsPortalProductServiceImpl.java

@@ -20,6 +20,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * 前台订单管理Service实现类
@@ -63,7 +64,8 @@ public class PmsPortalProductServiceImpl implements PmsPortalProductService {
             criteria.andBrandIdEqualTo(brandId);
         }
         if (productCategoryId != null) {
-            criteria.andProductCategoryIdEqualTo(productCategoryId);
+            List<Long> productCategoryIds = getProductCategoryIds(productCategoryId);
+            criteria.andProductCategoryIdIn(productCategoryIds);
         }
         if (productAttributeCategoryId != null) {
             criteria.andProductAttributeCategoryIdEqualTo(productAttributeCategoryId);
@@ -95,6 +97,29 @@ public class PmsPortalProductServiceImpl implements PmsPortalProductService {
 
     }
 
+    /**
+     * 获取当前分类和下级分类 id
+     *
+     * @param productCategoryId
+     * @return
+     */
+    private List<Long> getProductCategoryIds(Long productCategoryId) {
+        PmsProductCategoryExample productCategoryExample = new PmsProductCategoryExample();
+        productCategoryExample.setOrderByClause("sort desc");
+        productCategoryExample.createCriteria().andParentIdEqualTo(productCategoryId)
+               .andShowStatusEqualTo(1);
+        List<PmsProductCategory> pmsProductCategories = productCategoryMapper.selectByExample(productCategoryExample);
+        List<Long> productCategoryIds = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(pmsProductCategories)) {
+            productCategoryIds = pmsProductCategories
+                    .stream()
+                    .map(PmsProductCategory::getId)
+                    .collect(Collectors.toList());
+        }
+        productCategoryIds.add(productCategoryId);
+        return productCategoryIds;
+    }
+
     @Override
     public List<PmsProductCategoryNode> categoryTreeList() {
         PmsProductCategoryExample example = new PmsProductCategoryExample();