📄 simpletreeservice.java
字号:
/*
* Created on 2006-9-11 13:06:42
*
* By SinoBest
* Copyright hnisi.com.cn, 2005-2006, All rights reserved.
*/
package cn.com.juneng.system.common.taglib.tree;
import java.util.List;
import cn.com.juneng.system.common.COMMON;
import cn.com.juneng.system.common.exception.SystemBaseException;
import cn.com.juneng.system.common.exception.SystemRuleException;
/**
* @author yehailong
*
*/
public class SimpleTreeService {
/**
* 获取所有的父节点名,以"/"分隔
*
* @param nodeid
* @param treeType
* @return
* @throws Exception
*/
public static String getParentName(String nodeid, String treeType)
throws SystemBaseException {
StringBuffer parentName = new StringBuffer();
try {
ITreeService treeService = TreeUtil.getTreeService(treeType);
getParentName(treeService, nodeid, parentName);
} catch (Exception e) {
throw new SystemRuleException(e);
}
return parentName.toString();
}
private static void getParentName(ITreeService treeService, String nodeid,
StringBuffer name) throws Exception {
ITreeNode node = treeService.findByNodeId(nodeid);
if (node != null
&& (node.getNodeId().equals("0") || !node.getNodeId()
.startsWith("0"))) {
if (name.length() != 0) {
name.insert(0, "/");
}
name.insert(0, node.getNodeName());
if (!"0".equals(node.getParentId())) {
getParentName(treeService, node.getParentId(), name);
}
}
}
/**
* 获取子节点ID(一层),逗号分隔
*
* @param orgId
* @return
* @throws Exception
*/
public static String getSubNodeId(String nodeId, String treeType)
throws Exception {
ITreeService treeService = TreeUtil.getTreeService(treeType);
List list = treeService.findSubNode(nodeId);
if (COMMON.isEmpty(list)) {
return null;
} else {
return COMMON.getPropValueFromList(list, "nodeId", "");
}
}
/**
* 递归出所有子节点ID
*
* @param orgId
* @param subOrgId
* @throws ProcessingException
*/
private static void getAllSubNode(String nodeId, String treeType,
StringBuffer subNodeId) throws Exception {
String temp = getSubNodeId(nodeId, treeType);
if (temp != null) {
String[] nodeIdArr = temp.split(",");
for (int i = 0; i < nodeIdArr.length; i++) {
if (subNodeId == null) {
subNodeId = new StringBuffer("");
}
if (subNodeId.length() != 0) {
subNodeId.append(",");
}
subNodeId.append(nodeIdArr[i]);
getAllSubNode(nodeIdArr[i], treeType, subNodeId);
}
}
}
/**
* 获取某树节点的所有子节点ID,以逗号分隔
* <p>
* 注:返回的子节点不包含自身
*
* @param orgId
* @param treeType
* TreeUtil定义
* @return
* @throws ProcessingException
*/
public static String getAllSubNode(String nodeId, String treeType)
throws Exception {
StringBuffer subNodeId = new StringBuffer("");
getAllSubNode(nodeId, treeType, subNodeId);
return subNodeId.toString();
}
/**
* 获取树某个节点的所有子节点ID,以逗号分隔,并且nodeId以''包围,便于SQL查询
* <p>
* 注:该方法返回的子节点包含自身
*
* @param nodeId
* 节点ID
* @param treeType
* TreeUtil定义
* @return
* @throws ProcessingException
*/
public static String getAllSubNodeSql(String nodeId, String treeType)
throws Exception {
String subNodeId = getAllSubNode(nodeId, treeType);
StringBuffer sb = new StringBuffer("'" + nodeId + "'");
if (subNodeId != null) {
String[] subNodeArr = subNodeId.split(",");
for (int i = 0; i < subNodeArr.length; i++) {
sb.append(",'" + subNodeArr[i] + "'");
}
}
return sb.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -