java遍历无极树的源码

 /**
     * 加载无级功能树 ztree是我们本身封装的树对象、ztree
     * @author jhx
     * @date 2016-11-25
     * @param userID
     * @param tenantID
     * @param systemID
     * @param type "add edit"
     */
@Override
public List<ZTree> getModulesBySystemID(String userID, String tenantID,
String systemID, String type) {
List<ZTree> res = new ArrayList<ZTree>();
List<ZTree> trees = new ArrayList<ZTree>();
if(!StringHelper.isEmpty(type)&&type.equals("add")){
String[] allsystem = null;
if(StringHelper.isEmpty(systemID)){
List<System> systems =  commonDao.getDataList(System.class," 1= 1");
if(systems!=null&&systems.size()>0){
allsystem = new String[systems.size()];
for(int j=0;j<systems.size();j++){
allsystem[j]=systems.get(j).getId();
}
}
}
ZTree ztrroot = new ZTree();
ztrroot.setId("sysmoduleroot");
ztrroot.setIsParent(true);
ztrroot.setText("应用功能");
String[] systemsids = null;
if(StringHelper.isEmpty(systemID)){
systemsids = allsystem;
}else{
systemsids = systemID.split(",");
}
if(systemsids.length>0){
   for(int i= 0;i<systemsids.length;i++){
    ZTree ztr = new ZTree();
    System system =  commonDao.get(System.class,systemsids[i]);
    ztr.setId(system.getId());
    ztr.setIsParent(true);
    ztr.setText(system.getSysName());
    List<ZTree> ztreetem = getModulesTree(ztr);
    ztr.setChildren(ztreetem);
    trees.add(ztr);
   }
   
}
ztrroot.setChildren(trees);
res.add(ztrroot);
}
return res;
}
public List<ZTree> getModulesTree(ZTree ztree){
List<ZTree>  res = new ArrayList<ZTree>();
 SystemModule sys = null;
 List<ZTree> lists = null;
 if(!StringHelper.isEmpty(ztree.getId())){
 List<SystemModule> syslist = commonDao.getDataList(SystemModule.class,
 " SYSTEMID ='"+ztree.getId()+"' and PARENTID IS NULL");
 for(int i=0;i<syslist.size();i++){
 sys = syslist.get(i);
 ZTree Z = new ZTree();
 Z.setId(sys.getId());
     Z.setIsParent(true);
     Z.setText(sys.getSysModuleName());
 lists =getModulesTree(sys,null,Z);
 Z.setChildren(lists);
 res.add(Z);
 }
 }
return res;
}
public List<ZTree> getModulesTree(SystemModule system ,
List<ZTree> list,ZTree z){
if(list==null){
list = new ArrayList<ZTree>();
 }
List<SystemModule> syslist = commonDao.getDataList(SystemModule.class, " PARENTID ='"+system.getId()+"'");
if(syslist !=null && syslist.size()>0){
    for(int i=0;i<syslist.size();i++){
    SystemModule a = syslist.get(i);
    if(a.getIsLeaf().equals("0")){
    z = new ZTree();
z.setId(a.getId());
    z.setIsParent(true);
    z.setText(a.getSysModuleName());
    z.setChildren(getModulesTree(a,null,z));
    list.add(z);
    }else{
    getModulesTree(a,list,z);
    }
    } 
}else{
 ZTree Z = new ZTree();
 Z.setId(system.getId());
     Z.setIsParent(false);
     Z.setText(system.getSysModuleName());
     list.add(Z);
}
return list;
 

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值