jinshihui hace 3 días
padre
commit
467bdedbbc

+ 19 - 7
nightFragrance-admin/src/main/java/com/ylx/web/controller/massage/ProductController.java

@@ -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);
+        }
     }
 
     /**

+ 6 - 0
nightFragrance-massage/src/main/java/com/ylx/massage/domain/Product.java

@@ -42,6 +42,12 @@ public class Product implements Serializable {
     @TableField("category_id")
     private Long categoryId;
 
+    /**
+     * 分类名称
+     */
+    @TableField(exist = false)
+    private String categoryName;
+
     /**
      * 商品名称
      */