|  | @@ -0,0 +1,53 @@
 | 
	
		
			
				|  |  | +package com.sysu.admin.controller.lz.ns;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import com.sysu.admin.controller.lz.ns.bean.NsActionTree;
 | 
	
		
			
				|  |  | +import com.sysu.admin.support.base.BaseService;
 | 
	
		
			
				|  |  | +import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
 | 
	
		
			
				|  |  | +import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | +import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import java.util.List;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +@Service
 | 
	
		
			
				|  |  | +public class NsActionTreeService extends BaseService<NsActionTree, Integer> {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    NsActionTreeRepository repository;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public List<NsActionTree> findAllByTypeIdAndParentId(Integer typeId, Integer parentId){
 | 
	
		
			
				|  |  | +        return repository.findAllByTypeIdAndParentId(typeId, parentId);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 查找整棵树
 | 
	
		
			
				|  |  | +     * @return
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public List<NsActionTree> findTree(){
 | 
	
		
			
				|  |  | +        List<NsActionTree> roots = repository.findAllByParentId(-1);
 | 
	
		
			
				|  |  | +        roots.stream().forEach(root -> {
 | 
	
		
			
				|  |  | +            if(root.getLeaf() == 0){
 | 
	
		
			
				|  |  | +                recursive(root);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +        return roots;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 递归获取子节点数据
 | 
	
		
			
				|  |  | +     * @param nsActionTree
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private void recursive(NsActionTree nsActionTree){
 | 
	
		
			
				|  |  | +        List<NsActionTree> childList = repository.findAllByParentId(nsActionTree.getId());
 | 
	
		
			
				|  |  | +        nsActionTree.setChildList(childList);
 | 
	
		
			
				|  |  | +        childList.stream().forEach(child -> {
 | 
	
		
			
				|  |  | +            if(child.getLeaf() == 0){
 | 
	
		
			
				|  |  | +                recursive(child);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public JpaPlusRepository<NsActionTree, Integer> r() {
 | 
	
		
			
				|  |  | +        return repository;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |