From 5cd9494eba849bfc573bf3d3a173e5ba4d9bda4a Mon Sep 17 00:00:00 2001 From: Gary Date: Mon, 4 Mar 2024 13:36:11 +0800 Subject: [PATCH] 1.update random song need auth token 2.add found journal by journalNo --- .../src/main/java/constants/Constants.java | 1 + .../luoo/music/config/SaticScheduleTask.java | 4 ++-- .../music/controller/JournalController.java | 23 ++++++++++++++++++- .../luoo/music/controller/SongController.java | 4 ++-- .../luoo/music/service/JournalService.java | 12 ++++++++++ .../src/main/resources/caffeine.properties | 1 + 6 files changed, 40 insertions(+), 5 deletions(-) diff --git a/luoo_common/src/main/java/constants/Constants.java b/luoo_common/src/main/java/constants/Constants.java index 96e89b8..0a66480 100644 --- a/luoo_common/src/main/java/constants/Constants.java +++ b/luoo_common/src/main/java/constants/Constants.java @@ -12,6 +12,7 @@ public class Constants { public static final String J2CACHE_REGION_JOURNAL_QUERY_PAGE = "journal_query_page"; public static final String J2CACHE_REGION_JOURNAL_ID = "journal_id"; + public static final String J2CACHE_REGION_JOURNAL_NO = "journal_no"; public static final String J2CACHE_REGION_JOURNAL_SONG_KEY = "journal_song_key"; public static final String J2CACHE_REGION_JOURNAL_SONG_LIST = "journal_song_list"; diff --git a/luoo_music/src/main/java/com/luoo/music/config/SaticScheduleTask.java b/luoo_music/src/main/java/com/luoo/music/config/SaticScheduleTask.java index 8b892e4..82e45cc 100644 --- a/luoo_music/src/main/java/com/luoo/music/config/SaticScheduleTask.java +++ b/luoo_music/src/main/java/com/luoo/music/config/SaticScheduleTask.java @@ -46,7 +46,7 @@ public class SaticScheduleTask { private TagDao tagDao; // 1.凌晨4点执行更新期刊tag - @Scheduled(cron="0 0 4 * * ?") + @Scheduled(cron="0 0 4 * * *") private void updateJouranlTag() { AtomicLong updateCounter = new AtomicLong(); journalDao.findValidJournals().parallelStream().forEach(j -> updateJouranlTag(j, updateCounter)); @@ -56,7 +56,7 @@ public class SaticScheduleTask { } // 2.凌晨4:20点执行更新分词 - @Scheduled(cron="0 20 4 * * ?") + @Scheduled(cron="0 20 4 * * *") private void updateAutoComplete() { List validJournals = journalDao.findValidJournals(); validJournals.parallelStream().forEach(j -> { 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 4461bb2..5b07243 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 @@ -191,7 +191,28 @@ public class JournalController { return Result.success(journalRespDTO); } - @ApiOperation(value = "3.1 根据期刊id查询评论信息") + @ApiOperation(value = "3.1 根据期刊号查询期刊信息") + @GetMapping("/journalNo/{journalNo}") + @GlobalInterceptor + public Result findByJournalNo( + @RequestHeader(value = "Authorization", required = false) String authorization, + @PathVariable @VerifyParam(required = true) String journalNo) { + JournalRespDTO journalRespDTO=journalService.queryJournalByJournalNo(journalNo); + if(null==journalRespDTO) { + return Result.failed(StatusCode.MUSIC_COMMON_FAILED,"根据期刊号无法找到期刊, 期刊号: "+journalNo); + } + UserLoginDto user = jwtUtil.getUserLoginDto(authorization); + if (null == user && !isLatest10(journalNo)) { + return Result.unauthorized(null); + } + boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),journalRespDTO.getId(), CollectTypeEnum.JOURNAL); + journalRespDTO.setHaveCollect(isCollect); + return Result.success(journalRespDTO); + } + private boolean isLatest10(String journalNo) { + return journalService.isLatest10ByJournalNo(journalNo); + } + @ApiOperation(value = "3.2 根据期刊id查询评论信息") @GetMapping("/comment/{id}") @GlobalInterceptor public Result findCommentById( 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 52d50ed..cf2a9d1 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 @@ -137,9 +137,9 @@ public class SongController { @ApiOperation(value = "3.随机播放歌曲", notes = "雀乐FM") @ApiImplicitParams({ @ApiImplicitParam(name = "limit", value = "随机歌曲数,最少1首,最多30首", required = false) }) @GetMapping("/random/{limit}") - @GlobalInterceptor + @GlobalInterceptor(checkAppUserLogin = true) public Result> random( - @RequestHeader(value = "Authorization", required = false) String authorization, + @RequestHeader(value = "Authorization", required = true) String authorization, @PathVariable @VerifyParam(required = true, regex = VerifyRegexEnum.RANDOM_SONG_LIMIT) Integer limit) { List songs = journalSongService.random(limit); UserLoginDto user = jwtUtil.getUserLoginDto(authorization); 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 0b46d56..d1c1e62 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 @@ -390,4 +390,16 @@ public class JournalService { } return JournalMapper.getJournalRespDTO(journal,mongoTemplate,redisTemplate,commentDao); } + + public JournalRespDTO queryJournalByJournalNo(String journalNo) { + return (JournalRespDTO) this.cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_NO, journalNo, key -> getJournalRespDTOByJournalNo(journalNo), false).getValue(); + } + + private JournalRespDTO getJournalRespDTOByJournalNo(String journalNo) { + Journal journal=journalDao.findValidJournalByJournalNo(journalNo); + if(null==journal) { + return null; + } + return JournalMapper.getJournalRespDTO(journal,mongoTemplate,redisTemplate,commentDao); + } } diff --git a/luoo_music/src/main/resources/caffeine.properties b/luoo_music/src/main/resources/caffeine.properties index 831679f..c583992 100644 --- a/luoo_music/src/main/resources/caffeine.properties +++ b/luoo_music/src/main/resources/caffeine.properties @@ -1,5 +1,6 @@ default: 1000, 2h journal_query_page: 10000, 6h journal_id: 2000, 6h +journal_no: 2000, 6h journal_song_key: 10000, 6h journal_song_list: 2000, 6h \ No newline at end of file