Просмотр исходного кода

refactor(app): 优化getAllCategory方法

- 移除不必要的AppSite查询
- 使用appSitePlaceMapper直接获取分类ID
-简化代码结构,提高可读性和性能
SheepHy 2 недель назад
Родитель
Сommit
eb70b31614

+ 8 - 12
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/impl/DetailServiceImpl.java

@@ -376,19 +376,15 @@ public class DetailServiceImpl implements IDetailService {
 
     @Override
     public List<AppCategory> getAllCategory(String id) {
-        AppSite appSite = appSiteMapper.selectById(id);
         List<AppCategory> appCategories = new ArrayList<>();
-        if (appSite!=null &&StringUtils.isNotBlank(appSite.getCategoryId())){
-            List<String> strings = new ArrayList<>();
-            if (appSite.getCategoryId().indexOf(",")>0){
-                strings = Arrays.asList(appSite.getCategoryId().split(","));
-            }else {
-                strings.add(appSite.getCategoryId());
-            }
-            appCategories = appCategoryMapper.selectList(Wrappers.<AppCategory>lambdaQuery()
-                    .eq(AppCategory::getStatus, 0).in(AppCategory::getId,strings)
-                    .eq(AppCategory::getDelFlag, 0));
-        }
+        List<Object> objects = appSitePlaceMapper.selectObjs(Wrappers.<AppSitePlace>lambdaQuery()
+                .select(AppSitePlace::getCategoryId)
+                .eq(AppSitePlace::getSiteId, id)
+                .groupBy(AppSitePlace::getCategoryId));
+        if(null == objects || objects.isEmpty()) return appCategories;
+        appCategories = appCategoryMapper.selectList(Wrappers.<AppCategory>lambdaQuery()
+                .eq(AppCategory::getStatus, 0).in(AppCategory::getId,objects)
+                .eq(AppCategory::getDelFlag, 0));
         return appCategories;
     }