继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

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

Mr_XiMu
关注TA
已关注
手记 2
粉丝 0
获赞 0
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);
            }
        }
    }
}


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP