瀏覽代碼

合并解决

penghao 1 周之前
父節點
當前提交
6b7fefc47b
共有 1 個文件被更改,包括 116 次插入4 次删除
  1. 116 4
      alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java

+ 116 - 4
alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java

@@ -4625,8 +4625,6 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
 
 
         return parseDateString(endDateStr);
         return parseDateString(endDateStr);
     }
     }
-}
-
 
 
     @Override
     @Override
     public StoreInfoVo getClientStoreDetail(String storeId, String userId, String jingdu, String weidu) {
     public StoreInfoVo getClientStoreDetail(String storeId, String userId, String jingdu, String weidu) {
@@ -5154,13 +5152,127 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
             // 不设置subDataList,返回扁平化列表
             // 不设置subDataList,返回扁平化列表
             result.add(vo);
             result.add(vo);
         }
         }
+        return result;
+    }
 
 
+    @Override
+    public StoreThreeLevelStructureVo getStoreThreeLevelStructure(Integer storeId) {
+        // 1. 根据门店ID查询门店信息
+        StoreInfo storeInfo = storeInfoMapper.selectById(storeId);
+        if (storeInfo == null) {
+            log.warn("门店不存在,storeId={}", storeId);
+            StoreThreeLevelStructureVo vo = new StoreThreeLevelStructureVo();
+            vo.setStoreId(storeId);
+            vo.setStoreName(null);
+            vo.setThreeLevelStructure(new ArrayList<>());
+            return vo;
+        }
 
 
+        // 2. 获取门店表里的三级分类信息
+        Integer businessSection = storeInfo.getBusinessSection(); // 一级:经营板块ID
+        String businessTypes = storeInfo.getBusinessTypes(); // 二级:经营种类IDs(逗号分隔,fine_food类型)
+        String businessClassify = storeInfo.getBusinessClassify(); // 三级:分类IDs(逗号分隔)
 
 
+        // 3. 查询一级分类(business_section - 经营板块)
+        // business_section存储的是dictId(字符串),需要转换为String
+        List<StoreDictionary> allDicts = new ArrayList<>();
+        StoreDictionary firstLevelDict = null;
+        if (businessSection != null) {
+            firstLevelDict = storeDictionaryMapper.selectOne(
+                    new LambdaQueryWrapper<StoreDictionary>()
+                            .eq(StoreDictionary::getDictId, String.valueOf(businessSection))
+                            .eq(StoreDictionary::getTypeName, "business_section")
+                            .eq(StoreDictionary::getDeleteFlag, 0)
+            );
+            if (firstLevelDict != null) {
+                allDicts.add(firstLevelDict);
+                log.debug("查询到一级分类: id={}, dictId={}, dictDetail={}",
+                        firstLevelDict.getId(), firstLevelDict.getDictId(), firstLevelDict.getDictDetail());
+            } else {
+                log.warn("未查询到一级分类,businessSection={}", businessSection);
+            }
+        }
 
 
-        return result;
-    }
+        // 4. 查询二级分类(business_type - 根据门店表里的business_types字段,存储的是dictId)
+        List<StoreDictionary> secondLevelDicts = new ArrayList<>();
+        if (StringUtils.isNotEmpty(businessTypes) && firstLevelDict != null) {
+            // 解析二级分类dictId列表(business_types存储的是dictId字符串)
+            String[] typeDictIds = businessTypes.split(",");
+            List<String> typeDictIdList = new ArrayList<>();
+            for (String typeDictId : typeDictIds) {
+                if (StringUtils.isNotEmpty(typeDictId.trim())) {
+                    typeDictIdList.add(typeDictId.trim());
+                }
+            }
 
 
+            // 查询二级分类,需要满足:
+            // 1. dict_id 在门店配置的经营种类dictId列表中
+            // 2. type_name = "business_type"
+            // 3. parent_id = 一级分类的id(不是dictId)
+            if (!typeDictIdList.isEmpty() && firstLevelDict != null) {
+                LambdaQueryWrapper<StoreDictionary> secondLevelWrapper = new LambdaQueryWrapper<>();
+                secondLevelWrapper.in(StoreDictionary::getDictId, typeDictIdList);
+                secondLevelWrapper.eq(StoreDictionary::getTypeName, "business_type");
+                secondLevelWrapper.eq(StoreDictionary::getParentId, firstLevelDict.getId());
+                secondLevelWrapper.eq(StoreDictionary::getDeleteFlag, 0);
+//                secondLevelWrapper.orderByAsc(StoreDictionary::getSortId);
+                secondLevelDicts = storeDictionaryMapper.selectList(secondLevelWrapper);
+                allDicts.addAll(secondLevelDicts);
+                log.debug("查询到二级分类数量: {}, dictIds={}", secondLevelDicts.size(), typeDictIdList);
+            } else {
+                log.warn("无法查询二级分类: typeDictIdList为空或一级分类不存在, typeDictIdList={}, firstLevelDict={}",
+                        typeDictIdList, firstLevelDict != null ? firstLevelDict.getId() : null);
+            }
+        }
+
+        // 5. 查询三级分类(business_classify - 根据门店表里的business_classify字段,存储的是dictId)
+        if (!secondLevelDicts.isEmpty() && StringUtils.isNotEmpty(businessClassify)) {
+            // 解析三级分类dictId列表(business_classify存储的是dictId字符串)
+            String[] classifyDictIds = businessClassify.split(",");
+            List<String> classifyDictIdList = new ArrayList<>();
+            for (String classifyDictId : classifyDictIds) {
+                if (StringUtils.isNotEmpty(classifyDictId.trim())) {
+                    classifyDictIdList.add(classifyDictId.trim());
+                }
+            }
+
+            // 查询三级分类,需要满足:
+            // 1. dict_id 在门店配置的分类dictId列表中
+            // 2. parent_id 在二级分类的id列表中(不是dictId)
+            // 3. type_name = "business_classify"
+            if (!classifyDictIdList.isEmpty() && !secondLevelDicts.isEmpty()) {
+                Set<Integer> secondLevelIds = secondLevelDicts.stream()
+                        .map(StoreDictionary::getId)
+                        .collect(Collectors.toSet());
 
 
+                List<StoreDictionary> thirdLevelDicts = storeDictionaryMapper.selectList(
+                        new LambdaQueryWrapper<StoreDictionary>()
+                                .in(StoreDictionary::getDictId, classifyDictIdList)
+                                .in(StoreDictionary::getParentId, secondLevelIds)
+                                .eq(StoreDictionary::getTypeName, "business_classify")
+                                .eq(StoreDictionary::getDeleteFlag, 0)
+//                                .orderByAsc(StoreDictionary::getSortId)
+                );
+                allDicts.addAll(thirdLevelDicts);
+                log.debug("查询到三级分类数量: {}, dictIds={}, parentIds={}",
+                        thirdLevelDicts.size(), classifyDictIdList, secondLevelIds);
+            } else {
+                log.warn("无法查询三级分类: classifyDictIdList为空或二级分类为空, classifyDictIdList={}, secondLevelDicts.size={}",
+                        classifyDictIdList, secondLevelDicts.size());
+            }
+        }
+
+        // 6. 构建树形结构(根据parent_id关系组装)
+        List<StoreDictionary> treeStructure = buildTreeOptimized(allDicts);
+
+        // 7. 构建返回对象
+        StoreThreeLevelStructureVo vo = new StoreThreeLevelStructureVo();
+        vo.setStoreId(storeInfo.getId());
+        vo.setStoreName(storeInfo.getStoreName());
+        vo.setThreeLevelStructure(treeStructure);
+
+        return vo;
     }
     }
 
 
+}
+