|
|
|
@ -3,6 +3,7 @@ package com.luoo.music.controller;
|
|
|
|
|
import com.luoo.music.dto.response.SongRespDTO;
|
|
|
|
|
import com.luoo.music.pojo.Article;
|
|
|
|
|
import com.luoo.music.pojo.Song;
|
|
|
|
|
import com.luoo.music.service.ArticleService;
|
|
|
|
|
import com.luoo.music.service.SongService;
|
|
|
|
|
|
|
|
|
|
import annotation.GlobalInterceptor;
|
|
|
|
@ -10,10 +11,12 @@ import annotation.VerifyParam;
|
|
|
|
|
import api.PageResult;
|
|
|
|
|
import api.Result;
|
|
|
|
|
import constants.Constants;
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
|
import enums.VerifyRegexEnum;
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import util.JwtUtil;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
@ -32,7 +35,10 @@ public class SongController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private SongService songService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ArticleService articleService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
|
/**
|
|
|
|
|
* 查询全部数据
|
|
|
|
|
*
|
|
|
|
@ -43,24 +49,31 @@ public class SongController {
|
|
|
|
|
return Result.success(songService.findAll());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "1.根据期刊号查询歌曲信息")
|
|
|
|
|
@ApiOperation(value = "1.根据期刊号查询歌曲信息",notes="若为游客,期刊号须在最新10期内")
|
|
|
|
|
@GetMapping("/getByJournalNo/{journalNo}")
|
|
|
|
|
@GlobalInterceptor(checkLogin = true)
|
|
|
|
|
@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)) {
|
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
|
}
|
|
|
|
|
List<Song> songs = songService.findByVolid(journalNo);
|
|
|
|
|
List<SongRespDTO> results = songs.stream().map(s -> getSongRespDTO(s)).collect(Collectors.toList());
|
|
|
|
|
return Result.success(results);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isLatest10(String journalNo) {
|
|
|
|
|
return articleService.isLatest10(journalNo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "2.随机播放歌曲", notes = "雀乐FM")
|
|
|
|
|
@ApiImplicitParams({
|
|
|
|
|
@ApiImplicitParam(name = "limit", value = "随机歌曲数,最少1首,最多30首", required = false)
|
|
|
|
|
})
|
|
|
|
|
@GetMapping("/random/{limit}")
|
|
|
|
|
@GlobalInterceptor(checkLogin = true)
|
|
|
|
|
public Result<List<SongRespDTO>> random(@RequestHeader(value = "token", required = false) String token,
|
|
|
|
|
@PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.RANDOM_SONG_LIMIT) Integer limit) {
|
|
|
|
|
@GlobalInterceptor
|
|
|
|
|
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());
|
|
|
|
|
return Result.success(results);
|
|
|
|
|