統計成績排名
阿新 • • 發佈:2021-01-13
public static List<AgentCreditTankResponse> fun2(List<AgentCreditTankResponse> stus) { List<Map.Entry<BigDecimal, List<AgentCreditTankResponse>>> list = stus.stream().collect(Collectors.groupingBy(AgentCreditTankResponse::getVal)).entrySet() .stream().sorted((s1, s2) -> -s1.getKey().compareTo(s2.getKey())).collect(Collectors.toList()); int rank = 1;//設定排名 int index = 1;//設定排序號 List<AgentCreditTankResponse> finlist=new ArrayList<AgentCreditTankResponse>(); for (Map.Entry<BigDecimal, List<AgentCreditTankResponse>> entry : list) { for (AgentCreditTankResponse competitionWorkExhibitionPo1 : entry.getValue()) { if(entry.getValue().size()>1){ competitionWorkExhibitionPo1.setRankNumber(rank); }else{ competitionWorkExhibitionPo1.setRankNumber(index); rank++; } index++; finlist.add(competitionWorkExhibitionPo1); } } finlist.stream().forEach(System.out::println); return finlist; }