4
0
Эх сурвалжийг харах

作者:张哲
时间:2023/02/20
类型:优化
描述:里程碑(2)条件查询分类信息

ZizgZh 2 жил өмнө
parent
commit
55b7c26128

+ 16 - 0
src/main/java/com/redxun/knowledge/album/mapper/AlbumCategoryMapper.java

@@ -34,6 +34,22 @@ public interface AlbumCategoryMapper extends BaseDao<AlbumCategory> {
     IPage findAllAlbumCategory(IPage<AlbumCategory> page, @Param("params") Map<String, Object> params, @Param("order")
             Map<String, Object> order);
 
+    /**
+     * 查询一级分类信息
+     * @param params
+     * @param order
+     * @return
+     */
+    List<AlbumCategoryVo> findAllAlbumCategory1(@Param("params") Map<String, Object> params, @Param("order") Map<String, Object> order);
+
+    /**
+     * 查询二级分类信息
+     * @param params
+     * @param order
+     * @return
+     */
+    List<AlbumCategoryVo> findAllAlbumCategory2(@Param("params") Map<String, Object> params, @Param("order") Map<String, Object> order);
+
     /**
      * 查询对应级别的专辑分类列表
      * @param level

+ 54 - 31
src/main/java/com/redxun/knowledge/album/service/AlbumCategoryServiceImpl.java

@@ -1,5 +1,7 @@
 package com.redxun.knowledge.album.service;
 
+import cn.hutool.core.util.PageUtil;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -18,6 +20,7 @@ import com.redxun.knowledge.album.entity.vo.AlbumCategoryVo;
 import com.redxun.knowledge.album.mapper.AlbumCategoryMapper;
 import com.redxun.knowledge.album.mapper.AlbumInfoMapper;
 import com.redxun.knowledge.common.UserService;
+import com.redxun.knowledge.utils.PageListUtils;
 import org.apache.xalan.xsltc.compiler.util.NamedMethodGenerator;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -81,43 +84,63 @@ public class AlbumCategoryServiceImpl extends SuperServiceImpl<AlbumCategoryMapp
         Map<String, Object> params = PageHelper.constructParams(queryFilter);
         IPage page = albumCategoryMapper.findAllAlbumCategory(queryFilter.getPage(), queryFilter.getParams(), params);
         List<AlbumCategoryVo> records = page.getRecords();
-
-        // TODO: 2023/2/1 根据分类名称查询
         Map<String, Object> param = queryFilter.getParams();
         if (param.containsKey("name")){
-
-            // 孩子节点集合
-            //List<String> childrenList = new ArrayList<>();
-            //records.parallelStream().filter(e -> e.getGrade() == 1L).forEach(record -> {
-            //    List<AlbumCategory> albumCategoryList = albumCategoryMapper.
-            //            selectList(new LambdaQueryWrapper<AlbumCategory>().eq(AlbumCategory::getParent, record.getPkId()).orderByAsc(AlbumCategory::getSort));
-            //    albumCategoryList.forEach(albumCategory -> {
-            //        albumCategory.setOperator(userService.queryUser(record.getUpdateBy()).getFullName());
-            //        childrenList.add(albumCategory.getPkId());
-            //    });
-            //    record.setOperator(userService.queryUser(record.getUpdateBy()).getFullName());
-            //});
-            return null;
+            //一级分类信息
+            List<AlbumCategoryVo> allAlbumCategory1 = albumCategoryMapper.findAllAlbumCategory1(queryFilter.getParams(), params);
+            if (CollectionUtils.isEmpty(allAlbumCategory1)){
+                return null;
+            }
+            List<String> childIdList = findChild(allAlbumCategory1, true);
+            //查询符合条件的二级分类
+            List<AlbumCategoryVo> allAlbumCategory2 = albumCategoryMapper.findAllAlbumCategory2(queryFilter.getParams(), params);
+            if (CollectionUtils.isNotEmpty(allAlbumCategory2)){
+                allAlbumCategory2.forEach(albumCategoryVo2 -> {
+                    if (CollectionUtils.isNotEmpty(childIdList) && !childIdList.contains(albumCategoryVo2.getPkId())){
+                        allAlbumCategory1.add(albumCategoryVo2);
+                    }
+                });
+            }
+            return PageListUtils.getPages(queryFilter.getPage().getCurrent(), queryFilter.getPage().getSize(),allAlbumCategory1);
         } else {
             //查询一级分类下的二级分类
-            records.forEach(e -> {
-                List<AlbumCategory> albumCategoryList = albumCategoryMapper.
-                        selectList(new LambdaQueryWrapper<AlbumCategory>().eq(AlbumCategory::getParent, e.getPkId()).orderByAsc(AlbumCategory::getSort));
-                List<AlbumCategoryVo> childAlbumCategoryVoList = albumCategoryList.parallelStream().map(albumCategory -> {
-                    AlbumCategoryVo albumCategoryVo = new AlbumCategoryVo();
-                    BeanUtils.copyProperties(albumCategory, albumCategoryVo);
-                    albumCategoryVo.setOperator(userService.queryUser(albumCategoryVo.getUpdateBy()).getFullName());
-                    return albumCategoryVo;
-                }).collect(Collectors.toList());
-                if (CollectionUtils.isEmpty(albumCategoryList)){
-                    e.setChildren(null);
-                } else {
-                    e.setChildren(childAlbumCategoryVoList);
-                }
-                e.setOperator(userService.queryUser(e.getUpdateBy()).getFullName());
-            });
+            if (CollectionUtils.isNotEmpty(records)){
+                findChild(records,false);
+            }
             return page;
         }
+
+    }
+
+    /**
+     * 根据一级分类查询二级分类
+     * @param albumCategoryVoList
+     */
+    private List<String> findChild(List<AlbumCategoryVo> albumCategoryVoList,Boolean flag){
+        //孩子节点集合Id
+        List<String> childrenIdList = new ArrayList<>();
+        albumCategoryVoList.forEach(e -> {
+            List<AlbumCategory> albumCategoryList = albumCategoryMapper.
+                    selectList(new LambdaQueryWrapper<AlbumCategory>().eq(AlbumCategory::getParent, e.getPkId()).orderByAsc(AlbumCategory::getSort));
+            List<AlbumCategoryVo> childAlbumCategoryVoList = albumCategoryList.parallelStream().map(albumCategory -> {
+                AlbumCategoryVo albumCategoryVo = new AlbumCategoryVo();
+                BeanUtils.copyProperties(albumCategory, albumCategoryVo);
+                albumCategoryVo.setOperator(userService.queryUser(albumCategoryVo.getUpdateBy()).getFullName());
+                childrenIdList.add(albumCategoryVo.getPkId());
+                return albumCategoryVo;
+            }).collect(Collectors.toList());
+            if (CollectionUtils.isEmpty(albumCategoryList)){
+                e.setChildren(null);
+            } else {
+                e.setChildren(childAlbumCategoryVoList);
+            }
+            e.setOperator(userService.queryUser(e.getUpdateBy()).getFullName());
+        });
+        if (flag){
+            return childrenIdList;
+        } else {
+            return new ArrayList<>();
+        }
     }
 
     /**

+ 27 - 3
src/main/resources/mapper/knowledge/album/AlbumCategoryMapper.xml

@@ -54,11 +54,35 @@
         FROM KM_ALBUM_CATEGORY
         <where>
             <if test="@rx.Ognl@isNotEmpty(params.name)">
-                NAME LIKE '%' || #{params.name} || '%' and IS_DEL = 0 and PK_ID != '0'
+                NAME LIKE '%' || #{params.name} || '%'
             </if>
-            <if test="@rx.Ognl@isEmpty(params.name)">
-                IS_DEL = 0 and PARENT = '0'
+             and IS_DEL = 0 and PARENT = '0'
+        </where>
+        ORDER BY SORT
+    </select>
+
+    <select id="findAllAlbumCategory1" resultType="com.redxun.knowledge.album.entity.vo.AlbumCategoryVo">
+        SELECT
+        <include refid="COLUMNS"/>
+        FROM KM_ALBUM_CATEGORY
+        <where>
+            <if test="@rx.Ognl@isNotEmpty(params.name)">
+                NAME LIKE '%' || #{params.name} || '%'
+            </if>
+            and IS_DEL = 0 and PARENT = '0'
+        </where>
+        ORDER BY SORT
+    </select>
+
+    <select id="findAllAlbumCategory2" resultType="com.redxun.knowledge.album.entity.vo.AlbumCategoryVo">
+        SELECT
+        <include refid="COLUMNS"/>
+        FROM KM_ALBUM_CATEGORY
+        <where>
+            <if test="@rx.Ognl@isNotEmpty(params.name)">
+                NAME LIKE '%' || #{params.name} || '%'
             </if>
+            and IS_DEL = 0 and PARENT != '0'
         </where>
         ORDER BY SORT
     </select>