Commit 4a01348e0bf2a7b80cb111afbf246841241d0beb

Authored by wangzhs
1 parent 1811b96e

[新增][商品分类] 列表查询筛选增加 status、parentId 字段

yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/ProductCategoryListReqVO.java
@@ -10,4 +10,10 @@ public class ProductCategoryListReqVO { @@ -10,4 +10,10 @@ public class ProductCategoryListReqVO {
10 @Schema(description = "分类名称", example = "办公文具") 10 @Schema(description = "分类名称", example = "办公文具")
11 private String name; 11 private String name;
12 12
  13 + @Schema(description = "开启状态", example = "0")
  14 + private Integer status;
  15 +
  16 + @Schema(description = "父分类编号", example = "1")
  17 + private Long parentId;
  18 +
13 } 19 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/category/ProductCategoryMapper.java
@@ -19,6 +19,8 @@ public interface ProductCategoryMapper extends BaseMapperX<ProductCategoryDO> { @@ -19,6 +19,8 @@ public interface ProductCategoryMapper extends BaseMapperX<ProductCategoryDO> {
19 default List<ProductCategoryDO> selectList(ProductCategoryListReqVO listReqVO) { 19 default List<ProductCategoryDO> selectList(ProductCategoryListReqVO listReqVO) {
20 return selectList(new LambdaQueryWrapperX<ProductCategoryDO>() 20 return selectList(new LambdaQueryWrapperX<ProductCategoryDO>()
21 .likeIfPresent(ProductCategoryDO::getName, listReqVO.getName()) 21 .likeIfPresent(ProductCategoryDO::getName, listReqVO.getName())
  22 + .eqIfPresent(ProductCategoryDO::getParentId, listReqVO.getParentId())
  23 + .eqIfPresent(ProductCategoryDO::getStatus, listReqVO.getStatus())
22 .orderByDesc(ProductCategoryDO::getId)); 24 .orderByDesc(ProductCategoryDO::getId));
23 } 25 }
24 26
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImplTest.java
1 package cn.iocoder.yudao.module.product.service.category; 1 package cn.iocoder.yudao.module.product.service.category;
2 2
  3 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
3 import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; 4 import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
4 import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; 5 import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO;
5 import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; 6 import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO;
@@ -127,18 +128,28 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { @@ -127,18 +128,28 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest {
127 // mock 数据 128 // mock 数据
128 ProductCategoryDO dbCategory = randomPojo(ProductCategoryDO.class, o -> { // 等会查询到 129 ProductCategoryDO dbCategory = randomPojo(ProductCategoryDO.class, o -> { // 等会查询到
129 o.setName("奥特曼"); 130 o.setName("奥特曼");
  131 + o.setStatus(CommonStatusEnum.ENABLE.getStatus());
  132 + o.setParentId(ProductCategoryDO.PARENT_ID_NULL);
130 }); 133 });
131 productCategoryMapper.insert(dbCategory); 134 productCategoryMapper.insert(dbCategory);
132 // 测试 name 不匹配 135 // 测试 name 不匹配
133 productCategoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setName("奥特块"))); 136 productCategoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setName("奥特块")));
  137 + // 测试 status 不匹配
  138 + productCategoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
  139 + // 测试 parentId 不匹配
  140 + productCategoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setParentId(3333L)));
134 // 准备参数 141 // 准备参数
135 ProductCategoryListReqVO reqVO = new ProductCategoryListReqVO(); 142 ProductCategoryListReqVO reqVO = new ProductCategoryListReqVO();
136 reqVO.setName("特曼"); 143 reqVO.setName("特曼");
  144 + reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
  145 + reqVO.setParentId(ProductCategoryDO.PARENT_ID_NULL);
137 146
138 // 调用 147 // 调用
139 List<ProductCategoryDO> list = productCategoryService.getEnableCategoryList(reqVO); 148 List<ProductCategoryDO> list = productCategoryService.getEnableCategoryList(reqVO);
  149 + List<ProductCategoryDO> all = productCategoryService.getEnableCategoryList(new ProductCategoryListReqVO());
140 // 断言 150 // 断言
141 assertEquals(1, list.size()); 151 assertEquals(1, list.size());
  152 + assertEquals(4, all.size());
142 assertPojoEquals(dbCategory, list.get(0)); 153 assertPojoEquals(dbCategory, list.get(0));
143 } 154 }
144 155