master:商品列表获取分类列表功能完善;

pull/1121/head
liujiang 2025-08-16 19:04:52 +08:00
parent 4832edbfd3
commit b261bb9823
4 changed files with 39 additions and 3 deletions

View File

@ -72,6 +72,11 @@ public class SysProductCategoryController extends XktBaseController {
return R.ok(BeanUtil.copyToList(prodCateService.tree(BeanUtil.toBean(listVO, ProdCateListDTO.class)), ProdCateListResVO.class));
}
@ApiOperation(value = "商品管理列表获取所有商品二级分类及没有二级分类的一级分类", httpMethod = "POST", response = R.class)
@GetMapping("/leaf-node/list")
public R<List<ProdCateVO>> leafNodeList() {
return R.ok(BeanUtil.copyToList(prodCateService.leafNodeList(), ProdCateVO.class));
}
@ApiOperation(value = "获取商品分类列表", httpMethod = "POST", response = R.class)
@PostMapping("/list")
@ -79,7 +84,7 @@ public class SysProductCategoryController extends XktBaseController {
return R.ok(BeanUtil.copyToList(prodCateService.selectList(BeanUtil.toBean(listVO, ProdCateListDTO.class)), ProdCateListResVO.class));
}
@ApiOperation(value = "获取商品分类列表", httpMethod = "POST", response = R.class)
@ApiOperation(value = "app搜索框下商品分类列表", httpMethod = "POST", response = R.class)
@PostMapping("/app/list")
public R<List<ProdCateListResVO>> appList(@RequestBody ProdCateListVO listVO) {
return R.ok(BeanUtil.copyToList(prodCateService.selectAppList(BeanUtil.toBean(listVO, ProdCateListDTO.class)), ProdCateListResVO.class));

View File

@ -3172,8 +3172,6 @@ INSERT INTO `sys_product_category`
VALUES (49, '其他拖鞋', 8, 5, '0',
'https://pics1.baidu.com/feed/6609c93d70cf3bc758366c966adb10aecc112a85.png@f_auto?token=89fe04971fb0579147e9ccc52683a013',
'', 0, '0', '', '2025-04-15 19:57:12', '', '2025-04-15 19:57:12');
INSERT INTO `sys_product_category`
VALUES (50, '123', 1, 123, '1', NULL, '', 1, '0', '', '2025-06-28 17:36:35', 'admin', '2025-06-28 17:36:35');
SET
FOREIGN_KEY_CHECKS = 1;

View File

@ -91,6 +91,13 @@ public interface ISysProductCategoryService {
*/
List<ProdCateDTO> getAllSubList();
/**
*
*
* @return List<ProdCateDTO>
*/
List<ProdCateDTO> leafNodeList();
/**
*
*

View File

@ -269,6 +269,32 @@ public class SysProductCategoryServiceImpl implements ISysProductCategoryService
.collect(Collectors.toList());
}
/**
*
* @return List<ProdCateDTO>
*/
@Override
public List<ProdCateDTO> leafNodeList() {
List<SysProductCategory> cateList = this.prodCateMapper.selectList(new LambdaQueryWrapper<SysProductCategory>()
.eq(SysProductCategory::getDelFlag, Constants.UNDELETED)
// 排除最顶层的商品分类
.ne(SysProductCategory::getParentId, 0));
if (CollectionUtils.isEmpty(cateList)) {
return new ArrayList<>();
}
// 不是最顶层的商品分类
List<ProdCateDTO> leafNodeList = cateList.stream().filter(x -> !Objects.equals(x.getParentId(), TOPMOST_PRODUCT_CATEGORY_ID))
.map(x -> BeanUtil.toBean(x, ProdCateDTO.class).setProdCateId(x.getId())).collect(Collectors.toList());
final List<Long> hasSubCateIdList = leafNodeList.stream().map(ProdCateDTO::getParentId).distinct().collect(Collectors.toList());
List<ProdCateDTO> noSubCateList = cateList.stream()
.filter(x -> Objects.equals(x.getParentId(), TOPMOST_PRODUCT_CATEGORY_ID) && !hasSubCateIdList.contains(x.getId()))
.map(x -> BeanUtil.toBean(x, ProdCateDTO.class).setProdCateId(x.getId()))
.collect(Collectors.toList());
// 最顶层的商品分类(没有二级分类的)
CollectionUtils.addAll(leafNodeList, noSubCateList);
return leafNodeList;
}
/**
*