-- 查询出该组织下所有组织id的集合
--方法一:
public String getAllOrgidsTwo(Integer orgid){
List<Integer> orgids=new ArrayList<Integer>();
orgids.add(orgid);
List<Integer> result=new ArrayList<Integer>();
String result1=getAllOrgidTwo(orgids, result).toString();
result1=result1.replace("[", "");
result1=result1.replace("]", "");
String result2=getAllOrgids(orgid);
return result2;
}
/**
* 查询出该组织及以下组织的所有组织ID方法二
* @param orgid
* @param list
* @return
*/
public List<Integer> getAllOrgidTwo(List<Integer> orgid,List<Integer> list){
list.addAll(orgid);
List<Integer> intList=new ArrayList<Integer>();
for(Integer i : orgid){
List<Org> orglist = orgService.selectInfo(" FROM Org Where parentId="+i);
for(Org o : orglist){
intList.add(o.getOrgid());
}
}
if(intList.size()>0){
return getAllOrgidTwo(intList,list);
}
return list;
}
--方法二:
/**
* 传组织ID查询出该组织及以下组织的所有组织ID 2017-11-23 HJJ
*/
public String getAllOrgids(Integer orgid){
String allOrgId=getAllOrgid(orgid,"");
if("".equals(allOrgId)){
return orgid.toString();
}else{
allOrgId+=","+orgid;
return allOrgId;
}
}
/**
* 传组织ID和接收String,查询出该组织以下组织(不包括本组织)的所有组织ID 2017-11-23 HJJ
*/
public String getAllOrgid(Integer orgid,String str){
List<Org> orglist = orgService.selectInfo("FROM Org ");
if(orglist!=null&&orglist.size()>0){
int index = 0;
for(Org o : orglist){
String parentId1=o.getParentId().toString();
String orgidNow1=orgid.toString();
if(parentId1.equals(orgidNow1)){
if(index > 0){
str += ",";
index = 0;
}
str+=o.getOrgid();
boolean bool = false;
for(int j=0; j< orglist.size(); j++){
String parentId2=orglist.get(j).getParentId().toString();
String orgidNow2=o.getOrgid().toString();
if(parentId2.equals(orgidNow2)){
bool = true;
break;
}
}
if(bool){
// 调用自身,实现递归
str += ",";
str = getAllOrgid(o.getOrgid(),str);
}
index ++;
}
}
}
return str;
}