欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

在java端开展月报表汇总处理

更新时间: 2014-01-05 03:07:32 责任编辑: Author_N1

 

在java端进行月报表汇总处理

参考代码

public List<SalaryDetail> monthFormListFormat(List<SalaryDetail> oriSalaryList) {
		//未作任何处理的list
		if(oriSalaryList==null||oriSalaryList.size()==0)
			return null;
		
		int len = oriSalaryList.size();
		//目的List
		List<SalaryDetail> desSalaryList = oriSalaryList;
		//第一行的对象
		SalaryDetail firstLineSalary = oriSalaryList.get(0);
		//小计的对象
		SalaryDetail subtotalSalary = new SalaryDetail(); 
		//最后总计的对象
		SalaryDetail sumtotalSalary = new SalaryDetail(); 
		
		//存放小计对象的位置,以及小计对象
		Map<Integer,SalaryDetail> subtotalMap = new HashMap<Integer,SalaryDetail>();
		//插入了几行数据
		int n = 0;
		for(int i = 0;i<len;i++){
			if(firstLineSalary.getUserType().equals(oriSalaryList.get(i).getUserType()))	{
				if(i==len-1){
					subtotalSalary = getSubTotalSum(subtotalSalary, oriSalaryList.get(i),"1");
					subtotalSalary.setUserType("小计");
					subtotalSalary.setRowSpanCount(1);
					subtotalMap.put(i, subtotalSalary);
					sumtotalSalary = getSubTotalSum(sumtotalSalary, subtotalSalary,"1");
					break;
				}
				//如果用户类型相同则进行相加,以便得到小计的值
				subtotalSalary = getSubTotalSum(subtotalSalary, oriSalaryList.get(i),"1");
			}else{
				if(i==len-1){
					//把最后一条记录以上的计算一下,并清空【小计】
					subtotalSalary.setUserType("小计");
					subtotalSalary.setRowSpanCount(1);
					sumtotalSalary = getSubTotalSum(sumtotalSalary, subtotalSalary,"1");
					subtotalMap.put(i-1, subtotalSalary);
					subtotalSalary = new SalaryDetail();
					//最后一条记录的处理
					subtotalSalary = getSubTotalSum(subtotalSalary, oriSalaryList.get(i),"1");
					subtotalSalary.setUserType("小计");
					subtotalSalary.setRowSpanCount(1);
					sumtotalSalary = getSubTotalSum(sumtotalSalary, subtotalSalary,"1");
					subtotalMap.put(i, subtotalSalary);
					break;
				}
				//把每种用户类型的第一行修改,并在List副本里面加上一个小计的对象,
				firstLineSalary = oriSalaryList.get(i);
				subtotalSalary.setUserType("小计");
				subtotalSalary.setRowSpanCount(1);
				subtotalMap.put(i-1, subtotalSalary);
				sumtotalSalary = getSubTotalSum(sumtotalSalary, subtotalSalary,"1");
				subtotalSalary = new SalaryDetail();
				//把新的“第一个值”增加到小计中
				subtotalSalary = getSubTotalSum(subtotalSalary, firstLineSalary,"1");
				
			}
			
		}
		for(int i = oriSalaryList.size()-1;i>=0;i--){
			if(subtotalMap.containsKey(i)){
//				if(i == oriSalaryList.size()-1){
					oriSalaryList.add(i+1,subtotalMap.get(i));
//				}else{
//				oriSalaryList.add(i,subtotalMap.get(i));
//				}
			}
		}
		//插入最后一列
		sumtotalSalary.setUserType("总计");
		sumtotalSalary.setRowSpanCount(1);
		desSalaryList.add(desSalaryList.size(), sumtotalSalary);
		
		
		//新的第一行
		firstLineSalary = oriSalaryList.get(0);
		len = oriSalaryList.size();
		int rowSpan = 0;
		//加上rowspan
		for(int i = 0;i<len;i++){
			if(i<len-1){
				SalaryDetail nextLineSalary = oriSalaryList.get(i+1);
				if("小计".equals(nextLineSalary.getUserType())||"总计".equals(nextLineSalary.getUserType())){
					if(!"小计".equals(firstLineSalary.getUserType())&&!"总计".equals(firstLineSalary.getUserType())){
						firstLineSalary.setRowSpanCount(rowSpan+1);
					}
					continue;
				}
				if(firstLineSalary.getUserType().equals(nextLineSalary.getUserType())){
					rowSpan ++;
					firstLineSalary.setRowSpanCount(rowSpan+1);
				}else{
					rowSpan = 0;
					firstLineSalary = nextLineSalary;
				}
			}
		}
		return oriSalaryList;
	}
	
	/**
	 * 把原对象的值和目的对象的值相加,并返回目的对象
	 * @param desSalary
	 * @param oriSalary
	 * @return
	 */
	private SalaryDetail getSubTotalSum(SalaryDetail desSalary,SalaryDetail oriSalary,String flg){
		//desSalary.setUserType("小计");
		if("1".equals(flg)){
		desSalary.setEleYjdf(oriSalary.getEleYjdf()+(desSalary.getEleYjdf()==null?0:desSalary.getEleYjdf()));
		desSalary.setEleJxzxh(oriSalary.getEleJxzxh()+(desSalary.getEleJxzxh()==null?0:desSalary.getEleJxzxh()));
		desSalary.setEleHgkjxs(oriSalary.getEleHgkjxs()+(desSalary.getEleHgkjxs()==null?0:desSalary.getEleHgkjxs()));
		desSalary.setEleYdkhxs(oriSalary.getEleYdkhxs()+(desSalary.getEleYdkhxs()==null?0:desSalary.getEleYdkhxs()));
		desSalary.setEleGlkpxs(oriSalary.getEleGlkpxs()+(desSalary.getEleGlkpxs()==null?0:desSalary.getEleGlkpxs()));//管理考评
		//desSalary.setEleTcbl(oriSalary.getEleTcbl()+(desSalary.getEleTcbl()==null?0:desSalary.getEleTcbl()));//提成比例,不需要进行计算
		}
		if("2".equals(flg)){
			//设置虚拟的编号
			desSalary.setVid(oriSalary.getVid());
			desSalary.setUserCount(oriSalary.getUserCount()+desSalary.getUserCount());
		}
		desSalary.setEleQmkhzc(oriSalary.getEleQmkhzc()+(desSalary.getEleQmkhzc()==null?0:desSalary.getEleQmkhzc()));//期末客户资产
		desSalary.setEleYjfy(oriSalary.getEleYjfy()+(desSalary.getEleYjfy()==null?0:desSalary.getEleYjfy()));//一级费用
		desSalary.setEleCjl(oriSalary.getEleCjl()+(desSalary.getEleCjl()==null?0:desSalary.getEleCjl()));
		desSalary.setEleSsyj(oriSalary.getEleSsyj()+(desSalary.getEleSsyj()==null?0:desSalary.getEleSsyj()));//实收佣金
		
		desSalary.setEleYysjfj(oriSalary.getEleYysjfj()+(desSalary.getEleYysjfj()==null?0:desSalary.getEleYysjfj()));//营业税及附加
		desSalary.setEleTzzbhjj(oriSalary.getEleTzzbhjj()+(desSalary.getEleTzzbhjj()==null?0:desSalary.getEleTzzbhjj()));//投资者保护基金
		desSalary.setOthField1(oriSalary.getOthField1()+(desSalary.getOthField1()==null?0:desSalary.getOthField1()));//净佣金
		desSalary.setEleYyjjsr(oriSalary.getEleYyjjsr()+(desSalary.getEleYyjjsr()==null?0:desSalary.getEleYyjjsr()));//月佣金净收入
		
		desSalary.setSalYxtc(oriSalary.getSalYxtc()+(desSalary.getSalYxtc()==null?0:desSalary.getSalYxtc()));
		desSalary.setSalJbgzBefore(oriSalary.getSalJbgzBefore()+(desSalary.getSalJbgzBefore()==null?0:desSalary.getSalJbgzBefore())); //调整前基本工资
		desSalary.setSalJbgz(oriSalary.getSalJbgz()+(desSalary.getSalJbgz()==null?0:desSalary.getSalJbgz()));
		desSalary.setSalGljt(oriSalary.getSalGljt()+(desSalary.getSalGljt()==null?0:desSalary.getSalGljt()));
		desSalary.setSalKhjljcj(oriSalary.getSalKhjljcj()+(desSalary.getSalKhjljcj()==null?0:desSalary.getSalKhjljcj()));
		desSalary.setSalJjrjcj(oriSalary.getSalJjrjcj()+(desSalary.getSalJjrjcj()==null?0:desSalary.getSalJjrjcj()));
		desSalary.setSalJxzxhj(oriSalary.getSalJxzxhj()+(desSalary.getSalJxzxhj()==null?0:desSalary.getSalJxzxhj()));
		desSalary.setSalZqfxsczgj(oriSalary.getSalZqfxsczgj()+(desSalary.getSalZqfxsczgj()==null?0:desSalary.getSalZqfxsczgj()));
		desSalary.setSalQtcxwsr(oriSalary.getSalQtcxwsr()+(desSalary.getSalQtcxwsr()==null?0:desSalary.getSalQtcxwsr()));
		desSalary.setSalZyf(oriSalary.getSalZyf()+(desSalary.getSalZyf()==null?0:desSalary.getSalZyf()));
		desSalary.setSalJjx(oriSalary.getSalJjx()+(desSalary.getSalJjx()==null?0:desSalary.getSalJjx()));
		desSalary.setSalYfs(oriSalary.getSalYfs()+(desSalary.getSalYfs()==null?0:desSalary.getSalYfs()));
		
		desSalary.setRzrqYxjl(oriSalary.getRzrqYxjl()+(desSalary.getRzrqYxjl()==null?0:desSalary.getRzrqYxjl()));
		
		desSalary.setSalCpxsjl(oriSalary.getSalCpxsjl()+(desSalary.getSalCpxsjl()==null?0:desSalary.getSalCpxsjl()));
		desSalary.setSalCpxssy(oriSalary.getSalCpxssy()+(desSalary.getSalCpxssy()==null?0:desSalary.getSalCpxssy()));
		desSalary.setSalCpyjbl(oriSalary.getSalCpyjbl()+(desSalary.getSalCpyjbl()==null?0:desSalary.getSalCpyjbl()));
		return desSalary;
	}
 
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 03:07:32
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/18638/
本文WWW.DOC100.NET DOC100.NET版权所有。