|
@@ -1,16 +1,31 @@
|
|
|
package com.yonge.cooleshow.biz.dal.service.impl;
|
|
|
|
|
|
+import java.text.MessageFormat;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.yonge.cooleshow.biz.dal.dao.AlbumMusicRelateDao;
|
|
|
+import com.yonge.cooleshow.biz.dal.dao.MusicSheetDao;
|
|
|
+import com.yonge.cooleshow.biz.dal.dao.MusicSheetPurchaseRecordDao;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.MusicSheetPurchaseRecord;
|
|
|
+import com.yonge.cooleshow.biz.dal.enums.ChargeTypeEnum;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
|
|
|
+import com.yonge.cooleshow.biz.dal.enums.SourceTypeEnum;
|
|
|
+import com.yonge.cooleshow.biz.dal.enums.album.PurchaseRecordTypeEnum;
|
|
|
+import com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper;
|
|
@@ -62,6 +77,13 @@ public class MusicAlbumServiceImpl extends ServiceImpl<MusicAlbumDao,MusicAlbum>
|
|
|
|
|
|
@Autowired
|
|
|
private AlbumFavoriteService albumFavoriteService;
|
|
|
+ @Autowired
|
|
|
+ private MusicSheetPurchaseRecordDao musicSheetPurchaseRecordMapper;
|
|
|
+ @Autowired
|
|
|
+ private MusicSheetDao musicSheetMapper;
|
|
|
+ @Autowired
|
|
|
+ private AlbumMusicRelateDao albumMusicRelateMapper;
|
|
|
+
|
|
|
|
|
|
public MusicAlbumDao getDao() {
|
|
|
return musicAlbumDao;
|
|
@@ -101,13 +123,38 @@ public class MusicAlbumServiceImpl extends ServiceImpl<MusicAlbumDao,MusicAlbum>
|
|
|
albumDetailVo.setAlbumCoverUrl(musicAlbum.getAlbumCoverUrl());
|
|
|
albumDetailVo.setAlbumStatue(musicAlbum.getAlbumStatus());
|
|
|
albumDetailVo.setAlbumFavoriteCount(musicAlbum.getAlbumFavoriteCount());
|
|
|
+ albumDetailVo.setAlbumPrice(musicAlbum.getAlbumPrice());
|
|
|
+ albumDetailVo.setPaymentType(musicAlbum.getPaymentType());
|
|
|
albumDetailVo.setMusicTagNames(musicTagService.getMusicTagNames(StringUtil.toLongList(musicAlbum.getAlbumTag())));
|
|
|
|
|
|
+ // 新增专辑曲目查询条件
|
|
|
if (query.getType() != null && query.getType() == 1) {
|
|
|
query.setSubjectIds(musicAlbum.getSubjectId());
|
|
|
+
|
|
|
+ // 判断专辑收费类型;非免费类型,只能添加平台曲目
|
|
|
+ /*if (!ChargeTypeEnum.FREE.match(musicAlbum.getPaymentType())) {
|
|
|
+
|
|
|
+ // 曲目来源
|
|
|
+ query.setSourceType(SourceTypeEnum.PLATFORM);
|
|
|
+ // 曲目收费类型
|
|
|
+ if (musicAlbum.getPaymentType().contains(",")) {
|
|
|
+ // 多种付费方式
|
|
|
+ query.setPaymentTypes(Lists.newArrayList(musicAlbum.getPaymentType(), ChargeTypeEnum.FREE.getCode()));
|
|
|
+ } else {
|
|
|
+ // 单一付费方式
|
|
|
+ query.setChargeType(ChargeTypeEnum.valueOf(musicAlbum.getPaymentType()));
|
|
|
+ }
|
|
|
+
|
|
|
+ }*/
|
|
|
}
|
|
|
|
|
|
IPage<MusicSheetVo> musicSheetVoIPage = musicSheetService.selectAlbumDetailPage(page,query);
|
|
|
+
|
|
|
+ // 专辑曲目付费方式
|
|
|
+ List<String> paymentTypes = musicSheetVoIPage.getRecords().stream()
|
|
|
+ .flatMap(x -> Arrays.stream(x.getPaymentType().split(","))).distinct().collect(Collectors.toList());
|
|
|
+ albumDetailVo.setMusicPaymentTypes(paymentTypes);
|
|
|
+
|
|
|
albumDetailVo.setMusicSheetList(PageUtil.pageInfo(musicSheetVoIPage));
|
|
|
|
|
|
albumDetailVo.setMusicSheetCount((int) musicSheetVoIPage.getTotal());
|
|
@@ -121,6 +168,20 @@ public class MusicAlbumServiceImpl extends ServiceImpl<MusicAlbumDao,MusicAlbum>
|
|
|
if (musicAlbum == null) {
|
|
|
throw new BizException("未找到专辑信息");
|
|
|
}
|
|
|
+
|
|
|
+ // 付费专辑,需要校验是否已存在购买记录
|
|
|
+ /*if (!ChargeTypeEnum.VIP.match(musicAlbum.getPaymentType())) {
|
|
|
+
|
|
|
+ // 统计付费专辑的购买数量
|
|
|
+ Integer count = musicSheetPurchaseRecordMapper.selectCount(Wrappers.<MusicSheetPurchaseRecord>lambdaQuery()
|
|
|
+ .eq(MusicSheetPurchaseRecord::getMusicSheetId, albumId)
|
|
|
+ .eq(MusicSheetPurchaseRecord::getPurchaseType, PurchaseRecordTypeEnum.ALBUM)
|
|
|
+ );
|
|
|
+ if (Optional.ofNullable(count).orElse(0) > 0) {
|
|
|
+ throw new BizException("当前专辑已有购买记录");
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+
|
|
|
List<Long> musicSheetIdList = StringUtil.toLongList(musicSheetIds);
|
|
|
return albumMusicRelateService.delMusicSheet(albumId,musicSheetIdList);
|
|
|
}
|
|
@@ -132,6 +193,31 @@ public class MusicAlbumServiceImpl extends ServiceImpl<MusicAlbumDao,MusicAlbum>
|
|
|
if (musicAlbum == null) {
|
|
|
throw new BizException("未找到专辑信息");
|
|
|
}
|
|
|
+
|
|
|
+ // 付费专辑最多只能添加两首免费曲目
|
|
|
+ if (!ChargeTypeEnum.FREE.match(musicAlbum.getPaymentType())) {
|
|
|
+
|
|
|
+ // 新添加曲目统计
|
|
|
+ long freeNum = 0;
|
|
|
+ List<Long> musicIds = albumMusicList.stream()
|
|
|
+ .map(MusicAlbumSheetDto.AlbumMusic::getMusicSheetId).distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(musicIds)) {
|
|
|
+
|
|
|
+ freeNum = musicSheetMapper.selectBatchIds(musicIds).stream()
|
|
|
+ .filter(x -> ChargeTypeEnum.FREE.match(x.getPaymentType()))
|
|
|
+ .count();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 已添加曲目统计
|
|
|
+ Map<Long, Integer> collect = getBaseMapper().selectAlbumMusicSheetStatInfo(albumId, ChargeTypeEnum.FREE).stream()
|
|
|
+ .collect(Collectors.toMap(StatGroupWrapper::getId, StatGroupWrapper::getTotal, (o, n) -> n));
|
|
|
+
|
|
|
+ if ((collect.getOrDefault(albumId, 0) + freeNum) > 2) {
|
|
|
+ throw new BizException("专辑免费曲目最多2首");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return albumMusicRelateService.addMusicSheet(albumId,albumMusicList,userId);
|
|
|
}
|
|
|
|
|
@@ -157,6 +243,26 @@ public class MusicAlbumServiceImpl extends ServiceImpl<MusicAlbumDao,MusicAlbum>
|
|
|
if (musicAlbum.getAuditVersion() == null) {
|
|
|
musicAlbum.setAuditVersion(YesOrNoEnum.NO);
|
|
|
}
|
|
|
+
|
|
|
+ // 非付费类型,已添加曲目或者已购买,不允许修改付费方式
|
|
|
+ MusicAlbum album = getById(musicAlbum.getId());
|
|
|
+ if (Objects.isNull(album)) {
|
|
|
+ throw new BizException("无效的专辑ID");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 专辑从免费修改为付费方式,需要判断当前免费单曲数量
|
|
|
+ if (Objects.nonNull(musicAlbum.getPaymentType())
|
|
|
+ && ChargeTypeEnum.FREE.match(album.getPaymentType())
|
|
|
+ && !album.getPaymentType().equals(musicAlbum.getPaymentType())) {
|
|
|
+
|
|
|
+ Map<Long, Integer> collect = getBaseMapper().selectAlbumMusicSheetStatInfo(album.getId(), ChargeTypeEnum.FREE).stream()
|
|
|
+ .collect(Collectors.toMap(StatGroupWrapper::getId, StatGroupWrapper::getTotal, (o, n) -> n));
|
|
|
+
|
|
|
+ if (collect.getOrDefault(album.getId(), 0) > 2) {
|
|
|
+ throw new BizException(MessageFormat.format("当前专辑免费单曲数为 {0}, 已超过免费数量", collect.get(album.getId())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return this.updateById(musicAlbum);
|
|
|
}
|
|
|
|