在开发中遇到导入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);
}
}
谢谢大家观看!