|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
package com.luoo.music.controller;
|
|
|
|
|
|
|
|
|
|
import com.luoo.music.client.UserClient;
|
|
|
|
|
import com.luoo.music.dao.UserCollectDao;
|
|
|
|
|
import com.luoo.music.dto.response.SongRespDTO;
|
|
|
|
|
import com.luoo.music.pojo.Article;
|
|
|
|
|
import com.luoo.music.pojo.Song;
|
|
|
|
@ -12,10 +14,12 @@ import api.PageResult;
|
|
|
|
|
import api.Result;
|
|
|
|
|
import constants.Constants;
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
|
import enums.CollectTypeEnum;
|
|
|
|
|
import enums.VerifyRegexEnum;
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import mongodb.UserCollect;
|
|
|
|
|
import util.JwtUtil;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
@ -32,13 +36,15 @@ import java.util.stream.Collectors;
|
|
|
|
|
@CrossOrigin
|
|
|
|
|
@RequestMapping("/song")
|
|
|
|
|
public class SongController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserCollectDao userCollectDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private SongService songService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ArticleService articleService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询全部数据
|
|
|
|
|
*
|
|
|
|
@ -49,17 +55,17 @@ public class SongController {
|
|
|
|
|
return Result.success(songService.findAll());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "1.根据期刊号查询歌曲信息",notes="若为游客,期刊号须在最新10期内")
|
|
|
|
|
@ApiOperation(value = "1.根据期刊号查询歌曲信息", notes = "若为游客,期刊号须在最新10期内")
|
|
|
|
|
@GetMapping("/getByJournalNo/{journalNo}")
|
|
|
|
|
@GlobalInterceptor
|
|
|
|
|
public Result<List<SongRespDTO>> getByJournalNo(@RequestHeader(value = "token", required = false) String token,
|
|
|
|
|
@PathVariable String journalNo) {
|
|
|
|
|
UserLoginDto user=jwtUtil.getUserLoginDto(token);
|
|
|
|
|
if(null==user&&!isLatest10(journalNo)) {
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
if (null == user && !isLatest10(journalNo)) {
|
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
|
}
|
|
|
|
|
List<Song> songs = songService.findByVolid(journalNo);
|
|
|
|
|
List<SongRespDTO> results = songs.stream().map(s -> getSongRespDTO(s)).collect(Collectors.toList());
|
|
|
|
|
List<SongRespDTO> results = songs.stream().map(s -> getSongRespDTO(s, user)).collect(Collectors.toList());
|
|
|
|
|
return Result.success(results);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -68,18 +74,17 @@ public class SongController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "2.随机播放歌曲", notes = "雀乐FM")
|
|
|
|
|
@ApiImplicitParams({
|
|
|
|
|
@ApiImplicitParam(name = "limit", value = "随机歌曲数,最少1首,最多30首", required = false)
|
|
|
|
|
})
|
|
|
|
|
@ApiImplicitParams({ @ApiImplicitParam(name = "limit", value = "随机歌曲数,最少1首,最多30首", required = false) })
|
|
|
|
|
@GetMapping("/random/{limit}")
|
|
|
|
|
@GlobalInterceptor
|
|
|
|
|
public Result<List<SongRespDTO>> random(@PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.RANDOM_SONG_LIMIT) Integer limit) {
|
|
|
|
|
public Result<List<SongRespDTO>> random(
|
|
|
|
|
@PathVariable @VerifyParam(required = true, regex = VerifyRegexEnum.RANDOM_SONG_LIMIT) Integer limit) {
|
|
|
|
|
List<Song> songs = songService.random(limit);
|
|
|
|
|
List<SongRespDTO> results = songs.stream().map(s -> getSongRespDTO(s)).collect(Collectors.toList());
|
|
|
|
|
List<SongRespDTO> results = songs.stream().map(s -> getSongRespDTO(s, null)).collect(Collectors.toList());
|
|
|
|
|
return Result.success(results);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SongRespDTO getSongRespDTO(Song song) {
|
|
|
|
|
private SongRespDTO getSongRespDTO(Song song, UserLoginDto userLoginDto) {
|
|
|
|
|
SongRespDTO songRespDTO = new SongRespDTO();
|
|
|
|
|
songRespDTO.setJournalNo(song.getVolid());
|
|
|
|
|
songRespDTO.setAlbum(song.getAlbum());
|
|
|
|
@ -90,6 +95,11 @@ public class SongController {
|
|
|
|
|
songRespDTO.setPic(Constants.MUSIC_RESOURCE_PREFIX + song.getUrl().replace(".mp3", ".jpg"));
|
|
|
|
|
songRespDTO.setLrc(Constants.MUSIC_RESOURCE_PREFIX + song.getUrl().replace(".mp3", ".lyric"));
|
|
|
|
|
songRespDTO.setSongNo(song.getSongno());
|
|
|
|
|
// 根据userId查询是否已收藏
|
|
|
|
|
if (null != userLoginDto) {
|
|
|
|
|
long userCollectCount=userCollectDao.countByUserIdAndObjectIdAndCollectType(userLoginDto.getUserId(), songRespDTO.getId(), CollectTypeEnum.SONG.getType());
|
|
|
|
|
songRespDTO.setHaveCollect(userCollectCount>0);
|
|
|
|
|
}
|
|
|
|
|
return songRespDTO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|