sql数据实现排行榜
2020-01-07 本文已影响0人
荼蘼toome
//测试订阅
List<User> userList = Arrays.asList(new User("汪太勇", "18198318706", "重庆", 91),
new User("肖云云", "18198318707", "云南", 91),
new User("张开窍", "18198318708", "永川", 89),
new User("周忠明", "18198318709", "重庆", 78),
new User("周忠明", "18198318709", "a", 80),
new User("周忠明", "18198318709", "b", 80),
new User("汪太勇", "18198318706", "重庆", 67),
new User("汪太勇1", "18198318706", "重庆", 67),
new User("汪太勇2", "18198318706", "重庆", 100),
new User("汪太勇3", "18198318706", "重庆", 80));
userList.forEach(x-> System.out.println(x));
System.out.println("=======================");
Set<Integer> depts = userList.stream().map(x -> x.getDeptId()).collect(Collectors.toSet());
List<Integer> collect = depts.stream().sorted((x2 ,x1)->x1.compareTo(x2)).collect(Collectors.toList());
HashMap<Integer, Object> map = new HashMap<>();
for(int i=0; i<collect.size();i++){
map.put(collect.get(i) , i+1);
}
userList.forEach(x->x.setId(((Integer)map.get(x.getDeptId()))));
userList.stream().sorted((x1,x2)->x1.getId().compareTo(x2.getId())).forEach(x-> System.out.println(x));
虽然俺看不太懂懂..但是我以后一定会看懂地