|
|
@ -1,5 +1,7 @@
|
|
|
|
package com.luoo.music.controller;
|
|
|
|
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.dto.response.SongRespDTO;
|
|
|
|
import com.luoo.music.pojo.Article;
|
|
|
|
import com.luoo.music.pojo.Article;
|
|
|
|
import com.luoo.music.pojo.Song;
|
|
|
|
import com.luoo.music.pojo.Song;
|
|
|
@ -12,10 +14,12 @@ import api.PageResult;
|
|
|
|
import api.Result;
|
|
|
|
import api.Result;
|
|
|
|
import constants.Constants;
|
|
|
|
import constants.Constants;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
|
|
|
|
import enums.CollectTypeEnum;
|
|
|
|
import enums.VerifyRegexEnum;
|
|
|
|
import enums.VerifyRegexEnum;
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
|
|
import mongodb.UserCollect;
|
|
|
|
import util.JwtUtil;
|
|
|
|
import util.JwtUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@ -32,13 +36,15 @@ import java.util.stream.Collectors;
|
|
|
|
@CrossOrigin
|
|
|
|
@CrossOrigin
|
|
|
|
@RequestMapping("/song")
|
|
|
|
@RequestMapping("/song")
|
|
|
|
public class SongController {
|
|
|
|
public class SongController {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private UserCollectDao userCollectDao;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private SongService songService;
|
|
|
|
private SongService songService;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private ArticleService articleService;
|
|
|
|
private ArticleService articleService;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 查询全部数据
|
|
|
|
* 查询全部数据
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -59,7 +65,7 @@ public class SongController {
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Song> songs = songService.findByVolid(journalNo);
|
|
|
|
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);
|
|
|
|
return Result.success(results);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -68,18 +74,17 @@ public class SongController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "2.随机播放歌曲", notes = "雀乐FM")
|
|
|
|
@ApiOperation(value = "2.随机播放歌曲", notes = "雀乐FM")
|
|
|
|
@ApiImplicitParams({
|
|
|
|
@ApiImplicitParams({ @ApiImplicitParam(name = "limit", value = "随机歌曲数,最少1首,最多30首", required = false) })
|
|
|
|
@ApiImplicitParam(name = "limit", value = "随机歌曲数,最少1首,最多30首", required = false)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
@GetMapping("/random/{limit}")
|
|
|
|
@GetMapping("/random/{limit}")
|
|
|
|
@GlobalInterceptor
|
|
|
|
@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<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);
|
|
|
|
return Result.success(results);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private SongRespDTO getSongRespDTO(Song song) {
|
|
|
|
private SongRespDTO getSongRespDTO(Song song, UserLoginDto userLoginDto) {
|
|
|
|
SongRespDTO songRespDTO = new SongRespDTO();
|
|
|
|
SongRespDTO songRespDTO = new SongRespDTO();
|
|
|
|
songRespDTO.setJournalNo(song.getVolid());
|
|
|
|
songRespDTO.setJournalNo(song.getVolid());
|
|
|
|
songRespDTO.setAlbum(song.getAlbum());
|
|
|
|
songRespDTO.setAlbum(song.getAlbum());
|
|
|
@ -90,6 +95,11 @@ public class SongController {
|
|
|
|
songRespDTO.setPic(Constants.MUSIC_RESOURCE_PREFIX + song.getUrl().replace(".mp3", ".jpg"));
|
|
|
|
songRespDTO.setPic(Constants.MUSIC_RESOURCE_PREFIX + song.getUrl().replace(".mp3", ".jpg"));
|
|
|
|
songRespDTO.setLrc(Constants.MUSIC_RESOURCE_PREFIX + song.getUrl().replace(".mp3", ".lyric"));
|
|
|
|
songRespDTO.setLrc(Constants.MUSIC_RESOURCE_PREFIX + song.getUrl().replace(".mp3", ".lyric"));
|
|
|
|
songRespDTO.setSongNo(song.getSongno());
|
|
|
|
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;
|
|
|
|
return songRespDTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|