Explorar o código

月排行-按购买张数

licailing %!s(int64=4) %!d(string=hai) anos
pai
achega
7c02cddd7d

+ 1 - 0
src/main/java/com/izouma/nineth/repo/TokenHistoryRepo.java

@@ -20,6 +20,7 @@ public interface TokenHistoryRepo extends JpaRepository<TokenHistory, Long>, Jpa
     @Query("select t from TokenHistory t where t.projectId = ?2 and (t.toUserId = ?1 or t.fromUserId = ?1) order by t.createdAt desc")
     Page<TokenHistory> userHistoryAndProjectId(Long userId, int projectId, Pageable pageable);
 
+    List<TokenHistory> findAllByPriceIsNotNullAndOperationLike(String operation);
 
     @Transactional
     @Modifying

+ 15 - 0
src/main/java/com/izouma/nineth/service/AssetService.java

@@ -413,4 +413,19 @@ public class AssetService {
         });
         return result;
     }
+
+    /**
+     * 排行榜
+     */
+    public void leaderboard(Long userId, int size) {
+        List<TokenHistory> all = tokenHistoryRepo.findAllByPriceIsNotNullAndOperationLike("出售");
+        Map<Long, Long> countMap = all.stream()
+                .collect(Collectors.groupingBy(TokenHistory::getToUserId, Collectors.counting()));
+        Map<Long, Long> result = new HashMap<>();
+        countMap.entrySet()
+                .stream()
+                .sorted(Map.Entry.comparingByValue())
+                .forEachOrdered(b -> result.put(b.getKey(), b.getValue()));
+        if (result.entrySet().size() > size){}
+    }
 }