zoukankan      html  css  js  c++  java
  • ztree自动生成树状图

    public String getOrgTree(Map<String, String> paramTree) {
            String orgId = paramTree.get("orgId");
            String checkedData = paramTree.get("checkedData");
            String orgRoot = paramTree.get("orgRoot");
            List<SysOrg> list=new ArrayList<SysOrg>();
            
            SysOrgExample example=new SysOrgExample();
            SysOrgExample.Criteria criteria=example.createCriteria();
            example.setOrderByClause("ORG_ORDER");
            
            SysOrg org = sysOrgMapper.selectByPrimaryKey(BpsConst.DYBANK_ORG_ID);
            String rootName = "";
            if(org !=null){
                rootName = org.getOrgShrtNm();
            }
            
            if ("orgRoot".equals(orgRoot)) {
                list = getAllOrgByparentId(orgId);
                return JSONUtil.getTreeOrg(list, orgRoot, 0, checkedData, paramTree.get("orgName"),orgId).toString();
            }else {
                list=sysOrgMapper.selectWholeByExample(example);
                return JSONUtil.getTree(list,"orgRoot",0,checkedData,rootName).toString();
            }
        }
        
        public List<SysOrg> getAllOrgByparentId(String parentId){
            List<SysOrg> sysOrgList = new ArrayList<SysOrg>();
            
            SysOrgExample example=new SysOrgExample();
            SysOrgExample.Criteria criteria=example.createCriteria();
            example.setOrderByClause("ORG_ORDER");
            criteria.andFOrgIdEqualTo(parentId);
            
            List<SysOrg> orgList = sysOrgMapper.selectWholeByOrgId(example);
            for (SysOrg sysOrg:orgList) {
                sysOrgList.add(sysOrg);
                List<SysOrg> orgListL = getAllOrgByparentId(sysOrg.getOrgId());
                if(orgListL==null){
                    continue;
                }
                for (SysOrg sysOrgL :orgListL) {
                    sysOrgList.add(sysOrgL);
                }
            }
            return sysOrgList;
        }
     public static JSONArray getTreeOrg(List<SysOrg> list,String fatherId,int level,String checkedData,String rootName,String orgId){
            JSONArray jsonArray=new JSONArray();
            if(fatherId.equals("orgRoot")){
                JSONObject jsonObject=new JSONObject();
                jsonObject.put("id", orgId);
                jsonObject.put("pId","orgRoot");
                jsonObject.put("name",rootName);//T
                jsonObject.put("open",true);
                jsonObject.put("icon","plugins/zTree/3.5/zTreeStyle/img/diy/1_open.png");
                jsonObject.put("children", getTree(list,orgId,level+1,checkedData,""));
                jsonArray.add(jsonObject);
            }else{
                for(int i=0;i<list.size();i++){
                    if(list.get(i).getfOrgId().equals(fatherId)){
                        JSONObject jsonObject=new JSONObject();
                        List<String> listCheckedData = StringUtil.strToList(checkedData);
                        jsonObject.put("id", list.get(i).getOrgId());
                        jsonObject.put("pId",list.get(i).getfOrgId());
                        jsonObject.put("name",list.get(i).getOrgNm());
                        //jsonObject.put("open",true);
                        if(listCheckedData!=null && listCheckedData.contains(list.get(i).getOrgId())){
                            jsonObject.put("checked",true);
                        }
                        jsonObject.put("attribute", list.get(i));
                        jsonObject.put("children", getTree(list, list.get(i).getOrgId(),level+1,checkedData,""));
                        if(fatherId.equals(SysContant.ORG_ROOT_ID)){
                            jsonObject.put("icon", "static/images/application_side_expand.png");
                            jsonObject.put("open",true);
                        }else{
                            jsonObject.put("icon", "static/images/application.gif");
                        }
                        jsonArray.add(jsonObject);
                    }
                }
            }
            return jsonArray;
        }
     public static JSONArray getTree(List<SysOrg> list,String fatherId,int level,String checkedData,String rootName){
            JSONArray jsonArray=new JSONArray();
            if(fatherId.equals("orgRoot")){
                JSONObject jsonObject=new JSONObject();
                jsonObject.put("id", SysContant.DYBANK_ORG_ID);
                jsonObject.put("pId","orgRoot");
                jsonObject.put("name",rootName);
                jsonObject.put("open",true);
                jsonObject.put("icon","plugins/zTree/3.5/zTreeStyle/img/diy/1_open.png");
                jsonObject.put("children", getTree(list,SysContant.DYBANK_ORG_ID,level+1,checkedData,""));
                jsonArray.add(jsonObject);
            }else{
                for(int i=0;i<list.size();i++){
                    if(list.get(i).getfOrgId().equals(fatherId)){
                        JSONObject jsonObject=new JSONObject();
                        List<String> listCheckedData = StringUtil.strToList(checkedData);
                        jsonObject.put("id", list.get(i).getOrgId());
                        jsonObject.put("pId",list.get(i).getfOrgId());
                        jsonObject.put("name",list.get(i).getOrgNm());
                        //jsonObject.put("open",true);
                        if(listCheckedData!=null && listCheckedData.contains(list.get(i).getOrgId())){
                            jsonObject.put("checked",true);
                        }
                        jsonObject.put("attribute", list.get(i));
                        jsonObject.put("children", getTree(list, list.get(i).getOrgId(),level+1,checkedData,""));
                        if(fatherId.equals(SysContant.ORG_ROOT_ID)){
                            jsonObject.put("icon", "static/images/application_side_expand.png");
                            jsonObject.put("open",true);
                        }else{
                            jsonObject.put("icon", "static/images/application.gif");
                        }
                        jsonArray.add(jsonObject);
                    }
                }
            }
            return jsonArray;
        }
  • 相关阅读:
    Shell脚本sed命令
    Shell脚本常用unix命令
    Shell的case语句
    3.5.2 数值之间的转换
    3.5.1 数学函数与常量
    3.5 运算符
    3.4.2 常量
    3.4.1 变量初始化
    3.4 变量
    Python异常捕捉的一个小问题
  • 原文地址:https://www.cnblogs.com/bingrong/p/7229203.html
Copyright © 2011-2022 走看看