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 004dc6b..29ac4f2 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 @@ -61,7 +61,7 @@ public class JournalController { } Page
pageList = articleService.queryPage(queryReq); Set journalCollectSet = null==user?Collections.emptySet():userCollectService.getCollectSet(user.getUserId(),CollectTypeEnum.JOURNAL); - List list = pageList.stream().map(a -> getArticleRespDTO(a, journalCollectSet)) + List list = pageList.stream().map(a -> getJournalRespDTO(a, journalCollectSet)) .collect(Collectors.toList()); return Result.success(new PageResult(Long.valueOf(list.size()), list)); } @@ -81,12 +81,23 @@ public class JournalController { List objectIds=userCollectService.getCollectList(userId,pageNum,pageSize,CollectTypeEnum.JOURNAL); List
pageList = articleService.orderByField(objectIds); Set journalCollectSet = objectIds.isEmpty()?Collections.emptySet(): new HashSet<>(objectIds); - List list = pageList.stream().map(a -> getArticleRespDTO(a, journalCollectSet)) + List list = pageList.stream().map(a -> getJournalRespDTO(a, journalCollectSet)) .collect(Collectors.toList()); return Result.success(new PageResult(Long.valueOf(list.size()), list)); } - private JournalRespDTO getArticleRespDTO(Article article, Set journalCollectSet) { + @ApiOperation(value = "3.根据期刊id查询期刊信息") + @GetMapping("/{id}") + @GlobalInterceptor + public Result findById(@RequestHeader(value = "token", required = false) String token, + @PathVariable @VerifyParam(required = true) String id) { + UserLoginDto user = jwtUtil.getUserLoginDto(token); + Article journal=articleService.findById(id); + Set journalCollectSet = null==user?Collections.emptySet():userCollectService.getCollectSet(user.getUserId(),CollectTypeEnum.JOURNAL); + return Result.success(getJournalRespDTO(journal, journalCollectSet)); + } + + private JournalRespDTO getJournalRespDTO(Article article, Set journalCollectSet) { JournalRespDTO journalRespDTO = new JournalRespDTO(); journalRespDTO.setId(article.getId()); journalRespDTO.setJournalNo(article.getVolid()); 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 d1455d5..48db66f 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 @@ -1,5 +1,6 @@ package com.luoo.music.controller; +import com.luoo.music.dto.response.JournalRespDTO; import com.luoo.music.dto.response.SongRespDTO; import com.luoo.music.pojo.Article; import com.luoo.music.pojo.Song; @@ -64,8 +65,10 @@ public class SongController { return Result.unauthorized(null); } List songs = songService.findByVolid(journalNo); - Set songCollectSet = null==user?Collections.emptySet():userCollectService.getCollectSet(user.getUserId(),CollectTypeEnum.SONG); - List results = songs.stream().map(s -> getSongRespDTO(s, songCollectSet)).collect(Collectors.toList()); + Set songCollectSet = null == user ? Collections.emptySet() + : userCollectService.getCollectSet(user.getUserId(), CollectTypeEnum.SONG); + List results = songs.stream().map(s -> getSongRespDTO(s, songCollectSet)) + .collect(Collectors.toList()); return Result.success(results); } @@ -74,39 +77,50 @@ public class SongController { } @ApiOperation(value = "2.查询收藏歌曲信息") - @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "用户id", required = true), - @ApiImplicitParam(name = "pageNum", value = "分页: 页码,以1开始", required = true), - @ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) - }) + @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}") @GlobalInterceptor(checkAppUserLogin = true) - public Result> collectPage( - @PathVariable @VerifyParam(required = true)String userId, - @PathVariable @VerifyParam(required = true)Integer pageNum, - @PathVariable @VerifyParam(required = true)Integer pageSize) { - List objectIds=userCollectService.getCollectList(userId,pageNum,pageSize,CollectTypeEnum.SONG); + public Result> collectPage(@PathVariable @VerifyParam(required = true) String userId, + @PathVariable @VerifyParam(required = true) Integer pageNum, + @PathVariable @VerifyParam(required = true) Integer pageSize) { + List objectIds = userCollectService.getCollectList(userId, pageNum, pageSize, CollectTypeEnum.SONG); List songs = songService.orderByField(objectIds); - - Set songCollectSet = objectIds.isEmpty()?Collections.emptySet(): new HashSet<>(objectIds); - List results = songs.stream().map(s -> getSongRespDTO(s, songCollectSet)).collect(Collectors.toList()); + + Set songCollectSet = objectIds.isEmpty() ? Collections.emptySet() : new HashSet<>(objectIds); + List results = songs.stream().map(s -> getSongRespDTO(s, songCollectSet)) + .collect(Collectors.toList()); return Result.success(new PageResult(Long.valueOf(results.size()), results)); } - + @ApiOperation(value = "3.随机播放歌曲", notes = "雀乐FM") @ApiImplicitParams({ @ApiImplicitParam(name = "limit", value = "随机歌曲数,最少1首,最多30首", required = false) }) @GetMapping("/random/{limit}") @GlobalInterceptor - public Result> random( - @RequestHeader(value = "token", required = false) String token, + public Result> random(@RequestHeader(value = "token", required = false) String token, @PathVariable @VerifyParam(required = true, regex = VerifyRegexEnum.RANDOM_SONG_LIMIT) Integer limit) { List songs = songService.random(limit); UserLoginDto user = jwtUtil.getUserLoginDto(token); - Set songCollectSet = null==user?Collections.emptySet():userCollectService.getCollectSet(user.getUserId(),CollectTypeEnum.SONG); - List results = songs.stream().map(s -> getSongRespDTO(s, songCollectSet)).collect(Collectors.toList()); + Set songCollectSet = null == user ? Collections.emptySet() + : userCollectService.getCollectSet(user.getUserId(), CollectTypeEnum.SONG); + List results = songs.stream().map(s -> getSongRespDTO(s, songCollectSet)) + .collect(Collectors.toList()); return Result.success(results); } - + + @ApiOperation(value = "4.根据歌曲id查询歌曲信息") + @GetMapping("/{id}") + @GlobalInterceptor + public Result findById(@RequestHeader(value = "token", required = false) String token, + @PathVariable @VerifyParam(required = true) String id) { + UserLoginDto user = jwtUtil.getUserLoginDto(token); + Song song = songService.findById(id); + Set songCollectSet = null == user ? Collections.emptySet() + : userCollectService.getCollectSet(user.getUserId(), CollectTypeEnum.SONG); + return Result.success(getSongRespDTO(song, songCollectSet)); + } + private SongRespDTO getSongRespDTO(Song song, Set songCollectSet) { SongRespDTO songRespDTO = new SongRespDTO(); songRespDTO.setJournalNo(song.getVolid()); @@ -122,16 +136,15 @@ public class SongController { return songRespDTO; } - /** - * 根据ID查询 - * - * @param id ID - * @return - */ - @GetMapping("/{id}") - public Result findById(@PathVariable String id) { - return Result.success(songService.findById(id)); - } + /* *//** + * 根据ID查询 + * + * @param id ID + * @return + *//* + * @GetMapping("/{id}") public Result findById(@PathVariable String id) { + * return Result.success(songService.findById(id)); } + */ /** * 分页+多条件查询 diff --git a/luoo_user/src/main/java/com/luoo/user/controller/IndexController.java b/luoo_user/src/main/java/com/luoo/user/controller/IndexController.java new file mode 100644 index 0000000..8e7c912 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/controller/IndexController.java @@ -0,0 +1,30 @@ +package com.luoo.user.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.luoo.user.pojo.Carousel; +import com.luoo.user.service.CarouselService; + +import api.Result; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; + +import javax.annotation.Resource; +import java.util.List; +@Api(tags = "IndexController") +@RestController +@RequestMapping("/index") +public class IndexController { + + @Resource + private CarouselService carouselService; + + @ApiOperation(value = "1.获取轮播图", notes = "返回5个") + @GetMapping("/loadCarousel") + public Result> loadCarousel() { + List carouselList = carouselService.loadCarousel(); + return Result.success(carouselList); + } +} diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/Carousel.java b/luoo_user/src/main/java/com/luoo/user/pojo/Carousel.java new file mode 100644 index 0000000..637946d --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/pojo/Carousel.java @@ -0,0 +1,46 @@ +package com.luoo.user.pojo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + + +/** + * app轮播 + */ +@Getter +@Setter +@Builder +public class Carousel{ + + /** + * 自增ID + */ + @ApiModelProperty(value = "自增ID") + private Integer carouselId; + + /** + * 图片 + */ + @ApiModelProperty(value = "图片") + private String imgPath; + + /** + * 0:期刊 1:外部连接 + */ + @ApiModelProperty(value = "0:歌曲 1:期刊 2:外部连接") + private Integer objectType; + + /** + * 对象ID + */ + @ApiModelProperty(value = "对象ID") + private String objectId; + + /** + * 外部连接 + */ + @ApiModelProperty(value = "外部连接") + private String outerLink; +} diff --git a/luoo_user/src/main/java/com/luoo/user/service/CarouselService.java b/luoo_user/src/main/java/com/luoo/user/service/CarouselService.java new file mode 100644 index 0000000..9d95fd9 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/service/CarouselService.java @@ -0,0 +1,24 @@ +package com.luoo.user.service; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.stereotype.Service; + +import com.luoo.user.pojo.Carousel; + +@Service +public class CarouselService { + private static final List DEFAULT_CAROUSEL_LIST=new ArrayList<>(); + static { + DEFAULT_CAROUSEL_LIST.add(Carousel.builder().carouselId(1).imgPath("http://cdn.indie.cn/music/10016/07.jpg").objectType(0).objectId("1643965109602750464").outerLink(null).build()); + DEFAULT_CAROUSEL_LIST.add(Carousel.builder().carouselId(2).imgPath("http://cdn.indie.cn/music/00985/00.jpg").objectType(1).objectId("1635099768424370176").outerLink(null).build()); + DEFAULT_CAROUSEL_LIST.add(Carousel.builder().carouselId(3).imgPath("http://cdn.indie.cn/music/00984/00.jpg").objectType(1).objectId("1635099812296790016").outerLink(null).build()); + DEFAULT_CAROUSEL_LIST.add(Carousel.builder().carouselId(4).imgPath("http://cdn.indie.cn/music/00942/00.jpg").objectType(2).objectId(null).outerLink("http://116.62.145.60:3000/music").build()); + DEFAULT_CAROUSEL_LIST.add(Carousel.builder().carouselId(5).imgPath("http://cdn.indie.cn/music/00982/00.jpg").objectType(1).objectId("1635099717706846208").outerLink(null).build()); + } + public List loadCarousel() { + return DEFAULT_CAROUSEL_LIST; + } + +}