/** * 递归算法解析成树形结构 * * @param cid * @return * @author jiqinlin */ public TreeNodeModel recursiveTree(int org_code) { //根据cid获取节点对象(SELECT * FROM tb_tree t WHERE t.cid=?) MiddleOrgEntity middleOrgEntity = new MiddleOrgEntity(); middleOrgEntity.setTableName(TableConstants.EWX_MIDDEL_ORG); middleOrgEntity.setOrg_code(org_code); middleOrgEntity = (MiddleOrgEntity) commonService.selectOneByExample(middleOrgEntity); TreeNodeModel treeNodeModel = new TreeNodeModel(); treeNodeModel.setOrg_code(org_code); treeNodeModel.setOrg_name(middleOrgEntity.getOrg_name()); //TreeNodeModel node = personService.geTreeNodeModel(cid); //查询cid下的所有子节点(SELECT * FROM tb_tree t WHERE t.pid=?) MiddleOrgEntity entity = new MiddleOrgEntity(); entity.setTableName(TableConstants.EWX_MIDDEL_ORG); entity.setParent_org_code(org_code); List<MiddleOrgEntity> middleOrgEntityList = commonService.selectListByExample(entity); //List childTreeNodeModels = personService.queryTreeNodeModel(cid); //遍历子节点 for(MiddleOrgEntity child : middleOrgEntityList) { TreeNodeModel n = recursiveTree(child.getOrg_code()); //递归 treeNodeModel.getNodes().add(n); } return treeNodeModel; }
时间: 2024-12-28 01:53:54