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

pull/2/head
wangzhs 2023-03-15 11:36:45 +08:00
parent 1811b96eb5
commit 4a01348e0b
3 changed files with 19 additions and 0 deletions

View File

@ -10,4 +10,10 @@ public class ProductCategoryListReqVO {
@Schema(description = "分类名称", example = "办公文具") @Schema(description = "分类名称", example = "办公文具")
private String name; private String name;
@Schema(description = "开启状态", example = "0")
private Integer status;
@Schema(description = "父分类编号", example = "1")
private Long parentId;
} }

View File

@ -19,6 +19,8 @@ public interface ProductCategoryMapper extends BaseMapperX<ProductCategoryDO> {
default List<ProductCategoryDO> selectList(ProductCategoryListReqVO listReqVO) { default List<ProductCategoryDO> selectList(ProductCategoryListReqVO listReqVO) {
return selectList(new LambdaQueryWrapperX<ProductCategoryDO>() return selectList(new LambdaQueryWrapperX<ProductCategoryDO>()
.likeIfPresent(ProductCategoryDO::getName, listReqVO.getName()) .likeIfPresent(ProductCategoryDO::getName, listReqVO.getName())
.eqIfPresent(ProductCategoryDO::getParentId, listReqVO.getParentId())
.eqIfPresent(ProductCategoryDO::getStatus, listReqVO.getStatus())
.orderByDesc(ProductCategoryDO::getId)); .orderByDesc(ProductCategoryDO::getId));
} }

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.product.service.category; package cn.iocoder.yudao.module.product.service.category;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO;
@ -127,18 +128,28 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest {
// mock 数据 // mock 数据
ProductCategoryDO dbCategory = randomPojo(ProductCategoryDO.class, o -> { // 等会查询到 ProductCategoryDO dbCategory = randomPojo(ProductCategoryDO.class, o -> { // 等会查询到
o.setName("奥特曼"); o.setName("奥特曼");
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
o.setParentId(ProductCategoryDO.PARENT_ID_NULL);
}); });
productCategoryMapper.insert(dbCategory); productCategoryMapper.insert(dbCategory);
// 测试 name 不匹配 // 测试 name 不匹配
productCategoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setName("奥特块"))); productCategoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setName("奥特块")));
// 测试 status 不匹配
productCategoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
// 测试 parentId 不匹配
productCategoryMapper.insert(cloneIgnoreId(dbCategory, o -> o.setParentId(3333L)));
// 准备参数 // 准备参数
ProductCategoryListReqVO reqVO = new ProductCategoryListReqVO(); ProductCategoryListReqVO reqVO = new ProductCategoryListReqVO();
reqVO.setName("特曼"); reqVO.setName("特曼");
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
reqVO.setParentId(ProductCategoryDO.PARENT_ID_NULL);
// 调用 // 调用
List<ProductCategoryDO> list = productCategoryService.getEnableCategoryList(reqVO); List<ProductCategoryDO> list = productCategoryService.getEnableCategoryList(reqVO);
List<ProductCategoryDO> all = productCategoryService.getEnableCategoryList(new ProductCategoryListReqVO());
// 断言 // 断言
assertEquals(1, list.size()); assertEquals(1, list.size());
assertEquals(4, all.size());
assertPojoEquals(dbCategory, list.get(0)); assertPojoEquals(dbCategory, list.get(0));
} }