|
|
@@ -54,13 +54,25 @@ public class ProductController extends BaseController {
|
|
|
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
|
|
@ApiOperation("PC查询商品管理列表")
|
|
|
public R<Page<Product>> selectAll(Page<Product> page, Product product) {
|
|
|
- LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(product.getCategoryId() != null, Product::getCategoryId, product.getCategoryId())
|
|
|
- .like(StringUtils.isNotBlank(product.getName()), Product::getName, product.getName())
|
|
|
- .like(StringUtils.isNotBlank(product.getProductNo()), Product::getProductNo, product.getProductNo())
|
|
|
- .eq(product.getStatus() != null, Product::getStatus, product.getStatus())
|
|
|
- .orderByDesc(Product::getCreateTime);
|
|
|
- return R.ok(this.productService.page(page, queryWrapper));
|
|
|
+ try {
|
|
|
+ LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(product.getCategoryId() != null, Product::getCategoryId, product.getCategoryId())
|
|
|
+ .like(StringUtils.isNotBlank(product.getName()), Product::getName, product.getName())
|
|
|
+ .like(StringUtils.isNotBlank(product.getProductNo()), Product::getProductNo, product.getProductNo())
|
|
|
+ .eq(product.getStatus() != null, Product::getStatus, product.getStatus())
|
|
|
+ .orderByDesc(Product::getCreateTime);
|
|
|
+ Page<Product> page1 = this.productService.page(page, queryWrapper);
|
|
|
+ //根据分类ID查询分类的名称
|
|
|
+ List<Product> records = page1.getRecords();
|
|
|
+ for (Product record : records) {
|
|
|
+ ProductCategory productCategory = this.productCategoryService.getById(record.getCategoryId());
|
|
|
+ record.setCategoryName(productCategory.getName());
|
|
|
+ }
|
|
|
+ return R.ok(page1);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("商品查询失败", e);
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|