|
|
|
@ -1,10 +1,11 @@
|
|
|
|
|
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.SongService;
|
|
|
|
|
|
|
|
|
|
import annotation.GlobalInterceptor;
|
|
|
|
|
import api.PageResult;
|
|
|
|
|
import api.Result;
|
|
|
|
|
import constants.Constants;
|
|
|
|
@ -30,20 +31,36 @@ public class SongController {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询全部数据
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping
|
|
|
|
|
public Result<List<Song>> findAll(){
|
|
|
|
|
public Result<List<Song>> findAll() {
|
|
|
|
|
return Result.success(songService.findAll());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "1.根据期刊号查询歌曲信息")
|
|
|
|
|
@GetMapping("/getByJournalNo/{journalNo}")
|
|
|
|
|
public Result<List<SongRespDTO>> getByJournalNo(@PathVariable String journalNo){
|
|
|
|
|
List<Song> songs=songService.findByVolid(journalNo);
|
|
|
|
|
List<SongRespDTO> results=songs.stream().map(s->getSongRespDTO(s)).collect(Collectors.toList());
|
|
|
|
|
@GlobalInterceptor(checkLogin = true)
|
|
|
|
|
public Result<List<SongRespDTO>> getByJournalNo(@RequestHeader(value = "token", required = false) String token,
|
|
|
|
|
@PathVariable String journalNo) {
|
|
|
|
|
List<Song> songs = songService.findByVolid(journalNo);
|
|
|
|
|
List<SongRespDTO> results = songs.stream().map(s -> getSongRespDTO(s)).collect(Collectors.toList());
|
|
|
|
|
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); }
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
private SongRespDTO getSongRespDTO(Song song) {
|
|
|
|
|
SongRespDTO songRespDTO = new SongRespDTO();
|
|
|
|
|
songRespDTO.setJournalNo(song.getVolid());
|
|
|
|
@ -51,37 +68,39 @@ public class SongController {
|
|
|
|
|
songRespDTO.setArtist(song.getArtist());
|
|
|
|
|
songRespDTO.setId(song.getId());
|
|
|
|
|
songRespDTO.setTitle(song.getName());
|
|
|
|
|
songRespDTO.setSrc(Constants.MUSIC_RESOURCE_PREFIX+song.getUrl());
|
|
|
|
|
songRespDTO.setPic(Constants.MUSIC_RESOURCE_PREFIX+song.getUrl().replace(".mp3",".jpg"));
|
|
|
|
|
songRespDTO.setLrc(Constants.MUSIC_RESOURCE_PREFIX+song.getUrl().replace(".mp3",".lyric"));
|
|
|
|
|
songRespDTO.setSrc(Constants.MUSIC_RESOURCE_PREFIX + song.getUrl());
|
|
|
|
|
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());
|
|
|
|
|
return songRespDTO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据ID查询
|
|
|
|
|
*
|
|
|
|
|
* @param id ID
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/{id}")
|
|
|
|
|
public Result<Song> findById(@PathVariable String id){
|
|
|
|
|
public Result<Song> findById(@PathVariable String id) {
|
|
|
|
|
return Result.success(songService.findById(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页+多条件查询
|
|
|
|
|
*
|
|
|
|
|
* @param searchMap 查询条件封装
|
|
|
|
|
* @param page 页码
|
|
|
|
|
* @param size 页大小
|
|
|
|
|
* @return 分页结果
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/search/{page}/{size}")
|
|
|
|
|
public Result<PageResult<Song>> findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
|
|
|
|
|
public Result<PageResult<Song>> findSearch(@RequestBody Map searchMap, @PathVariable int page,
|
|
|
|
|
@PathVariable int size) {
|
|
|
|
|
Page<Song> pageList = songService.findSearch(searchMap, page, size);
|
|
|
|
|
return Result.success(new PageResult<Song>(pageList.getTotalElements(), pageList.getContent()) );
|
|
|
|
|
return Result.success(new PageResult<Song>(pageList.getTotalElements(), pageList.getContent()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/init")
|
|
|
|
|
public Result<Void> init(@RequestBody Map map) {
|
|
|
|
|
List<Map> data = (List) map.get("data");
|
|
|
|
@ -89,32 +108,31 @@ public class SongController {
|
|
|
|
|
Song song = new Song();
|
|
|
|
|
Set<Article> set = new HashSet<Article>();
|
|
|
|
|
|
|
|
|
|
int temp=0;
|
|
|
|
|
int num=0;
|
|
|
|
|
for (Map dataMap :data
|
|
|
|
|
) {
|
|
|
|
|
int temp = 0;
|
|
|
|
|
int num = 0;
|
|
|
|
|
for (Map dataMap : data) {
|
|
|
|
|
Article article = new Article();
|
|
|
|
|
article.setVolid(dataMap.get("id")+"");
|
|
|
|
|
article.setTitle(dataMap.get("title")+"");
|
|
|
|
|
String avatar = "0000"+dataMap.get("id");
|
|
|
|
|
article.setVolid(dataMap.get("id") + "");
|
|
|
|
|
article.setTitle(dataMap.get("title") + "");
|
|
|
|
|
String avatar = "0000" + dataMap.get("id");
|
|
|
|
|
String substring = avatar.substring(avatar.length() - 5);
|
|
|
|
|
System.out.println(substring);
|
|
|
|
|
article.setImage(substring+"/00.jpg");
|
|
|
|
|
if (temp== (int) dataMap.get("id")){
|
|
|
|
|
num = num+1;
|
|
|
|
|
}else {
|
|
|
|
|
article.setImage(substring + "/00.jpg");
|
|
|
|
|
if (temp == (int) dataMap.get("id")) {
|
|
|
|
|
num = num + 1;
|
|
|
|
|
} else {
|
|
|
|
|
num = 0;
|
|
|
|
|
}
|
|
|
|
|
temp = (int) dataMap.get("id");
|
|
|
|
|
String numstr = "0000"+(num+1);
|
|
|
|
|
System.out.println(numstr.substring(numstr.length()-2));
|
|
|
|
|
String numstr = "0000" + (num + 1);
|
|
|
|
|
System.out.println(numstr.substring(numstr.length() - 2));
|
|
|
|
|
|
|
|
|
|
song.setAlbum(dataMap.get("album")+"");
|
|
|
|
|
song.setArtist(dataMap.get("artist")+"");
|
|
|
|
|
song.setName(dataMap.get("name")+"");
|
|
|
|
|
song.setVolid(dataMap.get("id")+"");
|
|
|
|
|
song.setUrl(substring+"/"+numstr.substring(numstr.length()-2)+".mp3");
|
|
|
|
|
song.setSongno(num+1);
|
|
|
|
|
song.setAlbum(dataMap.get("album") + "");
|
|
|
|
|
song.setArtist(dataMap.get("artist") + "");
|
|
|
|
|
song.setName(dataMap.get("name") + "");
|
|
|
|
|
song.setVolid(dataMap.get("id") + "");
|
|
|
|
|
song.setUrl(substring + "/" + numstr.substring(numstr.length() - 2) + ".mp3");
|
|
|
|
|
song.setSongno(num + 1);
|
|
|
|
|
|
|
|
|
|
songService.add(song);
|
|
|
|
|
set.add(article);
|
|
|
|
@ -129,31 +147,33 @@ public class SongController {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据条件查询
|
|
|
|
|
*
|
|
|
|
|
* @param searchMap
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/search")
|
|
|
|
|
public Result<List<Song>> findSearch( @RequestBody Map searchMap){
|
|
|
|
|
public Result<List<Song>> findSearch(@RequestBody Map searchMap) {
|
|
|
|
|
return Result.success(songService.findSearch(searchMap));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 增加
|
|
|
|
|
*
|
|
|
|
|
* @param song
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping
|
|
|
|
|
public Result<Void> add(@RequestBody Song song){
|
|
|
|
|
public Result<Void> add(@RequestBody Song song) {
|
|
|
|
|
songService.add(song);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改
|
|
|
|
|
*
|
|
|
|
|
* @param song
|
|
|
|
|
*/
|
|
|
|
|
@PutMapping("/{id}")
|
|
|
|
|
public Result<Void> update(@RequestBody Song song, @PathVariable String id ){
|
|
|
|
|
public Result<Void> update(@RequestBody Song song, @PathVariable String id) {
|
|
|
|
|
song.setId(id);
|
|
|
|
|
songService.update(song);
|
|
|
|
|
return Result.success();
|
|
|
|
@ -161,10 +181,11 @@ public class SongController {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
*/
|
|
|
|
|
@DeleteMapping("/{id}")
|
|
|
|
|
public Result<Void> delete(@PathVariable String id ){
|
|
|
|
|
public Result<Void> delete(@PathVariable String id) {
|
|
|
|
|
songService.deleteById(id);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|