树形数据查找所有根节点并排序分页

这篇博客主要介绍了如何在Service层和DAO层处理树形数据,查找所有的根节点,并实现分页和排序的功能。同时,提到了实体类的设计以及数据库的DDL操作。
摘要由CSDN通过智能技术生成

Service层

@Service
public class DDeptclassifyServiceImpl implements DDeptclassifyService {
   

 	@Autowired
    private DDeptMapper mapper;

    @Autowired
    private DeptMapper deptMapper;

    @Override
    @Cacheable(value = "assistant-cache")
        public PageUtils recursion(DDeptExample example) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
   
        DDeptExample.Criteria dec = example.createCriteria();
        if(example.getDeptIdList() != null){
   
            dec.andDeptIdIn(example.getDeptIdList());
        }
        if(example.getDeptId() != null){
   
            dec.andDeptIdEqualTo(example.getDeptId());
        }
        if(example.getDeptIds() != null){
   
            dec.andDeptIdsLike(example.getDeptIds() + "%");
        }
        if(example.getDeptName() != null){
   
            dec.andDeptNameLike("%|" + example.getDeptName() + "|%");
        }
        if(example.getOrderNum() != null){
   
            dec.andOrderNumEqualTo(example.getOrderNum());
        }
        dec.andDelFlagEqualTo(0);

        List<DDeptTree> dDeptTreeList = mapper.selectTreeByExample(example);
        List<Integer> total = new ArrayList<>();

        int t = 0;
        for (DDeptTree dDeptTree : dDeptTreeList) {
   
            System.out.println(t++ + "---" +  dDeptTree.getDeptId() + "----" + dDeptTree.getDeptIds());
        }
        System.out.println("**********");

        int maxDeptId = mapper.findMaxDeptId();
        Object data = listForTree(dDeptTreeList,maxDeptId,total,example.getLimit(),example.getOffset() == null ? null : example.getOffset().intValue());
        List<DDeptTree> treeList = (List<DDeptTree>)data;
        PageUtils pageUtils = new PageUtils(treeList,total.size() == 0 ? 0 : (long)total.get(0));

        List<DDeptTree> dDeptTreeListNew = new ArrayList<>();
        boolean hasFatherNode;
        for (int i = dDeptTreeList.size() - 1; i >= 0 ; i--) {
   
            hasFatherNode = false;
            for(int j = dDeptTreeList.size() - 1; j >= 0; j--){
   
                if(dDeptTreeList.get(j).getDeptId().equals(dDeptTreeList.get(i).getParentId())){
   
                    if(dDeptTreeList.get(j).
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值