From 99e9fb3e913eeeae8a99218b533fd47b1285c1ad Mon Sep 17 00:00:00 2001 From: Gary Date: Fri, 1 Mar 2024 02:17:16 +0800 Subject: [PATCH] 1.add find all song by collected jouranls --- .../music/controller/JournalController.java | 21 +++++++++++++++++++ .../luoo/music/controller/SongController.java | 11 +++++++--- .../com/luoo/music/dao/JournalSongDao.java | 3 +++ .../luoo/music/service/JournalService.java | 9 ++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java index 036d8cd..f7cca33 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java @@ -17,6 +17,7 @@ import com.luoo.music.dto.request.JournalQueryReq; import com.luoo.music.dto.response.CommentDTO; import com.luoo.music.dto.response.JournalFilterDTO; import com.luoo.music.dto.response.JournalRespDTO; +import com.luoo.music.dto.response.SongRespDTO; import com.luoo.music.dto.response.TagDTO; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; @@ -28,6 +29,7 @@ import org.springframework.web.bind.annotation.*; import com.luoo.music.pojo.Journal; import com.luoo.music.pojo.Tag; import com.luoo.music.service.JournalService; +import com.luoo.music.service.SongInfoService; import com.luoo.music.service.TagService; import com.luoo.music.service.UserCollectInfoService; import annotation.GlobalInterceptor; @@ -58,6 +60,9 @@ public class JournalController { @Autowired private JournalService journalService; + @Autowired + private SongController songController; + @Autowired private TagService tagService; @@ -143,6 +148,22 @@ public class JournalController { return Result.success(new PageResult(Long.valueOf(list.size()), list)); } + + @ApiOperation(value = "2.1 查询所有收藏期刊的歌曲信息", notes = "pageNum/pageSize不传或者小于1,则返回所有收藏刊的歌曲") + @GetMapping("/collect/song") + @GlobalInterceptor(checkAppUserLogin = true) + public Result> collectJournalSongs( + @RequestHeader(value = "Authorization", required = true) String authorization, + @VerifyParam CollectQueryReq queryReq) { + List objectIds= getJournalObjectIds(queryReq); + UserLoginDto user = jwtUtil.getUserLoginDto(authorization); + return songController.getCollectSongs(user.getUserId(), queryReq.getUserId(),objectIds); + } + + private List getJournalObjectIds(CollectQueryReq queryReq) { + List jouranlIds=userCollectInfoService.findByUserIdAndCollectType(queryReq.getUserId(), CollectTypeEnum.JOURNAL); + return journalService.orderByJournalIdField(jouranlIds); + } private Set getMyCollectSet(String loginUser, String checkUser, List objectIds) { if(loginUser.equals(checkUser)) { return new HashSet<>(objectIds); diff --git a/luoo_music/src/main/java/com/luoo/music/controller/SongController.java b/luoo_music/src/main/java/com/luoo/music/controller/SongController.java index 4e6e967..33bdc19 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/SongController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/SongController.java @@ -90,17 +90,22 @@ public class SongController { @RequestHeader(value = "Authorization", required = true) String authorization, @VerifyParam CollectQueryReq queryReq) { List objectIds= getSongIds(queryReq); + UserLoginDto user = jwtUtil.getUserLoginDto(authorization); + return getCollectSongs(user.getUserId(),queryReq.getUserId(),objectIds); + + } + + public Result> getCollectSongs(String loginUserId, String queryUserId, List objectIds) { if (objectIds.isEmpty()) { return Result.success(new PageResult(0L, Collections.emptyList())); } List songs = songInfoService.orderByField(objectIds); - - UserLoginDto user = jwtUtil.getUserLoginDto(authorization); - Set songCollectSet = getMyCollectSet(user.getUserId(),queryReq.getUserId(),objectIds); + Set songCollectSet = getMyCollectSet(loginUserId,queryUserId,objectIds); List results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet)) .collect(Collectors.toList()); return Result.success(new PageResult(Long.valueOf(results.size()), results)); } + private Set getMyCollectSet(String loginUser, String checkUser, List objectIds) { if(loginUser.equals(checkUser)) { return new HashSet<>(objectIds); diff --git a/luoo_music/src/main/java/com/luoo/music/dao/JournalSongDao.java b/luoo_music/src/main/java/com/luoo/music/dao/JournalSongDao.java index 495104c..8495d1b 100644 --- a/luoo_music/src/main/java/com/luoo/music/dao/JournalSongDao.java +++ b/luoo_music/src/main/java/com/luoo/music/dao/JournalSongDao.java @@ -48,4 +48,7 @@ public interface JournalSongDao extends JpaRepository, JpaSp public List orderByField(List idList); List findByJournalNoOrderBySongNo(String journalNo); + + @Query(value = "select tbjs.song_id from tb_journal_song as tbjs,tb_journal as tbj where tbjs.journal_no=tbj.journal_no and tbj.id in ?1 order by field(tbj.id,?1), tbjs.song_no", nativeQuery = true) + List orderByJournalIdField(List jouranlIds); } 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 3ad8b78..d4189fb 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 @@ -26,6 +26,7 @@ import org.springframework.stereotype.Service; import util.IdWorker; import com.luoo.music.dao.JournalDao; +import com.luoo.music.dao.JournalSongDao; import com.luoo.music.dao.JournalTagDao; import com.luoo.music.dao.TagDao; import com.luoo.music.dto.request.JournalQueryReq; @@ -43,6 +44,9 @@ public class JournalService { @Autowired private JournalDao journalDao; + @Autowired + private JournalSongDao journalSongDao; + @Autowired private IdWorker idWorker; @Autowired @@ -340,4 +344,9 @@ public class JournalService { } return journalDao.orderByField(recommendIds); } + + + public List orderByJournalIdField(List jouranlIds) { + return journalSongDao.orderByJournalIdField(jouranlIds); + } }