分组的代码java,java代码实现分组

这篇博客介绍了在开发中处理Excel数据导入时,如何通过HashMap对团队进行分组,检查每个团队的扣发与调补是否相等。通过循环团队集合,将数据分组存储,并对比每个团队的总扣发与调补,如果发现不等,则抛出异常。这种方法确保了团队数据的一致性。
摘要由CSDN通过智能技术生成

在开发中遇到导入Excel,但是要根据导入的团队判断该团队下的扣发与调补是否相同,导入的团队有可能为多个,所以需要用到分组,进行排序,然后根据团队去判断,首先想到的是map集合,因此就写了以下代码。

//根据团队判断扣发调补是否相等

HashMap> map=new HashMap>();

//循环团队集合

for (Prpschannelchange prpschannelchange : insurancePayments) {

ListtempList = map.get(prpschannelchange.getTeamcode());

//如果取不到数据,那么直接new一个空的ArrayList

if (tempList == null) {

tempList = new  ArrayList();

tempList.add(prpschannelchange);

map.put(prpschannelchange.getTeamcode(), tempList);

}

else {

//某个团队之前已经存放过了,则直接追加数据到原来的List里

tempList.add(prpschannelchange);

}

}

for(String teamCode: map.keySet()){

//根据Key(团队代码),取出不同的Value(团队集合)

sumTbchannelperformance=BigDecimal.ZERO;

sumKftbbchannelperformance=BigDecimal.ZERO;

for(int i=0;isumTbchannelperformance=sumTbchannelperformance.add(map.get(teamCode).get(i).getTbchannelperformance());

sumKftbbchannelperformance=sumKftbbchannelperformance.add(map.get(teamCode).get(i).getKftbchannelperformance());

}

if(sumKftbbchannelperformance.compareTo(sumTbchannelperformance)!=0){

throw new BusinessException("团队"+teamCode+"调补与扣发不等,无法调补", false);

}

}

谢谢大家观看!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值