|
@@ -375,7 +375,7 @@ public class GoodsCategorySellerController {
|
|
|
return SldResponse.success(vos);
|
|
|
}
|
|
|
|
|
|
- @ApiOperation("获取分类列表接口")
|
|
|
+ @ApiOperation("获取品牌分类列表接口")
|
|
|
@ApiImplicitParams({
|
|
|
@ApiImplicitParam(name = "webSite", value = "站点", paramType = "query")
|
|
|
})
|
|
@@ -392,100 +392,14 @@ public class GoodsCategorySellerController {
|
|
|
example.setState(GoodsCategoryConst.CATEGORY_STATE_1);
|
|
|
example.setOrderBy("sort asc, create_time desc");
|
|
|
List<GoodsCategory> list = goodsCategoryModel.getGoodsCategoryList(example, null);
|
|
|
- //全部分类信息
|
|
|
+
|
|
|
+ //只获取一级分类,children设置为空集合
|
|
|
if (!CollectionUtils.isEmpty(list)) {
|
|
|
- // 将所有一级分类ID转换为逗号分隔的字符串
|
|
|
- StringBuilder firstLevelIdsBuilder = new StringBuilder();
|
|
|
for (GoodsCategory goodsCategory : list) {
|
|
|
- if (firstLevelIdsBuilder.length() > 0) {
|
|
|
- firstLevelIdsBuilder.append(",");
|
|
|
- }
|
|
|
- firstLevelIdsBuilder.append(goodsCategory.getCategoryId());
|
|
|
- }
|
|
|
- String firstLevelIds = firstLevelIdsBuilder.toString();
|
|
|
-
|
|
|
- if (!firstLevelIds.isEmpty()) {
|
|
|
- GoodsCategoryExample example2 = new GoodsCategoryExample();
|
|
|
- example2.setPidIn(firstLevelIds);
|
|
|
- example2.setState(GoodsCategoryConst.CATEGORY_STATE_1);
|
|
|
- example2.setOrderBy("sort asc, create_time desc");
|
|
|
- List<GoodsCategory> secondLevelList = goodsCategoryModel.getGoodsCategoryList(example2, null);
|
|
|
-
|
|
|
- // 按照一级分类ID分组二级分类
|
|
|
- Map<Integer, List<GoodsCategory>> secondLevelMap = new HashMap<>();
|
|
|
- for (GoodsCategory secondCategory : secondLevelList) {
|
|
|
- if (!secondLevelMap.containsKey(secondCategory.getPid())) {
|
|
|
- secondLevelMap.put(secondCategory.getPid(), new ArrayList<>());
|
|
|
- }
|
|
|
- secondLevelMap.get(secondCategory.getPid()).add(secondCategory);
|
|
|
- }
|
|
|
-
|
|
|
- // 获取所有三级分类IDs
|
|
|
- StringBuilder secondLevelIdsBuilder = new StringBuilder();
|
|
|
- for (GoodsCategory secondCategory : secondLevelList) {
|
|
|
- if (secondLevelIdsBuilder.length() > 0) {
|
|
|
- secondLevelIdsBuilder.append(",");
|
|
|
- }
|
|
|
- secondLevelIdsBuilder.append(secondCategory.getCategoryId());
|
|
|
- }
|
|
|
- String secondLevelIds = secondLevelIdsBuilder.toString();
|
|
|
-
|
|
|
- if (!secondLevelIds.isEmpty()) {
|
|
|
- GoodsCategoryExample example3 = new GoodsCategoryExample();
|
|
|
- example3.setPidIn(secondLevelIds);
|
|
|
- example3.setState(GoodsCategoryConst.CATEGORY_STATE_1);
|
|
|
- example3.setOrderBy("sort asc, create_time desc");
|
|
|
- List<GoodsCategory> thirdLevelList = goodsCategoryModel.getGoodsCategoryList(example3, null);
|
|
|
-
|
|
|
- // 按照二级分类ID分组三级分类
|
|
|
- Map<Integer, List<GoodsCategory>> thirdLevelMap = new HashMap<>();
|
|
|
- for (GoodsCategory thirdCategory : thirdLevelList) {
|
|
|
- if (!thirdLevelMap.containsKey(thirdCategory.getPid())) {
|
|
|
- thirdLevelMap.put(thirdCategory.getPid(), new ArrayList<>());
|
|
|
- }
|
|
|
- thirdLevelMap.get(thirdCategory.getPid()).add(thirdCategory);
|
|
|
- }
|
|
|
-
|
|
|
- // 构建完整的分类树
|
|
|
- for (GoodsCategory firstCategory : list) {
|
|
|
- FrontGoodsCategoryVO firstVO = new FrontGoodsCategoryVO(firstCategory);
|
|
|
- List<FrontGoodsCategoryVO> secondVOs = new ArrayList<>();
|
|
|
-
|
|
|
- List<GoodsCategory> secondCategories = secondLevelMap.get(firstCategory.getCategoryId());
|
|
|
- if (!CollectionUtils.isEmpty(secondCategories)) {
|
|
|
- for (GoodsCategory secondCategory : secondCategories) {
|
|
|
- FrontGoodsCategoryVO secondVO = new FrontGoodsCategoryVO(secondCategory);
|
|
|
- // 没有图片就用默认图片
|
|
|
- if (StringUtils.isEmpty(secondCategory.getCategoryImage())) {
|
|
|
- secondVO.setCategoryImage(FileUrlUtil.getFileUrl(stringRedisTemplate.opsForValue().get("default_goods_cate_grade2_image"), null));
|
|
|
- }
|
|
|
-
|
|
|
- List<FrontGoodsCategoryVO> thirdVOs = new ArrayList<>();
|
|
|
- List<GoodsCategory> thirdCategories = thirdLevelMap.get(secondCategory.getCategoryId());
|
|
|
- if (!CollectionUtils.isEmpty(thirdCategories)) {
|
|
|
- for (GoodsCategory thirdCategory : thirdCategories) {
|
|
|
- FrontGoodsCategoryVO thirdVO = new FrontGoodsCategoryVO(thirdCategory);
|
|
|
- // 没有图片就用默认图片
|
|
|
- if (StringUtils.isEmpty(thirdCategory.getCategoryImage())) {
|
|
|
- thirdVO.setCategoryImage(FileUrlUtil.getFileUrl(stringRedisTemplate.opsForValue().get("default_goods_cate_grade3_image"), null));
|
|
|
- }
|
|
|
- thirdVOs.add(thirdVO);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!CollectionUtils.isEmpty(thirdVOs)) {
|
|
|
- secondVO.setChildren(thirdVOs);
|
|
|
- secondVOs.add(secondVO);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!CollectionUtils.isEmpty(secondVOs)) {
|
|
|
- firstVO.setChildren(secondVOs);
|
|
|
- vos.add(firstVO);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ FrontGoodsCategoryVO vo = new FrontGoodsCategoryVO(goodsCategory);
|
|
|
+ // 设置children为空集合而不是null
|
|
|
+ vo.setChildren(new ArrayList<>());
|
|
|
+ vos.add(vo);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
@@ -496,13 +410,15 @@ public class GoodsCategorySellerController {
|
|
|
example.setState(StoreConst.STORE_CATEGORY_STATE_PASS);
|
|
|
List<StoreBindCategory> list = storeBindCategoryModel.getStoreBindCategoryList(example, null);
|
|
|
|
|
|
+ //只获取一级分类,children设置为空集合
|
|
|
if (!CollectionUtils.isEmpty(list)) {
|
|
|
- // 提取所有一级分类ID并转换为逗号分隔的字符串
|
|
|
+ // 提取所有一级分类ID并去重
|
|
|
Set<Integer> firstLevelIdSet = new HashSet<>();
|
|
|
for (StoreBindCategory bindCategory : list) {
|
|
|
firstLevelIdSet.add(bindCategory.getGoodsCategoryId1());
|
|
|
}
|
|
|
|
|
|
+ // 批量查询一级分类
|
|
|
StringBuilder firstLevelIdsBuilder = new StringBuilder();
|
|
|
for (Integer id : firstLevelIdSet) {
|
|
|
if (firstLevelIdsBuilder.length() > 0) {
|
|
@@ -512,23 +428,16 @@ public class GoodsCategorySellerController {
|
|
|
}
|
|
|
String firstLevelIds = firstLevelIdsBuilder.toString();
|
|
|
|
|
|
- if (!firstLevelIds.isEmpty()) {
|
|
|
- // 批量查询一级分类
|
|
|
- GoodsCategoryExample firstExample = new GoodsCategoryExample();
|
|
|
- firstExample.setCategoryIdIn(firstLevelIds);
|
|
|
- List<GoodsCategory> firstLevelCategories = goodsCategoryModel.getGoodsCategoryList(firstExample, null);
|
|
|
+ GoodsCategoryExample firstExample = new GoodsCategoryExample();
|
|
|
+ firstExample.setCategoryIdIn(firstLevelIds);
|
|
|
+ List<GoodsCategory> firstLevelCategories = goodsCategoryModel.getGoodsCategoryList(firstExample, null);
|
|
|
|
|
|
- Map<Integer, GoodsCategory> firstLevelMap = new HashMap<>();
|
|
|
- for (GoodsCategory category : firstLevelCategories) {
|
|
|
- firstLevelMap.put(category.getCategoryId(), category);
|
|
|
- }
|
|
|
-
|
|
|
- // 构建分类树
|
|
|
- for (GoodsCategory firstCategory : firstLevelCategories) {
|
|
|
- FrontGoodsCategoryVO firstVO = new FrontGoodsCategoryVO(firstCategory);
|
|
|
- firstVO = categoryTreeOptimized(firstVO, firstCategory.getCategoryId(), vendor.getStoreId(), webSite);
|
|
|
- vos.add(firstVO);
|
|
|
- }
|
|
|
+ // 构建返回结果,children设置为空集合
|
|
|
+ for (GoodsCategory firstCategory : firstLevelCategories) {
|
|
|
+ FrontGoodsCategoryVO vo = new FrontGoodsCategoryVO(firstCategory);
|
|
|
+ // 设置children为空集合而不是null
|
|
|
+ vo.setChildren(new ArrayList<>());
|
|
|
+ vos.add(vo);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -536,85 +445,5 @@ public class GoodsCategorySellerController {
|
|
|
return SldResponse.success(vos);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 优化后的构造分类树方法
|
|
|
- *
|
|
|
- * @param tree
|
|
|
- * @param categoryId
|
|
|
- * @param storeId
|
|
|
- * @param webSite
|
|
|
- * @return
|
|
|
- */
|
|
|
- public FrontGoodsCategoryVO categoryTreeOptimized(FrontGoodsCategoryVO tree, Integer categoryId, Long storeId, String webSite) {
|
|
|
- // 查询二级分类
|
|
|
- GoodsCategoryExample example2 = new GoodsCategoryExample();
|
|
|
- example2.setPid(categoryId);
|
|
|
- example2.setState(GoodsCategoryConst.CATEGORY_STATE_1);
|
|
|
- example2.setOrderBy("sort asc, create_time desc");
|
|
|
- List<GoodsCategory> list2 = goodsCategoryModel.getGoodsCategoryList(example2, null);
|
|
|
-
|
|
|
- if (!CollectionUtils.isEmpty(list2)) {
|
|
|
- // 将所有二级分类ID转换为逗号分隔的字符串
|
|
|
- StringBuilder secondLevelIdsBuilder = new StringBuilder();
|
|
|
- for (GoodsCategory category : list2) {
|
|
|
- if (secondLevelIdsBuilder.length() > 0) {
|
|
|
- secondLevelIdsBuilder.append(",");
|
|
|
- }
|
|
|
- secondLevelIdsBuilder.append(category.getCategoryId());
|
|
|
- }
|
|
|
- String secondLevelIds = secondLevelIdsBuilder.toString();
|
|
|
-
|
|
|
- if (!secondLevelIds.isEmpty()) {
|
|
|
- // 批量查询三级分类
|
|
|
- GoodsCategoryExample example3 = new GoodsCategoryExample();
|
|
|
- example3.setPidIn(secondLevelIds);
|
|
|
- example3.setState(GoodsCategoryConst.CATEGORY_STATE_1);
|
|
|
- example3.setOrderBy("sort asc, create_time desc");
|
|
|
- List<GoodsCategory> list3 = goodsCategoryModel.getGoodsCategoryList(example3, null);
|
|
|
-
|
|
|
- // 按二级分类ID分组三级分类
|
|
|
- Map<Integer, List<GoodsCategory>> thirdLevelMap = new HashMap<>();
|
|
|
- for (GoodsCategory thirdCategory : list3) {
|
|
|
- if (!thirdLevelMap.containsKey(thirdCategory.getPid())) {
|
|
|
- thirdLevelMap.put(thirdCategory.getPid(), new ArrayList<>());
|
|
|
- }
|
|
|
- thirdLevelMap.get(thirdCategory.getPid()).add(thirdCategory);
|
|
|
- }
|
|
|
-
|
|
|
- // 构造二级和三级分类树
|
|
|
- List<FrontGoodsCategoryVO> vos2 = new ArrayList<>();
|
|
|
- for (GoodsCategory goodsCategory2 : list2) {
|
|
|
- FrontGoodsCategoryVO tree2 = new FrontGoodsCategoryVO(goodsCategory2);
|
|
|
- // 没有图片就用默认图片
|
|
|
- if (StringUtils.isEmpty(goodsCategory2.getCategoryImage())) {
|
|
|
- tree2.setCategoryImage(FileUrlUtil.getFileUrl(stringRedisTemplate.opsForValue().get("default_goods_cate_grade2_image"), null));
|
|
|
- }
|
|
|
-
|
|
|
- // 获取当前二级分类下的三级分类
|
|
|
- List<FrontGoodsCategoryVO> vos3 = new ArrayList<>();
|
|
|
- List<GoodsCategory> thirdCategories = thirdLevelMap.get(goodsCategory2.getCategoryId());
|
|
|
- if (!CollectionUtils.isEmpty(thirdCategories)) {
|
|
|
- for (GoodsCategory goodsCategory3 : thirdCategories) {
|
|
|
- FrontGoodsCategoryVO tree3 = new FrontGoodsCategoryVO(goodsCategory3);
|
|
|
- // 没有图片就用默认图片
|
|
|
- if (StringUtils.isEmpty(goodsCategory3.getCategoryImage())) {
|
|
|
- tree3.setCategoryImage(FileUrlUtil.getFileUrl(stringRedisTemplate.opsForValue().get("default_goods_cate_grade3_image"), null));
|
|
|
- }
|
|
|
- vos3.add(tree3);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!CollectionUtils.isEmpty(vos3)) {
|
|
|
- tree2.setChildren(vos3);
|
|
|
- vos2.add(tree2);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- tree.setChildren(vos2);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return tree;
|
|
|
- }
|
|
|
|
|
|
}
|