|
|
@ -2,11 +2,14 @@ package com.luoo.music.service;
|
|
|
|
|
|
|
|
|
|
|
|
import api.PageResult;
|
|
|
|
import api.PageResult;
|
|
|
|
import com.luoo.music.client.UserClient;
|
|
|
|
import com.luoo.music.client.UserClient;
|
|
|
|
|
|
|
|
import com.luoo.music.config.MallConfig;
|
|
|
|
import com.luoo.music.dao.*;
|
|
|
|
import com.luoo.music.dao.*;
|
|
|
|
import com.luoo.music.dto.response.*;
|
|
|
|
import com.luoo.music.dto.response.*;
|
|
|
|
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;
|
|
|
|
|
|
|
|
import dto.MallProduct;
|
|
|
|
|
|
|
|
import dto.MallProductAttributeValue;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import enums.AlbumStateEnum;
|
|
|
|
import enums.AlbumStateEnum;
|
|
|
|
import enums.SongInfoChargeEnum;
|
|
|
|
import enums.SongInfoChargeEnum;
|
|
|
@ -16,6 +19,7 @@ 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;
|
|
|
|
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
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;
|
|
|
@ -32,6 +36,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 java.math.BigDecimal;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
@ -74,6 +79,12 @@ public class AlbumService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private UserClient userClient;
|
|
|
|
private UserClient userClient;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private MallConfig mallConfig;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
public PageResult<ArtistAlbum> getList(AlbumSearchDTO albumSearchDTO, Integer page, Integer size) {
|
|
|
|
public PageResult<ArtistAlbum> getList(AlbumSearchDTO albumSearchDTO, Integer page, Integer size) {
|
|
|
|
List<ArtistAlbum> result = new ArrayList<>();
|
|
|
|
List<ArtistAlbum> result = new ArrayList<>();
|
|
|
|
Sort sort = new Sort(Sort.Direction.DESC, "createTime");
|
|
|
|
Sort sort = new Sort(Sort.Direction.DESC, "createTime");
|
|
|
@ -254,7 +265,7 @@ public class AlbumService {
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
if (user != null) {
|
|
|
|
if (user != null) {
|
|
|
|
Integer type = artistAlbum.getType();
|
|
|
|
Integer type = artistAlbum.getType();
|
|
|
|
if(ObjectUtils.notEqual(UserTypeEnum.ARTIST_PERSON.getCode(), type) &&
|
|
|
|
if (ObjectUtils.notEqual(UserTypeEnum.ARTIST_PERSON.getCode(), type) &&
|
|
|
|
ObjectUtils.notEqual(UserTypeEnum.ARTIST_BAND.getCode(), type)
|
|
|
|
ObjectUtils.notEqual(UserTypeEnum.ARTIST_BAND.getCode(), type)
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
throw new BizException(ErrorConstants.USER_IS_NOT_ARTIST);
|
|
|
|
throw new BizException(ErrorConstants.USER_IS_NOT_ARTIST);
|
|
|
@ -262,7 +273,7 @@ public class AlbumService {
|
|
|
|
|
|
|
|
|
|
|
|
// 校验是否通过实名认证
|
|
|
|
// 校验是否通过实名认证
|
|
|
|
Boolean realNameInfo = userClient.getRealNameInfo(user.getUserId());
|
|
|
|
Boolean realNameInfo = userClient.getRealNameInfo(user.getUserId());
|
|
|
|
if(!realNameInfo) {
|
|
|
|
if (!realNameInfo) {
|
|
|
|
// 未通过实名认证
|
|
|
|
// 未通过实名认证
|
|
|
|
throw new BizException(ErrorConstants.THE_REAL_NAME_AUTHENTICATION_IS_NOT_PASSED);
|
|
|
|
throw new BizException(ErrorConstants.THE_REAL_NAME_AUTHENTICATION_IS_NOT_PASSED);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -299,7 +310,7 @@ public class AlbumService {
|
|
|
|
ArtistAlbum artistAlbum = new ArtistAlbum();
|
|
|
|
ArtistAlbum artistAlbum = new ArtistAlbum();
|
|
|
|
BeanUtils.copyProperties(albumUpdateDTO, artistAlbum);
|
|
|
|
BeanUtils.copyProperties(albumUpdateDTO, artistAlbum);
|
|
|
|
|
|
|
|
|
|
|
|
ArtistAlbum old = checkAlbum(token, artistAlbum.getId());
|
|
|
|
ArtistAlbum old = checkAlbumIsSelf(token, artistAlbum.getId());
|
|
|
|
artistAlbum.setArtistId(old.getArtistId());
|
|
|
|
artistAlbum.setArtistId(old.getArtistId());
|
|
|
|
artistAlbum.setArtistName(old.getArtistName());
|
|
|
|
artistAlbum.setArtistName(old.getArtistName());
|
|
|
|
|
|
|
|
|
|
|
@ -309,15 +320,20 @@ public class AlbumService {
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public void changeAlbumState(String token, String id, Integer state) {
|
|
|
|
public void changeAlbumState(String token, String id, Integer state) {
|
|
|
|
ArtistAlbum artistAlbum = checkAlbum(token, id);
|
|
|
|
ArtistAlbum artistAlbum = checkAlbumIsSelf(token, id);
|
|
|
|
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
switch (state) {
|
|
|
|
case -1:
|
|
|
|
case -1:
|
|
|
|
|
|
|
|
// 不可抗力强制下架
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 1:
|
|
|
|
// 申请审核操作
|
|
|
|
// 申请审核操作
|
|
|
|
checkForApply(id, artistAlbum);
|
|
|
|
checkForApply(id, artistAlbum);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
checkAlbum(artistAlbum);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
case 4:
|
|
|
|
// 上架操作
|
|
|
|
// 上架操作
|
|
|
|
shelving(artistAlbum);
|
|
|
|
shelving(artistAlbum);
|
|
|
@ -332,7 +348,7 @@ public class AlbumService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
artistAlbum.setState(state);
|
|
|
|
artistAlbum.setState(state);
|
|
|
|
if(ObjectUtils.notEqual(state, AlbumStateEnum.FORCE.getCode())) {
|
|
|
|
if (ObjectUtils.notEqual(state, AlbumStateEnum.FORCE.getCode())) {
|
|
|
|
// 强制下架不校验是否本人操作
|
|
|
|
// 强制下架不校验是否本人操作
|
|
|
|
checkUserIsSelf(token, artistAlbum);
|
|
|
|
checkUserIsSelf(token, artistAlbum);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -383,6 +399,16 @@ public class AlbumService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 审核专辑
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void checkAlbum(ArtistAlbum artistAlbum) {
|
|
|
|
|
|
|
|
if (ObjectUtils.notEqual(AlbumStateEnum.IN_APPROVE.getCode(), artistAlbum.getState())) {
|
|
|
|
|
|
|
|
// 必须在待审核状态下申请审核
|
|
|
|
|
|
|
|
throw new BizException(ErrorConstants.STATE_ERROR);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 上架操作
|
|
|
|
* 上架操作
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -393,6 +419,37 @@ public class AlbumService {
|
|
|
|
if (ObjectUtils.notEqual(AlbumStateEnum.WAIT_ARRIVE.getCode(), artistAlbum.getState())) {
|
|
|
|
if (ObjectUtils.notEqual(AlbumStateEnum.WAIT_ARRIVE.getCode(), artistAlbum.getState())) {
|
|
|
|
throw new BizException(ErrorConstants.STATE_ERROR);
|
|
|
|
throw new BizException(ErrorConstants.STATE_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 拼接MALL模块需要的商品对象和参数对象
|
|
|
|
|
|
|
|
List<SongInfo> songInfoList = songInfoDao.findByAlbumId(artistAlbum.getId());
|
|
|
|
|
|
|
|
for (SongInfo songInfo : songInfoList) {
|
|
|
|
|
|
|
|
MallProduct mallProduct = MallProduct.builder()
|
|
|
|
|
|
|
|
.brandId(mallConfig.getBrandId())
|
|
|
|
|
|
|
|
.brandName(mallConfig.getBrandName())
|
|
|
|
|
|
|
|
.productCategoryName(mallConfig.getProductCategoryName())
|
|
|
|
|
|
|
|
.productCategoryId(mallConfig.getProductCategoryId())
|
|
|
|
|
|
|
|
.productAttributeCategoryId(mallConfig.getProductAttributeCategoryId())
|
|
|
|
|
|
|
|
.name(songInfo.getName())
|
|
|
|
|
|
|
|
.pic(songInfo.getImage())
|
|
|
|
|
|
|
|
.subTitle(songInfo.getName())
|
|
|
|
|
|
|
|
.price(songInfo.getPrice())
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
List<MallProductAttributeValue> attributeValueList = new ArrayList<>();
|
|
|
|
|
|
|
|
attributeValueList.add(MallProductAttributeValue.builder().productAttributeId(mallConfig.getAlbumId()).value(artistAlbum.getId()).build());
|
|
|
|
|
|
|
|
attributeValueList.add(MallProductAttributeValue.builder().productAttributeId(mallConfig.getAlbumName()).value(artistAlbum.getName()).build());
|
|
|
|
|
|
|
|
attributeValueList.add(MallProductAttributeValue.builder().productAttributeId(mallConfig.getSongId()).value(songInfo.getId()).build());
|
|
|
|
|
|
|
|
attributeValueList.add(MallProductAttributeValue.builder().productAttributeId(mallConfig.getArtistId()).value(artistAlbum.getArtistId()).build());
|
|
|
|
|
|
|
|
attributeValueList.add(MallProductAttributeValue.builder().productAttributeId(mallConfig.getArtistName()).value(artistAlbum.getArtistName()).build());
|
|
|
|
|
|
|
|
Map<String, Object> mallMqMap = new HashMap<>();
|
|
|
|
|
|
|
|
mallMqMap.put("songId", songInfo.getId());
|
|
|
|
|
|
|
|
mallMqMap.put("mallProduct", mallProduct);
|
|
|
|
|
|
|
|
mallMqMap.put("attributeValueList", attributeValueList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rabbitTemplate.convertAndSend("luoo_mall_product_add", mallMqMap);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 上架的同时,发起MQ,MALL接收到后会调用商品新增的接口
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -428,7 +485,7 @@ public class AlbumService {
|
|
|
|
throw new BizException(ErrorConstants.THE_SONG_DOES_NOT_EXIST);
|
|
|
|
throw new BizException(ErrorConstants.THE_SONG_DOES_NOT_EXIST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
checkAlbum(token, artistAlbumSong.getAlbumId());
|
|
|
|
checkAlbumIsSelf(token, artistAlbumSong.getAlbumId());
|
|
|
|
|
|
|
|
|
|
|
|
artistAlbumSongDao.delete(artistAlbumSong);
|
|
|
|
artistAlbumSongDao.delete(artistAlbumSong);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -440,7 +497,7 @@ public class AlbumService {
|
|
|
|
* @param id 专辑id
|
|
|
|
* @param id 专辑id
|
|
|
|
* @return 如果是本人操作,返回该专辑对象
|
|
|
|
* @return 如果是本人操作,返回该专辑对象
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private ArtistAlbum checkAlbum(String token, String id) {
|
|
|
|
private ArtistAlbum checkAlbumIsSelf(String token, String id) {
|
|
|
|
ArtistAlbum artistAlbum = artistAlbumDao.findById(id).get();
|
|
|
|
ArtistAlbum artistAlbum = artistAlbumDao.findById(id).get();
|
|
|
|
|
|
|
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
@ -466,7 +523,7 @@ public class AlbumService {
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public void addNewSong(String token, String id, AlbumSongAddDTO albumSongAddDTO) {
|
|
|
|
public void addNewSong(String token, String id, AlbumSongAddDTO albumSongAddDTO) {
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
ArtistAlbum artistAlbum = checkAlbum(token, id);
|
|
|
|
ArtistAlbum artistAlbum = checkAlbumIsSelf(token, id);
|
|
|
|
addSongForAlbum(albumSongAddDTO, user, artistAlbum);
|
|
|
|
addSongForAlbum(albumSongAddDTO, user, artistAlbum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -481,7 +538,7 @@ public class AlbumService {
|
|
|
|
// 定价不能为空
|
|
|
|
// 定价不能为空
|
|
|
|
throw new BizException(ErrorConstants.PRICE_CAN_NOT_BE_EMPTY);
|
|
|
|
throw new BizException(ErrorConstants.PRICE_CAN_NOT_BE_EMPTY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (albumSongRequireDTO.getPrice() <= 0) {
|
|
|
|
if (albumSongRequireDTO.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
// 定价必须大于0
|
|
|
|
// 定价必须大于0
|
|
|
|
throw new BizException(ErrorConstants.PRICING_MUST_BE_GREATER_THAN_0);
|
|
|
|
throw new BizException(ErrorConstants.PRICING_MUST_BE_GREATER_THAN_0);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -502,7 +559,7 @@ public class AlbumService {
|
|
|
|
// 定价不能为空
|
|
|
|
// 定价不能为空
|
|
|
|
throw new BizException(ErrorConstants.PRICE_CAN_NOT_BE_EMPTY);
|
|
|
|
throw new BizException(ErrorConstants.PRICE_CAN_NOT_BE_EMPTY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (albumSongAddDTO.getPrice() <= 0) {
|
|
|
|
if (albumSongAddDTO.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
// 定价必须大于0
|
|
|
|
// 定价必须大于0
|
|
|
|
throw new BizException(ErrorConstants.PRICING_MUST_BE_GREATER_THAN_0);
|
|
|
|
throw new BizException(ErrorConstants.PRICING_MUST_BE_GREATER_THAN_0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|