From c3352ac700475d8834d2a1dffcca81c8073cc548 Mon Sep 17 00:00:00 2001 From: Gary Date: Thu, 8 Feb 2024 16:53:49 +0800 Subject: [PATCH] 1.fix recommend issue --- luoo_music/src/main/java/com/luoo/music/dao/JournalDao.java | 3 +++ .../src/main/java/com/luoo/music/service/JournalService.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) 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);