diff --git a/luoo_music/src/main/java/com/luoo/music/dao/JournalDao.java b/luoo_music/src/main/java/com/luoo/music/dao/JournalDao.java index 304557b..2b3a2a1 100644 --- a/luoo_music/src/main/java/com/luoo/music/dao/JournalDao.java +++ b/luoo_music/src/main/java/com/luoo/music/dao/JournalDao.java @@ -76,5 +76,8 @@ public interface JournalDao extends JpaRepository,JpaSpecificati @Query(value = "select id from tb_journal where id not in ?2 order by rand() limit ?1", nativeQuery = true) List random(int limit, List recommendIds); + + @Query(value = "select id from tb_journal order by rand() limit ?1", nativeQuery = true) + List random(int limit); } diff --git a/luoo_music/src/main/java/com/luoo/music/service/JournalService.java b/luoo_music/src/main/java/com/luoo/music/service/JournalService.java index 3a09066..f1a9fd1 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/JournalService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/JournalService.java @@ -306,7 +306,7 @@ public class JournalService { List recommendIds=journalTagDao.recommendByJournalId(id); List extraIds=Collections.emptyList(); if(recommendIds.size()<6) { - extraIds=journalDao.random(6-recommendIds.size(),recommendIds); + extraIds=recommendIds.isEmpty()?journalDao.random(6):journalDao.random(6-recommendIds.size(),recommendIds); } if(!extraIds.isEmpty()) { recommendIds.addAll(extraIds);