分类查询

pull/1/head
feijinping 3 years ago
parent 78e3fbef8f
commit cb6cfdc9e8

@ -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<List<ProductCategory>> allCategories() {
return ResponseEntity.ok(categoryService.h5Categories());
}
}

@ -29,4 +29,16 @@ public class HomeController {
res.setCategoryList(categoryService.queryCategoryWithProductsForH5()); res.setCategoryList(categoryService.queryCategoryWithProductsForH5());
return ResponseEntity.ok(res); return ResponseEntity.ok(res);
} }
/**
*
*
* @return
*/
@GetMapping("/product-count")
public ResponseEntity<HomeConfigVO> productCount() {
HomeConfigVO res = new HomeConfigVO();
res.setBanners(sysConfigService.selectConfigByKey("h5.home.banner"));
res.setCategoryList(categoryService.queryCategoryWithProductsForH5());
return ResponseEntity.ok(res);
}
} }

@ -28,7 +28,6 @@ import java.util.stream.Collectors;
/** /**
* Service * Service
* *
*
* @author zcc * @author zcc
*/ */
@Service @Service
@ -56,7 +55,7 @@ public class ProductCategoryService {
* *
* *
* @param query * @param query
* @param page * @param page
* @return * @return
*/ */
public List<ProductCategoryVO> selectList(ProductCategoryQuery query, Pageable page) { public List<ProductCategoryVO> selectList(ProductCategoryQuery query, Pageable page) {
@ -101,7 +100,7 @@ public class ProductCategoryService {
List<ProductCategoryVO> children = new ArrayList<>(); List<ProductCategoryVO> children = new ArrayList<>();
// 1先获取到所有根节点 // 1先获取到所有根节点
for (ProductCategoryVO node : nodes) { for (ProductCategoryVO node : nodes) {
if (node.getParentId() == null || node.getParentId() == 0 ) { if (node.getParentId() == null || node.getParentId() == 0) {
tree.add(node); tree.add(node);
} else { } else {
children.add(node); children.add(node);
@ -173,7 +172,8 @@ public class ProductCategoryService {
List<ProductCategory> categories = productCategoryMapper.selectPage(pageReq, qw1).getRecords(); List<ProductCategory> categories = productCategoryMapper.selectPage(pageReq, qw1).getRecords();
if (CollUtil.isEmpty(categories)) { if (CollUtil.isEmpty(categories)) {
return Collections.emptyList(); return Collections.emptyList();
}; }
;
return categories.stream().map(it -> { return categories.stream().map(it -> {
CategoryDTO dto = convert.do2dto(it); CategoryDTO dto = convert.do2dto(it);
// 寻找该分类下的所有子类 // 寻找该分类下的所有子类
@ -203,9 +203,17 @@ public class ProductCategoryService {
break; break;
} }
res.addAll(ids); res.addAll(ids);
level ++; level++;
} }
res.addAll(categoryIds); res.addAll(categoryIds);
return res; return res;
} }
public List<ProductCategory> h5Categories() {
QueryWrapper<ProductCategory> 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);
}
} }

Loading…
Cancel
Save