|
|
|
@ -14,6 +14,7 @@ import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
@ -66,9 +67,9 @@ public class CMSSongService {
|
|
|
|
|
*/
|
|
|
|
|
public Result<PageResult<SongVO>> search(SongQueryModel param, int page, int size) {
|
|
|
|
|
List<SongVO> result = new ArrayList<>();
|
|
|
|
|
// Sort sort = new Sort(Sort.Direction.DESC, "create_time");
|
|
|
|
|
// PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(page - 1, size);
|
|
|
|
|
Sort sort = new Sort(Sort.Direction.DESC, "id");
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
|
|
|
|
|
// PageRequest pageRequest = PageRequest.of(page - 1, size);
|
|
|
|
|
Page<SongInfo> songPage;
|
|
|
|
|
if (!Objects.isNull(param)) {
|
|
|
|
|
Specification<SongInfo> songSpecification = buildSearchSpecification(param);
|
|
|
|
@ -90,14 +91,19 @@ public class CMSSongService {
|
|
|
|
|
response.setArtist(item.getArtist());
|
|
|
|
|
response.setAlbum(item.getAlbum());
|
|
|
|
|
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.setDuration(CommonUtil.formatSongDuration(item.getDuration()));
|
|
|
|
|
response.setJournal(songJournalMap.get(id));
|
|
|
|
|
response.setUpdateTime(item.getUpdateTime().format(Constants.formatter));
|
|
|
|
|
response.setState(item.getState());
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -228,10 +234,9 @@ public class CMSSongService {
|
|
|
|
|
song.setName(param.getName());
|
|
|
|
|
song.setArtist(param.getArtist());
|
|
|
|
|
song.setAlbum(param.getAlbum());
|
|
|
|
|
song.setSize(param.getSize());
|
|
|
|
|
song.setDuration(param.getDuration());
|
|
|
|
|
if (StringUtils.isNotBlank(token)) {
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
song.setLyric(param.getLyric());
|
|
|
|
|
UserLoginDto user = getUserInfoByToken(token);
|
|
|
|
|
if (!Objects.isNull(user)) {
|
|
|
|
|
song.setUserId(user.getUserId());
|
|
|
|
|
song.setUserName(user.getNickName());
|
|
|
|
|
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
|
|
|
|
@ -339,19 +335,41 @@ public class CMSSongService {
|
|
|
|
|
if (param.getImage().contains(Constants.TEMP_KEY_PREFIX)) {
|
|
|
|
|
image = moveSongImage(id, param);
|
|
|
|
|
if (StringUtils.isBlank(image)) {
|
|
|
|
|
Result.failed("更新失败");
|
|
|
|
|
return Result.failed("更新失败");
|
|
|
|
|
}
|
|
|
|
|
song.setImage(image);
|
|
|
|
|
} else {
|
|
|
|
|
song.setImage(oldSong.getImage());
|
|
|
|
|
}
|
|
|
|
|
song.setState(oldSong.getState());
|
|
|
|
|
song.setCreateTime(oldSong.getCreateTime());
|
|
|
|
|
songDao.save(song);
|
|
|
|
|
songTagDao.deleteBySongId(id);
|
|
|
|
|
batchSaveSongTagInfo(id, param);
|
|
|
|
|
batchUpdateJournalSongInfo(id, song);
|
|
|
|
|
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
|
|
|
|
@ -427,17 +445,18 @@ public class CMSSongService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量上传歌曲
|
|
|
|
|
* 批量上传歌曲,获取不到歌曲的歌手乐队、专辑
|
|
|
|
|
* @param files
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Result batchUpload(List<MultipartFile> files) {
|
|
|
|
|
for (MultipartFile file : files) {
|
|
|
|
|
public Result batchUpload(List<MultipartFile> files, String token) {
|
|
|
|
|
UserLoginDto user = getUserInfoByToken(token);
|
|
|
|
|
for (MultipartFile file : files)
|
|
|
|
|
if (!file.isEmpty()) {
|
|
|
|
|
String id = String.valueOf(idWorker.nextId());
|
|
|
|
|
String originalFilename = file.getOriginalFilename();
|
|
|
|
|
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;
|
|
|
|
|
int upload = s3Service.upload(Constants.BUCKET, key, file);
|
|
|
|
|
if (upload > 0) {
|
|
|
|
@ -447,13 +466,40 @@ public class CMSSongService {
|
|
|
|
|
song.setUrl(keySuffix);
|
|
|
|
|
song.setSize(file.isEmpty() ? 0L : file.getSize());
|
|
|
|
|
song.setDuration(CommonUtil.getSongDuration(file));
|
|
|
|
|
if (!Objects.isNull(user)) {
|
|
|
|
|
song.setUserId(user.getUserId());
|
|
|
|
|
song.setUserName(user.getNickName());
|
|
|
|
|
song.setUserType(user.getRoles());
|
|
|
|
|
}
|
|
|
|
|
songDao.save(song);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
|
try {
|
|
|
|
|
// 创建 URL 对象
|
|
|
|
|