为了账号安全,请及时绑定邮箱和手机立即绑定

富文本中代码预览测试(Ueditor)

标签:
Html5
package com.sunwayland.websocket.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sunwayland.websocket.dao.TbPointDao;
import com.sunwayland.websocket.entity.TbPoint;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class PsaceServiceImpl {

    @Autowired
    private ObjectMapper objectMapper;

    @Autowired
    private TbPointDao tbPointDao;

    public String queryAllPoints() throws JsonProcessingException {
        long startTime = System.currentTimeMillis();
        TbPoint rootPoint = new TbPoint();
        rootPoint.setId(0);
        //查询根节点
        List<TbPoint> roots = tbPointDao.queryAllPointByParentId(rootPoint);
        TbPoint rootNodePoint = roots.get(0);

        // 第一级节点的集合
        List<TbPoint> firstLevelNodePointList = tbPointDao.queryAllPointByParentId(rootNodePoint);
        if(firstLevelNodePointList.size() > 0){
            iterator(firstLevelNodePointList);
            rootNodePoint.setTbPointList(firstLevelNodePointList);
        }
        long endTime = System.currentTimeMillis();
        long spendTime = (endTime - startTime)/ 1000;
        String result = "查询所有节点:共耗时=" + spendTime + " S";
        log.info(result);
        List<TbPoint> tbPointList = new ArrayList<>();
        tbPointList.add(rootNodePoint);
        return objectMapper.writeValueAsString(tbPointList);
    }

    public void iterator(List<TbPoint> nodePointList){
        for(int i = 0; i < nodePointList.size(); i++){
            TbPoint rootNodePoint = nodePointList.get(i);
//            byte pointType = 2;
//            rootNodePoint.setPointType(pointType);
            Integer childCount = tbPointDao.findCount(rootNodePoint);
            if(childCount != null){
                List<TbPoint> childNodePointList = tbPointDao.queryAllPointByParentIdAndPointType(rootNodePoint);
                Boolean isHasNode = false;
                //如果子节点数大于 0,且子节点中有类型为Node的节点,则需要对子节点集合进行迭代,否则停止
                if(childNodePointList.size() > 0){
                    for(int j = 0; j < childNodePointList.size(); j++){
                        TbPoint childPoint = childNodePointList.get(j);
                        if(childPoint.getPointType() == 0){
                            isHasNode = true;
                            break;
                        }
                    }
                }
                if(isHasNode){
                    iterator(childNodePointList);
                }
                nodePointList.get(i).setTbPointList(childNodePointList);
            }
        }
    }
}


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
JAVA开发工程师
手记
粉丝
0
获赞与收藏
0

关注作者,订阅最新文章

阅读免费教程

  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消