|
|
@ -8,8 +8,10 @@ import com.luoo.music.dto.response.AlbumSongAddDTO;
|
|
|
|
import com.luoo.music.dto.response.AlbumUpdateDTO;
|
|
|
|
import com.luoo.music.dto.response.AlbumUpdateDTO;
|
|
|
|
import com.luoo.music.pojo.*;
|
|
|
|
import com.luoo.music.pojo.*;
|
|
|
|
import com.luoo.music.util.Constants;
|
|
|
|
import com.luoo.music.util.Constants;
|
|
|
|
|
|
|
|
import constants.ErrorConstants;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import enums.AlbumStateEnum;
|
|
|
|
import enums.AlbumStateEnum;
|
|
|
|
|
|
|
|
import enums.SongInfoChargeEnum;
|
|
|
|
import enums.SongInfoStateEnum;
|
|
|
|
import enums.SongInfoStateEnum;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
@ -29,6 +31,7 @@ import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
@ -86,6 +89,12 @@ public class AlbumService {
|
|
|
|
result = albumPage.getContent();
|
|
|
|
result = albumPage.getContent();
|
|
|
|
for (ArtistAlbum artistAlbum : result) {
|
|
|
|
for (ArtistAlbum artistAlbum : result) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (artistAlbum.getState() != null) {
|
|
|
|
|
|
|
|
// 中文状态名
|
|
|
|
|
|
|
|
AlbumStateEnum byStatus = AlbumStateEnum.getByStatus(artistAlbum.getState());
|
|
|
|
|
|
|
|
artistAlbum.setStateStr(byStatus != null ? byStatus.getDesc() : "");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//todo 传递点赞,喜欢,评论,收益
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
long totalElements = albumPage.getTotalElements();
|
|
|
|
long totalElements = albumPage.getTotalElements();
|
|
|
@ -168,23 +177,25 @@ public class AlbumService {
|
|
|
|
public ArtistAlbum getOne(String id) {
|
|
|
|
public ArtistAlbum getOne(String id) {
|
|
|
|
ArtistAlbum artistAlbum = artistAlbumDao.findById(id).get();
|
|
|
|
ArtistAlbum artistAlbum = artistAlbumDao.findById(id).get();
|
|
|
|
if (artistAlbum == null) {
|
|
|
|
if (artistAlbum == null) {
|
|
|
|
throw new RuntimeException("专辑不存在,请刷新后重试");
|
|
|
|
// 专辑不存在,请刷新后重试
|
|
|
|
|
|
|
|
throw new RuntimeException(ErrorConstants.ALBUM_DOES_NOT_EXIST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ObjectUtils.equals(AlbumStateEnum.FORCE.getCode(), artistAlbum.getState())) {
|
|
|
|
if (ObjectUtils.equals(AlbumStateEnum.FORCE.getCode(), artistAlbum.getState())) {
|
|
|
|
throw new RuntimeException("专辑因不可抗力原因无法显示");
|
|
|
|
// 专辑因不可抗力原因无法显示
|
|
|
|
|
|
|
|
throw new RuntimeException(ErrorConstants.CAUSE_OF_FORCE_MAJEURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 整个数据库所有的tag
|
|
|
|
// 整个数据库所有的tag
|
|
|
|
List<Tag> tagAllList = tagDao.findAll();
|
|
|
|
List<Tag> tagAllList = tagDao.findAll();
|
|
|
|
Map<String, Tag> tagMap = tagAllList.stream().collect(Collectors.toMap(Tag::getId, item -> item));
|
|
|
|
Map<String, Tag> tagMap = tagAllList.stream().collect(Collectors.toMap(Tag::getId, item -> item));
|
|
|
|
log.info("------tagMap:{}",tagMap);
|
|
|
|
log.info("------tagMap:{}", tagMap);
|
|
|
|
|
|
|
|
|
|
|
|
// 处理album基础信息
|
|
|
|
// 处理album基础信息
|
|
|
|
if(StringUtils.isNotBlank(artistAlbum.getMainStyle())) {
|
|
|
|
if (StringUtils.isNotBlank(artistAlbum.getMainStyle())) {
|
|
|
|
List<Tag> style = new ArrayList<>();
|
|
|
|
List<Tag> style = new ArrayList<>();
|
|
|
|
String[] mainStyleArr = artistAlbum.getMainStyle().split(",");
|
|
|
|
String[] mainStyleArr = artistAlbum.getMainStyle().split(",");
|
|
|
|
for (String s : mainStyleArr) {
|
|
|
|
for (String s : mainStyleArr) {
|
|
|
|
if(StringUtils.isNotBlank(s)) {
|
|
|
|
if (StringUtils.isNotBlank(s)) {
|
|
|
|
style.add(tagMap.get(s));
|
|
|
|
style.add(tagMap.get(s));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -244,16 +255,15 @@ public class AlbumService {
|
|
|
|
if (user != null) {
|
|
|
|
if (user != null) {
|
|
|
|
artistAlbum.setCreateUser(user.getUserId());
|
|
|
|
artistAlbum.setCreateUser(user.getUserId());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new RuntimeException("用户校验失败,请重新登录");
|
|
|
|
// 用户校验失败,请重新登录
|
|
|
|
|
|
|
|
throw new RuntimeException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
artistAlbum.setState(AlbumStateEnum.SAVE.getCode());
|
|
|
|
artistAlbum.setState(AlbumStateEnum.SAVE.getCode());
|
|
|
|
artistAlbumDao.save(artistAlbum);
|
|
|
|
artistAlbumDao.save(artistAlbum);
|
|
|
|
|
|
|
|
|
|
|
|
// 处理歌曲对象
|
|
|
|
// 处理歌曲对象
|
|
|
|
List<AlbumSongAddDTO> songAddList = albumAddDTO.getSongAddList();
|
|
|
|
List<AlbumSongAddDTO> songAddList = albumAddDTO.getSongAddList();
|
|
|
|
if (songAddList.isEmpty()) {
|
|
|
|
if (!songAddList.isEmpty()) {
|
|
|
|
throw new RuntimeException("专辑音乐不能为空!");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
for (AlbumSongAddDTO albumSongAddDTO : songAddList) {
|
|
|
|
for (AlbumSongAddDTO albumSongAddDTO : songAddList) {
|
|
|
|
addSongForAlbum(albumSongAddDTO, user, artistAlbum);
|
|
|
|
addSongForAlbum(albumSongAddDTO, user, artistAlbum);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -274,11 +284,13 @@ public class AlbumService {
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
if (user != null) {
|
|
|
|
if (user != null) {
|
|
|
|
if (ObjectUtils.notEqual(user.getUserId(), artistAlbum.getCreateUser())) {
|
|
|
|
if (ObjectUtils.notEqual(user.getUserId(), artistAlbum.getCreateUser())) {
|
|
|
|
throw new RuntimeException("只允许本人操作!");
|
|
|
|
// 必须本人操作
|
|
|
|
|
|
|
|
throw new RuntimeException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
artistAlbum.setUpdateUser(user.getUserId());
|
|
|
|
artistAlbum.setUpdateUser(user.getUserId());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new RuntimeException("用户校验失败,请重新登录");
|
|
|
|
// 用户校验失败,请重新登
|
|
|
|
|
|
|
|
throw new RuntimeException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
artistAlbumDao.save(artistAlbum);
|
|
|
|
artistAlbumDao.save(artistAlbum);
|
|
|
@ -309,7 +321,8 @@ public class AlbumService {
|
|
|
|
|
|
|
|
|
|
|
|
ArtistAlbumSong artistAlbumSong = artistAlbumSongDao.findById(id).get();
|
|
|
|
ArtistAlbumSong artistAlbumSong = artistAlbumSongDao.findById(id).get();
|
|
|
|
if (artistAlbumSong.getId() == null) {
|
|
|
|
if (artistAlbumSong.getId() == null) {
|
|
|
|
throw new RuntimeException("该专辑不存在此歌曲");
|
|
|
|
// 该专辑不存在此歌曲
|
|
|
|
|
|
|
|
throw new RuntimeException(ErrorConstants.THE_SONG_DOES_NOT_EXIST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
checkAlbum(token, artistAlbumSong.getAlbumId());
|
|
|
|
checkAlbum(token, artistAlbumSong.getAlbumId());
|
|
|
@ -330,10 +343,12 @@ public class AlbumService {
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
if (user != null) {
|
|
|
|
if (user != null) {
|
|
|
|
if (ObjectUtils.notEqual(user.getUserId(), artistAlbum.getCreateUser())) {
|
|
|
|
if (ObjectUtils.notEqual(user.getUserId(), artistAlbum.getCreateUser())) {
|
|
|
|
throw new RuntimeException("只允许本人操作!");
|
|
|
|
// 必须本人操作
|
|
|
|
|
|
|
|
throw new RuntimeException(ErrorConstants.MUST_OPERATE_IN_PERSON);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new RuntimeException("用户校验失败,请重新登录");
|
|
|
|
// 用户校验失败,请重新登录
|
|
|
|
|
|
|
|
throw new RuntimeException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return artistAlbum;
|
|
|
|
return artistAlbum;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -352,6 +367,16 @@ public class AlbumService {
|
|
|
|
addSongForAlbum(albumSongAddDTO, user, artistAlbum);
|
|
|
|
addSongForAlbum(albumSongAddDTO, user, artistAlbum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
|
|
|
public void checkForApply(String token, String id) {
|
|
|
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
|
|
|
ArtistAlbum artistAlbum = checkAlbum(token, id);
|
|
|
|
|
|
|
|
if (ObjectUtils.notEqual(AlbumStateEnum.SAVE.getCode(), artistAlbum.getState())) {
|
|
|
|
|
|
|
|
// 必须在新建状态下申请审核
|
|
|
|
|
|
|
|
throw new RuntimeException(ErrorConstants.MUST_APPLY_FOR_REVIEW_IN_THE_NEW_STATE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 为专辑新增歌曲
|
|
|
|
* 为专辑新增歌曲
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -359,7 +384,18 @@ public class AlbumService {
|
|
|
|
* @param user 当前登录用户
|
|
|
|
* @param user 当前登录用户
|
|
|
|
* @param artistAlbum 专辑对象
|
|
|
|
* @param artistAlbum 专辑对象
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void addSongForAlbum(AlbumSongAddDTO albumSongAddDTO, UserLoginDto user, ArtistAlbum artistAlbum) {
|
|
|
|
private void addSongForAlbum(@Valid AlbumSongAddDTO albumSongAddDTO, UserLoginDto user, ArtistAlbum artistAlbum) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ObjectUtils.notEqual(SongInfoChargeEnum.CHARGE.getCode(), artistAlbum.getChargeType())) {
|
|
|
|
|
|
|
|
if(albumSongAddDTO.getPrice() == null) {
|
|
|
|
|
|
|
|
// 定价不能为空
|
|
|
|
|
|
|
|
throw new RuntimeException(ErrorConstants.PRICE_CAN_NOT_BE_EMPTY);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(albumSongAddDTO.getPrice() <= 0) {
|
|
|
|
|
|
|
|
// 定价必须大于0
|
|
|
|
|
|
|
|
throw new RuntimeException(ErrorConstants.PRICING_MUST_BE_GREATER_THAN_0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String albumName = artistAlbum.getName();
|
|
|
|
String albumName = artistAlbum.getName();
|
|
|
|
String artistName = artistAlbum.getArtistName();
|
|
|
|
String artistName = artistAlbum.getArtistName();
|
|
|
@ -374,7 +410,7 @@ public class AlbumService {
|
|
|
|
if (user != null) {
|
|
|
|
if (user != null) {
|
|
|
|
artistAlbum.setCreateUser(user.getUserId());
|
|
|
|
artistAlbum.setCreateUser(user.getUserId());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new RuntimeException("用户校验失败,请重新登录");
|
|
|
|
throw new RuntimeException(ErrorConstants.MUST_OPERATE_IN_PERSON);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
songInfoDao.save(songInfo);
|
|
|
|
songInfoDao.save(songInfo);
|
|
|
|
|
|
|
|
|
|
|
@ -389,10 +425,11 @@ public class AlbumService {
|
|
|
|
songInfoDao.updateSongLyricAndUrl(id, lyric, lyricUrl);
|
|
|
|
songInfoDao.updateSongLyricAndUrl(id, lyric, lyricUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 曲风绑定
|
|
|
|
// 曲风和语言绑定
|
|
|
|
List<String> tags = albumSongAddDTO.getTags();
|
|
|
|
List<String> tags = albumSongAddDTO.getTags();
|
|
|
|
|
|
|
|
List<String> language = albumSongAddDTO.getLanguage();
|
|
|
|
|
|
|
|
tags.addAll(language);
|
|
|
|
if (!tags.isEmpty()) {
|
|
|
|
if (!tags.isEmpty()) {
|
|
|
|
songTagDao.deleteBySongId(id);
|
|
|
|
|
|
|
|
List<SongTag> songTagList = new ArrayList<>();
|
|
|
|
List<SongTag> songTagList = new ArrayList<>();
|
|
|
|
for (String item : tags) {
|
|
|
|
for (String item : tags) {
|
|
|
|
SongTag songTag = new SongTag();
|
|
|
|
SongTag songTag = new SongTag();
|
|
|
|