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 index 8880263..9a6a080 100644 --- a/ruoyi-mall/src/main/java/com/cyl/h5/controller/CategoryController.java +++ b/ruoyi-mall/src/main/java/com/cyl/h5/controller/CategoryController.java @@ -6,6 +6,7 @@ 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.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -15,8 +16,14 @@ import java.util.List; public class CategoryController { @Autowired private ProductCategoryService categoryService; + @GetMapping("/all-categories") public ResponseEntity> allCategories() { return ResponseEntity.ok(categoryService.h5Categories()); } + + @GetMapping("/category-by-id") + public ResponseEntity> getBrotherAndChild(@RequestParam Long id, @RequestParam(name = "withChild", defaultValue = "false") boolean withChild) { + return ResponseEntity.ok(categoryService.getBrotherAndChild(id, withChild)); + } } diff --git a/ruoyi-mall/src/main/java/com/cyl/h5/controller/GoodController.java b/ruoyi-mall/src/main/java/com/cyl/h5/controller/GoodController.java new file mode 100644 index 0000000..d047afb --- /dev/null +++ b/ruoyi-mall/src/main/java/com/cyl/h5/controller/GoodController.java @@ -0,0 +1,33 @@ +package com.cyl.h5.controller; + +import com.cyl.h5.pojo.dto.ProductDTO; +import com.cyl.pms.convert.ProductConvert; +import com.cyl.pms.domain.Product; +import com.cyl.pms.pojo.query.ProductQuery; +import com.cyl.pms.service.ProductService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/no-auth/good") +public class GoodController { + @Autowired + private ProductService productService; + @Autowired + private ProductConvert productConvert; + + @PostMapping("/list") + public ResponseEntity> queryGoodByPage(@RequestBody ProductQuery query, Pageable page) { + List pageRes = productService.selectList(query, page); + return ResponseEntity.ok(new PageImpl<>(productConvert.dos2dtos(pageRes), page, ((com.github.pagehelper.Page) pageRes).getTotal())); + } +} 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 cacc58c..3632d75 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 @@ -1,6 +1,7 @@ package com.cyl.pms.service; import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -14,6 +15,7 @@ import com.cyl.pms.mapper.ProductMapper; import com.cyl.pms.pojo.query.ProductCategoryQuery; import com.cyl.pms.pojo.vo.ProductCategoryVO; import com.github.pagehelper.PageHelper; +import com.ruoyi.common.exception.base.BaseException; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; @@ -216,4 +218,29 @@ public class ProductCategoryService { qw.le("level", 2); return productCategoryMapper.selectList(qw); } + + public List getBrotherAndChild(Long id, boolean withChild) { + ProductCategory category = productCategoryMapper.selectById(id); + if (category == null) { + throw new BaseException("参数错误"); + } + LambdaQueryWrapper qw = new LambdaQueryWrapper<>(); + qw.eq(ProductCategory::getParentId, category.getParentId()); + qw.eq(ProductCategory::getLevel, category.getLevel()); + qw.eq(ProductCategory::getShowStatus, 1); + qw.select(ProductCategory::getId, ProductCategory::getParentId, ProductCategory::getName, ProductCategory::getLevel, ProductCategory::getSort, ProductCategory::getIcon); + List res = productCategoryMapper.selectList(qw); + if (withChild) { + qw.clear(); + qw.eq(ProductCategory::getParentId, category.getId()); + qw.eq(ProductCategory::getLevel, category.getLevel() + 1); + qw.eq(ProductCategory::getShowStatus, 1); + List childs = productCategoryMapper.selectList(qw); + res.addAll(childs); + } + if (category.getParentId() != null && category.getParentId() != -1) { + res.add(productCategoryMapper.selectById(category.getParentId())); + } + return res; + } }