فهرست منبع

优化字典列表查询

zhangchen 1 هفته پیش
والد
کامیت
e47f432c4c

+ 18 - 6
alien-store/src/main/java/shop/alien/store/service/impl/StoreDictServiceImpl.java

@@ -12,6 +12,7 @@ import shop.alien.entity.store.StoreMenu;
 import shop.alien.entity.store.vo.StoreDictionaryVo;
 import shop.alien.mapper.StoreDictionaryMapper;
 import shop.alien.store.service.StoreDictService;
+import shop.alien.store.util.CommonConstant;
 
 import java.util.*;
 import java.util.stream.Collectors;
@@ -68,21 +69,32 @@ public class StoreDictServiceImpl extends ServiceImpl<StoreDictionaryMapper, Sto
         return this.removeById(id);
     }
 
+    /**
+     * 根据typeName查询字典
+     *
+     * @param typeNameList 字典名称列表
+     * @return Map
+     */
     @Override
     public Map<String, List<StoreDictionary>> getDictList(List<String> typeNameList) {
+
+        // typeNameList为空,则使用默认的typeName列表
         if (CollectionUtils.isEmpty(typeNameList)){
-            // 为空,给与默认值
-            String typeName = "storeArea,businessStatus,week,specialDate,business_section,fine_food";
+            String typeName = CommonConstant.STORE_DICT_TYPENAME;
             typeNameList = Arrays.stream(typeName.split(","))
-                    .map(String::trim)  // 去除每个元素前后的空格
-                    .filter(s -> !s.isEmpty())  // 过滤掉空字符串
+                    .map(String::trim)
+                    .filter(s -> !s.isEmpty())
                     .collect(Collectors.toList());
         }
 
+        // 查询字典列表
         List<StoreDictionary> storeDictionaryList =  storeDictionaryMapper.selectList(
                 new LambdaQueryWrapper<StoreDictionary>().in(StoreDictionary::getTypeName, typeNameList).eq(StoreDictionary::getDeleteFlag,0));
 
+        // 对字典列表构造父子结构
         List<StoreDictionary> storeDictionaries = buildTreeOptimized(storeDictionaryList);
+
+        // 根据typeName进行分组
         return storeDictionaries.stream()
                 .collect(Collectors.groupingBy(StoreDictionary::getTypeName));
     }
@@ -93,7 +105,7 @@ public class StoreDictServiceImpl extends ServiceImpl<StoreDictionaryMapper, Sto
         Map<Integer, List<StoreDictionary>> parentChildMap = new HashMap<>();  // 父ID到子节点列表的映射
         List<StoreDictionary> result = new ArrayList<>();  // 结果列表
 
-        // 第一次遍历:填充nodeMap和parentChildMap
+        // 填充nodeMap和parentChildMap
         for (StoreDictionary entity : flatList) {
             Integer id = entity.getId();
             Integer parentId = entity.getParentId();
@@ -113,7 +125,7 @@ public class StoreDictServiceImpl extends ServiceImpl<StoreDictionaryMapper, Sto
             }
         }
 
-        // 第二次遍历:建立父子关系
+        // 建立父子关系
         for (StoreDictionary entity : flatList) {
             Integer id = entity.getId();
             if (parentChildMap.containsKey(id)) {

+ 1 - 0
alien-store/src/main/java/shop/alien/store/util/CommonConstant.java

@@ -47,4 +47,5 @@ public class CommonConstant {
     public static final Integer STORE_IMG_OTHER = 1;
     public static final Integer STORE_IMG_ALBUM = 2;
 
+    public static final String STORE_DICT_TYPENAME = "storeArea,businessStatus,week,specialDate,business_section,fine_food";
 }