Commit 4a01348e0bf2a7b80cb111afbf246841241d0beb
1 parent
1811b96e
[新增][商品分类] 列表查询筛选增加 status、parentId 字段
Showing
3 changed files
with
19 additions
and
0 deletions
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 | 10 | @Schema(description = "分类名称", example = "办公文具") |
| 11 | 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 | 19 | default List<ProductCategoryDO> selectList(ProductCategoryListReqVO listReqVO) { |
| 20 | 20 | return selectList(new LambdaQueryWrapperX<ProductCategoryDO>() |
| 21 | 21 | .likeIfPresent(ProductCategoryDO::getName, listReqVO.getName()) |
| 22 | + .eqIfPresent(ProductCategoryDO::getParentId, listReqVO.getParentId()) | |
| 23 | + .eqIfPresent(ProductCategoryDO::getStatus, listReqVO.getStatus()) | |
| 22 | 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 | 1 | package cn.iocoder.yudao.module.product.service.category; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 3 | 4 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 4 | 5 | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; |
| 5 | 6 | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; |
| ... | ... | @@ -127,18 +128,28 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest { |
| 127 | 128 | // mock 数据 |
| 128 | 129 | ProductCategoryDO dbCategory = randomPojo(ProductCategoryDO.class, o -> { // 等会查询到 |
| 129 | 130 | o.setName("奥特曼"); |
| 131 | + o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 132 | + o.setParentId(ProductCategoryDO.PARENT_ID_NULL); | |
| 130 | 133 | }); |
| 131 | 134 | productCategoryMapper.insert(dbCategory); |
| 132 | 135 | // 测试 name 不匹配 |
| 133 | 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 | 142 | ProductCategoryListReqVO reqVO = new ProductCategoryListReqVO(); |
| 136 | 143 | reqVO.setName("特曼"); |
| 144 | + reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 145 | + reqVO.setParentId(ProductCategoryDO.PARENT_ID_NULL); | |
| 137 | 146 | |
| 138 | 147 | // 调用 |
| 139 | 148 | List<ProductCategoryDO> list = productCategoryService.getEnableCategoryList(reqVO); |
| 149 | + List<ProductCategoryDO> all = productCategoryService.getEnableCategoryList(new ProductCategoryListReqVO()); | |
| 140 | 150 | // 断言 |
| 141 | 151 | assertEquals(1, list.size()); |
| 152 | + assertEquals(4, all.size()); | |
| 142 | 153 | assertPojoEquals(dbCategory, list.get(0)); |
| 143 | 154 | } |
| 144 | 155 | ... | ... |