|
|
@ -2,10 +2,7 @@ package com.luoo.music.service;
|
|
|
|
|
|
|
|
|
|
|
|
import api.PageResult;
|
|
|
|
import api.PageResult;
|
|
|
|
import com.luoo.music.dao.*;
|
|
|
|
import com.luoo.music.dao.*;
|
|
|
|
import com.luoo.music.dto.response.AlbumAddDTO;
|
|
|
|
import com.luoo.music.dto.response.*;
|
|
|
|
import com.luoo.music.dto.response.AlbumSearchDTO;
|
|
|
|
|
|
|
|
import com.luoo.music.dto.response.AlbumSongAddDTO;
|
|
|
|
|
|
|
|
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 constants.ErrorConstants;
|
|
|
@ -13,6 +10,7 @@ import dto.UserLoginDto;
|
|
|
|
import enums.AlbumStateEnum;
|
|
|
|
import enums.AlbumStateEnum;
|
|
|
|
import enums.SongInfoChargeEnum;
|
|
|
|
import enums.SongInfoChargeEnum;
|
|
|
|
import enums.SongInfoStateEnum;
|
|
|
|
import enums.SongInfoStateEnum;
|
|
|
|
|
|
|
|
import exception.BizException;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
@ -24,6 +22,7 @@ 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.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import util.IdWorker;
|
|
|
|
import util.IdWorker;
|
|
|
|
import util.JwtUtil;
|
|
|
|
import util.JwtUtil;
|
|
|
|
|
|
|
|
|
|
|
@ -31,7 +30,6 @@ 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;
|
|
|
@ -178,11 +176,11 @@ public class AlbumService {
|
|
|
|
ArtistAlbum artistAlbum = artistAlbumDao.findById(id).get();
|
|
|
|
ArtistAlbum artistAlbum = artistAlbumDao.findById(id).get();
|
|
|
|
if (artistAlbum == null) {
|
|
|
|
if (artistAlbum == null) {
|
|
|
|
// 专辑不存在,请刷新后重试
|
|
|
|
// 专辑不存在,请刷新后重试
|
|
|
|
throw new RuntimeException(ErrorConstants.ALBUM_DOES_NOT_EXIST);
|
|
|
|
throw new BizException(ErrorConstants.ALBUM_DOES_NOT_EXIST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ObjectUtils.equals(AlbumStateEnum.FORCE.getCode(), artistAlbum.getState())) {
|
|
|
|
if (ObjectUtils.equals(AlbumStateEnum.FORCE.getCode(), artistAlbum.getState())) {
|
|
|
|
// 专辑因不可抗力原因无法显示
|
|
|
|
// 专辑因不可抗力原因无法显示
|
|
|
|
throw new RuntimeException(ErrorConstants.CAUSE_OF_FORCE_MAJEURE);
|
|
|
|
throw new BizException(ErrorConstants.CAUSE_OF_FORCE_MAJEURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 整个数据库所有的tag
|
|
|
|
// 整个数据库所有的tag
|
|
|
@ -256,7 +254,7 @@ public class AlbumService {
|
|
|
|
artistAlbum.setCreateUser(user.getUserId());
|
|
|
|
artistAlbum.setCreateUser(user.getUserId());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// 用户校验失败,请重新登录
|
|
|
|
// 用户校验失败,请重新登录
|
|
|
|
throw new RuntimeException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
artistAlbum.setState(AlbumStateEnum.SAVE.getCode());
|
|
|
|
artistAlbum.setState(AlbumStateEnum.SAVE.getCode());
|
|
|
|
artistAlbumDao.save(artistAlbum);
|
|
|
|
artistAlbumDao.save(artistAlbum);
|
|
|
@ -285,12 +283,12 @@ public class AlbumService {
|
|
|
|
if (user != null) {
|
|
|
|
if (user != null) {
|
|
|
|
if (ObjectUtils.notEqual(user.getUserId(), artistAlbum.getCreateUser())) {
|
|
|
|
if (ObjectUtils.notEqual(user.getUserId(), artistAlbum.getCreateUser())) {
|
|
|
|
// 必须本人操作
|
|
|
|
// 必须本人操作
|
|
|
|
throw new RuntimeException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
artistAlbum.setUpdateUser(user.getUserId());
|
|
|
|
artistAlbum.setUpdateUser(user.getUserId());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// 用户校验失败,请重新登
|
|
|
|
// 用户校验失败,请重新登
|
|
|
|
throw new RuntimeException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
artistAlbumDao.save(artistAlbum);
|
|
|
|
artistAlbumDao.save(artistAlbum);
|
|
|
@ -322,7 +320,7 @@ 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(ErrorConstants.THE_SONG_DOES_NOT_EXIST);
|
|
|
|
throw new BizException(ErrorConstants.THE_SONG_DOES_NOT_EXIST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
checkAlbum(token, artistAlbumSong.getAlbumId());
|
|
|
|
checkAlbum(token, artistAlbumSong.getAlbumId());
|
|
|
@ -344,11 +342,11 @@ public class AlbumService {
|
|
|
|
if (user != null) {
|
|
|
|
if (user != null) {
|
|
|
|
if (ObjectUtils.notEqual(user.getUserId(), artistAlbum.getCreateUser())) {
|
|
|
|
if (ObjectUtils.notEqual(user.getUserId(), artistAlbum.getCreateUser())) {
|
|
|
|
// 必须本人操作
|
|
|
|
// 必须本人操作
|
|
|
|
throw new RuntimeException(ErrorConstants.MUST_OPERATE_IN_PERSON);
|
|
|
|
throw new BizException(ErrorConstants.MUST_OPERATE_IN_PERSON);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// 用户校验失败,请重新登录
|
|
|
|
// 用户校验失败,请重新登录
|
|
|
|
throw new RuntimeException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return artistAlbum;
|
|
|
|
return artistAlbum;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -367,13 +365,49 @@ public class AlbumService {
|
|
|
|
addSongForAlbum(albumSongAddDTO, user, artistAlbum);
|
|
|
|
addSongForAlbum(albumSongAddDTO, user, artistAlbum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 提交审核
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param token token
|
|
|
|
|
|
|
|
* @param id 专辑id
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public void checkForApply(String token, String id) {
|
|
|
|
public void checkForApply(String token, String id) {
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
|
|
|
ArtistAlbum artistAlbum = checkAlbum(token, id);
|
|
|
|
ArtistAlbum artistAlbum = checkAlbum(token, id);
|
|
|
|
if (ObjectUtils.notEqual(AlbumStateEnum.SAVE.getCode(), artistAlbum.getState())) {
|
|
|
|
if (ObjectUtils.notEqual(AlbumStateEnum.SAVE.getCode(), artistAlbum.getState())) {
|
|
|
|
// 必须在新建状态下申请审核
|
|
|
|
// 必须在新建状态下申请审核
|
|
|
|
throw new RuntimeException(ErrorConstants.MUST_APPLY_FOR_REVIEW_IN_THE_NEW_STATE);
|
|
|
|
throw new BizException(ErrorConstants.MUST_APPLY_FOR_REVIEW_IN_THE_NEW_STATE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ArtistAlbum album = getOne(id);
|
|
|
|
|
|
|
|
List<SongInfo> songList = album.getSongList();
|
|
|
|
|
|
|
|
if(songList.isEmpty()) {
|
|
|
|
|
|
|
|
throw new BizException(ErrorConstants.ALBUM_SONG_LIST_IS_EMPTY);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (SongInfo songInfo : songList) {
|
|
|
|
|
|
|
|
AlbumSongRequireDTO albumSongRequireDTO = new AlbumSongRequireDTO();
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(songInfo, albumSongRequireDTO);
|
|
|
|
|
|
|
|
checkSong(albumSongRequireDTO);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
artistAlbum.setState(AlbumStateEnum.IN_APPROVE.getCode());
|
|
|
|
|
|
|
|
artistAlbumDao.save(artistAlbum);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 必填校验
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param albumSongRequireDTO 校验对象
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void checkSong(@Validated AlbumSongRequireDTO albumSongRequireDTO) {
|
|
|
|
|
|
|
|
if(ObjectUtils.notEqual(SongInfoChargeEnum.CHARGE.getCode(), albumSongRequireDTO.getCharge())) {
|
|
|
|
|
|
|
|
if(albumSongRequireDTO.getPrice() == null) {
|
|
|
|
|
|
|
|
// 定价不能为空
|
|
|
|
|
|
|
|
throw new BizException(ErrorConstants.PRICE_CAN_NOT_BE_EMPTY);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(albumSongRequireDTO.getPrice() <= 0) {
|
|
|
|
|
|
|
|
// 定价必须大于0
|
|
|
|
|
|
|
|
throw new BizException(ErrorConstants.PRICING_MUST_BE_GREATER_THAN_0);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -384,16 +418,16 @@ public class AlbumService {
|
|
|
|
* @param user 当前登录用户
|
|
|
|
* @param user 当前登录用户
|
|
|
|
* @param artistAlbum 专辑对象
|
|
|
|
* @param artistAlbum 专辑对象
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void addSongForAlbum(@Valid AlbumSongAddDTO albumSongAddDTO, UserLoginDto user, ArtistAlbum artistAlbum) {
|
|
|
|
private void addSongForAlbum(@Validated AlbumSongAddDTO albumSongAddDTO, UserLoginDto user, ArtistAlbum artistAlbum) {
|
|
|
|
|
|
|
|
|
|
|
|
if(ObjectUtils.notEqual(SongInfoChargeEnum.CHARGE.getCode(), artistAlbum.getChargeType())) {
|
|
|
|
if(ObjectUtils.notEqual(SongInfoChargeEnum.CHARGE.getCode(), albumSongAddDTO.getCharge())) {
|
|
|
|
if(albumSongAddDTO.getPrice() == null) {
|
|
|
|
if(albumSongAddDTO.getPrice() == null) {
|
|
|
|
// 定价不能为空
|
|
|
|
// 定价不能为空
|
|
|
|
throw new RuntimeException(ErrorConstants.PRICE_CAN_NOT_BE_EMPTY);
|
|
|
|
throw new BizException(ErrorConstants.PRICE_CAN_NOT_BE_EMPTY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(albumSongAddDTO.getPrice() <= 0) {
|
|
|
|
if(albumSongAddDTO.getPrice() <= 0) {
|
|
|
|
// 定价必须大于0
|
|
|
|
// 定价必须大于0
|
|
|
|
throw new RuntimeException(ErrorConstants.PRICING_MUST_BE_GREATER_THAN_0);
|
|
|
|
throw new BizException(ErrorConstants.PRICING_MUST_BE_GREATER_THAN_0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -410,7 +444,7 @@ public class AlbumService {
|
|
|
|
if (user != null) {
|
|
|
|
if (user != null) {
|
|
|
|
artistAlbum.setCreateUser(user.getUserId());
|
|
|
|
artistAlbum.setCreateUser(user.getUserId());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new RuntimeException(ErrorConstants.MUST_OPERATE_IN_PERSON);
|
|
|
|
throw new BizException(ErrorConstants.MUST_OPERATE_IN_PERSON);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
songInfoDao.save(songInfo);
|
|
|
|
songInfoDao.save(songInfo);
|
|
|
|
|
|
|
|
|
|
|
|