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 03aa41d..c7a25a0 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 @@ -1,6 +1,5 @@ package com.luoo.music.controller; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -13,6 +12,7 @@ import java.util.stream.Collectors; import com.luoo.music.dao.CommentDao; import com.luoo.music.dto.mapper.CommentMapper; import com.luoo.music.dto.mapper.JournalMapper; +import com.luoo.music.dto.request.CollectQueryReq; import com.luoo.music.dto.request.JournalQueryReq; import com.luoo.music.dto.response.CommentDTO; import com.luoo.music.dto.response.JournalFilterDTO; @@ -21,10 +21,8 @@ import com.luoo.music.dto.response.TagDTO; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.util.StopWatch; import org.springframework.web.bind.annotation.*; import com.luoo.music.pojo.Journal; import com.luoo.music.pojo.Tag; @@ -125,19 +123,13 @@ public class JournalController { return set; } - @ApiOperation(value = "2.查询收藏期刊信息") - @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", required = true), - @ApiImplicitParam(name = "pageNum", value = "分页: 页码,以1开始", required = true), - @ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) }) - @GetMapping("/collect/{userId}/{pageNum}/{pageSize}") + @ApiOperation(value = "2.查询收藏期刊信息", notes = "pageNum/pageSize不传或者小于1,则返回所有收藏刊") + @GetMapping("/collect") @GlobalInterceptor(checkAppUserLogin = true) - public Result> collectPage( + public Result> collectJournals( @RequestHeader(value = "Authorization", required = true) String authorization, - @PathVariable @VerifyParam(required = true) String userId, - @PathVariable @VerifyParam(required = true) Integer pageNum, - @PathVariable @VerifyParam(required = true) Integer pageSize) { - Pageable pageable = PageRequest.of(pageNum-1,pageSize); - List objectIds=userCollectInfoService.findByUserIdAndCollectType(userId, CollectTypeEnum.JOURNAL, pageable); + @VerifyParam CollectQueryReq queryReq) { + List objectIds= getObjectIds(queryReq); if (objectIds.isEmpty()) { return Result.success(new PageResult(0L, Collections.emptyList())); } @@ -147,7 +139,15 @@ public class JournalController { .collect(Collectors.toList()); return Result.success(new PageResult(Long.valueOf(list.size()), list)); } - + + private List getObjectIds(CollectQueryReq queryReq) { + if(null==queryReq.getPageNum()||queryReq.getPageNum()<1||null==queryReq.getPageSize()||queryReq.getPageSize()<1) { + return userCollectInfoService.findByUserIdAndCollectType(queryReq.getUserId(), CollectTypeEnum.JOURNAL); + } + PageRequest pageRequest = PageRequest.of(queryReq.getPageNum()-1, queryReq.getPageSize()); + return userCollectInfoService.findByUserIdAndCollectType(queryReq.getUserId(), CollectTypeEnum.JOURNAL, pageRequest); + } + @ApiOperation(value = "3.根据期刊id查询期刊信息") @GetMapping("/{id}") @GlobalInterceptor 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 0334833..1627ea6 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 @@ -78,9 +78,6 @@ public class SongController { } @ApiOperation(value = "2.查询收藏歌曲信息", notes = "pageNum/pageSize不传或者小于1,则返回所有收藏歌曲") - @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", required = true), - @ApiImplicitParam(name = "pageNum", value = "分页: 页码", required = false), - @ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = false) }) @GetMapping("/collect") @GlobalInterceptor(checkAppUserLogin = true) public Result> collectSongs( diff --git a/luoo_music/src/main/java/com/luoo/music/dto/mapper/JournalMapper.java b/luoo_music/src/main/java/com/luoo/music/dto/mapper/JournalMapper.java index 2dbc9fe..bffc1b3 100644 --- a/luoo_music/src/main/java/com/luoo/music/dto/mapper/JournalMapper.java +++ b/luoo_music/src/main/java/com/luoo/music/dto/mapper/JournalMapper.java @@ -61,7 +61,7 @@ public class JournalMapper { journalRespDTO.setJournalNo(journal.getJournalNo()); journalRespDTO.setTitle(journal.getTitle()); journalRespDTO.setImage(Constants.MUSIC_RESOURCE_PREFIX + journal.getImage()); - journalRespDTO.setDate(getEditDate(journal)); + journalRespDTO.setDate(getPublishDate(journal)); journalRespDTO.setHaveCollect(journalCollectSet.contains(journalRespDTO.getId())); journalRespDTO.setIpLocation("广东"); @@ -104,8 +104,8 @@ public class JournalMapper { return journalTagMap.getOrDefault(journalNo, Collections.emptyList()); } - private static String getEditDate(Journal journal) { - LocalDateTime date = null == journal.getUpdateTime() ? journal.getCreateTime() : journal.getUpdateTime(); + private static String getPublishDate(Journal journal) { + LocalDateTime date = null == journal.getPubTime() ? journal.getCreateTime() : journal.getPubTime(); return DateUtil.format(date, DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern()); } } diff --git a/luoo_music/src/main/java/com/luoo/music/dto/request/CollectQueryReq.java b/luoo_music/src/main/java/com/luoo/music/dto/request/CollectQueryReq.java index 2f8ceb4..f8e3cc8 100644 --- a/luoo_music/src/main/java/com/luoo/music/dto/request/CollectQueryReq.java +++ b/luoo_music/src/main/java/com/luoo/music/dto/request/CollectQueryReq.java @@ -14,13 +14,13 @@ import annotation.VerifyParam; @ApiModel public class CollectQueryReq implements Serializable { private static final long serialVersionUID = 1L; - @VerifyParam(required = true) - @ApiModelProperty(value = "用户id") + @VerifyParam(required = true) + @ApiModelProperty(value = "用户id", required = true) private String userId; - @VerifyParam(required = false) + @VerifyParam(required = false) @ApiModelProperty(value = "分页: 页码", example = "1") private Integer pageNum; - @VerifyParam(required = false) + @VerifyParam(required = false) @ApiModelProperty(value = "分页: 每页数量", example = "10") private Integer pageSize; }