List rptResult = new ArrayList();
List tempResult = new ArrayList();
tempResult = //从数据库取出已order的数据集;
rptResult = sortRPT(tempResult);
@SuppressWarnings("rawtypes")
private List sortRPT(List tempResult) {
List rptResult=new ArrayList();
Map<String,List> temps=new HashMap<String,List>();
for (Object object : tempResult) {
Map<String,Object> e = (Map<String,Object>)object;
Double pkey=(Double)e.get("PARENTID");
if(null==temps.get(pkey.intValue()+"")){
temps.put(pkey.intValue()+"",new ArrayList<>());
}
temps.get(pkey.intValue()+"").add(e);
}
String[] strs ={"10000", "20000", "30000", "40000", "50000", "60000", "70000"};//一级
for (String string : strs) {
rptResult = addChirdren(rptResult,string,temps);
}
return rptResult;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private List addChirdren(List rptResult, String string, Map<String, List> temps) {
List strList = temps.get(string);
if(null!=strList){
for (Object object : strList) {
Map<String,Object> e = (Map<String,Object>)object;
rptResult.add(e);
BigInteger key=(BigInteger)e.get("ID");
if(null!=temps.get(key.intValue()+"")){
rptResult = addChirdren(rptResult,key.intValue()+"",temps);
}
}
}
return rptResult;
}