/**
* 计算驻留时长返回的记录
* col to rows
* 2011-11-4
* @param list
* @param mulColF 需要转换的列
* @param groupKeyF 分组的字段
* @param calcValueF需计算结果的字段
* @return 返回最终需要展示的结果集
* List<HashMap<String,Object>>
* Yang,Hualong
*/
public static List<HashMap<String,Object>> calcZzbbZl(List<HashMap<String,Object>> list,String mulColF,String[] groupKeyF,String[] calcValueF){
LinkedHashMap<String,HashMap<String,Object>> tempMap = new LinkedHashMap(100);
LinkedHashSet<String> prefixKeys = new LinkedHashSet<String>();
LinkedHashSet<String> suffixKeys = new LinkedHashSet<String>();
String suffix = "H";
for(int i = 0 ;i < list.size();i++){
HashMap<String,Object> record = list.get(i);
String key = record.get(mulColF).toString();
String others = "";
for(int j = 0 ;j < groupKeyF.length;j++){
others+= record.get(groupKeyF[j]).toString()+suffix;
//System.out.println(others);
}
prefixKeys.add(others);//sid Key
suffixKeys.add(key);//statykey
tempMap.put(others+key, record);//
}
List<HashMap<String,Object>> retrunList = new ArrayList<HashMap<String,Object>>();
// System.out.println("otherKeys:"+otherKeys);//sidKey
// System.out.println("mainKeys:"+mainKeys);//hourKey
// System.out.println("map:"+map);
for(String row:prefixKeys){//sid
Double sumtotal=0d;//获取每个小区下面的合计值
HashMap<String,Object> newRecord = new HashMap<String,Object>(100);
HashMap<String,Object> containValueRecord = new HashMap<String,Object>(100);
for(String col: suffixKeys){//stathours
String key = (row+col);
HashMap<String,Object> temp = tempMap.get(key);
if(temp==null){
continue;
}
for(int i = 0 ;i < groupKeyF.length;i++){//sid
newRecord.put(groupKeyF[i], temp.get(groupKeyF[i]));
}
for(int i = 0 ;i < calcValueF.length;i++){//total
for (int j = 1; j < MAX_STATHOURS; j++) {
if(j==new Integer(col)){//如果当前
//System.out.println(col+suffix+":"+temp.get(calcValueF[i]));
containValueRecord.put(col+suffix,temp.get(calcValueF[i]));
sumtotal+=(Double)temp.get(calcValueF[i]);
}else{
newRecord.put(j+suffix,0);
//System.out.println(j+suffix+":"+0);
}
}
}
}
System.out.println("newRecord2:"+containValueRecord);
System.out.println("size:"+newRecord.size());
newRecord.putAll(containValueRecord);
newRecord.put("stotal", sumtotal);//合计值
retrunList.add(newRecord);
}
return retrunList;
}