首页标签树

This commit is contained in:
wuchunlei
2025-02-26 16:36:11 +08:00
parent 91ee685e61
commit b7e07f9a7e
4 changed files with 47 additions and 2 deletions

View File

@@ -3,11 +3,15 @@ package com.peanut.modules.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.CoursePsyche;
import com.peanut.modules.common.to.ParamTo;
import java.util.List;
public interface CoursePsycheService extends IService<CoursePsyche> {
List<CoursePsyche> getCoursePsycheTree();
List<CoursePsyche> getChildCoursePsycheTree(ParamTo param);
List<CoursePsyche> getCoursePsycheList();

View File

@@ -9,6 +9,7 @@ import com.peanut.modules.common.dao.CourseToPsycheDao;
import com.peanut.modules.common.entity.CoursePsyche;
import com.peanut.modules.common.entity.CourseToPsyche;
import com.peanut.modules.common.service.CoursePsycheService;
import com.peanut.modules.common.to.ParamTo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -48,6 +49,31 @@ public class CoursePsycheServiceImpl extends ServiceImpl<CoursePsycheDao, Course
return children;
}
@Override
public List<CoursePsyche> getChildCoursePsycheTree(ParamTo param) {
List<CoursePsyche> psyches = this.list(new QueryWrapper<>());
List<CoursePsyche> psychesTree = psyches.stream().filter((coursePsyche) ->
coursePsyche.getPid() == param.getId()
).map((psyche)->{
psyche.setChildren(getChildPsycheChildrens(psyche,psyches));
return psyche;
}).sorted((sort1,sort2)->{
return (sort1.getSort() == null? 0 : sort1.getSort()) - (sort2.getSort()==null?0:sort2.getSort());
}).collect(Collectors.toList());
return psychesTree;
}
private List<CoursePsyche> getChildPsycheChildrens(CoursePsyche root, List<CoursePsyche> all){
List<CoursePsyche> children = all.stream().filter(coursePsyche -> {
return root.getId().equals(coursePsyche.getPid());
}).map(coursePsyche -> {
coursePsyche.setChildren(getChildPsycheChildrens(coursePsyche, all));
return coursePsyche;
}).sorted((sort1,sort2)->{
return (sort1.getSort()==null?0:sort1.getSort()) - (sort2.getSort()==null?0:sort2.getSort());
}).collect(Collectors.toList());
return children;
}
@Override
public List<CoursePsyche> getCoursePsycheList() {
return this.Psyches(0);