1.add random song list interface

main
Gary 10 months ago
parent 6ff77ebbcc
commit aeb2f55811

@ -2,6 +2,7 @@ package enums;
public enum VerifyRegexEnum {
NO("", "不校验"),
RANDOM_SONG_LIMIT("[1-9]|[12][0-9]|30", "歌曲随机数限制,[1~30]"),
MOBILE("(1[0-9])\\d{9}$", "手机号码"),
MOBILE_CHECK_CODE("\\d{6}$", "手机短信验证号码"),
PASSWORD("^(?=.*\\d)(?=.*[a-zA-Z])[\\da-zA-Z~!@#$%^&*_]{8,}$", "只能是数字,字母,特殊字符 8-18位");

@ -26,6 +26,7 @@ public class BaseExceptionHandler {
@ResponseBody
public Result<String> error(BizException e) {
log.info("业务错误:{}", e.getMessage());
return Result.failed(StatusCode.MUSIC_COMMON_FAILED, e.getMessage());
StatusCode statusCode = null == e.getCodeEnum() ? StatusCode.MUSIC_COMMON_FAILED : e.getCodeEnum();
return Result.failed(statusCode, e.getMessage());
}
}

@ -16,6 +16,7 @@ import com.luoo.music.pojo.Article;
import com.luoo.music.service.ArticleService;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.PageResult;
import api.Result;
import constants.Constants;
@ -38,7 +39,7 @@ public class JournalController {
@GetMapping("/list")
@GlobalInterceptor(checkLogin = true)
public Result<PageResult<JournalRespDTO>> page(@RequestHeader(value = "token", required = false) String token,
JournalQueryReq queryReq){
@VerifyParam JournalQueryReq queryReq){
Page<Article> pageList = articleService.queryPage(queryReq);
List<JournalRespDTO> list=pageList.stream().map(a->getArticleRespDTO(a)).collect(Collectors.toList());
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list) );

@ -6,9 +6,13 @@ import com.luoo.music.pojo.Song;
import com.luoo.music.service.SongService;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.PageResult;
import api.Result;
import constants.Constants;
import enums.VerifyRegexEnum;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@ -49,18 +53,19 @@ public class SongController {
return Result.success(results);
}
/*
* @ApiOperation(value = "2.随机播放歌曲",notes="雀乐FM")
*
* @GetMapping("/random/{limit}")
*
* @GlobalInterceptor(checkLogin = true) public Result<List<SongRespDTO>>
* getByJournalNo(@RequestHeader(value = "token", required = false) String
* token) { List<Song> songs = songService.random(); List<SongRespDTO> results =
* songs.stream().map(s -> getSongRespDTO(s)).collect(Collectors.toList());
* return Result.success(results); }
*/
@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) {
List<Song> songs = songService.random(limit);
List<SongRespDTO> results = songs.stream().map(s -> getSongRespDTO(s)).collect(Collectors.toList());
return Result.success(results);
}
private SongRespDTO getSongRespDTO(Song song) {
SongRespDTO songRespDTO = new SongRespDTO();
songRespDTO.setJournalNo(song.getVolid());

@ -3,10 +3,14 @@ package com.luoo.music.dao;
import com.luoo.music.pojo.Song;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface SongDao extends JpaRepository<Song,String>, JpaSpecificationExecutor<Song> {
public List<Song> findSongsByVolid(String volid);
@Query(value = "select * from tb_song order by rand() limit ?1 ", nativeQuery = true)
List<Song> random(int limit);
}

@ -1,6 +1,8 @@
package com.luoo.music.dto.request;
import com.fasterxml.jackson.annotation.JsonFormat;
import annotation.VerifyParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -17,12 +19,14 @@ import java.time.LocalDateTime;
@ApiModel
public class JournalQueryReq implements Serializable {
private static final long serialVersionUID = -1198060864891902188L;
@ApiModelProperty(value = "风格")
@ApiModelProperty(value = "筛选条件:风格")
private String style;
@ApiModelProperty(value = "语言")
@ApiModelProperty(value = "筛选条件:语言")
private String language;
@ApiModelProperty(value = "分页: 页码", example = "1")
private int pageNum = 1;
@VerifyParam(required=true)
@ApiModelProperty(value = "分页: 页码以1开始即获取最新的几期", example = "1")
private Integer pageNum = 1;
@VerifyParam(required=true)
@ApiModelProperty(value = "分页: 每页数量", example = "10")
private int pageSize = 10;
private Integer pageSize = 10;
}

@ -145,4 +145,8 @@ public class SongService {
public List<Song> findByVolid(String volid){
return songDao.findSongsByVolid(volid);
}
public List<Song> random(Integer limit) {
return songDao.random(limit);
}
}

Loading…
Cancel
Save