|
@@ -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<>();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|