From a55ec19878c71f49e07def86825936f636a0a88c Mon Sep 17 00:00:00 2001 From: Gary Date: Tue, 5 Mar 2024 01:01:59 +0800 Subject: [PATCH] 1.add getCollectLatestImage interface --- .../music/controller/JournalController.java | 22 +++++++++++++++++++ .../luoo/music/dao/UserCollectInfoDao.java | 2 ++ .../music/service/UserCollectInfoService.java | 5 +++++ 3 files changed, 29 insertions(+) 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 f35b0a0..bf8ce8d 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 @@ -37,6 +37,7 @@ import constants.Constants; import dto.UserLoginDto; import enums.CollectTypeEnum; import util.JwtUtil; +import util.StringTools; /** * 控制器层 @@ -139,6 +140,27 @@ public class JournalController { return songController.getCollectSongs(user.getUserId(), queryReq.getUserId(),objectIds, true); } + @ApiOperation(value = "2.2 获取用户收藏最新一期的期刊封面") + @GetMapping("/collectLatestImage/{userId}") + @GlobalInterceptor(checkAppUserLogin = true) + public Result collectLatestImage( + @RequestHeader(value = "Authorization", required = true) String authorization, + @PathVariable @VerifyParam(required = true) String userId) { + String objectId=getCollectLatest(userId); + if (StringTools.isEmpty(objectId)) { + return Result.success(null); + } + JournalRespDTO journalRespDTO=journalService.queryJournalById(objectId); + if(null==journalRespDTO) { + return Result.success(null); + } + return Result.success(journalRespDTO.getImage()); + } + + private String getCollectLatest(String userId) { + return userCollectInfoService.getCollectLatest(userId, CollectTypeEnum.JOURNAL); + } + private List getJournalObjectIds(CollectQueryReq queryReq) { List jouranlIds=userCollectInfoService.findByUserIdAndCollectType(queryReq.getUserId(), CollectTypeEnum.JOURNAL); return journalService.orderByJournalIdField(jouranlIds); diff --git a/luoo_music/src/main/java/com/luoo/music/dao/UserCollectInfoDao.java b/luoo_music/src/main/java/com/luoo/music/dao/UserCollectInfoDao.java index 7fcbc5c..3bd7ba7 100644 --- a/luoo_music/src/main/java/com/luoo/music/dao/UserCollectInfoDao.java +++ b/luoo_music/src/main/java/com/luoo/music/dao/UserCollectInfoDao.java @@ -15,4 +15,6 @@ public interface UserCollectInfoDao extends MongoRepository findByUserIdAndCollectTypeAndObjectIdIn(String userId, Integer collectType, List objectIds); + + UserCollectInfo findFirstByUserIdAndCollectTypeOrderByCreateTimeDesc(String userId, Integer collectType); } diff --git a/luoo_music/src/main/java/com/luoo/music/service/UserCollectInfoService.java b/luoo_music/src/main/java/com/luoo/music/service/UserCollectInfoService.java index 8602498..8796903 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/UserCollectInfoService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/UserCollectInfoService.java @@ -62,4 +62,9 @@ public class UserCollectInfoService { return userCollectInfoDao.findByUserIdAndCollectTypeAndObjectIdIn(userId, collectTypeEnum.getType(),objectIds).stream().map(UserCollectInfo::getObjectId).collect(Collectors.toList()); } + + public String getCollectLatest(String userId, CollectTypeEnum collectTypeEnum) { + UserCollectInfo userCollectInfo=userCollectInfoDao.findFirstByUserIdAndCollectTypeOrderByCreateTimeDesc(userId, collectTypeEnum.getType()); + return null==userCollectInfo?null:userCollectInfo.getObjectId(); + } }