分类商品列表界面

pull/1/head
feijinping 3 years ago
parent cb6cfdc9e8
commit 6bd7a99a83

@ -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<List<ProductCategory>> allCategories() {
return ResponseEntity.ok(categoryService.h5Categories());
}
@GetMapping("/category-by-id")
public ResponseEntity<List<ProductCategory>> getBrotherAndChild(@RequestParam Long id, @RequestParam(name = "withChild", defaultValue = "false") boolean withChild) {
return ResponseEntity.ok(categoryService.getBrotherAndChild(id, withChild));
}
}

@ -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<Page<ProductDTO>> queryGoodByPage(@RequestBody ProductQuery query, Pageable page) {
List<Product> pageRes = productService.selectList(query, page);
return ResponseEntity.ok(new PageImpl<>(productConvert.dos2dtos(pageRes), page, ((com.github.pagehelper.Page) pageRes).getTotal()));
}
}

@ -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<ProductCategory> getBrotherAndChild(Long id, boolean withChild) {
ProductCategory category = productCategoryMapper.selectById(id);
if (category == null) {
throw new BaseException("参数错误");
}
LambdaQueryWrapper<ProductCategory> 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<ProductCategory> 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<ProductCategory> childs = productCategoryMapper.selectList(qw);
res.addAll(childs);
}
if (category.getParentId() != null && category.getParentId() != -1) {
res.add(productCategoryMapper.selectById(category.getParentId()));
}
return res;
}
}

Loading…
Cancel
Save