|
|
@@ -3616,6 +3616,66 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
|
|
|
return buildTreeOptimized(storeDictionaryList);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<StoreDictionary> getAllBusinessSection(String businessSection) {
|
|
|
+ // 如果没有传入一级分类参数,返回所有分类
|
|
|
+ if (businessSection == null || businessSection.trim().isEmpty()) {
|
|
|
+ return getAllBusinessSection();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 根据dictId查询一级分类
|
|
|
+ StoreDictionary firstLevelDict = storeDictionaryMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<StoreDictionary>()
|
|
|
+ .eq(StoreDictionary::getDictId, businessSection.trim())
|
|
|
+ .eq(StoreDictionary::getTypeName, "business_section")
|
|
|
+ .eq(StoreDictionary::getDeleteFlag, 0)
|
|
|
+ );
|
|
|
+
|
|
|
+ if (firstLevelDict == null) {
|
|
|
+ log.warn("未找到一级分类,businessSection={}", businessSection);
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 查询该一级分类下的所有二级分类(business_type)
|
|
|
+ List<StoreDictionary> secondLevelDicts = storeDictionaryMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<StoreDictionary>()
|
|
|
+ .eq(StoreDictionary::getTypeName, "business_type")
|
|
|
+ .eq(StoreDictionary::getParentId, firstLevelDict.getId())
|
|
|
+ .eq(StoreDictionary::getDeleteFlag, 0)
|
|
|
+ .orderByAsc(StoreDictionary::getSortId)
|
|
|
+ );
|
|
|
+
|
|
|
+ if (secondLevelDicts.isEmpty()) {
|
|
|
+ // 如果没有二级分类,只返回一级分类
|
|
|
+ firstLevelDict.setStoreDictionaryList(new ArrayList<>());
|
|
|
+ return Collections.singletonList(firstLevelDict);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 获取所有二级分类的ID
|
|
|
+ List<Integer> secondLevelIds = secondLevelDicts.stream()
|
|
|
+ .map(StoreDictionary::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 4. 查询这些二级分类下的所有三级分类(business_classify)
|
|
|
+ List<StoreDictionary> thirdLevelDicts = storeDictionaryMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<StoreDictionary>()
|
|
|
+ .eq(StoreDictionary::getTypeName, "business_classify")
|
|
|
+ .in(StoreDictionary::getParentId, secondLevelIds)
|
|
|
+ .eq(StoreDictionary::getDeleteFlag, 0)
|
|
|
+ .orderByAsc(StoreDictionary::getSortId)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 5. 构建树形结构
|
|
|
+ // 将一级分类、二级分类、三级分类合并
|
|
|
+ List<StoreDictionary> allDicts = new ArrayList<>();
|
|
|
+ allDicts.add(firstLevelDict);
|
|
|
+ allDicts.addAll(secondLevelDicts);
|
|
|
+ allDicts.addAll(thirdLevelDicts);
|
|
|
+
|
|
|
+ // 构建树形结构
|
|
|
+ return buildTreeOptimized(allDicts);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 构建树形结构(优化版)
|
|
|
*
|