|
|
|
@ -2,11 +2,14 @@ package com.luoo.music.service;
|
|
|
|
|
|
|
|
|
|
import api.PageResult;
|
|
|
|
|
import com.luoo.music.client.UserClient;
|
|
|
|
|
import com.luoo.music.config.MallConfig;
|
|
|
|
|
import com.luoo.music.dao.*;
|
|
|
|
|
import com.luoo.music.dto.response.*;
|
|
|
|
|
import com.luoo.music.pojo.*;
|
|
|
|
|
import com.luoo.music.util.Constants;
|
|
|
|
|
import constants.ErrorConstants;
|
|
|
|
|
import dto.MallProduct;
|
|
|
|
|
import dto.MallProductAttributeValue;
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
|
import enums.AlbumStateEnum;
|
|
|
|
|
import enums.SongInfoChargeEnum;
|
|
|
|
@ -16,6 +19,7 @@ import exception.BizException;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
@ -32,6 +36,7 @@ import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
@ -74,6 +79,12 @@ public class AlbumService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserClient userClient;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MallConfig mallConfig;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
|
|
|
|
public PageResult<ArtistAlbum> getList(AlbumSearchDTO albumSearchDTO, Integer page, Integer size) {
|
|
|
|
|
List<ArtistAlbum> result = new ArrayList<>();
|
|
|
|
|
Sort sort = new Sort(Sort.Direction.DESC, "createTime");
|
|
|
|
@ -254,7 +265,7 @@ public class AlbumService {
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
if (user != null) {
|
|
|
|
|
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)
|
|
|
|
|
) {
|
|
|
|
|
throw new BizException(ErrorConstants.USER_IS_NOT_ARTIST);
|
|
|
|
@ -262,7 +273,7 @@ public class AlbumService {
|
|
|
|
|
|
|
|
|
|
// 校验是否通过实名认证
|
|
|
|
|
Boolean realNameInfo = userClient.getRealNameInfo(user.getUserId());
|
|
|
|
|
if(!realNameInfo) {
|
|
|
|
|
if (!realNameInfo) {
|
|
|
|
|
// 未通过实名认证
|
|
|
|
|
throw new BizException(ErrorConstants.THE_REAL_NAME_AUTHENTICATION_IS_NOT_PASSED);
|
|
|
|
|
}
|
|
|
|
@ -299,7 +310,7 @@ public class AlbumService {
|
|
|
|
|
ArtistAlbum artistAlbum = new ArtistAlbum();
|
|
|
|
|
BeanUtils.copyProperties(albumUpdateDTO, artistAlbum);
|
|
|
|
|
|
|
|
|
|
ArtistAlbum old = checkAlbum(token, artistAlbum.getId());
|
|
|
|
|
ArtistAlbum old = checkAlbumIsSelf(token, artistAlbum.getId());
|
|
|
|
|
artistAlbum.setArtistId(old.getArtistId());
|
|
|
|
|
artistAlbum.setArtistName(old.getArtistName());
|
|
|
|
|
|
|
|
|
@ -309,15 +320,20 @@ public class AlbumService {
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void changeAlbumState(String token, String id, Integer state) {
|
|
|
|
|
ArtistAlbum artistAlbum = checkAlbum(token, id);
|
|
|
|
|
ArtistAlbum artistAlbum = checkAlbumIsSelf(token, id);
|
|
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
|
case -1:
|
|
|
|
|
// 不可抗力强制下架
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
// 申请审核操作
|
|
|
|
|
checkForApply(id, artistAlbum);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
case 3:
|
|
|
|
|
checkAlbum(artistAlbum);
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
// 上架操作
|
|
|
|
|
shelving(artistAlbum);
|
|
|
|
@ -332,7 +348,7 @@ public class AlbumService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
artistAlbum.setState(state);
|
|
|
|
|
if(ObjectUtils.notEqual(state, AlbumStateEnum.FORCE.getCode())) {
|
|
|
|
|
if (ObjectUtils.notEqual(state, AlbumStateEnum.FORCE.getCode())) {
|
|
|
|
|
// 强制下架不校验是否本人操作
|
|
|
|
|
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())) {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkAlbum(token, artistAlbumSong.getAlbumId());
|
|
|
|
|
checkAlbumIsSelf(token, artistAlbumSong.getAlbumId());
|
|
|
|
|
|
|
|
|
|
artistAlbumSongDao.delete(artistAlbumSong);
|
|
|
|
|
}
|
|
|
|
@ -440,7 +497,7 @@ public class AlbumService {
|
|
|
|
|
* @param id 专辑id
|
|
|
|
|
* @return 如果是本人操作,返回该专辑对象
|
|
|
|
|
*/
|
|
|
|
|
private ArtistAlbum checkAlbum(String token, String id) {
|
|
|
|
|
private ArtistAlbum checkAlbumIsSelf(String token, String id) {
|
|
|
|
|
ArtistAlbum artistAlbum = artistAlbumDao.findById(id).get();
|
|
|
|
|
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
@ -466,7 +523,7 @@ public class AlbumService {
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void addNewSong(String token, String id, AlbumSongAddDTO albumSongAddDTO) {
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
ArtistAlbum artistAlbum = checkAlbum(token, id);
|
|
|
|
|
ArtistAlbum artistAlbum = checkAlbumIsSelf(token, id);
|
|
|
|
|
addSongForAlbum(albumSongAddDTO, user, artistAlbum);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -481,7 +538,7 @@ public class AlbumService {
|
|
|
|
|
// 定价不能为空
|
|
|
|
|
throw new BizException(ErrorConstants.PRICE_CAN_NOT_BE_EMPTY);
|
|
|
|
|
}
|
|
|
|
|
if (albumSongRequireDTO.getPrice() <= 0) {
|
|
|
|
|
if (albumSongRequireDTO.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
// 定价必须大于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);
|
|
|
|
|
}
|
|
|
|
|
if (albumSongAddDTO.getPrice() <= 0) {
|
|
|
|
|
if (albumSongAddDTO.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
// 定价必须大于0
|
|
|
|
|
throw new BizException(ErrorConstants.PRICING_MUST_BE_GREATER_THAN_0);
|
|
|
|
|
}
|
|
|
|
|