From cb6cfdc9e869ed2721f1dca5c55c09bca58cd980 Mon Sep 17 00:00:00 2001 From: feijinping Date: Tue, 17 Jan 2023 18:37:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=B1=BB=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cyl/h5/controller/CategoryController.java | 22 +++++++++++++++++++ .../com/cyl/h5/controller/HomeController.java | 12 ++++++++++ .../pms/service/ProductCategoryService.java | 18 ++++++++++----- 3 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 ruoyi-mall/src/main/java/com/cyl/h5/controller/CategoryController.java diff --git a/ruoyi-mall/src/main/java/com/cyl/h5/controller/CategoryController.java b/ruoyi-mall/src/main/java/com/cyl/h5/controller/CategoryController.java new file mode 100644 index 0000000..8880263 --- /dev/null +++ b/ruoyi-mall/src/main/java/com/cyl/h5/controller/CategoryController.java @@ -0,0 +1,22 @@ +package com.cyl.h5.controller; + +import com.cyl.pms.domain.ProductCategory; +import com.cyl.pms.service.ProductCategoryService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/no-auth/category") +public class CategoryController { + @Autowired + private ProductCategoryService categoryService; + @GetMapping("/all-categories") + public ResponseEntity> allCategories() { + return ResponseEntity.ok(categoryService.h5Categories()); + } +} diff --git a/ruoyi-mall/src/main/java/com/cyl/h5/controller/HomeController.java b/ruoyi-mall/src/main/java/com/cyl/h5/controller/HomeController.java index e9732c3..37a45ef 100644 --- a/ruoyi-mall/src/main/java/com/cyl/h5/controller/HomeController.java +++ b/ruoyi-mall/src/main/java/com/cyl/h5/controller/HomeController.java @@ -29,4 +29,16 @@ public class HomeController { res.setCategoryList(categoryService.queryCategoryWithProductsForH5()); return ResponseEntity.ok(res); } + /** + * 首页配置 + * + * @return 首页配置 + */ + @GetMapping("/product-count") + public ResponseEntity productCount() { + HomeConfigVO res = new HomeConfigVO(); + res.setBanners(sysConfigService.selectConfigByKey("h5.home.banner")); + res.setCategoryList(categoryService.queryCategoryWithProductsForH5()); + return ResponseEntity.ok(res); + } } diff --git a/ruoyi-mall/src/main/java/com/cyl/pms/service/ProductCategoryService.java b/ruoyi-mall/src/main/java/com/cyl/pms/service/ProductCategoryService.java index a67f1d2..cacc58c 100644 --- a/ruoyi-mall/src/main/java/com/cyl/pms/service/ProductCategoryService.java +++ b/ruoyi-mall/src/main/java/com/cyl/pms/service/ProductCategoryService.java @@ -28,7 +28,6 @@ import java.util.stream.Collectors; /** * 商品分类Service业务层处理 * - * * @author zcc */ @Service @@ -56,7 +55,7 @@ public class ProductCategoryService { * 查询商品分类列表 * * @param query 查询条件 - * @param page 分页条件 + * @param page 分页条件 * @return 商品分类 */ public List selectList(ProductCategoryQuery query, Pageable page) { @@ -101,7 +100,7 @@ public class ProductCategoryService { List children = new ArrayList<>(); // 1)先获取到所有根节点 for (ProductCategoryVO node : nodes) { - if (node.getParentId() == null || node.getParentId() == 0 ) { + if (node.getParentId() == null || node.getParentId() == 0) { tree.add(node); } else { children.add(node); @@ -173,7 +172,8 @@ public class ProductCategoryService { List categories = productCategoryMapper.selectPage(pageReq, qw1).getRecords(); if (CollUtil.isEmpty(categories)) { return Collections.emptyList(); - }; + } + ; return categories.stream().map(it -> { CategoryDTO dto = convert.do2dto(it); // 寻找该分类下的所有子类 @@ -203,9 +203,17 @@ public class ProductCategoryService { break; } res.addAll(ids); - level ++; + level++; } res.addAll(categoryIds); return res; } + + public List h5Categories() { + QueryWrapper qw = new QueryWrapper<>(); + qw.select("id", "parent_id", "name", "level", "sort", "icon"); + qw.eq("show_status", 1); + qw.le("level", 2); + return productCategoryMapper.selectList(qw); + } }