错误代码记录

/**
 * 分页查询评论数据
 * @param current
 * @param limit
 * @param postId
 * @param type 0 只看楼主
 *            1 正序 楼主创建时间早的在前面
 * @return
 */
@Override
public Page<PostRemark> getRemarkPage(Long current, Long limit, String postId, Integer type) {

    Page<PostRemark> page=new Page<>(current,limit);

    if(type==1){
        //全部帖子集合
        LambdaQueryWrapper<PostRemark> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(PostRemark::getPostId,postId);
        queryWrapper.orderByDesc(PostRemark::getGmtCreate);
        List<PostRemark> currentPostlists = this.list(queryWrapper);
        //封装子集
        int a = 0;
        int b = 0;
        for (PostRemark one:currentPostlists){
            //存值的变量
            String currentID=one.getId();
            a++;
            System.out.println("当前下标"+a+"->当前id"+currentID);
            while(!this.getById(currentID).getParentId().equals("0")){
                //找父类
                PostRemark currentRemark = this.getById(currentID);
                PostRemark currentParentRemark = this.getById(currentRemark.getParentId());
                if(currentParentRemark!=null){
                    //父类添加孩子
                    if(currentParentRemark.getChildren()==null){
                        List<PostRemark> children =  new ArrayList<>();
                        currentParentRemark.setChildren(children);
                    }
                    List<PostRemark> children = currentParentRemark.getChildren();
                    children.add(currentRemark);
                    currentParentRemark.setChildren(children);

                    //当前父亲再变成孩子
                    currentID=currentParentRemark.getId();
                    b++;
                    System.out.println("子级下标:"+b);
                }else {
                    break;
                }
            }

        }
        //返回数据返回一级评论集合
        List<PostRemark> firstRemarkLists=new ArrayList<>();
        for(PostRemark first:currentPostlists){
            if(first.getParentId().equals("0")){
                firstRemarkLists.add(first);
            }
        }
        return page.setRecords(firstRemarkLists);


    }else if(type==0){

        //全部帖子集合
        LambdaQueryWrapper<PostRemark> queryWrapper=new LambdaQueryWrapper<>();
        Post byId = postService.getById(postId);

        queryWrapper.eq(PostRemark::getPostId,postId);
        queryWrapper.orderByDesc(PostRemark::getGmtCreate);
        //queryWrapper.eq(PostRemark::getCreatorId,byId.getCreatedBy());
        List<PostRemark> currentPostlists = this.list(queryWrapper);
        //封装子集
        for (PostRemark one:currentPostlists){
            //存值的变量
            PostRemark temp;
            temp=one;

            while(temp.getParentId()!="0"){
                //找父类
                PostRemark currentParentRemark = this.getById(temp.getParentId());
                //孩子集合
                List<PostRemark> childs=new ArrayList<>();
                childs.add(temp);
                //父类找孩子
                currentParentRemark.setChildren(childs);

                //当前父亲再变成孩子
                temp=currentParentRemark;
            }

        }
        //返回数据返回一级评论集合
        List<PostRemark> firstRemarkLists=new ArrayList<>();
        for(PostRemark first:currentPostlists){
            if(first.getParentId().equals("0")){
                firstRemarkLists.add(first);
            }
        }
        return page.setRecords(firstRemarkLists);


    }
    throw new NktException(404,"参数检验不合格");

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值