Procházet zdrojové kódy

八大类经营板块分类

ldz před 2 týdny
rodič
revize
8c2d2d17e7

+ 20 - 0
alien-store/src/main/java/shop/alien/store/controller/StoreInfoController.java

@@ -883,4 +883,24 @@ public class StoreInfoController {
         StoreInfoVo storeDetail = storeInfoService.getClientStoreDetail(id, userId, jingdu, weidu);
         return R.data(storeDetail);
     }
+
+    /**
+     * 获取休闲娱乐分类数据(主分类和子分类)
+     * 根据图片需求,返回层级结构的分类数据
+     *
+     * @return R<List<StoreDictionaryVo>> 分类列表,包含主分类和子分类
+     */
+    @ApiOperation("获取休闲娱乐分类数据(主分类和子分类)")
+    @ApiOperationSupport(order = 18)
+    @GetMapping("/getLeisureEntertainmentCategories")
+    public R<List<StoreDictionaryVo>> getLeisureEntertainmentCategories() {
+        log.info("StoreInfoController.getLeisureEntertainmentCategories");
+        try {
+            List<StoreDictionaryVo> result = storeInfoService.getLeisureEntertainmentCategories();
+            return R.data(result);
+        } catch (Exception e) {
+            log.error("获取休闲娱乐分类数据异常", e);
+            return R.fail("获取分类数据失败,请稍后重试");
+        }
+    }
 }

+ 8 - 0
alien-store/src/main/java/shop/alien/store/service/StoreInfoService.java

@@ -321,4 +321,12 @@ public interface StoreInfoService extends IService<StoreInfo> {
      * web端查询门店明细
      */
     StoreInfoVo getClientStoreDetail(String storeId, String userId, String jingdu, String weidu);
+
+    /**
+     * 获取休闲娱乐分类数据(主分类和子分类)
+     * 返回层级结构的分类数据,包含主分类和对应的子分类
+     *
+     * @return List<StoreDictionaryVo> 分类列表,包含主分类和子分类
+     */
+    List<StoreDictionaryVo> getLeisureEntertainmentCategories();
 }

+ 66 - 0
alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java

@@ -3358,4 +3358,70 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
         }
         return result;
     }
+
+    @Override
+    public List<StoreDictionaryVo> getLeisureEntertainmentCategories() {
+        // 定义四种主分类名称
+        List<String> mainCategoryNames = Arrays.asList("酒吧", "KTV", "洗浴汗蒸", "按摩足浴");
+
+        // 查询所有主分类(business_section类型)
+        List<StoreDictionary> allMainCategories = storeDictionaryMapper.selectList(
+                new LambdaQueryWrapper<StoreDictionary>()
+                        .eq(StoreDictionary::getTypeName, "business_section")
+                        .in(StoreDictionary::getDictDetail, mainCategoryNames)
+                        .eq(StoreDictionary::getDeleteFlag, 0)
+        );
+
+        // 构建主分类列表,包含"全部"选项
+        List<StoreDictionaryVo> result = new ArrayList<>();
+
+        // 添加"全部"选项
+        StoreDictionaryVo allCategory = new StoreDictionaryVo();
+        allCategory.setId(0);
+        allCategory.setDictId("0");
+        allCategory.setDictDetail("全部");
+        allCategory.setTypeName("business_section");
+        allCategory.setSubDataList(new ArrayList<>());
+        result.add(allCategory);
+
+        // 查询所有子分类(根据parent_id关联)
+        Map<Integer, List<StoreDictionary>> subCategoryMap = new HashMap<>();
+        if (!CollectionUtils.isEmpty(allMainCategories)) {
+            List<Integer> mainCategoryIds = allMainCategories.stream()
+                    .map(StoreDictionary::getId)
+                    .collect(Collectors.toList());
+
+            // 查询所有子分类
+            List<StoreDictionary> allSubCategories = storeDictionaryMapper.selectList(
+                    new LambdaQueryWrapper<StoreDictionary>()
+                            .in(StoreDictionary::getParentId, mainCategoryIds)
+                            .eq(StoreDictionary::getDeleteFlag, 0)
+            );
+
+            // 按parentId分组
+            subCategoryMap = allSubCategories.stream()
+                    .collect(Collectors.groupingBy(StoreDictionary::getParentId));
+        }
+
+        // 构建主分类及其子分类
+        for (StoreDictionary mainCategory : allMainCategories) {
+            StoreDictionaryVo mainVo = new StoreDictionaryVo();
+            BeanUtils.copyProperties(mainCategory, mainVo);
+
+            // 获取该主分类下的子分类
+            List<StoreDictionary> subCategories = subCategoryMap.getOrDefault(mainCategory.getId(), new ArrayList<>());
+            List<StoreDictionaryVo> subVoList = new ArrayList<>();
+
+            for (StoreDictionary subCategory : subCategories) {
+                StoreDictionaryVo subVo = new StoreDictionaryVo();
+                BeanUtils.copyProperties(subCategory, subVo);
+                subVoList.add(subVo);
+            }
+
+            mainVo.setSubDataList(subVoList);
+            result.add(mainVo);
+        }
+
+        return result;
+    }
 }