|
|
@ -14,6 +14,7 @@ import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
|
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
@ -66,9 +67,9 @@ public class CMSSongService {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Result<PageResult<SongVO>> search(SongQueryModel param, int page, int size) {
|
|
|
|
public Result<PageResult<SongVO>> search(SongQueryModel param, int page, int size) {
|
|
|
|
List<SongVO> result = new ArrayList<>();
|
|
|
|
List<SongVO> result = new ArrayList<>();
|
|
|
|
// Sort sort = new Sort(Sort.Direction.DESC, "create_time");
|
|
|
|
Sort sort = new Sort(Sort.Direction.DESC, "id");
|
|
|
|
// PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
|
|
|
|
PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
|
|
|
|
PageRequest pageRequest = PageRequest.of(page - 1, size);
|
|
|
|
// PageRequest pageRequest = PageRequest.of(page - 1, size);
|
|
|
|
Page<SongInfo> songPage;
|
|
|
|
Page<SongInfo> songPage;
|
|
|
|
if (!Objects.isNull(param)) {
|
|
|
|
if (!Objects.isNull(param)) {
|
|
|
|
Specification<SongInfo> songSpecification = buildSearchSpecification(param);
|
|
|
|
Specification<SongInfo> songSpecification = buildSearchSpecification(param);
|
|
|
@ -90,14 +91,19 @@ public class CMSSongService {
|
|
|
|
response.setArtist(item.getArtist());
|
|
|
|
response.setArtist(item.getArtist());
|
|
|
|
response.setAlbum(item.getAlbum());
|
|
|
|
response.setAlbum(item.getAlbum());
|
|
|
|
response.setTags(songTagMap.get(id));
|
|
|
|
response.setTags(songTagMap.get(id));
|
|
|
|
response.setImage(Constants.SONG_RESOURCE_PREFIX + item.getImage());
|
|
|
|
if (StringUtils.isNotBlank(item.getImage())) {
|
|
|
|
|
|
|
|
response.setImage(Constants.SONG_RESOURCE_PREFIX + item.getImage());
|
|
|
|
|
|
|
|
}
|
|
|
|
response.setSize(CommonUtil.formatSongSize(item.getSize()));
|
|
|
|
response.setSize(CommonUtil.formatSongSize(item.getSize()));
|
|
|
|
response.setDuration(CommonUtil.formatSongDuration(item.getDuration()));
|
|
|
|
response.setDuration(CommonUtil.formatSongDuration(item.getDuration()));
|
|
|
|
response.setJournal(songJournalMap.get(id));
|
|
|
|
response.setJournal(songJournalMap.get(id));
|
|
|
|
response.setUpdateTime(item.getUpdateTime().format(Constants.formatter));
|
|
|
|
response.setUpdateTime(item.getUpdateTime().format(Constants.formatter));
|
|
|
|
response.setState(item.getState());
|
|
|
|
response.setState(item.getState());
|
|
|
|
response.setUserId(item.getUserId());
|
|
|
|
response.setUserId(item.getUserId());
|
|
|
|
response.setUrl(Constants.SONG_RESOURCE_PREFIX + item.getUrl());
|
|
|
|
response.setUserName(item.getUserName());
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(item.getUrl())) {
|
|
|
|
|
|
|
|
response.setUrl(Constants.SONG_RESOURCE_PREFIX + item.getUrl());
|
|
|
|
|
|
|
|
}
|
|
|
|
result.add(response);
|
|
|
|
result.add(response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -228,10 +234,9 @@ public class CMSSongService {
|
|
|
|
song.setName(param.getName());
|
|
|
|
song.setName(param.getName());
|
|
|
|
song.setArtist(param.getArtist());
|
|
|
|
song.setArtist(param.getArtist());
|
|
|
|
song.setAlbum(param.getAlbum());
|
|
|
|
song.setAlbum(param.getAlbum());
|
|
|
|
song.setSize(param.getSize());
|
|
|
|
song.setLyric(param.getLyric());
|
|
|
|
song.setDuration(param.getDuration());
|
|
|
|
UserLoginDto user = getUserInfoByToken(token);
|
|
|
|
if (StringUtils.isNotBlank(token)) {
|
|
|
|
if (!Objects.isNull(user)) {
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
|
|
|
song.setUserId(user.getUserId());
|
|
|
|
song.setUserId(user.getUserId());
|
|
|
|
song.setUserName(user.getNickName());
|
|
|
|
song.setUserName(user.getNickName());
|
|
|
|
song.setUserType(user.getRoles());
|
|
|
|
song.setUserType(user.getRoles());
|
|
|
@ -284,15 +289,6 @@ public class CMSSongService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 更新期刊中歌曲的信息
|
|
|
|
|
|
|
|
* @param id
|
|
|
|
|
|
|
|
* @param param
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void batchSaveSongJournalInfo(String id, SongAddModel param) {
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 查询曲目详情
|
|
|
|
* 查询曲目详情
|
|
|
|
* @param id
|
|
|
|
* @param id
|
|
|
@ -339,19 +335,41 @@ public class CMSSongService {
|
|
|
|
if (param.getImage().contains(Constants.TEMP_KEY_PREFIX)) {
|
|
|
|
if (param.getImage().contains(Constants.TEMP_KEY_PREFIX)) {
|
|
|
|
image = moveSongImage(id, param);
|
|
|
|
image = moveSongImage(id, param);
|
|
|
|
if (StringUtils.isBlank(image)) {
|
|
|
|
if (StringUtils.isBlank(image)) {
|
|
|
|
Result.failed("更新失败");
|
|
|
|
return Result.failed("更新失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
song.setImage(image);
|
|
|
|
song.setImage(image);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
song.setImage(oldSong.getImage());
|
|
|
|
song.setImage(oldSong.getImage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
song.setState(oldSong.getState());
|
|
|
|
song.setState(oldSong.getState());
|
|
|
|
|
|
|
|
song.setCreateTime(oldSong.getCreateTime());
|
|
|
|
songDao.save(song);
|
|
|
|
songDao.save(song);
|
|
|
|
songTagDao.deleteBySongId(id);
|
|
|
|
songTagDao.deleteBySongId(id);
|
|
|
|
batchSaveSongTagInfo(id, param);
|
|
|
|
batchSaveSongTagInfo(id, param);
|
|
|
|
|
|
|
|
batchUpdateJournalSongInfo(id, song);
|
|
|
|
return Result.success();
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 更新期刊歌曲表中歌曲的信息
|
|
|
|
|
|
|
|
* @param id
|
|
|
|
|
|
|
|
* @param song
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void batchUpdateJournalSongInfo(String id, SongInfo song) {
|
|
|
|
|
|
|
|
List<JournalSong> journalSongList = journalSongDao.findBySongId(id);
|
|
|
|
|
|
|
|
if (journalSongList.size() > 0) {
|
|
|
|
|
|
|
|
for (JournalSong item : journalSongList) {
|
|
|
|
|
|
|
|
item.setName(song.getName());
|
|
|
|
|
|
|
|
item.setArtist(song.getArtist());
|
|
|
|
|
|
|
|
item.setAlbum(song.getAlbum());
|
|
|
|
|
|
|
|
item.setUrl(song.getUrl());
|
|
|
|
|
|
|
|
item.setImage(song.getImage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s3Service.fromSongToMusic(journalSongList);
|
|
|
|
|
|
|
|
journalSongDao.saveAll(journalSongList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 更新歌曲状态
|
|
|
|
* 更新歌曲状态
|
|
|
|
* @param id
|
|
|
|
* @param id
|
|
|
@ -427,17 +445,18 @@ public class CMSSongService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 批量上传歌曲
|
|
|
|
* 批量上传歌曲,获取不到歌曲的歌手乐队、专辑
|
|
|
|
* @param files
|
|
|
|
* @param files
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Result batchUpload(List<MultipartFile> files) {
|
|
|
|
public Result batchUpload(List<MultipartFile> files, String token) {
|
|
|
|
for (MultipartFile file : files) {
|
|
|
|
UserLoginDto user = getUserInfoByToken(token);
|
|
|
|
|
|
|
|
for (MultipartFile file : files)
|
|
|
|
if (!file.isEmpty()) {
|
|
|
|
if (!file.isEmpty()) {
|
|
|
|
String id = String.valueOf(idWorker.nextId());
|
|
|
|
String id = String.valueOf(idWorker.nextId());
|
|
|
|
String originalFilename = file.getOriginalFilename();
|
|
|
|
String originalFilename = file.getOriginalFilename();
|
|
|
|
String suffix = originalFilename.substring(originalFilename.lastIndexOf(Constants.DOT));
|
|
|
|
String suffix = originalFilename.substring(originalFilename.lastIndexOf(Constants.DOT));
|
|
|
|
String keySuffix = id + "/00" + suffix;
|
|
|
|
String keySuffix = id + "/00" + suffix;
|
|
|
|
String key = Constants.SONG_KEY_PREFIX + keySuffix;
|
|
|
|
String key = Constants.SONG_KEY_PREFIX + keySuffix;
|
|
|
|
int upload = s3Service.upload(Constants.BUCKET, key, file);
|
|
|
|
int upload = s3Service.upload(Constants.BUCKET, key, file);
|
|
|
|
if (upload > 0) {
|
|
|
|
if (upload > 0) {
|
|
|
@ -447,13 +466,40 @@ public class CMSSongService {
|
|
|
|
song.setUrl(keySuffix);
|
|
|
|
song.setUrl(keySuffix);
|
|
|
|
song.setSize(file.isEmpty() ? 0L : file.getSize());
|
|
|
|
song.setSize(file.isEmpty() ? 0L : file.getSize());
|
|
|
|
song.setDuration(CommonUtil.getSongDuration(file));
|
|
|
|
song.setDuration(CommonUtil.getSongDuration(file));
|
|
|
|
|
|
|
|
if (!Objects.isNull(user)) {
|
|
|
|
|
|
|
|
song.setUserId(user.getUserId());
|
|
|
|
|
|
|
|
song.setUserName(user.getNickName());
|
|
|
|
|
|
|
|
song.setUserType(user.getRoles());
|
|
|
|
|
|
|
|
}
|
|
|
|
songDao.save(song);
|
|
|
|
songDao.save(song);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result.success();
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 根据 token 获取用户信息
|
|
|
|
|
|
|
|
* @param token
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private UserLoginDto getUserInfoByToken(String token) {
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(token)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
|
|
|
if (!Objects.isNull(user)) {
|
|
|
|
|
|
|
|
return user;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 读取歌词文件
|
|
|
|
|
|
|
|
* @param lyricUrl
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
private String readLyric(String lyricUrl) {
|
|
|
|
private String readLyric(String lyricUrl) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// 创建 URL 对象
|
|
|
|
// 创建 URL 对象
|
|
|
|