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 c7a25a0..8ee27f4 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 @@ -33,6 +33,7 @@ import annotation.GlobalInterceptor; import annotation.VerifyParam; import api.PageResult; import api.Result; +import api.StatusCode; import constants.Constants; import dto.UserLoginDto; import enums.CollectTypeEnum; @@ -154,11 +155,12 @@ public class JournalController { public Result findById( @RequestHeader(value = "Authorization", required = false) String authorization, @PathVariable @VerifyParam(required = true) String id) { - UserLoginDto user = jwtUtil.getUserLoginDto(authorization); - if (null == user && !journalService.isLatest10ByJournalId(id)) { - return Result.unauthorized(null); - } Journal journal = journalService.findById(id); + if(null==journal) { + return Result.failed(StatusCode.MUSIC_COMMON_FAILED,"根据id无法找到期刊, id: "+id); + } + UserLoginDto user = jwtUtil.getUserLoginDto(authorization); + JournalRespDTO journalRespDTO=JournalMapper.getJournalRespDTO(journal, Collections.emptySet(),mongoTemplate,redisTemplate,commentDao); boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.JOURNAL); journalRespDTO.setHaveCollect(isCollect); 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 4283092..fbcb3a1 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 @@ -98,8 +98,11 @@ public class JournalService { Journal journal = (Journal) redisTemplate.opsForValue().get("journal_"+id); if (journal==null) { - journal =journalDao.findById(id).get(); - redisTemplate.opsForValue().set("journal_"+id,journal); + Optional optional=journalDao.findById(id); + if(optional.isPresent()) { + journal =optional.get(); + redisTemplate.opsForValue().set("journal_"+id,journal); + } } return journal;