美文网首页
sql数据实现排行榜

sql数据实现排行榜

作者: 荼蘼toome | 来源:发表于2020-01-07 16:33 被阅读0次
    //测试订阅
    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));
    

    虽然俺看不太懂懂..但是我以后一定会看懂地

    相关文章

      网友评论

          本文标题:sql数据实现排行榜

          本文链接:https://www.haomeiwen.com/subject/zatdactx.html