feat(category): 增加按祖级 ID 查询分类信息功能- 新增 categoryByAncestors 接口,根据祖级 ID 获取分类信息列表
- 在 TzCategory 模型中添加 ancestors 字段,用于存储祖级列表 - 在 TzCategoryService接口中添加 listByAncestors 方法 - 在 TzCategoryServiceImpl 中实现 listByAncestors 方法 - 更新相关 BO 和 VO 类,支持 ancestors 字段
This commit is contained in:
@@ -215,13 +215,21 @@ public class ApiProdController {
|
||||
}
|
||||
|
||||
@GetMapping("/categoryInfo")
|
||||
@Operation(summary = "分类信息列表", description = "获取所有的产品分类信息,顶级分类的parentId为0,默认为顶级分类")
|
||||
@Operation(summary = "根据父级ID获取分类信息列表", description = "获取所有的产品分类信息,顶级分类的parentId为0,默认为顶级分类")
|
||||
@Parameter(name = "parentId", description = "分类ID")
|
||||
public ServerResponseEntity<List<TzCategoryVo>> categoryInfo(@RequestParam(value = "parentId", defaultValue = "0") Long parentId) {
|
||||
List<TzCategoryVo> categories = categoryService.listByParentId(parentId);
|
||||
return ServerResponseEntity.success(categories);
|
||||
}
|
||||
|
||||
@GetMapping("/categoryByAncestors")
|
||||
@Operation(summary = "根据祖级ID获取分类信息列表", description = "获取所有的产品分类信息,顶级分类的ancestors为0,默认为顶级分类")
|
||||
@Parameter(name = "ancestors", description = "祖级ID")
|
||||
public ServerResponseEntity<List<TzCategoryVo>> categoryByAncestors(@RequestParam(value = "ancestors", defaultValue = "0") Long ancestors) {
|
||||
List<TzCategoryVo> categories = categoryService.listByAncestors(ancestors);
|
||||
return ServerResponseEntity.success(categories);
|
||||
}
|
||||
|
||||
@PostMapping("/searchProdPage")
|
||||
@Operation(summary = "分页排序搜索商品", description = "根据商品名搜索")
|
||||
@Parameters({@Parameter(name = "categoryId", description = "分类ID"),@Parameter(name = "prodName", description = "商品名"), @Parameter(name = "floor", description = "是否特价 1:是 2:否", required = true),@Parameter(name = "sort", description = "排序(0综合 1价格排序 2热门 3新品)", required = true), @Parameter(name = "orderBy", description = "排序(0升序 1降序)--sort选择1时必传")})
|
||||
|
||||
@@ -30,9 +30,9 @@ public class TzCategory extends BaseEntity {
|
||||
private Long categoryId;
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
* 祖级列表
|
||||
*/
|
||||
private Long shopId;
|
||||
private String ancestors;
|
||||
|
||||
/**
|
||||
* 父节点
|
||||
|
||||
@@ -30,9 +30,9 @@ public class TzCategoryBo extends BaseEntity {
|
||||
private Long categoryId;
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
* 祖级列表
|
||||
*/
|
||||
private Long shopId;
|
||||
private String ancestors;
|
||||
|
||||
/**
|
||||
* 父节点
|
||||
|
||||
@@ -33,10 +33,10 @@ public class TzCategoryVo implements Serializable {
|
||||
private Long categoryId;
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
* 祖级列表
|
||||
*/
|
||||
@ExcelProperty(value = "店铺ID")
|
||||
private Long shopId;
|
||||
@ExcelProperty(value = "祖级列表")
|
||||
private String ancestors;
|
||||
|
||||
/**
|
||||
* 父节点
|
||||
|
||||
@@ -68,4 +68,11 @@ public interface ITzCategoryService {
|
||||
* @return
|
||||
*/
|
||||
List<TzCategoryVo> categoryAll();
|
||||
|
||||
/**
|
||||
* 分类信息列表
|
||||
* @param ancestors
|
||||
* @return
|
||||
*/
|
||||
List<TzCategoryVo> listByAncestors(Long ancestors);
|
||||
}
|
||||
|
||||
@@ -75,6 +75,10 @@ public class TzCategoryServiceImpl implements ITzCategoryService {
|
||||
bo.setGrade(category.getGrade()+1);
|
||||
category.setSubset(1);
|
||||
baseMapper.updateById(category);
|
||||
|
||||
bo.setAncestors(category.getAncestors()+StringUtils.SEPARATOR+category.getCategoryId());
|
||||
}else{
|
||||
bo.setAncestors("0");
|
||||
}
|
||||
bo.setRecTime(new Date());
|
||||
TzCategory add = MapstructUtils.convert(bo, TzCategory.class);
|
||||
@@ -94,6 +98,10 @@ public class TzCategoryServiceImpl implements ITzCategoryService {
|
||||
bo.setGrade(category.getGrade()+1);
|
||||
category.setSubset(1);
|
||||
baseMapper.updateById(category);
|
||||
|
||||
bo.setAncestors(category.getAncestors()+StringUtils.SEPARATOR+category.getCategoryId());
|
||||
}else{
|
||||
bo.setAncestors("0");
|
||||
}
|
||||
TzCategory update = MapstructUtils.convert(bo, TzCategory.class);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
@@ -113,19 +121,24 @@ public class TzCategoryServiceImpl implements ITzCategoryService {
|
||||
|
||||
/**
|
||||
* 根据父级ID查询子类信息
|
||||
*
|
||||
* @param parentId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<TzCategoryVo> listByParentId(Long parentId) {
|
||||
return baseMapper.selectVoList(new LambdaQueryWrapper<TzCategory>().eq(TzCategory::getParentId, parentId).eq(TzCategory::getStatus,1).eq(TzCategory::getSubset,1));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类信息列表
|
||||
* @param ancestors
|
||||
*/
|
||||
@Override
|
||||
public List<TzCategoryVo> listByAncestors(Long ancestors) {
|
||||
return baseMapper.selectVoList(new LambdaQueryWrapper<TzCategory>().like(TzCategory::getAncestors, ancestors).eq(TzCategory::getStatus,1).eq(TzCategory::getSubset,1));
|
||||
}
|
||||
|
||||
/**
|
||||
* 全部分类信息列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<TzCategoryVo> categoryAll() {
|
||||
|
||||
Reference in New Issue
Block a user