有1张表 org 部门
有字段 id name parent children // parent 为该部门的 父部门
//children 为 其它部门的父部门是这个部门现在我要根据 id 查询 出 该部门的父部门name 的父部门 name 递归 到其没有父部门为止
返回的是: 最上一级的父部门name 第2级父部门name 。到该部门name
用一个String 类型 返回 name,name,name 然后 我在把它分割就行了
求教 怎么取 该部门 的 “路径” 谢谢 帮忙啊 大神们!
有字段 id name parent children // parent 为该部门的 父部门
//children 为 其它部门的父部门是这个部门现在我要根据 id 查询 出 该部门的父部门name 的父部门 name 递归 到其没有父部门为止
返回的是: 最上一级的父部门name 第2级父部门name 。到该部门name
用一个String 类型 返回 name,name,name 然后 我在把它分割就行了
求教 怎么取 该部门 的 “路径” 谢谢 帮忙啊 大神们!
public String findPathByorgId(int orgid) throws Exception {
String url = "";
organization = organizationService.findOrganization(orgid);
ouputParent(organization, url);
return url;
} // 递归
public void ouputParent(Organization org, String url) throws Exception {
// 创建一个非持久化对象接收查询出的类型,不会存库
Organization organization = new Organization();
organization.setName(org.getName());
organization.setId(org.getId());
// 将修改完的父节点Name保存到加入到String url
if (url.equals("")) {
url = url + organization.getName();
} else {
url = organization.getName() + "," + url;
} // 查找父亲节点 其父亲不为空
if (org.getParent() != null) {
// 获得父亲
Organization parent = organization.getParent();
// 将父亲节点也放到递归中 递归到没有 。。
ouputParent(parent, url);
} else {
return;
}
}
原来也不是很难 慢慢 摸索 自己弄出来了
public boolean findBooleanByorgidempid(int empid, int orgid)throws Exception {
// 根据orgid 找到所有下属的所有机构
organization=organizationService.findOrganization(orgid);
String idss = "";
idss = children(organization, "");
String[] opary = idss.split("\\,");
// 找到emp属于那些结构 找到该emp的所有机构id
employeeOrganizationList = employeeOrganizationService.findOrganizationempid(empid);
for (int j = 0; j < employeeOrganizationList.size(); j++) {
System.out.println(employeeOrganizationList.get(j).getOrganization().getId());
for (int i = 0; i < opary.length; i++) {
int m=Integer.parseInt(opary[i]);
if(employeeOrganizationList.get(j).getOrganization().getId()==m)
{
return true;
}
}
}
return false;
} // 递归
public String children(Organization org, String idss) throws Exception {
// 查找孩子节点 不为空
if (org.getChildren().size() >0) {
//获得所有 孩子节点
Set<Organization> chilrenList = org.getChildren();
// 循环所有孩子节点
for (Organization child : chilrenList)
{
//将孩子节点的孩子在放到 里面递归
idss = children(child, idss);
}
}else{
if(idss.equals(""))
{
idss+=org.getId();
}
else
{
idss += "," + org.getId();
}
}
return idss;
}
start with
o.id = 1397 //要查询的部门id
connect by prior
o.parentid = o.id
结果是 查询单位的所有上级部门包含查询的这个部门:1397部门,XX部门,XX部门