col to rows

    /**
     * 计算驻留时长返回的记录
     * 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;
	}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值